From 51e6db90a8c3a75b76bbf8dd47074f9d2a812c59 Mon Sep 17 00:00:00 2001 From: dogfootman Date: Tue, 19 Sep 2023 06:04:37 +0900 Subject: [PATCH 1/8] =?UTF-8?q?Alibaba=20RegionZone=20Api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drivers/alibaba/AlibabaDriver.go | 10 +- .../alibaba/connect/AlibabaCloudConnection.go | 18 +- .../drivers/alibaba/main/Test_Resources.go | 63 +++- .../alibaba/resources/CommonHandler.go | 64 ++++ .../alibaba/resources/RegionZoneHandler.go | 304 ++++++++++++++++++ 5 files changed, 446 insertions(+), 13 deletions(-) create mode 100644 cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go b/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go index 658186cd6..12725c1ea 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go @@ -47,6 +47,7 @@ func (AlibabaDriver) GetDriverCapability() idrv.DriverCapabilityInfo { drvCapabilityInfo.VMSpecHandler = false drvCapabilityInfo.DiskHandler = false drvCapabilityInfo.ClusterHandler = true + drvCapabilityInfo.RegionZoneHandler = false return drvCapabilityInfo } @@ -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 } diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/connect/AlibabaCloudConnection.go b/cloud-control-manager/cloud-driver/drivers/alibaba/connect/AlibabaCloudConnection.go index 7384f5176..a0483b856 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/connect/AlibabaCloudConnection.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/connect/AlibabaCloudConnection.go @@ -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 + SubnetClient *vpc.Client + VmSpecClient *ecs.Client + NLBClient *slb.Client + DiskClient *ecs.Client + MyImageClient *ecs.Client + RegionZoneClient *ecs.Client } -// CreateRegionZoneHandler implements connect.CloudConnection. -func (*AlibabaCloudConnection) CreateRegionZoneHandler() (irs.RegionZoneHandler, error) { - return nil, errors.New("Driver: not implemented") +func (cloudConn *AlibabaCloudConnection) CreateRegionZoneHandler() (irs.RegionZoneHandler, error) { + regionZoneHandler := alirs.AlibabaRegionZoneHandler{Region: cloudConn.Region, Client: cloudConn.RegionZoneClient} + + return ®ionZoneHandler, nil } /* diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go b/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go index 4b40a9846..b56815459 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go @@ -1511,6 +1511,66 @@ 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 ") + + 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) + } + + } + } + } +} + func main() { cblogger.Info("Alibaba Cloud Resource Test") cblogger.Debug("Debug mode") @@ -1521,10 +1581,11 @@ func main() { //handleSecurity() //handleKeyPair() //handleVM() - handleNLB() + //handleNLB() //handlePublicIP() // PublicIP 생성 후 conf //handleVNic() //Lancard + handleRegionZone() /* //StartTime := "2020-05-07T01:35:00Z" diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go index 22479c5cf..e8b4aa151 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go @@ -559,3 +559,67 @@ func GetSnapShotIdList(ecsImage ecs.Image) []string { return snapShotIdList } + +// Region status +func GetRegionStatus(status string) irs.ZoneStatus { + if status == "UP" { + return irs.ZoneAvailable + } else { + return irs.ZoneUnavailable + } +} + +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: "", + 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 +} diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go new file mode 100644 index 000000000..219e8e666 --- /dev/null +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go @@ -0,0 +1,304 @@ +package resources + +// https://next.api.alibabacloud.com/document/Ecs/2014-05-26/DescribeRegions +// https://next.api.alibabacloud.com/document/Ecs/2014-05-26/DescribeZones +// https://next.api.alibabacloud.com/api/Ecs/2014-05-26/DescribeRegions?lang=GO + +import ( + "fmt" + "reflect" + + "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs" + 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" +) + +type AlibabaRegionZoneHandler struct { + Region idrv.RegionInfo + Client *ecs.Client +} + +// 모든 Region 및 Zone 정보 조회 +func (regionZoneHandler AlibabaRegionZoneHandler) ListRegionZone() ([]*irs.RegionZoneInfo, error) { + var regionZoneInfoList []*irs.RegionZoneInfo + + 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: regionZoneHandler.Region.Zone, + // ResourceType: call.REGIONZONE, + // ResourceName: "Regions", + // CloudOSAPI: "ListRegionZone()", + // ElapsedTime: "", + // ErrorMSG: "", + // } + // callLogStart := call.Start() + // result, err := regionZoneHandler.Client.DescribeRegions(request) + // callLogInfo.ElapsedTime = call.Elapsed(callLogStart) + // if err != nil { + // callLogInfo.ErrorMSG = err.Error() + // callogger.Error(call.String(callLogInfo)) + // return regionZoneInfoList, err + // } + // callogger.Info(call.String(callLogInfo)) + result, err := DescribeRegions(regionZoneHandler.Client) + if err != nil { + return regionZoneInfoList, err + } + + for _, item := range result.Regions.Region { + regionId := item.RegionId + + info := irs.RegionZoneInfo{} + info.Name = regionId + info.DisplayName = item.LocalName + + regionStatus := GetRegionStatus(item.Status) + cblogger.Info("regionStatus ", regionStatus) + + // ZoneList + var zoneInfoList []irs.ZoneInfo + + zonesResult, err := DescribeZonesByRegion(regionZoneHandler.Client, regionId) + if err != nil { + cblogger.Debug("DescribeZone failed ", err) + } + for _, zone := range zonesResult.Zones.Zone { + zoneInfo := irs.ZoneInfo{} + zoneInfo.Name = zone.ZoneId + zoneInfo.DisplayName = zone.LocalName + zoneInfo.Status = regionStatus + + keyValueList := []irs.KeyValue{} + itemType := reflect.TypeOf(zone) + if itemType.Kind() == reflect.Ptr { + itemType = itemType.Elem() + } + itemValue := reflect.ValueOf(zone) + if itemValue.Kind() == reflect.Ptr { + itemValue = itemValue.Elem() + } + numFields := itemType.NumField() + + // 속성 이름과 값을 출력합니다. + for i := 0; i < numFields; i++ { + field := itemType.Field(i) + value := itemValue.Field(i).Interface() + + keyValue := irs.KeyValue{} + keyValue.Key = field.Name + keyValue.Value = fmt.Sprintf("%v", value) + keyValueList = append(keyValueList, keyValue) + } + zoneInfo.KeyValueList = keyValueList + + zoneInfoList = append(zoneInfoList, zoneInfo) + } + info.ZoneList = zoneInfoList + // "ZoneType": "AvailabilityZone", + // "LocalName": "曼谷 可用区A", + // "ZoneId": "ap-southeast-7a", + + keyValueList := []irs.KeyValue{} + keyValue := irs.KeyValue{} + keyValue.Key = "RegionEndpoint" + keyValue.Value = item.RegionEndpoint + info.KeyValueList = keyValueList + + regionZoneInfoList = append(regionZoneInfoList, &info) + } + + return regionZoneInfoList, err + +} + +// 모든 Region 정보 조회(json return) +func (regionZoneHandler AlibabaRegionZoneHandler) ListOrgRegion() (string, 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: regionZoneHandler.Region.Zone, + // ResourceType: call.REGIONZONE, + // ResourceName: "", + // CloudOSAPI: "ListOrgRegion()", + // ElapsedTime: "", + // ErrorMSG: "", + // } + + // callLogStart := call.Start() + // result, err := regionZoneHandler.Client.DescribeRegions(request) + // callLogInfo.ElapsedTime = call.Elapsed(callLogStart) + // if err != nil { + // callLogInfo.ErrorMSG = err.Error() + // callogger.Error(call.String(callLogInfo)) + // return "", err + // } + // callogger.Info(call.String(callLogInfo)) + + result, err := DescribeRegions(regionZoneHandler.Client) + if err != nil { + return "", err + } + + jsonString, errJson := ConvertJsonString(result.Regions) + if errJson != nil { + cblogger.Error(errJson) + } + return jsonString, errJson + +} + +// 모든 Zone 정보 조회(json return) +// Region에 따라 zone 정보가 달려있으므로 region 조회 후 -> zone 정보 조회 +func (regionZoneHandler AlibabaRegionZoneHandler) ListOrgZone() (string, error) { + + // request := ecs.CreateDescribeZonesRequest() + // 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: regionZoneHandler.Region.Zone, + // ResourceType: call.REGIONZONE, + // ResourceName: "", + // CloudOSAPI: "ListOrgZone()", + // ElapsedTime: "", + // ErrorMSG: "", + // } + + // callLogStart := call.Start() + // result, err := regionZoneHandler.Client.DescribeZones(request) + // callLogInfo.ElapsedTime = call.Elapsed(callLogStart) + // if err != nil { + // callLogInfo.ErrorMSG = err.Error() + // callogger.Error(call.String(callLogInfo)) + // return "", err + // } + // callogger.Info(call.String(callLogInfo)) + + regionsResult, err := DescribeRegions(regionZoneHandler.Client) + if err != nil { + return "", err + } + + //zoneList := map[string]*ecs.DescribeZonesResponse{} + zoneList := make(map[string]*ecs.DescribeZonesResponse) + for _, item := range regionsResult.Regions.Region { + + regionId := item.RegionId + zonesResult, err := DescribeZonesByRegion(regionZoneHandler.Client, regionId) + + if err != nil { + return "", err + } + zoneList[regionId] = zonesResult + } + + jsonString, errJson := ConvertJsonString(zoneList) + if errJson != nil { + cblogger.Error(errJson) + } + return jsonString, errJson +} + +// regionList Result +// { +// "RequestId": "509F4448-81A7-3EB2-9D9D-2FC0BFD1AE86", +// "Regions": { +// "Region": [ +// { +// "RegionId": "cn-qingdao", +// "RegionEndpoint": "ecs.cn-qingdao.aliyuncs.com", +// "LocalName": "China (Qingdao)" +// }, +// { +// "RegionId": "cn-beijing", +// "RegionEndpoint": "ecs.cn-beijing.aliyuncs.com", +// "LocalName": "China (Beijing)" +// }, + +// zoneList Result +// { +// "RequestId": "153128B3-EAE6-316D-A0DF-9B33D71C4C6B", +// "Zones": { +// "Zone": [ +// { +// "ZoneId": "ap-southeast-7a", +// "ZoneType": "AvailabilityZone", +// "LocalName": "曼谷 可用区A", +// "AvailableResourceCreation": { +// "ResourceTypes": [ +// "VSwitch", "IoOptimized", "Instance", "DedicatedHost", "Disk" +// ] +// }, +// "DedicatedHostGenerations": { +// "DedicatedHostGeneration": [ +// "ddh-5", +// "ddh-4" +// ] +// }, +// "AvailableInstanceTypes": { +// "InstanceTypes": [ +// "ecs.c6e.8xlarge",... +// ] +// }, +// "AvailableDedicatedHostTypes": { +// "DedicatedHostType": [ +// "ddh.g6", "ddh.g5nse", "ddh.g6e", "ddh.c6" +// ] +// }, +// "AvailableResources": { +// "ResourcesInfo": [ +// { +// "InstanceGenerations": { +// "supportedInstanceGeneration": [ +// "ecs-5", "ecs-4", "ecs-6" +// ] +// }, +// "NetworkTypes": { +// "supportedNetworkCategory": [ +// "vpc" +// ] +// }, +// "IoOptimized": true, +// "SystemDiskCategories": { +// "supportedSystemDiskCategory": [ +// "cloud_auto", "cloud_essd" +// ] +// }, +// "InstanceTypes": { +// "supportedInstanceType": [ +// "ecs.c6e.8xlarge", ... +// ] +// }, +// "InstanceTypeFamilies": { +// "supportedInstanceTypeFamily": [ +// "ecs.gn7i",... +// ] +// }, +// "DataDiskCategories": { +// "supportedDataDiskCategory": [ +// "cloud_auto", "cloud_essd" +// ] +// } +// } +// ] +// }, +// "AvailableDiskCategories": { +// "DiskCategories": [ +// "cloud_auto", "cloud_essd" +// ] +// }, +// "AvailableVolumeCategories": { +// "VolumeCategories": [] +// } +// } +// ] +// } +// } From 033debd50fe7b1b9d12831e876cbe0b22d9ce676 Mon Sep 17 00:00:00 2001 From: dogfootman Date: Tue, 19 Sep 2023 07:07:57 +0900 Subject: [PATCH 2/8] =?UTF-8?q?alibaba=20region=20zone=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alibaba/connect/AlibabaCloudConnection.go | 2 +- .../alibaba/resources/CommonHandler.go | 29 +++++++++++++++++-- .../alibaba/resources/RegionZoneHandler.go | 11 +++---- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/connect/AlibabaCloudConnection.go b/cloud-control-manager/cloud-driver/drivers/alibaba/connect/AlibabaCloudConnection.go index a0483b856..75b74f516 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/connect/AlibabaCloudConnection.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/connect/AlibabaCloudConnection.go @@ -51,8 +51,8 @@ type AlibabaCloudConnection struct { } 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 ®ionZoneHandler, nil } diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go index e8b4aa151..a2ca7b181 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go @@ -578,12 +578,11 @@ func DescribeRegions(client *ecs.Client) (*ecs.DescribeRegionsResponse, error) { CloudOS: call.ALIBABA, RegionZone: "", ResourceType: call.REGIONZONE, - ResourceName: "", - CloudOSAPI: "ListRegions()", + ResourceName: "Regions", + CloudOSAPI: "ListRegionZone()", ElapsedTime: "", ErrorMSG: "", } - callLogStart := call.Start() result, err := client.DescribeRegions(request) callLogInfo.ElapsedTime = call.Elapsed(callLogStart) @@ -593,6 +592,30 @@ func DescribeRegions(client *ecs.Client) (*ecs.DescribeRegionsResponse, error) { 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 } diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go index 219e8e666..5733df188 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go @@ -22,8 +22,8 @@ type AlibabaRegionZoneHandler struct { func (regionZoneHandler AlibabaRegionZoneHandler) ListRegionZone() ([]*irs.RegionZoneInfo, error) { var regionZoneInfoList []*irs.RegionZoneInfo - request := ecs.CreateDescribeRegionsRequest() - request.AcceptLanguage = "en-US" // Only Chinese (zh-CN : default), English (en-US), and Japanese (ja) are allowed + // 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{ @@ -44,6 +44,7 @@ func (regionZoneHandler AlibabaRegionZoneHandler) ListRegionZone() ([]*irs.Regio // return regionZoneInfoList, err // } // callogger.Info(call.String(callLogInfo)) + result, err := DescribeRegions(regionZoneHandler.Client) if err != nil { return regionZoneInfoList, err @@ -61,7 +62,7 @@ func (regionZoneHandler AlibabaRegionZoneHandler) ListRegionZone() ([]*irs.Regio // ZoneList var zoneInfoList []irs.ZoneInfo - + cblogger.Info("regionId ", regionId) zonesResult, err := DescribeZonesByRegion(regionZoneHandler.Client, regionId) if err != nil { cblogger.Debug("DescribeZone failed ", err) @@ -117,8 +118,8 @@ func (regionZoneHandler AlibabaRegionZoneHandler) ListRegionZone() ([]*irs.Regio // 모든 Region 정보 조회(json return) func (regionZoneHandler AlibabaRegionZoneHandler) ListOrgRegion() (string, error) { - request := ecs.CreateDescribeRegionsRequest() - request.AcceptLanguage = "en-US" // Only Chinese (zh-CN : default), English (en-US), and Japanese (ja) are allowed + // 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{ From 9adef55edc3a85b660ae11b60ce2a42c01b83845 Mon Sep 17 00:00:00 2001 From: dogfootman Date: Tue, 19 Sep 2023 08:35:40 +0900 Subject: [PATCH 3/8] =?UTF-8?q?Test=20code=20=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drivers/alibaba/main/conf/Test_Config.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/main/conf/Test_Config.go b/cloud-control-manager/cloud-driver/drivers/alibaba/main/conf/Test_Config.go index a4c2ecc7e..ee3b132e0 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/main/conf/Test_Config.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/main/conf/Test_Config.go @@ -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) @@ -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) @@ -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 { From 607d564061c537e598731e54ced919e902706e3b Mon Sep 17 00:00:00 2001 From: dogfootman Date: Tue, 19 Sep 2023 08:49:47 +0900 Subject: [PATCH 4/8] =?UTF-8?q?GetRegionStatus=20=EB=B3=B4=EC=99=84.=20ava?= =?UTF-8?q?ilable,=20soldOut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloud-driver/drivers/alibaba/resources/CommonHandler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go index a2ca7b181..659ef5dc2 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go @@ -560,9 +560,9 @@ func GetSnapShotIdList(ecsImage ecs.Image) []string { return snapShotIdList } -// Region status +// Region status : available, soldOut func GetRegionStatus(status string) irs.ZoneStatus { - if status == "UP" { + if status == "available" { return irs.ZoneAvailable } else { return irs.ZoneUnavailable From b4c2b303cb2d9ba778091176c0d4be94970bf82d Mon Sep 17 00:00:00 2001 From: dogfootman Date: Tue, 19 Sep 2023 09:19:22 +0900 Subject: [PATCH 5/8] =?UTF-8?q?region=20Status=20=EB=A5=BC=20=EB=B9=84?= =?UTF-8?q?=EC=96=B4=EC=9E=88=EC=9D=84=20=EB=95=8C=EC=97=90=EB=8F=84=20ava?= =?UTF-8?q?ilable=EB=A1=9C=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloud-driver/drivers/alibaba/resources/CommonHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go index 659ef5dc2..6bcde2bce 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go @@ -562,7 +562,7 @@ func GetSnapShotIdList(ecsImage ecs.Image) []string { // Region status : available, soldOut func GetRegionStatus(status string) irs.ZoneStatus { - if status == "available" { + if status == "available" || status == "" { return irs.ZoneAvailable } else { return irs.ZoneUnavailable From b23596f17e10a915291fa1e86838b16e425516c9 Mon Sep 17 00:00:00 2001 From: dogfootman Date: Tue, 19 Sep 2023 09:33:30 +0900 Subject: [PATCH 6/8] =?UTF-8?q?Zone=EC=9D=98=20=EC=83=81=ED=83=9C=EA=B0=92?= =?UTF-8?q?=EC=9D=B4=20=EC=97=86=EC=9C=BC=EB=AF=80=EB=A1=9C=20set=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drivers/alibaba/resources/CommonHandler.go | 8 ++++++++ .../drivers/alibaba/resources/RegionZoneHandler.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go index 6bcde2bce..38f3ee996 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go @@ -569,6 +569,14 @@ func GetRegionStatus(status string) irs.ZoneStatus { } } +func GetZoneStatus(status string) irs.ZoneStatus { + if status == "available" { + return irs.ZoneAvailable + } else { + return irs.ZoneUnavailable + } +} + 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 diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go index 5733df188..80e8a154f 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go @@ -71,7 +71,7 @@ func (regionZoneHandler AlibabaRegionZoneHandler) ListRegionZone() ([]*irs.Regio zoneInfo := irs.ZoneInfo{} zoneInfo.Name = zone.ZoneId zoneInfo.DisplayName = zone.LocalName - zoneInfo.Status = regionStatus + //zoneInfo.Status = regionStatus // Zone의 상태값이 없으므로 set하지 않도록 변경. keyValueList := []irs.KeyValue{} itemType := reflect.TypeOf(zone) From 476676951cedce36e05de8622f67ca6aadbd2107 Mon Sep 17 00:00:00 2001 From: dogfootman Date: Tue, 19 Sep 2023 19:59:32 +0900 Subject: [PATCH 7/8] =?UTF-8?q?DriverCapability=20=EB=B3=B4=EC=99=84=20VNi?= =?UTF-8?q?cHandler=EC=99=B8=20=EA=B5=AC=ED=98=84=EB=90=9C=20handler=20tru?= =?UTF-8?q?e=EB=A1=9C=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drivers/alibaba/AlibabaDriver.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go b/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go index 12725c1ea..3424b8767 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/AlibabaDriver.go @@ -37,17 +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 = false + drvCapabilityInfo.RegionZoneHandler = true return drvCapabilityInfo } From f37f00f4f491cc98b0f2ebab33064d1f077e50eb Mon Sep 17 00:00:00 2001 From: dogfootman Date: Tue, 19 Sep 2023 20:29:54 +0900 Subject: [PATCH 8/8] =?UTF-8?q?ali=20GetRegionZone=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drivers/alibaba/main/Test_Resources.go | 10 +++ .../alibaba/resources/CommonHandler.go | 26 +++--- .../alibaba/resources/RegionZoneHandler.go | 81 ++++++++++++++++++- 3 files changed, 101 insertions(+), 16 deletions(-) diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go b/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go index b56815459..8d809c048 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go @@ -1527,6 +1527,7 @@ func handleRegionZone() { 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) @@ -1565,6 +1566,15 @@ func handleRegionZone() { 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) + } } } diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go index 38f3ee996..3e9c97d6a 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go @@ -561,20 +561,20 @@ func GetSnapShotIdList(ecsImage ecs.Image) []string { } // Region status : available, soldOut -func GetRegionStatus(status string) irs.ZoneStatus { - if status == "available" || status == "" { - return irs.ZoneAvailable - } else { - return irs.ZoneUnavailable - } -} - +// 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 { - if status == "available" { - return irs.ZoneAvailable - } else { - return irs.ZoneUnavailable - } + return irs.NotSupported } func DescribeRegions(client *ecs.Client) (*ecs.DescribeRegionsResponse, error) { diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go index 80e8a154f..a55b5234e 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/RegionZoneHandler.go @@ -57,8 +57,8 @@ func (regionZoneHandler AlibabaRegionZoneHandler) ListRegionZone() ([]*irs.Regio info.Name = regionId info.DisplayName = item.LocalName - regionStatus := GetRegionStatus(item.Status) - cblogger.Info("regionStatus ", regionStatus) + // regionStatus := GetRegionStatus(item.Status) + // cblogger.Info("regionStatus ", regionStatus) // ZoneList var zoneInfoList []irs.ZoneInfo @@ -71,7 +71,7 @@ func (regionZoneHandler AlibabaRegionZoneHandler) ListRegionZone() ([]*irs.Regio zoneInfo := irs.ZoneInfo{} zoneInfo.Name = zone.ZoneId zoneInfo.DisplayName = zone.LocalName - //zoneInfo.Status = regionStatus // Zone의 상태값이 없으므로 set하지 않도록 변경. + zoneInfo.Status = GetZoneStatus("") // Zone의 상태값이 없으므로 set하지 않도록 변경. keyValueList := []irs.KeyValue{} itemType := reflect.TypeOf(zone) @@ -208,6 +208,81 @@ func (regionZoneHandler AlibabaRegionZoneHandler) ListOrgZone() (string, error) return jsonString, errJson } +// 특정 Region에 대한 정보 조회. +func (regionZoneHandler AlibabaRegionZoneHandler) GetRegionZone(reqRegionId string) (irs.RegionZoneInfo, error) { + regionInfo := irs.RegionZoneInfo{} + result, err := DescribeRegions(regionZoneHandler.Client) + if err != nil { + return regionInfo, err + } + + for _, item := range result.Regions.Region { + regionId := item.RegionId + + if reqRegionId != regionId { + continue + } + + regionInfo.Name = regionId + regionInfo.DisplayName = item.LocalName + + // regionStatus := GetRegionStatus(item.Status) + // cblogger.Info("regionStatus ", regionStatus) + + // ZoneList + var zoneInfoList []irs.ZoneInfo + cblogger.Info("regionId ", regionId) + zonesResult, err := DescribeZonesByRegion(regionZoneHandler.Client, regionId) + if err != nil { + cblogger.Debug("DescribeZone failed ", err) + } + for _, zone := range zonesResult.Zones.Zone { + zoneInfo := irs.ZoneInfo{} + zoneInfo.Name = zone.ZoneId + zoneInfo.DisplayName = zone.LocalName + zoneInfo.Status = GetZoneStatus("") // Zone의 상태값이 없으므로 set하지 않도록 변경. + + keyValueList := []irs.KeyValue{} + itemType := reflect.TypeOf(zone) + if itemType.Kind() == reflect.Ptr { + itemType = itemType.Elem() + } + itemValue := reflect.ValueOf(zone) + if itemValue.Kind() == reflect.Ptr { + itemValue = itemValue.Elem() + } + numFields := itemType.NumField() + + // 속성 이름과 값을 출력합니다. + for i := 0; i < numFields; i++ { + field := itemType.Field(i) + value := itemValue.Field(i).Interface() + + keyValue := irs.KeyValue{} + keyValue.Key = field.Name + keyValue.Value = fmt.Sprintf("%v", value) + keyValueList = append(keyValueList, keyValue) + } + zoneInfo.KeyValueList = keyValueList + + zoneInfoList = append(zoneInfoList, zoneInfo) + } + regionInfo.ZoneList = zoneInfoList + // "ZoneType": "AvailabilityZone", + // "LocalName": "曼谷 可用区A", + // "ZoneId": "ap-southeast-7a", + + keyValueList := []irs.KeyValue{} + keyValue := irs.KeyValue{} + keyValue.Key = "RegionEndpoint" + keyValue.Value = item.RegionEndpoint + regionInfo.KeyValueList = keyValueList + + break + } + return regionInfo, nil +} + // regionList Result // { // "RequestId": "509F4448-81A7-3EB2-9D9D-2FC0BFD1AE86",