Skip to content

Commit

Permalink
Merge pull request #923 from MZC-CSC/feature_RegionZoneHandler_ALI
Browse files Browse the repository at this point in the history
[+Region/Zone] Alibaba Cloud Driver Implementation #911
  • Loading branch information
powerkimhub authored Sep 20, 2023
2 parents 75fcd97 + f37f00f commit 16e0872
Show file tree
Hide file tree
Showing 6 changed files with 580 additions and 28 deletions.
24 changes: 13 additions & 11 deletions cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ func (AlibabaDriver) GetDriverVersion() string {
func (AlibabaDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
var drvCapabilityInfo idrv.DriverCapabilityInfo

drvCapabilityInfo.ImageHandler = false
drvCapabilityInfo.VPCHandler = false
drvCapabilityInfo.SecurityHandler = false
drvCapabilityInfo.KeyPairHandler = false
drvCapabilityInfo.ImageHandler = true
drvCapabilityInfo.VPCHandler = true
drvCapabilityInfo.SecurityHandler = true
drvCapabilityInfo.KeyPairHandler = true
drvCapabilityInfo.VNicHandler = false
drvCapabilityInfo.PublicIPHandler = false
drvCapabilityInfo.VMHandler = false
drvCapabilityInfo.VMSpecHandler = false
drvCapabilityInfo.DiskHandler = false
drvCapabilityInfo.VMHandler = true
drvCapabilityInfo.VMSpecHandler = true
drvCapabilityInfo.DiskHandler = true
drvCapabilityInfo.ClusterHandler = true
drvCapabilityInfo.RegionZoneHandler = true

return drvCapabilityInfo
}
Expand Down Expand Up @@ -87,10 +88,11 @@ func (driver *AlibabaDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (i
//VNetClient: VPCClient,
//VNicClient: ECSClient,
//SubnetClient: VPCClient,
VmSpecClient: ECSClient,
NLBClient: NLBClient,
DiskClient: ECSClient,
MyImageClient: ECSClient,
VmSpecClient: ECSClient,
NLBClient: NLBClient,
DiskClient: ECSClient,
MyImageClient: ECSClient,
RegionZoneClient: ECSClient,
}
return &iConn, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ type AlibabaCloudConnection struct {
//VNetClient *vpc.Client
VpcClient *vpc.Client
//VNicClient *ecs.Client
SubnetClient *vpc.Client
VmSpecClient *ecs.Client
NLBClient *slb.Client
DiskClient *ecs.Client
MyImageClient *ecs.Client
}

// CreateRegionZoneHandler implements connect.CloudConnection.
func (*AlibabaCloudConnection) CreateRegionZoneHandler() (irs.RegionZoneHandler, error) {
return nil, errors.New("Driver: not implemented")
SubnetClient *vpc.Client
VmSpecClient *ecs.Client
NLBClient *slb.Client
DiskClient *ecs.Client
MyImageClient *ecs.Client
RegionZoneClient *ecs.Client
}

func (cloudConn *AlibabaCloudConnection) CreateRegionZoneHandler() (irs.RegionZoneHandler, error) {
//regionZoneHandler := alirs.AlibabaRegionZoneHandler{Region: cloudConn.Region, Client: cloudConn.RegionZoneClient}
regionZoneHandler := alirs.AlibabaRegionZoneHandler{Region: cloudConn.Region, Client: cloudConn.RegionZoneClient}
return &regionZoneHandler, nil
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,76 @@ func handleNLB() {
}
}

func handleRegionZone() {
cblogger.Debug("Start RegionZone Test")
ResourceHandler, err := testconf.GetResourceHandler("RegionZone")
if err != nil {
//panic(err)
cblogger.Error(err)
}
handler := ResourceHandler.(irs.RegionZoneHandler)
cblogger.Info(handler)

for {
fmt.Println("Handler Management")
fmt.Println("0. Quit")
fmt.Println("1. ListRegionZone List")
fmt.Println("2. ListOrgRegion ")
fmt.Println("3. ListOrgZone ")
fmt.Println("4. GetRegionZone ")

var commandNum int
inputCnt, err := fmt.Scan(&commandNum)
if err != nil {
panic(err)
}

if inputCnt == 1 {
switch commandNum {
case 0:
return

case 1:
result, err := handler.ListRegionZone()
if err != nil {
cblogger.Infof(" RegionZone 목록 조회 실패 : ", err)
} else {
cblogger.Info("RegionZone 목록 조회 결과")
spew.Dump(result)
}

case 2:
result, err := handler.ListOrgRegion()
if err != nil {
cblogger.Infof(" ListOrgRegion 목록 조회 실패 : ", err)
} else {
cblogger.Info("ListOrgRegion 목록 조회 결과")
spew.Dump(result)
}

case 3:
result, err := handler.ListOrgZone()
if err != nil {
cblogger.Infof(" ListOrgZone 목록 조회 실패 : ", err)
} else {
cblogger.Info("ListOrgZone 목록 조회 결과")
spew.Dump(result)
}
case 4:
regionId := "ap-northeast-2"
result, err := handler.GetRegionZone(regionId)
if err != nil {
cblogger.Infof(" GetRegionZone 조회 실패 : ", regionId, err)
} else {
cblogger.Info("GetRegionZone 조회 결과", regionId)
spew.Dump(result)
}

}
}
}
}

func main() {
cblogger.Info("Alibaba Cloud Resource Test")
cblogger.Debug("Debug mode")
Expand All @@ -1521,10 +1591,11 @@ func main() {
//handleSecurity()
//handleKeyPair()
//handleVM()
handleNLB()
//handleNLB()
//handlePublicIP() // PublicIP 생성 후 conf

//handleVNic() //Lancard
handleRegionZone()

/*
//StartTime := "2020-05-07T01:35:00Z"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ type Config struct {
} `yaml:"ali"`
}

//환경 설정 파일 읽기
//환경변수 CBSPIDER_PATH 설정 후 해당 폴더 하위에 /config/config.yaml 파일 생성해야 함.
// 환경 설정 파일 읽기
// 환경변수 CBSPIDER_PATH 설정 후 해당 폴더 하위에 /config/config.yaml 파일 생성해야 함.
func ReadConfigFile() Config {
// Set Environment Value of Project Root Path
rootPath := os.Getenv("CBSPIDER_PATH")
//rootpath := "D:/Workspace/mcloud-barista-config"
// /mnt/d/Workspace/mcloud-barista-config/config/config.yaml
cblogger.Debugf("Test Data 설정파일 : [%]", rootPath+"/config/configAli.yaml")
cblogger.Debugf("Test Data 설정파일 : [%]", rootPath+"/config/config.yaml")

data, err := ioutil.ReadFile(rootPath + "/config/configAli.yaml")
data, err := ioutil.ReadFile(rootPath + "/config/config.yaml")
//data, err := ioutil.ReadFile("D:/Workspace/mcloud-bar-config/config/config.yaml")
if err != nil {
panic(err)
Expand All @@ -91,8 +91,8 @@ func ReadConfigFile() Config {
return config
}

//handlerType : resources폴더의 xxxHandler.go에서 Handler이전까지의 문자열
//(예) ImageHandler.go -> "Image"
// handlerType : resources폴더의 xxxHandler.go에서 Handler이전까지의 문자열
// (예) ImageHandler.go -> "Image"
func GetResourceHandler(handlerType string) (interface{}, error) {
var cloudDriver idrv.CloudDriver
cloudDriver = new(alidrv.AlibabaDriver)
Expand Down Expand Up @@ -138,6 +138,8 @@ func GetResourceHandler(handlerType string) (interface{}, error) {
resourceHandler, err = cloudConnection.CreateVMHandler()
case "NLB":
resourceHandler, err = cloudConnection.CreateNLBHandler()
case "RegionZone":
resourceHandler, err = cloudConnection.CreateRegionZoneHandler()
}

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,98 @@ func GetSnapShotIdList(ecsImage ecs.Image) []string {

return snapShotIdList
}

// Region status : available, soldOut
// deprecated : Region에 대한 Status는 따로 관리하지 않음.
// func GetRegionStatus(status string) irs.ZoneStatus {
// if status == "available" || status == "Available" {
// return irs.ZoneAvailable
// } else if status == "soldOut" || status == "soldout" {
// return irs.ZoneUnavailable
// } else {
// return irs.NotSupported
// }
// }

// Alibaba에서 Zone에 대한 status는 관리하고 있지 않음
func GetZoneStatus(status string) irs.ZoneStatus {
return irs.NotSupported
}

func DescribeRegions(client *ecs.Client) (*ecs.DescribeRegionsResponse, error) {
request := ecs.CreateDescribeRegionsRequest()
request.AcceptLanguage = "en-US" // Only Chinese (zh-CN : default), English (en-US), and Japanese (ja) are allowed

callogger := call.GetLogger("HISCALL")
callLogInfo := call.CLOUDLOGSCHEMA{
CloudOS: call.ALIBABA,
RegionZone: "",
ResourceType: call.REGIONZONE,
ResourceName: "Regions",
CloudOSAPI: "ListRegionZone()",
ElapsedTime: "",
ErrorMSG: "",
}
callLogStart := call.Start()
result, err := client.DescribeRegions(request)
callLogInfo.ElapsedTime = call.Elapsed(callLogStart)
if err != nil {
callLogInfo.ErrorMSG = err.Error()
callogger.Error(call.String(callLogInfo))
return nil, err
}
callogger.Info(call.String(callLogInfo))

// request := ecs.CreateDescribeRegionsRequest()
// request.AcceptLanguage = "en-US" // Only Chinese (zh-CN : default), English (en-US), and Japanese (ja) are allowed

// callogger := call.GetLogger("HISCALL")
// callLogInfo := call.CLOUDLOGSCHEMA{
// CloudOS: call.ALIBABA,
// RegionZone: "",
// ResourceType: call.REGIONZONE,
// ResourceName: "",
// CloudOSAPI: "ListRegions()",
// ElapsedTime: "",
// ErrorMSG: "",
// }

// callLogStart := call.Start()
// result, err := client.DescribeRegions(request)
// callLogInfo.ElapsedTime = call.Elapsed(callLogStart)
// if err != nil {
// callLogInfo.ErrorMSG = err.Error()
// callogger.Error(call.String(callLogInfo))
// return nil, err
// }
// callogger.Info(call.String(callLogInfo))
return result, nil
}

func DescribeZonesByRegion(client *ecs.Client, regionId string) (*ecs.DescribeZonesResponse, error) {
request := ecs.CreateDescribeZonesRequest()
request.AcceptLanguage = "en-US" // Only Chinese (zh-CN : default), English (en-US), and Japanese (ja) are allowed
request.RegionId = regionId

callogger := call.GetLogger("HISCALL")
callLogInfo := call.CLOUDLOGSCHEMA{
CloudOS: call.ALIBABA,
RegionZone: "",
ResourceType: call.REGIONZONE,
ResourceName: "",
CloudOSAPI: "ListZones()",
ElapsedTime: "",
ErrorMSG: "",
}

callLogStart := call.Start()
result, err := client.DescribeZones(request)
callLogInfo.ElapsedTime = call.Elapsed(callLogStart)
if err != nil {
callLogInfo.ErrorMSG = err.Error()
callogger.Error(call.String(callLogInfo))
return nil, err
}
callogger.Info(call.String(callLogInfo))
return result, nil
}
Loading

0 comments on commit 16e0872

Please sign in to comment.