Skip to content

Commit

Permalink
Merge pull request #938 from ish-hcc/master
Browse files Browse the repository at this point in the history
[+Region/Zone] Implement IBM's RegionZoneHandler
  • Loading branch information
powerkimhub authored Sep 27, 2023
2 parents c47e451 + 4c9126a commit 7ce64cb
Show file tree
Hide file tree
Showing 4 changed files with 508 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (IbmCloudDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
drvCapabilityInfo.VMHandler = true
drvCapabilityInfo.VMSpecHandler = true
drvCapabilityInfo.NLBHandler = true
drvCapabilityInfo.RegionZoneHandler = true

return drvCapabilityInfo
}
Expand Down Expand Up @@ -79,12 +80,18 @@ func (driver *IbmCloudDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (
},
URL: endPoint,
})
if err != nil {
return nil, err
}
vpcService0230, err := vpc0230.NewVpcV1(&vpc0230.VpcV1Options{
Authenticator: &core.IamAuthenticator{
ApiKey: connectionInfo.CredentialInfo.ApiKey,
},
URL: endPoint,
})
if err != nil {
return nil, err
}
clusterService, err := kubernetesserviceapiv1.NewKubernetesServiceApiV1(&kubernetesserviceapiv1.KubernetesServiceApiV1Options{
Authenticator: &core.IamAuthenticator{
ApiKey: connectionInfo.CredentialInfo.ApiKey,
Expand All @@ -98,6 +105,9 @@ func (driver *IbmCloudDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (
ApiKey: connectionInfo.CredentialInfo.ApiKey,
},
})
if err != nil {
return nil, err
}

iConn := connect.IbmCloudConnection{
CredentialInfo: connectionInfo.CredentialInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package connect
import (
"context"
"errors"

"github.com/IBM/platform-services-go-sdk/globaltaggingv1"
vpcv0230 "github.com/IBM/vpc-go-sdk/0.23.0/vpcv1"
"github.com/IBM/vpc-go-sdk/vpcv1"
Expand Down Expand Up @@ -32,11 +31,6 @@ type IbmCloudConnection struct {
Ctx context.Context
}

// CreateRegionZoneHandler implements connect.CloudConnection.
func (*IbmCloudConnection) CreateRegionZoneHandler() (irs.RegionZoneHandler, error) {
return nil, errors.New("Driver: not implemented")
}

func (cloudConn *IbmCloudConnection) CreateImageHandler() (irs.ImageHandler, error) {
cblogger.Info("Ibm Cloud Driver: called CreateImageHandler()!")
imageHandler := ibmrs.IbmImageHandler{
Expand Down Expand Up @@ -159,3 +153,13 @@ func (cloudConn *IbmCloudConnection) CreateMyImageHandler() (irs.MyImageHandler,
func (cloudConn *IbmCloudConnection) CreateAnyCallHandler() (irs.AnyCallHandler, error) {
return nil, errors.New("Ibm Driver: not implemented")
}

func (cloudConn *IbmCloudConnection) CreateRegionZoneHandler() (irs.RegionZoneHandler, error) {
cblogger.Info("Ibm Cloud Driver: called CreateRegionZoneHandler()!")
regionZoneHandler := ibmrs.IbmRegionZoneHandler{
Region: cloudConn.Region,
VpcService: cloudConn.VpcService,
Ctx: cloudConn.Ctx,
}
return &regionZoneHandler, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ func init() {
func readConfigFile() Config {
// Set Environment Value of Project Root Path
rootPath := os.Getenv("CBSPIDER_ROOT")
fmt.Println(rootPath)
data, err := ioutil.ReadFile(rootPath + "/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc/main/conf/config.yaml")
if err != nil {
cblogger.Error(err)
Expand All @@ -252,8 +251,9 @@ func showTestHandlerInfo() {
cblogger.Info("7. NLBHandler")
cblogger.Info("8. DiskHandler")
cblogger.Info("9. MyImageHandler")
cblogger.Info("10. ClusterHandler")
cblogger.Info("11. Exit")
cblogger.Info("10. RegionZoneHandler")
cblogger.Info("11. ClusterHandler")
cblogger.Info("12. Exit")
cblogger.Info("==========================================================")
}

Expand Down Expand Up @@ -298,6 +298,8 @@ func getResourceHandler(resourceType string, config Config) (interface{}, error)
resourceHandler, err = ibmCon.CreateDiskHandler()
case "myimage":
resourceHandler, err = ibmCon.CreateMyImageHandler()
case "regionzone":
resourceHandler, err = ibmCon.CreateRegionZoneHandler()
case "cluster":
resourceHandler, err = ibmCon.CreateClusterHandler()
}
Expand Down Expand Up @@ -1359,6 +1361,82 @@ Loop:
}
}

func testRegionZoneHandlerListPrint() {
cblogger.Info("Test RegionZoneHandler")
cblogger.Info("0. Print Menu")
cblogger.Info("1. ListRegionZone()")
cblogger.Info("2. GetRegionZone()")
cblogger.Info("3. ListOrgRegion()")
cblogger.Info("4. ListOrgZone()")
cblogger.Info("5. Exit")
}

func testRegionZoneHandler(config Config) {
resourceHandler, err := getResourceHandler("regionzone", config)
if err != nil {
cblogger.Error(err)
return
}
regionzoneHandler := resourceHandler.(irs.RegionZoneHandler)

testRegionZoneHandlerListPrint()
Loop:
for {
var commandNum int
inputCnt, err := fmt.Scan(&commandNum)
if err != nil {
cblogger.Error(err)
}

if inputCnt == 1 {
switch commandNum {
case 0:
testRegionZoneHandlerListPrint()
case 1:
cblogger.Info("Start ListRegionZone() ...")
if listRegionZone, err := regionzoneHandler.ListRegionZone(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(listRegionZone)
}
cblogger.Info("Finish ListRegionZone()")
case 2:
cblogger.Info("Start GetRegionZone() ...")
var region string
fmt.Print("Enter Region Name: ")
if _, err := fmt.Scanln(&region); err != nil {
cblogger.Error(err)
}
if listRegionZone, err := regionzoneHandler.GetRegionZone(region); err != nil {
cblogger.Error(err)
} else {
spew.Dump(listRegionZone)
}
cblogger.Info("Finish GetRegionZone()")
case 3:
cblogger.Info("Start ListOrgRegion() ...")
if listOrgRegion, err := regionzoneHandler.ListOrgRegion(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(listOrgRegion)
}
cblogger.Info("Finish ListOrgRegion()")
case 4:
cblogger.Info("Start ListOrgZone() ...")
if listOrgZone, err := regionzoneHandler.ListOrgZone(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(listOrgZone)
}
cblogger.Info("Finish ListOrgZone()")
case 5:
cblogger.Info("Exit")
break Loop
}
}
}
}

func testClusterHandlerListPrint() {
cblogger.Info("Test ClusterHandler")
cblogger.Info("0. Print Menu")
Expand Down Expand Up @@ -1563,7 +1641,6 @@ Loop:
case 6:
testVMHandler(config)
showTestHandlerInfo()

case 7:
testNLBHandler(config)
showTestHandlerInfo()
Expand All @@ -1574,9 +1651,12 @@ Loop:
testMyImageHandler(config)
showTestHandlerInfo()
case 10:
testClusterHandler(config)
testRegionZoneHandler(config)
showTestHandlerInfo()
case 11:
testClusterHandler(config)
showTestHandlerInfo()
case 12:
cblogger.Info("Exit Test ResourceHandler Program")
break Loop
}
Expand Down
Loading

0 comments on commit 7ce64cb

Please sign in to comment.