Skip to content

Commit

Permalink
ali GetRegionZone 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dogfootman committed Sep 19, 2023
1 parent 4766769 commit f37f00f
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit f37f00f

Please sign in to comment.