From b32ee071dbe354b8e7c8d57d9c87eeea1febffdb Mon Sep 17 00:00:00 2001 From: powerkimhub Date: Wed, 27 Oct 2021 13:39:57 +0000 Subject: [PATCH] Fix duplicate code between StaticDriver and PluginDriver --- build_all_driver_lib.sh | 2 +- .../alibaba-plugin/AlibabaDriver-lib.go | 145 +-------- .../drivers/alibaba/AlibabaDriver.go | 2 - .../drivers/aws-plugin/AwsDriver-lib.go | 115 +------ .../cloud-driver/drivers/aws/AwsDriver.go | 5 - .../drivers/azure-plugin/AzureDriver-lib.go | 298 +----------------- .../cloud-driver/drivers/azure/AzureDriver.go | 1 - .../cloudit-plugin/ClouditDriver-lib.go | 60 +--- .../drivers/cloudit/ClouditDriver.go | 1 - .../drivers/docker-plugin/DockerDriver-lib.go | 69 +--- .../drivers/docker/DockerDriver.go | 2 - .../drivers/gcp-plugin/GCPDriver-lib.go | 113 +------ .../cloud-driver/drivers/gcp/GCPDriver.go | 3 - .../ibmcloud-vpc-plugin/IBMCloudDriver-lib.go | 99 +----- .../drivers/ibmcloud-vpc/IBMCloudDriver.go | 1 + .../drivers/mock-plugin/MockDriver-lib.go | 62 +--- .../cloud-driver/drivers/mock/MockDriver.go | 2 - .../openstack-plugin/OpenStackDriver-lib.go | 160 +--------- .../drivers/openstack/OpenStackDriver.go | 1 - .../tencent-plugin/TencentDriver-lib.go | 160 +--------- .../drivers/tencent/TencentDriver.go | 3 - 21 files changed, 31 insertions(+), 1273 deletions(-) diff --git a/build_all_driver_lib.sh b/build_all_driver_lib.sh index 039855f17..8529f5f12 100755 --- a/build_all_driver_lib.sh +++ b/build_all_driver_lib.sh @@ -2,7 +2,7 @@ source setup.env #DRIVERS=( aws-plugin azure-plugin openstack-plugin gcp-plugin alibaba-plugin cloudit-plugin docker-plugin ncp-plugin ncpvpc-plugin) -DRIVERS=( aws-plugin azure-plugin gcp-plugin alibaba-plugin openstack-plugin cloudit-plugin docker-plugin mock-plugin tencent-plugin ) +DRIVERS=( aws-plugin azure-plugin gcp-plugin alibaba-plugin openstack-plugin cloudit-plugin docker-plugin mock-plugin tencent-plugin ibmcloud-vpc-plugin ) DRIVER_PATH=$CBSPIDER_ROOT/cloud-control-manager/cloud-driver/drivers DRIVERLIB_PATH=$CBSPIDER_ROOT/cloud-driver-libs diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba-plugin/AlibabaDriver-lib.go b/cloud-control-manager/cloud-driver/drivers/alibaba-plugin/AlibabaDriver-lib.go index 38e0364f5..456164ee0 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba-plugin/AlibabaDriver-lib.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba-plugin/AlibabaDriver-lib.go @@ -8,150 +8,11 @@ // // by zephy@mz.co.kr, 2019.09. -//package alibaba - package main import ( - "C" - "fmt" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" - "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs" - "github.com/aliyun/alibaba-cloud-sdk-go/services/vpc" - alicon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/alibaba/connect" - idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" - icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect" - "github.com/davecgh/go-spew/spew" + "C" + alibaba "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/alibaba" ) -type AlibabaDriver struct{} - -func (AlibabaDriver) GetDriverVersion() string { - return "ALIBABA-CLOUD DRIVER Version 1.0" -} - -func (AlibabaDriver) GetDriverCapability() idrv.DriverCapabilityInfo { - var drvCapabilityInfo idrv.DriverCapabilityInfo - - drvCapabilityInfo.ImageHandler = false - drvCapabilityInfo.VPCHandler = false - drvCapabilityInfo.SecurityHandler = false - drvCapabilityInfo.KeyPairHandler = false - drvCapabilityInfo.VNicHandler = false - drvCapabilityInfo.PublicIPHandler = false - drvCapabilityInfo.VMHandler = false - drvCapabilityInfo.VMSpecHandler = false - - return drvCapabilityInfo -} - -func (driver *AlibabaDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of Test A Cloud with credential info. - // 3. create CloudConnection Instance of "connect/TDA_CloudConnection". - // 4. return CloudConnection Interface of TDA_CloudConnection. - - ECSClient, err := getECSClient(connectionInfo) - if err != nil { - return nil, err - } - - VPCClient, err := getVPCClient(connectionInfo) - if err != nil { - return nil, err - } - - iConn := alicon.AlibabaCloudConnection{ - Region: connectionInfo.RegionInfo, - VMClient: ECSClient, - KeyPairClient: ECSClient, - ImageClient: ECSClient, - //PublicIPClient: VPCClient, - SecurityGroupClient: ECSClient, - VpcClient: VPCClient, - //VNetClient: VPCClient, - //VNicClient: ECSClient, - //SubnetClient: VPCClient, - VmSpecClient: ECSClient, - } - return &iConn, nil -} - -func getECSClient(connectionInfo idrv.ConnectionInfo) (*ecs.Client, error) { - - // Region Info - fmt.Println("AlibabaDriver : getECSClient() - Region : [" + connectionInfo.RegionInfo.Region + "]") - - /* - // Customize config - config := sdk.NewConfig(). - WithEnableAsync(true). - WithGoRoutinePoolSize(5). - WithMaxTaskQueueSize(1000) - // 600*time.Second - - //fmt.Println(config) - spew.Dump(config) - */ - - // Create a credential object - credential := &credentials.BaseCredential{ - AccessKeyId: connectionInfo.CredentialInfo.ClientId, - AccessKeySecret: connectionInfo.CredentialInfo.ClientSecret, - } - - escClient, err := ecs.NewClientWithAccessKey(connectionInfo.RegionInfo.Region, credential.AccessKeyId, credential.AccessKeySecret) - - //escClient, err := ecs.NewClientWithOptions(connectionInfo.RegionInfo.Region, config, credential) - if err != nil { - fmt.Println("Could not create alibaba's ecs service client", err) - spew.Dump(err) - return nil, err - } - - //spew.Dump(escClient) - - /* - escClient, err := sdk.NewClientWithAccessKey("REGION_ID", "ACCESS_KEY_ID", "ACCESS_KEY_SECRET") - if err != nil { - // Handle exceptions - panic(err) - } - */ - - return escClient, nil -} - -func getVPCClient(connectionInfo idrv.ConnectionInfo) (*vpc.Client, error) { - - // Region Info - fmt.Println("AlibabaDriver : getVPCClient() - Region : [" + connectionInfo.RegionInfo.Region + "]") - - /* - // Customize config - config := sdk.NewConfig(). - WithEnableAsync(true). - WithGoRoutinePoolSize(5). - WithMaxTaskQueueSize(1000) - // 600*time.Second - //fmt.Println(config) - */ - - // Create a credential object - credential := &credentials.BaseCredential{ - AccessKeyId: connectionInfo.CredentialInfo.ClientId, - AccessKeySecret: connectionInfo.CredentialInfo.ClientSecret, - } - - vpcClient, err := vpc.NewClientWithAccessKey(connectionInfo.RegionInfo.Region, credential.AccessKeyId, credential.AccessKeySecret) - //vpcClient, err := vpc.NewClientWithOptions(connectionInfo.RegionInfo.Region, config, credential) - if err != nil { - fmt.Println("Could not create alibaba's vpc service client", err) - return nil, err - } - - return vpcClient, nil -} - -var CloudDriver AlibabaDriver +var CloudDriver alibaba.AlibabaDriver diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go b/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go index c9d007577..b2f1567ae 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go @@ -11,7 +11,6 @@ package alibaba import ( - "C" "fmt" "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" @@ -183,4 +182,3 @@ func getVPCClient(connectionInfo idrv.ConnectionInfo) (*vpc.Client, error) { return vpcClient, nil } -var CloudDriver AlibabaDriver diff --git a/cloud-control-manager/cloud-driver/drivers/aws-plugin/AwsDriver-lib.go b/cloud-control-manager/cloud-driver/drivers/aws-plugin/AwsDriver-lib.go index 68dec43f1..5cfa97ce4 100644 --- a/cloud-control-manager/cloud-driver/drivers/aws-plugin/AwsDriver-lib.go +++ b/cloud-control-manager/cloud-driver/drivers/aws-plugin/AwsDriver-lib.go @@ -12,118 +12,7 @@ package main import ( "C" - - acon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/aws/connect" - idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" - - icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect" - //icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect/AwsNewIfCloudConnect" - //icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect/connect" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/ec2" -) -import ( - "fmt" - - "github.com/aws/aws-sdk-go/aws/credentials" + aws "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/aws" ) -type AwsDriver struct { -} - -func (AwsDriver) GetDriverVersion() string { - return "TEST AWS DRIVER Version 1.0" -} - -func (AwsDriver) GetDriverCapability() idrv.DriverCapabilityInfo { - var drvCapabilityInfo idrv.DriverCapabilityInfo - - drvCapabilityInfo.ImageHandler = true - drvCapabilityInfo.VPCHandler = true - drvCapabilityInfo.SecurityHandler = true - drvCapabilityInfo.KeyPairHandler = true - drvCapabilityInfo.VNicHandler = false - drvCapabilityInfo.PublicIPHandler = false - drvCapabilityInfo.VMHandler = true - drvCapabilityInfo.VMSpecHandler = true - - return drvCapabilityInfo -} - -//func getVMClient(regionInfo idrv.RegionInfo) (*ec2.EC2, error) { -func getVMClient(connectionInfo idrv.ConnectionInfo) (*ec2.EC2, error) { - - // setup Region - fmt.Println("AwsDriver : getVMClient() - Region : [" + connectionInfo.RegionInfo.Region + "]") - //fmt.Println("전달 받은 커넥션 정보") - //spew.Dump(connectionInfo) - - sess, err := session.NewSession(&aws.Config{ - Region: aws.String(connectionInfo.RegionInfo.Region), - //Region: aws.String("ap-northeast-2"), - Credentials: credentials.NewStaticCredentials(connectionInfo.CredentialInfo.ClientId, connectionInfo.CredentialInfo.ClientSecret, "")}, - ) - if err != nil { - fmt.Println("Could not create aws New Session", err) - return nil, err - } - - // Create EC2 service client - svc := ec2.New(sess) - if err != nil { - fmt.Println("Could not create EC2 service client", err) - return nil, err - } - - return svc, nil -} - -func (driver *AwsDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of Test A Cloud with credential info. - // 3. create CloudConnection Instance of "connect/TDA_CloudConnection". - // 4. return CloudConnection Interface of TDA_CloudConnection. - - //fmt.Println("ConnectCloud의 전달 받은 idrv.ConnectionInfo 정보") - //spew.Dump(connectionInfo) - - // sample code, do not user like this^^ - //var iConn icon.CloudConnection - vmClient, err := getVMClient(connectionInfo) - //vmClient, err := getVMClient(connectionInfo.RegionInfo) - if err != nil { - return nil, err - } - - //iConn = acon.AwsCloudConnection{} - iConn := acon.AwsCloudConnection{ - Region: connectionInfo.RegionInfo, - VMClient: vmClient, - KeyPairClient: vmClient, - - VNetworkClient: vmClient, - //VNicClient: vmClient, - ImageClient: vmClient, - //PublicIPClient: vmClient, - SecurityClient: vmClient, - VmSpecClient: vmClient, - } - - return &iConn, nil // return type: (icon.CloudConnection, error) -} - -/* -func (AwsDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of Test A Cloud with credential info. - // 3. create CloudConnection Instance of "connect/TDA_CloudConnection". - // 4. return CloudConnection Interface of TDA_CloudConnection. - // sample code, do not user like this^^ - var iConn icon.CloudConnection - iConn = acon.AwsCloudConnection{} - return iConn, nil // return type: (icon.CloudConnection, error) -} -*/ -var CloudDriver AwsDriver +var CloudDriver aws.AwsDriver diff --git a/cloud-control-manager/cloud-driver/drivers/aws/AwsDriver.go b/cloud-control-manager/cloud-driver/drivers/aws/AwsDriver.go index 83f0ff9b5..b078ed47a 100644 --- a/cloud-control-manager/cloud-driver/drivers/aws/AwsDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/aws/AwsDriver.go @@ -8,13 +8,9 @@ // // by CB-Spider Team, 2019.06. -//package main - package aws import ( - "C" - acon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/aws/connect" idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" @@ -130,4 +126,3 @@ func (AwsDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudCon return iConn, nil // return type: (icon.CloudConnection, error) } */ -var CloudDriver AwsDriver diff --git a/cloud-control-manager/cloud-driver/drivers/azure-plugin/AzureDriver-lib.go b/cloud-control-manager/cloud-driver/drivers/azure-plugin/AzureDriver-lib.go index c74e4d837..6940649ba 100644 --- a/cloud-control-manager/cloud-driver/drivers/azure-plugin/AzureDriver-lib.go +++ b/cloud-control-manager/cloud-driver/drivers/azure-plugin/AzureDriver-lib.go @@ -11,300 +11,8 @@ package main import ( - "context" - "time" - - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-03-01/compute" - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-02-01/network" - "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-10-01/resources" - "github.com/Azure/go-autorest/autorest/azure/auth" - "github.com/Azure/go-autorest/autorest/to" - - azcon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/azure/connect" - azrs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/azure/resources" - idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" - icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect" + "C" + azure "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/azure" ) -type AzureDriver struct{} - -func (AzureDriver) GetDriverVersion() string { - return "AZURE DRIVER Version 1.0" -} - -func (AzureDriver) GetDriverCapability() idrv.DriverCapabilityInfo { - var drvCapabilityInfo idrv.DriverCapabilityInfo - - drvCapabilityInfo.ImageHandler = true - drvCapabilityInfo.VPCHandler = true - drvCapabilityInfo.SecurityHandler = true - drvCapabilityInfo.KeyPairHandler = true - drvCapabilityInfo.VNicHandler = false - drvCapabilityInfo.PublicIPHandler = false - drvCapabilityInfo.VMHandler = true - drvCapabilityInfo.VMSpecHandler = true - - return drvCapabilityInfo -} - -func (driver *AzureDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of Test A Cloud with credential info. - // 3. create CloudConnection Instance of "connect/TDA_CloudConnection". - // 4. return CloudConnection Interface of TDA_CloudConnection. - - // Initialize Logger - azrs.InitLog() - - // Credentail에 등록된 ResourceGroup 존재 여부 체크 및 생성 - err := checkResourceGroup(connectionInfo.CredentialInfo, connectionInfo.RegionInfo) - if err != nil { - return nil, err - } - - Ctx, VMClient, err := getVMClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - Ctx, imageClient, err := getImageClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - Ctx, publicIPClient, err := getPublicIPClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - Ctx, sgClient, err := getSecurityGroupClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - Ctx, vNicClient, err := getVNicClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - Ctx, SubnetClient, err := getSubnetClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - Ctx, VNetClient, err := getVNetworkClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - Ctx, IPConfigClient, err := getIPConfigClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - Ctx, VMImageClient, err := getVMImageClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - Ctx, DiskClient, err := getDiskClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - Ctx, VmSpecClient, err := getVmSpecClient(connectionInfo.CredentialInfo) - if err != nil { - return nil, err - } - - iConn := azcon.AzureCloudConnection{ - CredentialInfo: connectionInfo.CredentialInfo, - Region: connectionInfo.RegionInfo, - Ctx: Ctx, - VMClient: VMClient, - ImageClient: imageClient, - PublicIPClient: publicIPClient, - SecurityGroupClient: sgClient, - VNetClient: VNetClient, - VNicClient: vNicClient, - IPConfigClient: IPConfigClient, - SubnetClient: SubnetClient, - VMImageClient: VMImageClient, - DiskClient: DiskClient, - VmSpecClient: VmSpecClient, - } - return &iConn, nil -} - -func checkResourceGroup(credential idrv.CredentialInfo, region idrv.RegionInfo) error { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil - } - - resourceClient := resources.NewGroupsClient(credential.SubscriptionId) - resourceClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - rg, err := resourceClient.Get(ctx, region.ResourceGroup) - - // 해당 리소스 그룹이 없을 경우 생성 - if rg.ID == nil { - rg, err = resourceClient.CreateOrUpdate(ctx, region.ResourceGroup, - resources.Group{ - Name: to.StringPtr(region.ResourceGroup), - Location: to.StringPtr(region.Region), - }) - if err != nil { - return err - } - } - return nil -} - -func getVMClient(credential idrv.CredentialInfo) (context.Context, *compute.VirtualMachinesClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - vmClient := compute.NewVirtualMachinesClient(credential.SubscriptionId) - vmClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &vmClient, nil -} - -func getImageClient(credential idrv.CredentialInfo) (context.Context, *compute.ImagesClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - imageClient := compute.NewImagesClient(credential.SubscriptionId) - imageClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &imageClient, nil -} - -func getPublicIPClient(credential idrv.CredentialInfo) (context.Context, *network.PublicIPAddressesClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - publicIPClient := network.NewPublicIPAddressesClient(credential.SubscriptionId) - publicIPClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &publicIPClient, nil -} - -func getSecurityGroupClient(credential idrv.CredentialInfo) (context.Context, *network.SecurityGroupsClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - sgClient := network.NewSecurityGroupsClient(credential.SubscriptionId) - sgClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &sgClient, nil -} - -func getVNetworkClient(credential idrv.CredentialInfo) (context.Context, *network.VirtualNetworksClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - vNetClient := network.NewVirtualNetworksClient(credential.SubscriptionId) - vNetClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &vNetClient, nil -} - -func getVNicClient(credential idrv.CredentialInfo) (context.Context, *network.InterfacesClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - vNicClient := network.NewInterfacesClient(credential.SubscriptionId) - vNicClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &vNicClient, nil -} - -func getIPConfigClient(credential idrv.CredentialInfo) (context.Context, *network.InterfaceIPConfigurationsClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - ipConfigClient := network.NewInterfaceIPConfigurationsClient(credential.SubscriptionId) - ipConfigClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &ipConfigClient, nil -} - -func getSubnetClient(credential idrv.CredentialInfo) (context.Context, *network.SubnetsClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - subnetClient := network.NewSubnetsClient(credential.SubscriptionId) - subnetClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &subnetClient, nil -} - -func getVMImageClient(credential idrv.CredentialInfo) (context.Context, *compute.VirtualMachineImagesClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - vmImageClient := compute.NewVirtualMachineImagesClient(credential.SubscriptionId) - vmImageClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &vmImageClient, nil -} - -func getDiskClient(credential idrv.CredentialInfo) (context.Context, *compute.DisksClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - diskClient := compute.NewDisksClient(credential.SubscriptionId) - diskClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &diskClient, nil -} - -func getVmSpecClient(credential idrv.CredentialInfo) (context.Context, *compute.VirtualMachineSizesClient, error) { - config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) - authorizer, err := config.Authorizer() - if err != nil { - return nil, nil, err - } - - vmSpecClient := compute.NewVirtualMachineSizesClient(credential.SubscriptionId) - vmSpecClient.Authorizer = authorizer - ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) - - return ctx, &vmSpecClient, nil -} - -var CloudDriver AzureDriver +var CloudDriver azure.AzureDriver diff --git a/cloud-control-manager/cloud-driver/drivers/azure/AzureDriver.go b/cloud-control-manager/cloud-driver/drivers/azure/AzureDriver.go index 466152bbd..71038c2fc 100644 --- a/cloud-control-manager/cloud-driver/drivers/azure/AzureDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/azure/AzureDriver.go @@ -311,4 +311,3 @@ func getVmSpecClient(credential idrv.CredentialInfo) (context.Context, *compute. return ctx, &vmSpecClient, nil } -var CloudDriver AzureDriver diff --git a/cloud-control-manager/cloud-driver/drivers/cloudit-plugin/ClouditDriver-lib.go b/cloud-control-manager/cloud-driver/drivers/cloudit-plugin/ClouditDriver-lib.go index a43a7c28a..5f42cd826 100644 --- a/cloud-control-manager/cloud-driver/drivers/cloudit-plugin/ClouditDriver-lib.go +++ b/cloud-control-manager/cloud-driver/drivers/cloudit-plugin/ClouditDriver-lib.go @@ -1,62 +1,8 @@ package main import ( - "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/cloudit/client" - cicon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/cloudit/connect" - cirs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/cloudit/resources" - idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" - icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect" + "C" + cloudit "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/cloudit" ) -type ClouditDriver struct{} - -func (ClouditDriver) GetDriverVersion() string { - return "CLOUDIT DRIVER Version 1.0" -} - -func (ClouditDriver) GetDriverCapability() idrv.DriverCapabilityInfo { - var drvCapabilityInfo idrv.DriverCapabilityInfo - - drvCapabilityInfo.ImageHandler = false - drvCapabilityInfo.VPCHandler = false - drvCapabilityInfo.SecurityHandler = false - drvCapabilityInfo.KeyPairHandler = false - drvCapabilityInfo.VNicHandler = false - drvCapabilityInfo.PublicIPHandler = false - drvCapabilityInfo.VMHandler = true - - return drvCapabilityInfo -} - -func (driver *ClouditDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of Test A Cloud with credential info. - // 3. create CloudConnection Instance of "connect/TDA_CloudConnection". - // 4. return CloudConnection Interface of TDA_CloudConnection. - - // Initialize Logger - cirs.InitLog() - - Client, err := getServiceClient(connectionInfo) - if err != nil { - return nil, err - } - - iConn := cicon.ClouditCloudConnection{ - CredentialInfo: connectionInfo.CredentialInfo, - Client: *Client, - } - - return &iConn, nil -} - -func getServiceClient(connInfo idrv.ConnectionInfo) (*client.RestClient, error) { - restClient := client.RestClient{ - IdentityBase: connInfo.CredentialInfo.IdentityEndpoint, - ClouditVersion: "v4.0", - TenantID: connInfo.CredentialInfo.TenantId, - } - return &restClient, nil -} - -var CloudDriver ClouditDriver +var CloudDriver cloudit.ClouditDriver diff --git a/cloud-control-manager/cloud-driver/drivers/cloudit/ClouditDriver.go b/cloud-control-manager/cloud-driver/drivers/cloudit/ClouditDriver.go index 94eec8424..c23454049 100644 --- a/cloud-control-manager/cloud-driver/drivers/cloudit/ClouditDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/cloudit/ClouditDriver.go @@ -59,4 +59,3 @@ func getServiceClient(connInfo idrv.ConnectionInfo) (*client.RestClient, error) return &restClient, nil } -var CloudDriver ClouditDriver diff --git a/cloud-control-manager/cloud-driver/drivers/docker-plugin/DockerDriver-lib.go b/cloud-control-manager/cloud-driver/drivers/docker-plugin/DockerDriver-lib.go index 85ddb3d1e..e39a20b7e 100644 --- a/cloud-control-manager/cloud-driver/drivers/docker-plugin/DockerDriver-lib.go +++ b/cloud-control-manager/cloud-driver/drivers/docker-plugin/DockerDriver-lib.go @@ -11,71 +11,8 @@ package main import ( - "C" - "github.com/sirupsen/logrus" - cblog "github.com/cloud-barista/cb-log" - "context" - "github.com/docker/docker/client" - - dkcon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/docker/connect" - idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" - icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect" + "C" + docker "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/docker" ) -type DockerDriver struct{} -var cblogger *logrus.Logger - -func init() { - // cblog is a global variable. - cblogger = cblog.GetLogger("CB-SPIDER") -} - - -func (DockerDriver) GetDriverVersion() string { - return "DOCKER DRIVER Version 1.0" -} - -func (DockerDriver) GetDriverCapability() idrv.DriverCapabilityInfo { - var drvCapabilityInfo idrv.DriverCapabilityInfo - - drvCapabilityInfo.ImageHandler = true - drvCapabilityInfo.VPCHandler = false - drvCapabilityInfo.SecurityHandler = false - drvCapabilityInfo.KeyPairHandler = false - drvCapabilityInfo.VNicHandler = false - drvCapabilityInfo.PublicIPHandler = false - drvCapabilityInfo.VMHandler = true - drvCapabilityInfo.VMSpecHandler = false - - return drvCapabilityInfo -} - -func (driver *DockerDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of XXX Cloud with credential info. - // 3. create CloudConnection Instance of "connect/XXX_CloudConnection". - // 4. return CloudConnection Interface of XXX_CloudConnection. - - //thisContext, _ := context.WithTimeout(context.Background(), 600*time.Second) - thisContext := context.Background() - - // ex) - // IdentityEndpoint = "http://18.191.129.154:1004" - // APIVersion = "v1.36" - Host:= connectionInfo.CredentialInfo.Host - APIVersion:= connectionInfo.CredentialInfo.APIVersion - client, err := client.NewClient(Host, APIVersion, nil, nil) - if err != nil { - cblogger.Error(err) - return nil, err - } - - iConn := dkcon.DockerCloudConnection{ - ConnectionInfo: connectionInfo, - Context: thisContext, - Client: client, - } - return &iConn, nil -} - -var CloudDriver DockerDriver +var CloudDriver docker.DockerDriver diff --git a/cloud-control-manager/cloud-driver/drivers/docker/DockerDriver.go b/cloud-control-manager/cloud-driver/drivers/docker/DockerDriver.go index 2fd6c8901..71359db25 100644 --- a/cloud-control-manager/cloud-driver/drivers/docker/DockerDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/docker/DockerDriver.go @@ -11,7 +11,6 @@ package docker import ( - "C" "github.com/sirupsen/logrus" cblog "github.com/cloud-barista/cb-log" "context" @@ -78,4 +77,3 @@ func (driver *DockerDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (ic return &iConn, nil } -var CloudDriver DockerDriver diff --git a/cloud-control-manager/cloud-driver/drivers/gcp-plugin/GCPDriver-lib.go b/cloud-control-manager/cloud-driver/drivers/gcp-plugin/GCPDriver-lib.go index 67b9ef522..2feff06e0 100644 --- a/cloud-control-manager/cloud-driver/drivers/gcp-plugin/GCPDriver-lib.go +++ b/cloud-control-manager/cloud-driver/drivers/gcp-plugin/GCPDriver-lib.go @@ -10,116 +10,9 @@ package main -//package gcp - import ( - "C" - - "context" - "encoding/json" - "fmt" - - gcpcon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/gcp/connect" - idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" - - icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect" - - o2 "golang.org/x/oauth2" - goo "golang.org/x/oauth2/google" - - compute "google.golang.org/api/compute/v1" + "C" + gcp "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/gcp" ) -type GCPDriver struct { -} - -func (GCPDriver) GetDriverVersion() string { - return "GCP DRIVER Version 1.0" -} - -func (GCPDriver) GetDriverCapability() idrv.DriverCapabilityInfo { - var drvCapabilityInfo idrv.DriverCapabilityInfo - - drvCapabilityInfo.ImageHandler = true - drvCapabilityInfo.VPCHandler = true - drvCapabilityInfo.SecurityHandler = true - drvCapabilityInfo.KeyPairHandler = true - //drvCapabilityInfo.VNicHandler = true - //drvCapabilityInfo.PublicIPHandler = true - drvCapabilityInfo.VMHandler = true - drvCapabilityInfo.VMSpecHandler = true - drvCapabilityInfo.VPCHandler = true - - return drvCapabilityInfo -} - -func (driver *GCPDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of Test A Cloud with credential info. - // 3. create CloudConnection Instance of "connect/TDA_CloudConnection". - // 4. return CloudConnection Interface of TDA_CloudConnection. - - Ctx, VMClient, err := getVMClient(connectionInfo.CredentialInfo) - fmt.Println("################## getVMClient ##################") - fmt.Println("getVMClient") - fmt.Println("################## getVMClient ##################") - if err != nil { - return nil, err - } - - iConn := gcpcon.GCPCloudConnection{ - Region: connectionInfo.RegionInfo, - Credential: connectionInfo.CredentialInfo, - Ctx: Ctx, - VMClient: VMClient, - ImageClient: VMClient, - // PublicIPClient: VMClient, - SecurityGroupClient: VMClient, - // VNetClient: VMClient, - // VNicClient: VMClient, - SubnetClient: VMClient, - VMSpecHandler: VMClient, - VPCHandler: VMClient, - } - - //fmt.Println("################## resource ConnectionInfo ##################") - //fmt.Println("iConn : ", iConn) - //fmt.Println("################## resource ConnectionInfo ##################") - return &iConn, nil -} - -func getVMClient(credential idrv.CredentialInfo) (context.Context, *compute.Service, error) { - - // GCP 는 ClientSecret에 - gcpType := "service_account" - data := make(map[string]string) - - data["type"] = gcpType - data["private_key"] = credential.PrivateKey - data["client_email"] = credential.ClientEmail - - fmt.Println("################## data ##################") - //fmt.Println("data to json : ", data) - fmt.Println("################## data ##################") - - res, _ := json.Marshal(data) - // data, err := ioutil.ReadFile(credential.ClientSecret) - authURL := "https://www.googleapis.com/auth/compute" - - conf, err := goo.JWTConfigFromJSON(res, authURL) - - if err != nil { - - return nil, nil, err - } - - client := conf.Client(o2.NoContext) - - vmClient, err := compute.New(client) - - ctx := context.Background() - - return ctx, vmClient, nil -} - -var CloudDriver GCPDriver +var CloudDriver gcp.GCPDriver diff --git a/cloud-control-manager/cloud-driver/drivers/gcp/GCPDriver.go b/cloud-control-manager/cloud-driver/drivers/gcp/GCPDriver.go index 535e9a8c2..28ff8fac7 100644 --- a/cloud-control-manager/cloud-driver/drivers/gcp/GCPDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/gcp/GCPDriver.go @@ -11,8 +11,6 @@ package gcp import ( - "C" - "context" "encoding/json" "fmt" @@ -120,4 +118,3 @@ func getVMClient(credential idrv.CredentialInfo) (context.Context, *compute.Serv return ctx, vmClient, nil } -var CloudDriver GCPDriver diff --git a/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc-plugin/IBMCloudDriver-lib.go b/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc-plugin/IBMCloudDriver-lib.go index 920de1aa3..320944396 100644 --- a/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc-plugin/IBMCloudDriver-lib.go +++ b/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc-plugin/IBMCloudDriver-lib.go @@ -1,101 +1,8 @@ package main import ( - "context" - "errors" - "github.com/IBM/go-sdk-core/v5/core" - "github.com/IBM/vpc-go-sdk/vpcv1" - "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc/connect" - ibms "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc/resources" - idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" - icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect" - "time" + "C" + ibm "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc" ) -type IbmCloudDriver struct{} - -const ( - cspTimeout time.Duration = 6000 -) - -func (IbmCloudDriver) GetDriverVersion() string { - return "IBM DRIVER Version 1.0" -} -func (IbmCloudDriver) GetDriverCapability() idrv.DriverCapabilityInfo { - var drvCapabilityInfo idrv.DriverCapabilityInfo - - drvCapabilityInfo.ImageHandler = true - drvCapabilityInfo.VPCHandler = true - drvCapabilityInfo.SecurityHandler = true - drvCapabilityInfo.KeyPairHandler = true - drvCapabilityInfo.VNicHandler = false - drvCapabilityInfo.PublicIPHandler = false - drvCapabilityInfo.VMHandler = true - drvCapabilityInfo.VMSpecHandler = true - - return drvCapabilityInfo -} - -func (driver *IbmCloudDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - ibms.InitLog() - err := checkConnectionInfo(connectionInfo) - if err != nil { - return nil, err - } - ctx, _ := context.WithTimeout(context.Background(), cspTimeout*time.Second) - - // Region & Zone Check - initVpcService, err := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{ - Authenticator: &core.IamAuthenticator{ - ApiKey: connectionInfo.CredentialInfo.ApiKey, - }, - }) - if err != nil { - return nil, err - } - var endPoint string - getRegionOptions := &vpcv1.GetRegionOptions{} - getRegionOptions.SetName(connectionInfo.RegionInfo.Region) - region, _, err := initVpcService.GetRegionWithContext(ctx, getRegionOptions) - if err != nil { - return nil, err - } else { - getZoneOptions := &vpcv1.GetRegionZoneOptions{} - getZoneOptions.SetRegionName(*region.Name) - getZoneOptions.SetName(connectionInfo.RegionInfo.Zone) - _, _, err := initVpcService.GetRegionZoneWithContext(ctx, getZoneOptions) - if err != nil { - return nil, err - } - endPoint = *region.Endpoint + "/v1" - } - vpcService, err := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{ - Authenticator: &core.IamAuthenticator{ - ApiKey: connectionInfo.CredentialInfo.ApiKey, - }, - URL: endPoint, - }) - if err != nil { - return nil, err - } - iConn := connect.IbmCloudConnection{ - CredentialInfo: connectionInfo.CredentialInfo, - Region: connectionInfo.RegionInfo, - VpcService: vpcService, - Ctx: ctx, - } - return &iConn, nil -} - -func checkConnectionInfo(connectionInfo idrv.ConnectionInfo) error { - if connectionInfo.CredentialInfo.ApiKey == "" { - return errors.New("not exist ApiKey") - } - if connectionInfo.RegionInfo.Region == "" { - return errors.New("not exist Region") - } - if connectionInfo.RegionInfo.Zone == "" { - return errors.New("not exist Zone") - } - return nil -} +var CloudDriver ibm.IbmCloudDriver diff --git a/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc/IBMCloudDriver.go b/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc/IBMCloudDriver.go index 6d8ebeaa7..7e542791e 100644 --- a/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc/IBMCloudDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc/IBMCloudDriver.go @@ -99,3 +99,4 @@ func checkConnectionInfo(connectionInfo idrv.ConnectionInfo) error { } return nil } + diff --git a/cloud-control-manager/cloud-driver/drivers/mock-plugin/MockDriver-lib.go b/cloud-control-manager/cloud-driver/drivers/mock-plugin/MockDriver-lib.go index f0caf1d97..2ec62ea17 100644 --- a/cloud-control-manager/cloud-driver/drivers/mock-plugin/MockDriver-lib.go +++ b/cloud-control-manager/cloud-driver/drivers/mock-plugin/MockDriver-lib.go @@ -11,64 +11,8 @@ package main import ( - "C" - - cblog "github.com/cloud-barista/cb-log" - "github.com/sirupsen/logrus" - - mkcon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/mock/connect" - mkrs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/mock/resources" - idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" - icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect" + "C" + mock "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/mock" ) -type MockDriver struct{} - -var cblogger *logrus.Logger - -func init() { - // cblog is a global variable. - cblogger = cblog.GetLogger("CB-SPIDER") -} - -func (MockDriver) GetDriverVersion() string { - return "MOCK DRIVER Version 1.0" -} - -func (MockDriver) GetDriverCapability() idrv.DriverCapabilityInfo { - var drvCapabilityInfo idrv.DriverCapabilityInfo - - drvCapabilityInfo.ImageHandler = true - drvCapabilityInfo.VPCHandler = true - drvCapabilityInfo.SecurityHandler = true - drvCapabilityInfo.KeyPairHandler = true - drvCapabilityInfo.VNicHandler = false - drvCapabilityInfo.PublicIPHandler = false - drvCapabilityInfo.VMHandler = true - drvCapabilityInfo.VMSpecHandler = true - - return drvCapabilityInfo -} - -func (driver *MockDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of XXX Cloud with credential info. - // 3. create CloudConnection Instance of "connect/XXX_CloudConnection". - // 4. return CloudConnection Interface of XXX_CloudConnection. - - // ex) - // MockName = "mock01" - iConn := mkcon.MockConnection{ - Region: connectionInfo.RegionInfo, - MockName: connectionInfo.CredentialInfo.MockName, - } - - // Please, do not delete this line. - mkrs.PrepareVMImage(iConn.MockName) - mkrs.PrepareVMSpec(iConn.MockName) - - return &iConn, nil -} - -var CloudDriver MockDriver +var CloudDriver mock.MockDriver diff --git a/cloud-control-manager/cloud-driver/drivers/mock/MockDriver.go b/cloud-control-manager/cloud-driver/drivers/mock/MockDriver.go index 2e38db520..75540984f 100644 --- a/cloud-control-manager/cloud-driver/drivers/mock/MockDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/mock/MockDriver.go @@ -11,7 +11,6 @@ package mock import ( - "C" cblog "github.com/cloud-barista/cb-log" "github.com/sirupsen/logrus" @@ -71,4 +70,3 @@ func (driver *MockDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon return &iConn, nil } -var CloudDriver MockDriver diff --git a/cloud-control-manager/cloud-driver/drivers/openstack-plugin/OpenStackDriver-lib.go b/cloud-control-manager/cloud-driver/drivers/openstack-plugin/OpenStackDriver-lib.go index 720921c85..5869982e8 100644 --- a/cloud-control-manager/cloud-driver/drivers/openstack-plugin/OpenStackDriver-lib.go +++ b/cloud-control-manager/cloud-driver/drivers/openstack-plugin/OpenStackDriver-lib.go @@ -11,162 +11,8 @@ package main import ( - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack" - - oscon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/openstack/connect" - osrs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/openstack/resources" - idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" - icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect" + "C" + openstack "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/openstack" ) -type OpenStackDriver struct{} - -func (OpenStackDriver) GetDriverVersion() string { - return "OPENSTACK DRIVER Version 1.0" -} - -func (OpenStackDriver) GetDriverCapability() idrv.DriverCapabilityInfo { - var drvCapabilityInfo idrv.DriverCapabilityInfo - - drvCapabilityInfo.ImageHandler = true - drvCapabilityInfo.VPCHandler = true - drvCapabilityInfo.SecurityHandler = true - drvCapabilityInfo.KeyPairHandler = true - drvCapabilityInfo.VNicHandler = false - drvCapabilityInfo.PublicIPHandler = false - drvCapabilityInfo.VMHandler = true - drvCapabilityInfo.VMSpecHandler = true - - return drvCapabilityInfo -} - -// modifiled by powerkim, 2019.07.29. -func (driver *OpenStackDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of Test A Cloud with credential info. - // 3. create CloudConnection Instance of "connect/TDA_CloudConnection". - // 4. return CloudConnection Interface of TDA_CloudConnection. - - // Initialize Logger - osrs.InitLog() - - Client, err := getServiceClient(connectionInfo) - if err != nil { - return nil, err - } - ImageClient, err := getImageClient(connectionInfo) - if err != nil { - return nil, err - } - NetworkClient, err := getNetworkClient(connectionInfo) - if err != nil { - return nil, err - } - VolumeClient, err := getVolumeClient(connectionInfo) - if err != nil { - return nil, err - } - - iConn := oscon.OpenStackCloudConnection{Region: connectionInfo.RegionInfo, Client: Client, ImageClient: ImageClient, NetworkClient: NetworkClient, VolumeClient: VolumeClient} - - return &iConn, nil -} - -// moved by powerkim, 2019.07.29. -func getServiceClient(connInfo idrv.ConnectionInfo) (*gophercloud.ServiceClient, error) { - - authOpts := gophercloud.AuthOptions{ - IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint, - Username: connInfo.CredentialInfo.Username, - Password: connInfo.CredentialInfo.Password, - DomainName: connInfo.CredentialInfo.DomainName, - TenantID: connInfo.CredentialInfo.ProjectID, - } - - provider, err := openstack.AuthenticatedClient(authOpts) - if err != nil { - return nil, err - } - - client, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{ - Region: connInfo.RegionInfo.Region, - }) - if err != nil { - return nil, err - } - - return client, err -} - -func getImageClient(connInfo idrv.ConnectionInfo) (*gophercloud.ServiceClient, error) { - - authOpts := gophercloud.AuthOptions{ - IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint, - Username: connInfo.CredentialInfo.Username, - Password: connInfo.CredentialInfo.Password, - DomainName: connInfo.CredentialInfo.DomainName, - TenantID: connInfo.CredentialInfo.ProjectID, - } - provider, err := openstack.AuthenticatedClient(authOpts) - if err != nil { - return nil, err - } - - c, err := openstack.NewImageServiceV2(provider, gophercloud.EndpointOpts{ - Region: connInfo.RegionInfo.Region, - }) - if err != nil { - return nil, err - } - - return c, err -} - -func getNetworkClient(connInfo idrv.ConnectionInfo) (*gophercloud.ServiceClient, error) { - - authOpts := gophercloud.AuthOptions{ - IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint, - Username: connInfo.CredentialInfo.Username, - Password: connInfo.CredentialInfo.Password, - DomainName: connInfo.CredentialInfo.DomainName, - TenantID: connInfo.CredentialInfo.ProjectID, - } - - provider, err := openstack.AuthenticatedClient(authOpts) - if err != nil { - return nil, err - } - - client, err := openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{ - Name: "neutron", - Region: connInfo.RegionInfo.Region, - }) - if err != nil { - return nil, err - } - - return client, err -} -func getVolumeClient(connInfo idrv.ConnectionInfo) (*gophercloud.ServiceClient, error) { - authOpts := gophercloud.AuthOptions{ - IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint, - Username: connInfo.CredentialInfo.Username, - Password: connInfo.CredentialInfo.Password, - DomainName: connInfo.CredentialInfo.DomainName, - TenantID: connInfo.CredentialInfo.ProjectID, - } - provider, err := openstack.AuthenticatedClient(authOpts) - if err != nil { - return nil, err - } - client, err := openstack.NewBlockStorageV2(provider, gophercloud.EndpointOpts{ - Region: connInfo.RegionInfo.Region, - }) - if err != nil { - return nil, err - } - return client, err -} - -var CloudDriver OpenStackDriver +var CloudDriver openstack.OpenStackDriver diff --git a/cloud-control-manager/cloud-driver/drivers/openstack/OpenStackDriver.go b/cloud-control-manager/cloud-driver/drivers/openstack/OpenStackDriver.go index 5e2da8577..639da34bf 100644 --- a/cloud-control-manager/cloud-driver/drivers/openstack/OpenStackDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/openstack/OpenStackDriver.go @@ -169,4 +169,3 @@ func getVolumeClient(connInfo idrv.ConnectionInfo) (*gophercloud.ServiceClient, return client, err } -var CloudDriver OpenStackDriver diff --git a/cloud-control-manager/cloud-driver/drivers/tencent-plugin/TencentDriver-lib.go b/cloud-control-manager/cloud-driver/drivers/tencent-plugin/TencentDriver-lib.go index 2dd245995..adaf3d0d9 100644 --- a/cloud-control-manager/cloud-driver/drivers/tencent-plugin/TencentDriver-lib.go +++ b/cloud-control-manager/cloud-driver/drivers/tencent-plugin/TencentDriver-lib.go @@ -11,162 +11,8 @@ package main import ( - "errors" - - tcon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/tencent/connect" - idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" - icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect" - - "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" - "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" - cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" - vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312" - - cblog "github.com/cloud-barista/cb-log" - "github.com/sirupsen/logrus" + "C" + tencent "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/tencent" ) -type TencentDriver struct { -} - -func (TencentDriver) GetDriverVersion() string { - return "Test Tencent Driver Version 0.1" -} - -func (TencentDriver) GetDriverCapability() idrv.DriverCapabilityInfo { - var drvCapabilityInfo idrv.DriverCapabilityInfo - - drvCapabilityInfo.ImageHandler = true - drvCapabilityInfo.VPCHandler = true - drvCapabilityInfo.SecurityHandler = true - drvCapabilityInfo.KeyPairHandler = true - drvCapabilityInfo.VNicHandler = false - drvCapabilityInfo.PublicIPHandler = false - drvCapabilityInfo.VMHandler = true - drvCapabilityInfo.VMSpecHandler = true - - return drvCapabilityInfo -} - -var cblogger *logrus.Logger - -func init() { - // cblog is a global variable. - cblogger = cblog.GetLogger("CB-SPIDER TencentDriver") -} - -func getVmClient(connectionInfo idrv.ConnectionInfo) (*cvm.Client, error) { - // setup Region - cblogger.Debug("TencentDriver : getVpcClient() - Region : [" + connectionInfo.RegionInfo.Region + "]") - cblogger.Debug("TencentDriver : getVpcClient() - Zone : [" + connectionInfo.RegionInfo.Zone + "]") - cblogger.Debug("TencentDriver : getVpcClient() - ClientId : [" + connectionInfo.CredentialInfo.ClientId + "]") - - zoneId := connectionInfo.RegionInfo.Zone - if len(zoneId) < 1 { - cblogger.Error("Connection 정보에 Zone 정보가 없습니다.") - return nil, errors.New("Connection 정보에 Zone 정보가 없습니다") - } - - credential := common.NewCredential( - connectionInfo.CredentialInfo.ClientId, - connectionInfo.CredentialInfo.ClientSecret, - ) - - cpf := profile.NewClientProfile() - cpf.HttpProfile.Endpoint = "cvm.tencentcloudapi.com" - client, err := cvm.NewClient(credential, connectionInfo.RegionInfo.Region, cpf) - - if err != nil { - cblogger.Error("Could not create aws New Session") - cblogger.Error(err) - // fmt.Println("Could not create aws New Session", err) - return nil, err - } - - return client, nil -} - -func getVpcClient(connectionInfo idrv.ConnectionInfo) (*vpc.Client, error) { - // setup Region - cblogger.Debug("TencentDriver : getVpcClient() - Region : [" + connectionInfo.RegionInfo.Region + "]") - cblogger.Debug("TencentDriver : getVpcClient() - Zone : [" + connectionInfo.RegionInfo.Zone + "]") - cblogger.Debug("TencentDriver : getVpcClient() - ClientId : [" + connectionInfo.CredentialInfo.ClientId + "]") - - zoneId := connectionInfo.RegionInfo.Zone - if len(zoneId) < 1 { - cblogger.Error("Connection 정보에 Zone 정보가 없습니다.") - return nil, errors.New("Connection 정보에 Zone 정보가 없습니다") - } - - credential := common.NewCredential( - connectionInfo.CredentialInfo.ClientId, - connectionInfo.CredentialInfo.ClientSecret, - ) - - cpf := profile.NewClientProfile() - cpf.HttpProfile.Endpoint = "vpc.tencentcloudapi.com" - client, err := vpc.NewClient(credential, connectionInfo.RegionInfo.Region, cpf) - - if err != nil { - cblogger.Error("Could not create aws New Session") - cblogger.Error(err) - // fmt.Println("Could not create aws New Session", err) - return nil, err - } - - return client, nil -} - -func (driver *TencentDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of Test A Cloud with credential info. - // 3. create CloudConnection Instance of "connect/TDA_CloudConnection". - // 4. return CloudConnection Interface of TDA_CloudConnection. - - //fmt.Println("ConnectCloud의 전달 받은 idrv.ConnectionInfo 정보") - //spew.Dump(connectionInfo) - - // sample code, do not user like this^^ - //var iConn icon.CloudConnection - vmClient, err := getVmClient(connectionInfo) - if err != nil { - cblogger.Error(err) - return nil, err - } - - vpcClient, err := getVpcClient(connectionInfo) - if err != nil { - cblogger.Error(err) - return nil, err - } - - iConn := tcon.TencentCloudConnection{ - Region: connectionInfo.RegionInfo, - VNetworkClient: vpcClient, - - VMClient: vmClient, - KeyPairClient: vmClient, - ImageClient: vmClient, - SecurityClient: vpcClient, - VmSpecClient: vmClient, - - //VNicClient: vmClient, - //PublicIPClient: vmClient, - } - - return &iConn, nil // return type: (icon.CloudConnection, error) -} - -/* -func (TencentDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) { - // 1. get info of credential and region for Test A Cloud from connectionInfo. - // 2. create a client object(or service object) of Test A Cloud with credential info. - // 3. create CloudConnection Instance of "connect/TDA_CloudConnection". - // 4. return CloudConnection Interface of TDA_CloudConnection. - // sample code, do not user like this^^ - var iConn icon.CloudConnection - iConn = tcon.TencentCloudConnection{} - return iConn, nil // return type: (icon.CloudConnection, error) -} -*/ -var CloudDriver TencentDriver +var CloudDriver tencent.TencentDriver diff --git a/cloud-control-manager/cloud-driver/drivers/tencent/TencentDriver.go b/cloud-control-manager/cloud-driver/drivers/tencent/TencentDriver.go index 9bf589e0c..8228ebdbc 100644 --- a/cloud-control-manager/cloud-driver/drivers/tencent/TencentDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/tencent/TencentDriver.go @@ -8,8 +8,6 @@ // // by CB-Spider Team, 2019.06. -//package main - package tencent import ( @@ -173,4 +171,3 @@ func (TencentDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.Clou return iConn, nil // return type: (icon.CloudConnection, error) } */ -var CloudDriver TencentDriver