-
Notifications
You must be signed in to change notification settings - Fork 7
/
results.go
322 lines (290 loc) · 10.9 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
package instances
import (
"encoding/json"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud/pagination"
)
type commonResult struct {
golangsdk.Result
}
// GetResult represents the result of a create operation.
type CreateResult struct {
commonResult
}
type CreateResp struct {
Id string `json:"instance_id"`
Message string `json:"message"`
}
//Call its Extract method to interpret it as a Instance Id.
func (r CreateResult) Extract() (*CreateResp, error) {
var s CreateResp
err := r.ExtractInto(&s)
return &s, err
}
// GetResult represents the result of a Get operation.
type GetResult struct {
commonResult
}
// UpdateResult represents the result of a Update operation.
type UpdateResult struct {
commonResult
}
type Instance struct {
// Instance ID.
Id string `json:"id"`
// Project ID.
ProjectId string `json:"project_id"`
// Instance name.
Name string `json:"instance_name"`
// Instance status. The value are as following:
// Creating, CreateSuccess, CreateFail, Initing, Registering, Running, InitingFailed, RegisterFailed, Installing
// InstallFailed, Updating, UpdateFailed, Rollbacking, RollbackSuccess, RollbackFailed, Deleting, DeleteFailed
// Unregistering, UnRegisterFailed, CreateTimeout, InitTimeout, RegisterTimeout, InstallTimeout, UpdateTimeout
// RollbackTimeout, DeleteTimeout, UnregisterTimeout, Starting, Freezing, Frozen, Restarting, RestartFail
// Unhealthy, RestartTimeout
// The status 'Deleting' is not supported, it's a BUG. --2021/06/15
Status string `json:"status"`
// Instance status ID.
// 1:Creating, 2:CreateSuccess, 3:CreateFail, 4:Initing, 5:Registering, 6:Running, 7:InitingFailed
// 8:RegisterFailed, 10:Installing, 11:InstallFailed, 12:Updating, 13:UpdateFailed, 20:Rollbacking
// 21:RollbackSuccess, 22:RollbackFailed, 23:Deleting, 24:DeleteFailed, 25:Unregistering, 26:UnRegisterFailed
// 27:CreateTimeout, 28:InitTimeout, 29:RegisterTimeout, 30:InstallTimeout, 31:UpdateTimeout
// 32:RollbackTimeout, 33:DeleteTimeout, 34:UnregisterTimeout, 35:Starting, 36:Freezing, 37:Frozen, 38:Restarting
// 39:RestartFail, 40:Unhealthy, 41:RestartTimeout
// Ditto: Issue of status id 23 (Deleting). --2021/06/15
StatusId int `json:"instance_status"`
// Instance type.
Type string `json:"type"`
// Instance edition.
Edition string `json:"spec"`
// Time when the APIG dedicated instance is created, in Unix timestamp format.
CreateTimestamp int64 `json:"create_time"`
// Enterprise project ID.
EnterpriseProjectId string `json:"enterprise_project_id"`
// Billing mode of the APIG dedicated instance.
// 0:Pay per use
// 1:Pay per use
ChargeMode int `json:"charging_mode"`
// Yearly/Monthly subscription order ID.
CbcMetadata string `json:"cbc_metadata"`
// The type of load balancer used by the instance.
// The valid values are as follows:
// + lvs: Linux virtual server
// + elb: Elastic load balance
LoadbalancerProvider string `json:"loadbalancer_provider"`
// Description about the APIG dedicated instance.
Description string `json:"description"`
// VPC ID.
VpcId string `json:"vpc_id"`
// Subnet network ID.
SubnetId string `json:"subnet_id"`
// ID of the security group to which the APIG dedicated instance belongs to.
SecurityGroupId string `json:"security_group_id"`
// Start time of the maintenance time window in the format "xx:00:00".
MaintainBegin string `json:"maintain_begin"`
// End time of the maintenance time window in the format "xx:00:00".
MaintainEnd string `json:"maintain_end"`
// VPC ingress private address.
Ipv4VpcIngressAddress string `json:"ingress_ip"`
// VPC ingress private address (IPv6).
Ipv6VpcIngressAddress string `json:"ingress_ip_v6"`
// ID of the account to which the APIG dedicated instance belongs.
UserId string `json:"user_id"`
// EIP bound to the APIG dedicated instance.
Ipv4IngressEipAddress string `json:"eip_address"`
// EIP (IPv6).
Ipv6IngressEipAddress string `json:"eip_ipv6_address"`
// Public egress address (IPv6).
Ipv6EgressCidr string `json:"nat_eip_ipv6_cidr"`
// IP address for public outbound access.
Ipv4EgressAddress string `json:"nat_eip_address"`
// Outbound access bandwidth.
BandwidthSize int `json:"bandwidth_size"`
// AZs.
AvailableZoneIds string `json:"available_zone_ids"`
// Instance version.
Version string `json:"instance_version"`
// Supported features.
SupportedFeatures []string `json:"supported_features"`
// THe list of endpoint service.
EndpointServices []EndpointService `json:"endpoint_services"`
// The IP of the serivce node.
NodeIp NodeIp `json:"node_ips"`
// The ingress address list of public network.
PublicIps []IpDetail `json:"publicips"`
// The ingress address list of private network.
PrivateIps []IpDetail `json:"privateips"`
}
type EndpointService struct {
// The service name of the endpoint node.
ServiceName string `json:"service_name"`
// The create time of the endpoint node.
CreatedAt string `json:"created_at"`
}
type NodeIp struct {
// The IP address list of the livedata node.
LiveData []string `json:"livedata"`
// The IP address list of the shubao node.
Shubao []string `json:"shubao"`
}
type IpDetail struct {
// IP address.
IpAddress string `json:"ip_address"`
// Bandwidth size.
BandwidthSize int `json:"bandwidth_size"`
}
// Call its Extract method to interpret it as a Instance.
func (r commonResult) Extract() (*Instance, error) {
var s Instance
err := r.ExtractInto(&s)
return &s, err
}
type BaseInstance struct {
// Instance ID.
Id string `json:"id"`
// Project ID
ProjectId string `json:"project_id"`
// Instance name.
Name string `json:"instance_name"`
// Instance status. The value are as following:
// Creating, CreateSuccess, CreateFail, Initing, Registering, Running, InitingFailed, RegisterFailed, Installing
// InstallFailed, Updating, UpdateFailed, Rollbacking, RollbackSuccess, RollbackFailed, Deleting, DeleteFailed
// Unregistering, UnRegisterFailed, CreateTimeout, InitTimeout, RegisterTimeout, InstallTimeout, UpdateTimeout
// RollbackTimeout, DeleteTimeout, UnregisterTimeout, Starting, Freezing, Frozen, Restarting, RestartFail
// Unhealthy, RestartTimeout
// Ditto: Issue of status 'Deleting'. --2021/06/15
Status string `json:"status"`
// Instance status ID.
// 1:Creating, 2:CreateSuccess, 3:CreateFail, 4:Initing, 5:Registering, 6:Running, 7:InitingFailed
// 8:RegisterFailed, 10:Installing, 11:InstallFailed, 12:Updating, 13:UpdateFailed, 20:Rollbacking
// 21:RollbackSuccess, 22:RollbackFailed, 23:Deleting, 24:DeleteFailed, 25:Unregistering, 26:UnRegisterFailed
// 27:CreateTimeout, 28:InitTimeout, 29:RegisterTimeout, 30:InstallTimeout, 31:UpdateTimeout
// 32:RollbackTimeout, 33:DeleteTimeout, 34:UnregisterTimeout, 35:Starting, 36:Freezing, 37:Frozen, 38:Restarting
// 39:RestartFail, 40:Unhealthy, 41:RestartTimeout
// Ditto: Issue of status id 23 (Deleting). --2021/06/15
StatusId int `json:"instance_status"`
// Instance type.
Type string `json:"type"`
// Instance edition.
Edition string `json:"spec"`
// Time when the APIG dedicated instance is created, in Unix timestamp format.
CreateTimestamp int64 `json:"create_time"`
// Enterprise project ID.
EnterpriseProjectId string `json:"enterprise_project_id"`
// EIP bound to the APIG dedicated instance.
Ipv4Address string `json:"eip_address"`
// Billing mode of the APIG dedicated instance.
// 0:Pay per use
// 1:Pay per use
ChargeMode int `json:"charging_mode"`
// Yearly/Monthly subscription order ID.
CbcMetadata string `json:"cbc_metadata"`
}
// InstancePage represents the result of a List operation.
type InstancePage struct {
pagination.SinglePageBase
}
// Call its Extract method to interpret it as a BaseInstance array.
func ExtractInstances(r pagination.Page) ([]BaseInstance, error) {
var s []BaseInstance
err := r.(InstancePage).Result.ExtractIntoSlicePtr(&s, "instances")
return s, err
}
// DeleteResult represents the result of a Delete operation.
type DeleteResult struct {
golangsdk.ErrResult
}
// EnableEgressResult represents the result of a EnableEgressAccess operation.
type EnableEgressResult struct {
golangsdk.Result
}
// UdpateEgressResult represents the result of a UpdateEgressBandwidth operation.
type UdpateEgressResult struct {
golangsdk.Result
}
type EgressResult struct {
golangsdk.Result
}
type Egress struct {
Id string `json:"id"`
CloudEipId string `json:"cloudEipId"`
CloudEipAddress string `json:"cloudEipAddress"`
InstanceId string `json:"instanceId"`
CloudBandwidthId string `json:"cloudBandwidthId"`
BandwidthName string `json:"bandwidthName"`
BandwidthSize int `json:"bandwidthSize"`
}
// Extract is a method to interpret the response body or json string as an Egress.
func (r UdpateEgressResult) Extract() (*Egress, error) {
var s Egress
if r.Err != nil {
return &s, r.Err
}
body, ok := r.Body.(string)
if ok {
err := json.Unmarshal([]byte(body), &s)
return &s, err
}
err := r.ExtractInto(&s)
return &s, err
}
// Extract is a method to interpret the response body as an Egress.
func (r EnableEgressResult) Extract() (*Egress, error) {
var s Egress
err := r.ExtractInto(&s)
return &s, err
}
// DisableEgressResult represents the result of a DisableEgressAccess operation.
type DisableEgressResult struct {
golangsdk.ErrResult
}
// EnableIngressResult represents the result of a EnableIngressAccess operation.
type EnableIngressResult struct {
commonResult
}
type Ingress struct {
Id string `json:"eip_id"`
EipAddress string `json:"eip_address"`
Status string `json:"eip_status"`
Ipv6Address string `json:"eip_ipv6_address"`
}
// Call its Extract method to interpret it as a Ingress.
func (r EnableIngressResult) Extract() (*Ingress, error) {
var s Ingress
err := r.ExtractInto(&s)
return &s, err
}
// DisableIngressResult represents the result of a DisableIngressAccess operation.
type DisableIngressResult struct {
golangsdk.ErrResult
}
// Feature represents the result of a feature configuration.
type Feature struct {
// Feature ID.
ID string `json:"id"`
// Feature name.
Name string `json:"name"`
// Whether to enable the feature.
Enable bool `json:"enable"`
// Parameter configuration.
Config string `json:"config"`
// Dedicated APIG instance ID.
InstanceId string `json:"instance_id"`
// Feature update time.
UpdatedAt string `json:"update_time"`
}
// FeaturePage is a single page maximum result representing a query by offset page.
type FeaturePage struct {
pagination.OffsetPageBase
}
// IsEmpty checks whether a FeaturePage struct is empty.
func (b FeaturePage) IsEmpty() (bool, error) {
arr, err := ExtractFeatures(b)
return len(arr) == 0, err
}
// ExtractFeatures is a method to extract the list of feature configuration details for APIG instance.
func ExtractFeatures(r pagination.Page) ([]Feature, error) {
var s []Feature
err := r.(FeaturePage).Result.ExtractIntoSlicePtr(&s, "features")
return s, err
}