forked from huaweicloud/huaweicloud-sdk-go
/
results.go
206 lines (161 loc) · 6.1 KB
/
results.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package configures
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
"strconv"
)
type commonResult struct {
gophercloud.Result
}
type PublicIp struct {
// Specifies the configuration parameter for creating an EIP that
// will be automatically assigned to the ECS.
Eip Eip `json:"eip"`
}
type Eip struct {
// Specifies the IP address type.Enumerated values of the IP
// address type:5_bgp: indicates the dynamic BGP.5_lxbgp: BGP,5_telcom: indicates China
// Telecom.5_union: indicates China Unicom.
IpType string `json:"ip_type"`
// Specifies the bandwidth.
Bandwidth Bandwidth `json:"bandwidth"`
}
type Bandwidth struct {
ID string `json:"id"`
// Specifies the bandwidth (Mbit/s). The value range is 1 to
// 100.
Size int `json:"size"`
// Specifies the bandwidth sharing type.Enumerated value: PER
// (indicates exclusive bandwidth).Only exclusive bandwidth is available.
ShareType string `json:"share_type"`
// Specifies the bandwidth charging mode.If the field value is
// bandwidth, the ECS service is charged by bandwidth.If the field value is traffic, the
// ECS service is charged by traffic.If the field value is others, the ECS creation will
// fail.
ChargingMode string `json:"charging_mode"`
}
type InstanceConfig struct {
// This field is reserved.
InstanceName string `json:"instance_name"`
// Specifies the ECS ID. When using the existing ECS
// specifications as the template to create AS configurations, specify this parameter.
// In this case, flavorRef, imageRef, and disk fields do not take effect.If the
// instance_id field is not specified, flavorRef, imageRef, and disk fields are
// mandatory.
InstanceId string `json:"instance_id"`
// Specifies the ECS specifications ID, which defines the
// specifications of the CPU and memory for the ECS. You can obtain its value from the
// API used to query specifications and expansion details about ECSs. For details, see
// section Querying Specifications and Expansion Details About ECSs in the Elastic Cloud
// Server API Reference.
FlavorRef string `json:"flavorRef"`
// Specifies the image ID. It is the same as image_id. You can
// obtain its value from the API used to query IMS images. For details, see section
// Querying Images in the Image Management Service API Reference.
ImageRef string `json:"imageRef"`
// Specifies the disk group information. System disks are
// mandatory and data disks are optional.
Disk []Disk `json:"disk"`
// This field is reserved.
AdminPass string `json:"adminPass"`
// Specifies the name of the SSH key pair used to log in to the
// ECS.
KeyName string `json:"key_name"`
// Specifies information about the injected file. Only text files
// can be injected. A maximum of five files can be injected at a time and the maximum
// size of each file is 1 KB.
Personality []Personality `json:"personality"`
// Specifies the EIP of the ECS. The EIP can be configured in the
// following two ways:Not configured (delete this field),Assigned automatically
PublicIp PublicIp `json:"public_ip"`
// Specifies the cloud-init user data.Text, text files, and gzip
// files can be injected. The file content must be encoded with Base64, and the maximum
// allowed file size is 32 KB.
UserData string `json:"user_data"`
// Specifies the metadata of ECSs to be created.
Metadata map[string]interface{} `json:"metadata"`
SecurityGroups []SecurityGroup `json:"security_groups"`
ServerGroupID string `json:"server_group_id"`
Tenancy string `json:"tenancy"`
DedicatedHostID string `json:"dedicated_host_id"`
MarketType string `json:"market_type"`
KeyFingerPrint string `json:"key_fingerprint"`
}
type ScalingConfiguration struct {
// Specifies the AS configuration ID. This parameter is globally
// unique.
ScalingConfigurationId string `json:"scaling_configuration_id"`
// Specifies the tenant ID.
Tenant string `json:"tenant"`
// Specifies the AS configuration name.
ScalingConfigurationName string `json:"scaling_configuration_name"`
// Specifies the information about instance configurations.
InstanceConfig InstanceConfig `json:"instance_config"`
// Specifies the time when AS configurations are created. The time
// format complies with UTC.
CreateTime string `json:"create_time"`
}
type CreateResult struct {
commonResult
}
func (r CreateResult) Extract() (*CreateResponse, error) {
var response CreateResponse
err := r.ExtractInto(&response)
return &response, err
}
type CreateResponse struct {
// Specifies the AS configuration ID.
ScalingConfigurationId string `json:"scaling_configuration_id"`
}
type DeleteResult struct {
gophercloud.ErrResult
}
type DeleteWithBatchResult struct {
gophercloud.ErrResult
}
type GetResult struct {
commonResult
}
func (r GetResult) Extract() (*ScalingConfiguration, error) {
var s struct {
ScalingConfiguration ScalingConfiguration `json:"scaling_configuration"`
}
err := r.ExtractInto(&s)
return &s.ScalingConfiguration, err
}
type ListResponse struct {
// Specifies the total number of query records.
TotalNumber int `json:"total_number"`
// Specifies the start line number.
StartNumber int `json:"start_number"`
// Specifies the number of query records.
Limit int `json:"limit"`
// Specifies the AS configuration list.
ScalingConfigurations []ScalingConfiguration `json:"scaling_configurations"`
}
type ConfigPage struct {
pagination.NumberPageBase
}
// IsEmpty returns true if a ListResult contains no services.
func (r ConfigPage) IsEmpty() (bool, error) {
data, err := ExtractConfigs(r)
return data.StartNumber > data.TotalNumber, err
}
// LastMarker returns the last service in a ListResult.
func (r ConfigPage) LastStartNumber() (string, error) {
data, err := ExtractConfigs(r)
if err != nil {
return "", err
}
nextStartNumber := data.Limit + data.StartNumber
if nextStartNumber >= data.TotalNumber {
return "", nil
}
return strconv.Itoa(nextStartNumber), nil
}
// ExtractServices is a function that takes a ListResult and returns the services' information.
func ExtractConfigs(r pagination.Page) (ListResponse, error) {
var s ListResponse
err := (r.(ConfigPage)).ExtractInto(&s)
return s, err
}