2017-03-03 04:19:16 -05:00
|
|
|
package ecs
|
|
|
|
|
|
|
|
import "github.com/denverdino/aliyungo/common"
|
|
|
|
|
|
|
|
type ResourceType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
ResourceTypeInstance = ResourceType("Instance")
|
|
|
|
ResourceTypeDisk = ResourceType("Disk")
|
|
|
|
ResourceTypeVSwitch = ResourceType("VSwitch")
|
|
|
|
ResourceTypeIOOptimizedInstance = ResourceType("IoOptimized")
|
|
|
|
)
|
|
|
|
|
2017-08-03 21:56:04 -04:00
|
|
|
// The sub-item of the type AvailableResourcesType
|
|
|
|
type SupportedResourceType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
SupportedInstanceType = SupportedResourceType("supportedInstanceType")
|
|
|
|
SupportedInstanceTypeFamily = SupportedResourceType("supportedInstanceTypeFamily")
|
|
|
|
SupportedInstanceGeneration = SupportedResourceType("supportedInstanceGeneration")
|
|
|
|
SupportedSystemDiskCategory = SupportedResourceType("supportedSystemDiskCategory")
|
|
|
|
SupportedDataDiskCategory = SupportedResourceType("supportedDataDiskCategory")
|
|
|
|
SupportedNetworkCategory = SupportedResourceType("supportedNetworkCategory")
|
|
|
|
|
|
|
|
)
|
|
|
|
//
|
|
|
|
// You can read doc at https://help.aliyun.com/document_detail/25670.html?spm=5176.doc25640.2.1.J24zQt
|
|
|
|
type ResourcesInfoType struct {
|
|
|
|
ResourcesInfo []AvailableResourcesType
|
|
|
|
}
|
|
|
|
// Because the sub-item of AvailableResourcesType starts with supported and golang struct cann't refer them, this uses map to parse ResourcesInfo
|
|
|
|
type AvailableResourcesType struct {
|
|
|
|
IoOptimized bool
|
|
|
|
NetworkTypes map[SupportedResourceType][]string
|
|
|
|
InstanceGenerations map[SupportedResourceType][]string
|
|
|
|
InstanceTypeFamilies map[SupportedResourceType][]string
|
|
|
|
InstanceTypes map[SupportedResourceType][]string
|
|
|
|
SystemDiskCategories map[SupportedResourceType][]DiskCategory
|
|
|
|
DataDiskCategories map[SupportedResourceType][]DiskCategory
|
|
|
|
}
|
|
|
|
|
2017-03-03 04:19:16 -05:00
|
|
|
type DescribeZonesArgs struct {
|
|
|
|
RegionId common.Region
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/datatype&availableresourcecreationtype
|
|
|
|
type AvailableResourceCreationType struct {
|
|
|
|
ResourceTypes []ResourceType //enum for Instance, Disk, VSwitch
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/datatype&availablediskcategoriestype
|
|
|
|
type AvailableDiskCategoriesType struct {
|
|
|
|
DiskCategories []DiskCategory //enum for cloud, ephemeral, ephemeral_ssd
|
|
|
|
}
|
|
|
|
|
|
|
|
type AvailableInstanceTypesType struct {
|
|
|
|
InstanceTypes []string
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/datatype&zonetype
|
|
|
|
type ZoneType struct {
|
|
|
|
ZoneId string
|
|
|
|
LocalName string
|
2017-08-03 21:56:04 -04:00
|
|
|
AvailableResources ResourcesInfoType
|
2017-03-03 04:19:16 -05:00
|
|
|
AvailableInstanceTypes AvailableInstanceTypesType
|
|
|
|
AvailableResourceCreation AvailableResourceCreationType
|
|
|
|
AvailableDiskCategories AvailableDiskCategoriesType
|
|
|
|
}
|
|
|
|
|
|
|
|
type DescribeZonesResponse struct {
|
|
|
|
common.Response
|
|
|
|
Zones struct {
|
|
|
|
Zone []ZoneType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DescribeZones describes zones
|
|
|
|
func (client *Client) DescribeZones(regionId common.Region) (zones []ZoneType, err error) {
|
2017-08-03 21:56:04 -04:00
|
|
|
response, err := client.DescribeZonesWithRaw(regionId)
|
|
|
|
if err == nil {
|
|
|
|
return response.Zones.Zone, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return []ZoneType{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *Client) DescribeZonesWithRaw(regionId common.Region) (response *DescribeZonesResponse, err error) {
|
2017-03-03 04:19:16 -05:00
|
|
|
args := DescribeZonesArgs{
|
|
|
|
RegionId: regionId,
|
|
|
|
}
|
2017-08-03 21:56:04 -04:00
|
|
|
response = &DescribeZonesResponse{}
|
2017-03-03 04:19:16 -05:00
|
|
|
|
2017-08-03 21:56:04 -04:00
|
|
|
err = client.Invoke("DescribeZones", &args, response)
|
2017-03-03 04:19:16 -05:00
|
|
|
|
|
|
|
if err == nil {
|
2017-08-03 21:56:04 -04:00
|
|
|
return response, nil
|
2017-03-03 04:19:16 -05:00
|
|
|
}
|
|
|
|
|
2017-08-03 21:56:04 -04:00
|
|
|
return nil, err
|
2017-03-03 04:19:16 -05:00
|
|
|
}
|