This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
results.go
297 lines (264 loc) · 8.32 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
package nodes
import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/openstack/common/tags"
)
//Describes the Node Structure of cluster
type ListNode struct {
// API type, fixed value "List"
Kind string `json:"kind"`
// API version, fixed value "v3"
Apiversion string `json:"apiVersion"`
// all Clusters
Nodes []Nodes `json:"items"`
}
// Individual nodes of the cluster
type Nodes struct {
// API type, fixed value " Host "
Kind string `json:"kind"`
// API version, fixed value v3
Apiversion string `json:"apiVersion"`
// Node metadata
Metadata Metadata `json:"metadata"`
// Node detailed parameters
Spec Spec `json:"spec"`
// Node status information
Status Status `json:"status"`
}
// Metadata required to create a node
type Metadata struct {
//Node name
Name string `json:"name"`
//Node ID
Id string `json:"uid"`
// Node tag, key value pair format
Labels map[string]string `json:"labels,omitempty"`
//Node annotation, keyvalue pair format
Annotations map[string]string `json:"annotations,omitempty"`
}
// Spec describes Nodes specification
type Spec struct {
// Node specifications
Flavor string `json:"flavor" required:"true"`
// The value of the available partition name
Az string `json:"az" required:"true"`
// The OS of the node
Os string `json:"os,omitempty"`
// ID of the dedicated host to which nodes will be scheduled
DedicatedHostID string `json:"dedicatedHostId,omitempty"`
// Node login parameters
Login LoginSpec `json:"login" required:"true"`
// System disk parameter of the node
RootVolume VolumeSpec `json:"rootVolume" required:"true"`
// The data disk parameter of the node must currently be a disk
DataVolumes []VolumeSpec `json:"dataVolumes" required:"true"`
// Elastic IP parameters of the node
PublicIP PublicIPSpec `json:"publicIP,omitempty"`
// The billing mode of the node: the value is 0 (on demand)
BillingMode int `json:"billingMode,omitempty"`
// Number of nodes when creating in batch
Count int `json:"count" required:"true"`
// The node nic spec
NodeNicSpec NodeNicSpec `json:"nodeNicSpec,omitempty"`
// Extended parameter
ExtendParam map[string]interface{} `json:"extendParam,omitempty"`
// UUID of an ECS group
EcsGroupID string `json:"ecsGroupId,omitempty"`
// Tag of a VM, key value pair format
UserTags []tags.ResourceTag `json:"userTags,omitempty"`
// Tag of a Kubernetes node, key value pair format
K8sTags map[string]string `json:"k8sTags,omitempty"`
// The runtime spec
RunTime *RunTimeSpec `json:"runtime,omitempty"`
// taints to created nodes to configure anti-affinity
Taints []TaintSpec `json:"taints,omitempty"`
}
// Gives the Nic spec of the node
type NodeNicSpec struct {
// The primary Nic of the Node
PrimaryNic PrimaryNic `json:"primaryNic,omitempty"`
}
// Gives the Primary Nic of the node
type PrimaryNic struct {
// The Subnet ID of the primary Nic
SubnetId string `json:"subnetId,omitempty"`
// Fixed ips of the primary Nic
FixedIps []string `json:"fixedIps,omitempty"`
}
// TaintSpec to created nodes to configure anti-affinity
type TaintSpec struct {
Key string `json:"key" required:"true"`
Value string `json:"value" required:"true"`
// Available options are NoSchedule, PreferNoSchedule, and NoExecute
Effect string `json:"effect" required:"true"`
}
// Gives the current status of the node
type Status struct {
// The state of the Node
Phase string `json:"phase"`
// The virtual machine ID of the node in the ECS
ServerID string `json:"ServerID"`
// Elastic IP of the node
PublicIP string `json:"PublicIP"`
//Private IP of the node
PrivateIP string `json:"privateIP"`
// The ID of the Job that is operating asynchronously in the Node
JobID string `json:"jobID"`
// Reasons for the Node to become current
Reason string `json:"reason"`
// Details of the node transitioning to the current state
Message string `json:"message"`
//The status of each component in the Node
Conditions Conditions `json:"conditions"`
}
type LoginSpec struct {
// Select the key pair name when logging in by key pair mode
SshKey string `json:"sshKey,omitempty"`
// Select the user/password when logging in
UserPassword UserPassword `json:"userPassword,omitempty"`
}
type UserPassword struct {
Username string `json:"username" required:"true"`
Password string `json:"password" required:"true"`
}
type VolumeSpec struct {
// Disk size in GB
Size int `json:"size" required:"true"`
// Disk type
VolumeType string `json:"volumetype" required:"true"`
//hw:passthrough
HwPassthrough bool `json:"hw:passthrough,omitempty"`
// Disk extension parameter
ExtendParam map[string]interface{} `json:"extendParam,omitempty"`
}
type PublicIPSpec struct {
// List of existing elastic IP IDs
Ids []string `json:"ids,omitempty"`
// The number of elastic IPs to be dynamically created
Count int `json:"count,omitempty"`
// Elastic IP parameters
Eip EipSpec `json:"eip,omitempty"`
}
type EipSpec struct {
// The value of the iptype keyword
IpType string `json:"iptype,omitempty"`
// Elastic IP bandwidth parameters
Bandwidth BandwidthOpts `json:"bandwidth,omitempty"`
}
type RunTimeSpec struct {
// the name of runtime: docker or containerd
Name string `json:"name,omitempty"`
}
type BandwidthOpts struct {
ChargeMode string `json:"chargemode,omitempty"`
Size int `json:"size,omitempty"`
ShareType string `json:"sharetype,omitempty"`
}
type Conditions struct {
//The type of component
Type string `json:"type"`
//The state of the component
Status string `json:"status"`
//The reason that the component becomes current
Reason string `json:"reason"`
}
// Describes the Job Structure
type Job struct {
// API type, fixed value "Job"
Kind string `json:"kind"`
// API version, fixed value "v3"
Apiversion string `json:"apiVersion"`
// Node metadata
Metadata JobMetadata `json:"metadata"`
// Node detailed parameters
Spec JobSpec `json:"spec"`
//Node status information
Status JobStatus `json:"status"`
}
type JobMetadata struct {
// ID of the job
ID string `json:"uid"`
}
type JobSpec struct {
// Type of job
Type string `json:"type"`
// ID of the cluster where the job is located
ClusterID string `json:"clusterUID"`
// ID of the IaaS resource for the job operation
ResourceID string `json:"resourceID"`
// The name of the IaaS resource for the job operation
ResourceName string `json:"resourceName"`
// List of child jobs
SubJobs []Job `json:"subJobs"`
// ID of the parent job
OwnerJob string `json:"ownerJob"`
}
type JobStatus struct {
// Job status
Phase string `json:"phase"`
// The reason why the job becomes the current state
Reason string `json:"reason"`
// The job becomes the current state details
Message string `json:"message"`
}
type AddNodeResponse struct {
JobID string `json:"jobid"`
}
func (r commonResult) ExtractAddNode() (*AddNodeResponse, error) {
var s AddNodeResponse
err := r.ExtractInto(&s)
return &s, err
}
type commonResult struct {
golangsdk.Result
}
// Extract is a function that accepts a result and extracts a node.
func (r commonResult) Extract() (*Nodes, error) {
var s Nodes
err := r.ExtractInto(&s)
return &s, err
}
// ExtractNode is a function that accepts a ListOpts struct, which allows you to filter and sort
// the returned collection for greater efficiency.
func (r commonResult) ExtractNode() ([]Nodes, error) {
var s ListNode
err := r.ExtractInto(&s)
if err != nil {
return nil, err
}
return s.Nodes, nil
}
// ExtractJob is a function that accepts a result and extracts a job.
func (r commonResult) ExtractJob() (*Job, error) {
var s Job
err := r.ExtractInto(&s)
return &s, err
}
// ListResult represents the result of a list operation. Call its ExtractNode
// method to interpret it as a Nodes.
type ListResult struct {
commonResult
}
// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Node.
type CreateResult struct {
commonResult
}
type AddResult struct {
commonResult
}
// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Node.
type GetResult struct {
commonResult
}
// UpdateResult represents the result of an update operation. Call its Extract
// method to interpret it as a Node.
type UpdateResult struct {
commonResult
}
// DeleteResult represents the result of a delete operation. Call its ExtractErr
// method to determine if the request succeeded or failed.
type DeleteResult struct {
golangsdk.ErrResult
}