-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix duplicate code between StaticDriver and PluginDriver
- Loading branch information
1 parent
e78e8ca
commit b32ee07
Showing
21 changed files
with
31 additions
and
1,273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.