Skip to content

Commit

Permalink
Fix duplicate code between StaticDriver and PluginDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
powerkimhub committed Oct 27, 2021
1 parent e78e8ca commit b32ee07
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 1,273 deletions.
2 changes: 1 addition & 1 deletion build_all_driver_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,150 +8,11 @@
//
// by [email protected], 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package alibaba

import (
"C"
"fmt"

"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
Expand Down Expand Up @@ -183,4 +182,3 @@ func getVPCClient(connectionInfo idrv.ConnectionInfo) (*vpc.Client, error) {
return vpcClient, nil
}

var CloudDriver AlibabaDriver
115 changes: 2 additions & 113 deletions cloud-control-manager/cloud-driver/drivers/aws-plugin/AwsDriver-lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions cloud-control-manager/cloud-driver/drivers/aws/AwsDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -130,4 +126,3 @@ func (AwsDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudCon
return iConn, nil // return type: (icon.CloudConnection, error)
}
*/
var CloudDriver AwsDriver
Loading

0 comments on commit b32ee07

Please sign in to comment.