Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
powerkimhub committed Jun 7, 2024
2 parents fc63f47 + 22301c3 commit 3027ea7
Show file tree
Hide file tree
Showing 51 changed files with 1,334 additions and 1,361 deletions.
46 changes: 23 additions & 23 deletions cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
package alibaba

import (
"fmt"

cs2015 "github.com/alibabacloud-go/cs-20151215/v4/client"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
ecs2014 "github.com/alibabacloud-go/ecs-20140526/v4/client"
"github.com/alibabacloud-go/tea/tea"
vpc2016 "github.com/alibabacloud-go/vpc-20160428/v6/client"
"github.com/sirupsen/logrus"

"github.com/aliyun/alibaba-cloud-sdk-go/services/bssopenapi"
"github.com/aliyun/alibaba-cloud-sdk-go/services/slb"
Expand All @@ -28,13 +27,19 @@ import (
"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"
cblogger "github.com/cloud-barista/cb-log"
alicon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/alibaba/connect"
alirs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/alibaba/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"
"github.com/davecgh/go-spew/spew"
)

var cblog *logrus.Logger

func init() {
cblog = cblogger.GetLogger("CLOUD-BARISTA")
}

type AlibabaDriver struct{}

func (AlibabaDriver) GetDriverVersion() string {
Expand Down Expand Up @@ -132,7 +137,7 @@ func (driver *AlibabaDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (i
func getECSClient(connectionInfo idrv.ConnectionInfo) (*ecs.Client, error) {

// Region Info
fmt.Println("AlibabaDriver : getECSClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")
cblog.Info("AlibabaDriver : getECSClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")

/*
// Customize config
Expand All @@ -142,8 +147,6 @@ func getECSClient(connectionInfo idrv.ConnectionInfo) (*ecs.Client, error) {
WithMaxTaskQueueSize(1000)
// 600*time.Second
//fmt.Println(config)
spew.Dump(config)
*/

// Create a credential object
Expand All @@ -169,13 +172,10 @@ func getECSClient(connectionInfo idrv.ConnectionInfo) (*ecs.Client, error) {

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)
cblog.Error("Could not create alibaba's ecs service client", err)
return nil, err
}

//spew.Dump(escClient)

/*
escClient, err := sdk.NewClientWithAccessKey("REGION_ID", "ACCESS_KEY_ID", "ACCESS_KEY_SECRET")
if err != nil {
Expand All @@ -190,7 +190,7 @@ func getECSClient(connectionInfo idrv.ConnectionInfo) (*ecs.Client, error) {
func getVPCClient(connectionInfo idrv.ConnectionInfo) (*vpc.Client, error) {

// Region Info
fmt.Println("AlibabaDriver : getVPCClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")
cblog.Info("AlibabaDriver : getVPCClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")

/*
// Customize config
Expand All @@ -199,7 +199,7 @@ func getVPCClient(connectionInfo idrv.ConnectionInfo) (*vpc.Client, error) {
WithGoRoutinePoolSize(5).
WithMaxTaskQueueSize(1000)
// 600*time.Second
//fmt.Println(config)
*/

// Create a credential object
Expand All @@ -224,7 +224,7 @@ func getVPCClient(connectionInfo idrv.ConnectionInfo) (*vpc.Client, error) {
//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)
cblog.Error("Could not create alibaba's vpc service client", err)
return nil, err
}

Expand All @@ -234,7 +234,7 @@ func getVPCClient(connectionInfo idrv.ConnectionInfo) (*vpc.Client, error) {
func getNLBClient(connectionInfo idrv.ConnectionInfo) (*slb.Client, error) {

// Region Info
fmt.Println("AlibabaDriver : getNLBClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")
cblog.Info("AlibabaDriver : getNLBClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")

credential := &credentials.AccessKeyCredential{
AccessKeyId: connectionInfo.CredentialInfo.ClientId,
Expand All @@ -249,7 +249,7 @@ func getNLBClient(connectionInfo idrv.ConnectionInfo) (*slb.Client, error) {

nlbClient, err := slb.NewClientWithOptions(connectionInfo.RegionInfo.Region, config, credential)
if err != nil {
fmt.Println("Could not create alibaba's server loadbalancer service client", err)
cblog.Error("Could not create alibaba's server loadbalancer service client", err)
return nil, err
}

Expand All @@ -258,7 +258,7 @@ func getNLBClient(connectionInfo idrv.ConnectionInfo) (*slb.Client, error) {

func getBssClient(connectionInfo idrv.ConnectionInfo) (*bssopenapi.Client, error) {
// Region Info
fmt.Println("AlibabaDriver : getBssClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")
cblog.Info("AlibabaDriver : getBssClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")

credential := &credentials.AccessKeyCredential{
AccessKeyId: connectionInfo.CredentialInfo.ClientId,
Expand Down Expand Up @@ -298,7 +298,7 @@ func getBssClient(connectionInfo idrv.ConnectionInfo) (*bssopenapi.Client, error

bssClient, err := bssopenapi.NewClientWithOptions(targetRegion, config, credential)
if err != nil {
fmt.Println("Could not create alibaba's server bss open api client", err)
cblog.Error("Could not create alibaba's server bss open api client", err)
return nil, err
}

Expand All @@ -308,7 +308,7 @@ func getBssClient(connectionInfo idrv.ConnectionInfo) (*bssopenapi.Client, error
func getVpc2016Client(connectionInfo idrv.ConnectionInfo) (*vpc2016.Client, error) {

// Region Info
fmt.Println("AlibabaDriver : getVpc2016Client() - Region : [" + connectionInfo.RegionInfo.Region + "]")
cblog.Info("AlibabaDriver : getVpc2016Client() - Region : [" + connectionInfo.RegionInfo.Region + "]")

config := &openapi.Config{
AccessKeyId: tea.String(connectionInfo.CredentialInfo.ClientId),
Expand All @@ -318,7 +318,7 @@ func getVpc2016Client(connectionInfo idrv.ConnectionInfo) (*vpc2016.Client, erro

vpcClient, err := vpc2016.NewClient(config)
if err != nil {
fmt.Println("Could not create alibaba's vpc service client", err)
cblog.Error("Could not create alibaba's vpc service client", err)
return nil, err
}

Expand All @@ -328,7 +328,7 @@ func getVpc2016Client(connectionInfo idrv.ConnectionInfo) (*vpc2016.Client, erro
func getCs2015Client(connectionInfo idrv.ConnectionInfo) (*cs2015.Client, error) {

// Region Info
fmt.Println("AlibabaDriver : getCs2015Client() - Region : [" + connectionInfo.RegionInfo.Region + "]")
cblog.Info("AlibabaDriver : getCs2015Client() - Region : [" + connectionInfo.RegionInfo.Region + "]")

config := &openapi.Config{
AccessKeyId: tea.String(connectionInfo.CredentialInfo.ClientId),
Expand All @@ -338,7 +338,7 @@ func getCs2015Client(connectionInfo idrv.ConnectionInfo) (*cs2015.Client, error)

csClient, err := cs2015.NewClient(config)
if err != nil {
fmt.Println("Could not create alibaba's cs service client", err)
cblog.Error("Could not create alibaba's cs service client", err)
return nil, err
}

Expand All @@ -348,7 +348,7 @@ func getCs2015Client(connectionInfo idrv.ConnectionInfo) (*cs2015.Client, error)
func getEcs2014Client(connectionInfo idrv.ConnectionInfo) (*ecs2014.Client, error) {

// Region Info
fmt.Println("AlibabaDriver : getEcs2014Client() - Region : [" + connectionInfo.RegionInfo.Region + "]")
cblog.Info("AlibabaDriver : getEcs2014Client() - Region : [" + connectionInfo.RegionInfo.Region + "]")

config := &openapi.Config{
AccessKeyId: tea.String(connectionInfo.CredentialInfo.ClientId),
Expand All @@ -358,7 +358,7 @@ func getEcs2014Client(connectionInfo idrv.ConnectionInfo) (*ecs2014.Client, erro

ecsClient, err := ecs2014.NewClient(config)
if err != nil {
fmt.Println("Could not create alibaba's ecs service client", err)
cblog.Error("Could not create alibaba's ecs service client", err)
return nil, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/davecgh/go-spew/spew"
"reflect"
"strconv"
"sync"
Expand All @@ -24,7 +25,6 @@ import (
call "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/call-log"
idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces"
irs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources"
"github.com/davecgh/go-spew/spew"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -153,7 +153,7 @@ func SetNameTag(Client *ecs.Client, resourceId string, resourceType string, valu
}
_, errtag := Client.AddTags(request)
if errtag != nil {
cblogger.Error("Name Tag 설정 실패 : ")
cblogger.Error("Name Tag setting failed: ")
cblogger.Error(errtag)
return false
}
Expand All @@ -165,7 +165,7 @@ func SetNameTag(Client *ecs.Client, resourceId string, resourceType string, valu
func ConvertJsonString(v interface{}) (string, error) {
jsonBytes, errJson := json.Marshal(v)
if errJson != nil {
cblogger.Error("JSON 변환 실패")
cblogger.Error("JSON conversion failed")
cblogger.Error(errJson)
return "", errJson
}
Expand Down Expand Up @@ -203,14 +203,16 @@ func ConvertToString(value interface{}) (string, error) {

// Cloud Object를 CB-KeyValue 형식으로 변환이 필요할 경우 이용
func ConvertKeyValueList(v interface{}) ([]irs.KeyValue, error) {
spew.Dump(v)
if cblogger.Level.String() == "debug" {
spew.Dump(v)
}

var keyValueList []irs.KeyValue
var i map[string]interface{}

jsonBytes, errJson := json.Marshal(v)
if errJson != nil {
cblogger.Error("KeyValue 변환 실패")
cblogger.Error("KeyValue conversion failed")
cblogger.Error(errJson)
return nil, errJson
}
Expand All @@ -230,7 +232,7 @@ func ConvertKeyValueList(v interface{}) ([]irs.KeyValue, error) {
//value := fmt.Sprint(v)
value, errString := ConvertToString(v)
if errString != nil {
cblogger.Errorf("Key[%s]의 값은 변환 불가 - [%s]", k, errString)
cblogger.Errorf("The value for Key[%s] cannot be converted - [%s]", k, errString)
continue
}
keyValueList = append(keyValueList, irs.KeyValue{k, value})
Expand All @@ -244,8 +246,8 @@ func ConvertKeyValueList(v interface{}) ([]irs.KeyValue, error) {
// array에 주어진 string이 있는지 체크
func ContainString(s []string, str string) bool {
for _, v := range s {
cblogger.Info(v + " : " + str)
cblogger.Info(v == str)
cblogger.Debug(v + " : " + str)
cblogger.Debug(v == str)
if v == str {
return true
}
Expand All @@ -260,9 +262,9 @@ json 형태로 출력
func printToJson(class interface{}) {
e, err := json.Marshal(class)
if err != nil {
cblogger.Info(err)
cblogger.Error(err)
}
cblogger.Info(string(e))
cblogger.Debug(string(e))
}

// irs.KeyValue 배열에서 특정 키를 가진 KeyValue 가 있는지 검사
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func DescribeDisks(client *ecs.Client, regionInfo idrv.RegionInfo, instanceIID i
resultDiskList = append(resultDiskList, result.Disks.Disk...)
if CBPageOn {
totalCount = len(resultDiskList)
cblogger.Infof("CSP 전체 Disk 갯수 : [%d] - 현재 페이지:[%d] - 누적 결과 개수:[%d]", result.TotalCount, curPage, totalCount)
cblogger.Infof("Total number of disks across CSP: [%d] - Current page: [%d] - Accumulated result count: [%d]", result.TotalCount, curPage, totalCount)
if totalCount >= result.TotalCount {
break
}
Expand All @@ -93,7 +93,7 @@ func DescribeDisks(client *ecs.Client, regionInfo idrv.RegionInfo, instanceIID i
break
}
}
cblogger.Info(cblogger.Level.String())

if cblogger.Level.String() == "debug" {
spew.Dump(resultDiskList)
}
Expand Down Expand Up @@ -190,7 +190,7 @@ func DescribeAvailableResource(client *ecs.Client, regionId string, zoneId strin
//request.DataDiskCategory = "cloud"
//spew.Dump(request)
result, err := client.DescribeAvailableResource(request)
cblogger.Info(result)
cblogger.Debug(result)
if err != nil {
cblogger.Errorf("DescribeAvailableResource %v.", err)
}
Expand Down Expand Up @@ -222,7 +222,7 @@ func DescribeAvailableSystemDisksByInstanceType(client *ecs.Client, regionId str
request.InstanceType = insTanceType

result, err := client.DescribeAvailableResource(request)
cblogger.Info(result)
cblogger.Debug(result)
if err != nil {
cblogger.Errorf("DescribeAvailableResource %v.", err)
}
Expand Down Expand Up @@ -267,7 +267,7 @@ func AttachDisk(client *ecs.Client, regionInfo idrv.RegionInfo, ownerVM irs.IID,
callLogStart := call.Start()
result, err := client.AttachDisk(request)
callLogInfo.ElapsedTime = call.Elapsed(callLogStart)
cblogger.Info(result)
cblogger.Debug(result)
if err != nil {
callLogInfo.ErrorMSG = err.Error()
callogger.Error(call.String(callLogInfo))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"errors"
"fmt"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -284,7 +283,7 @@ func (diskHandler *AlibabaDiskHandler) ChangeDiskSize(diskIID irs.IID, size stri

result, err := diskHandler.Client.ResizeDisk(request)
hiscallInfo.ElapsedTime = call.Elapsed(start)
cblogger.Info(result)
cblogger.Debug(result)
if err != nil {
LoggingError(hiscallInfo, err)

Expand Down Expand Up @@ -312,7 +311,7 @@ func (diskHandler *AlibabaDiskHandler) DeleteDisk(diskIID irs.IID) (bool, error)

result, err := diskHandler.Client.DeleteDisk(request)
hiscallInfo.ElapsedTime = call.Elapsed(start)
cblogger.Info(result)
cblogger.Debug(result)
if err != nil {
LoggingError(hiscallInfo, err)

Expand Down Expand Up @@ -437,7 +436,7 @@ func (diskHandler *AlibabaDiskHandler) DetachDisk(diskIID irs.IID, ownerVM irs.I

result, err := diskHandler.Client.DetachDisk(request)
hiscallInfo.ElapsedTime = call.Elapsed(start)
cblogger.Info(result)
cblogger.Debug(result)
if err != nil {
LoggingError(hiscallInfo, err)

Expand Down Expand Up @@ -531,12 +530,12 @@ func validateCreateDisk(diskReqInfo *irs.DiskInfo) error {
}

if reqDiskSize < diskSizeValue.diskMinSize {
fmt.Println("Disk Size Error!!: ", reqDiskSize, diskSizeValue.diskMinSize, diskSizeValue.diskMaxSize)
cblogger.Error("Disk Size Error!!: ", reqDiskSize, diskSizeValue.diskMinSize, diskSizeValue.diskMaxSize)
return errors.New("Disk Size must be at least the default size (" + strconv.FormatInt(diskSizeValue.diskMinSize, 10) + " GB).")
}

if reqDiskSize > diskSizeValue.diskMaxSize {
fmt.Println("Disk Size Error!!: ", reqDiskSize, diskSizeValue.diskMinSize, diskSizeValue.diskMaxSize)
cblogger.Error("Disk Size Error!!: ", reqDiskSize, diskSizeValue.diskMinSize, diskSizeValue.diskMaxSize)
return errors.New("Disk Size must be smaller than the maximum size (" + strconv.FormatInt(diskSizeValue.diskMaxSize, 10) + " GB).")
}

Expand Down Expand Up @@ -606,12 +605,12 @@ func validateModifyDisk(diskReqInfo irs.DiskInfo, diskSize string) error {
}

if targetDiskSize < diskSizeValue.diskMinSize {
fmt.Println("Disk Size Error!!: ", targetDiskSize, diskSizeValue.diskMinSize, diskSizeValue.diskMaxSize)
cblogger.Error("Disk Size Error!!: ", targetDiskSize, diskSizeValue.diskMinSize, diskSizeValue.diskMaxSize)
return errors.New("Disk Size must be at least the default size (" + strconv.FormatInt(diskSizeValue.diskMinSize, 10) + " GB).")
}

if targetDiskSize > diskSizeValue.diskMaxSize {
fmt.Println("Disk Size Error!!: ", targetDiskSize, diskSizeValue.diskMinSize, diskSizeValue.diskMaxSize)
cblogger.Error("Disk Size Error!!: ", targetDiskSize, diskSizeValue.diskMinSize, diskSizeValue.diskMaxSize)
return errors.New("Disk Size must be smaller than the maximum size (" + strconv.FormatInt(diskSizeValue.diskMaxSize, 10) + " GB).")
}

Expand Down
Loading

0 comments on commit 3027ea7

Please sign in to comment.