-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost.go
637 lines (550 loc) · 15.3 KB
/
host.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
package vmmanagerapi
import (
"encoding/json"
"fmt"
"github.com/gadost/go-vmmanager-api/types"
)
// Hosts get hosts info
func (a *Api) Hosts(where *ParamsQuery) (*types.HostsResponse, error) {
uri := fmt.Sprintf("/host%s", where)
bodyResp, err := a.NewRequest(NilPayload, uri, requestTypeGet, DefaultService)
var h *types.HostsResponse
json.Unmarshal(bodyResp, &h)
return h, err
}
// HostNew create new host
func (a *Api) HostNew(hid int, params *types.NewHostRequest) (*types.RecipeTask, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(payload, HostUri, requestTypePost, DefaultService)
var t *types.RecipeTask
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostByID returns host params
func (a *Api) HostByID(hid int) (*types.HostResponse, error) {
uri := fmt.Sprintf("/host/%d", hid)
bodyResp, err := a.NewRequest(NilPayload, uri, requestTypeGet, DefaultService)
var h *types.HostResponse
json.Unmarshal(bodyResp, &h)
return h, err
}
// HostUpdate update host params
func (a *Api) HostUpdate(hid int, params *types.HostUpdateRequest) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostDelete delete host
func (a *Api) HostDelete(hid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d", hid),
requestTypeDelete,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostChangeOwner change host owner
func (a *Api) HostChangeOwner(hid int, params *types.Account) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/account", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostImageSizeLimit set image size limit
func (a *Api) HostImageSizeLimit(hid int, params *types.ImageSize) (*types.ImageSize, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/bill_option/image_gib", hid),
requestTypePost,
DefaultService)
var i *types.ImageSize
json.Unmarshal(bodyResp, &i)
return i, err
}
// HostClone clone host
func (a *Api) HostClone(hid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/clone", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostRepairGuestAgent repair guest agent
func (a *Api) HostRepairGuestAgent(hid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/guest_agent", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostHistory returns host history
func (a *Api) HostHistory(hid int) (*types.HostHistoryResponse, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/history", hid),
requestTypeGet,
DefaultService)
var h *types.HostHistoryResponse
json.Unmarshal(bodyResp, &h)
return h, err
}
// HostNewLogEntry create new log entry
func (a *Api) HostNewLogEntry(hid int, payload []byte) ([]byte, error) {
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/histroy", hid),
requestTypePost,
DefaultService)
return bodyResp, err
}
// HostInteface get host interfaces
func (a *Api) HostInteface(hid int) (*types.IFace, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/iface", hid),
requestTypeGet,
DefaultService)
var h *types.IFace
json.Unmarshal(bodyResp, &h)
return h, err
}
// HostIntefaceNew create new interface
func (a *Api) HostIntefaceNew(hid int, params *types.IFaceParams) ([]byte, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/iface", hid),
requestTypePost,
DefaultService)
return bodyResp, err
}
// HostIntefaceUpdate update host interface params
func (a *Api) HostIntefaceUpdate(hid int, iface string, params *types.IFaceModel) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/iface/%s", hid, iface),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostIntefaceDelete delete host interface
func (a *Api) HostIntefaceDelete(hid int, iface string) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/iface/%s", hid, iface),
requestTypeDelete,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostIPNew add ip to host
func (a *Api) HostIPNew(hid int, params *types.AddIPToHostRequest) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/ip", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostIPAutomationUpdate update IP automation on host
func (a *Api) HostIPAutomationUpdate(hid int, params *types.IPAutomationType) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/ip_automation", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostIPV4 return IPV4 host info
func (a *Api) HostIPV4(hid int) (*types.IPV4Info, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/ipv4", hid),
requestTypeGet,
DefaultService)
var h *types.IPV4Info
json.Unmarshal(bodyResp, &h)
return h, err
}
// HostIPV6 return IPV6 host info
func (a *Api) HostIPV6(hid int) (*types.IPV6Info, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/ipv6", hid),
requestTypeGet,
DefaultService)
var h *types.IPV6Info
json.Unmarshal(bodyResp, &h)
return h, err
}
// HostISODisconnectWithoutReinstall disconnect ISO without reinstall
func (a *Api) HostISODisconnectWithoutReinstall(hid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/iso/cancel", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostISODisconnectWithReinstall disconnect ISO with reinstall
func (a *Api) HostISODisconnectWithReinstall(hid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/iso/finish", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostISOConnect connect ISO to host
func (a *Api) HostISOConnect(hid int, params *types.ISOTags) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/iso/mount", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostLXDConsole return LXD console socket
func (a *Api) HostLXDConsole(hid int) (*types.Socket, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/lxd/console", hid),
requestTypePost,
DefaultService)
var t *types.Socket
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostMetrics returns host metrics
func (a *Api) HostMetrics(hid int) ([]byte, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/metrics", hid),
requestTypeGet,
DefaultService)
return bodyResp, err
}
// HostMigrateForm returns migrate form
func (a *Api) HostMigrateForm(hid int) (*types.HostMigrateResponse, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/migrate", hid),
requestTypeGet,
DefaultService)
var h *types.HostMigrateResponse
json.Unmarshal(bodyResp, &h)
return h, err
}
// HostMigrate start host migration
func (a *Api) HostMigrate(hid int, params *types.HostMigrateRequest) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/migrate", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostPasswordUpdate update host password
func (a *Api) HostPasswordUpdate(hid int, params *types.Password) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/password", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostPTRNew add PTR record
func (a *Api) HostPTRNew(hid int, params *types.PTRUpdateRequest) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/ptr", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostPTR return PTRs
func (a *Api) HostPTR(hid int) (*types.PTRResponse, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/ptr", hid),
requestTypeGet,
DefaultService)
var h *types.PTRResponse
json.Unmarshal(bodyResp, &h)
return h, err
}
// HostPTRUpdate update host PTR record
func (a *Api) HostPTRUpdate(hid int, domain string, params *types.Domain) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/ptr/%s", hid, domain),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostPTRDelete delete PTR record
func (a *Api) HostPTRDelete(hid int, domain string) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/ptr/%s", hid, domain),
requestTypeDelete,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostReinstall reinstall host
func (a *Api) HostReinstall(hid int, params *types.HostReinstallRequest) (*types.RecipeTask, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/reinstall", hid),
requestTypePost,
DefaultService)
var t *types.RecipeTask
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostRelocate relocate host
func (a *Api) HostRelocate(hid int, params *types.Node) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/relocate", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostRescueMode start rescue mode
func (a *Api) HostRescueMode(hid int, params *types.RescueMode) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/rescue_mode", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostResourceUpdate update host resource
func (a *Api) HostResourceUpdate(hid int, params *types.HostResourceUpdateRequest) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/resource", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostRestart restart host
func (a *Api) HostRestart(hid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/restart", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostRestore restore host
func (a *Api) HostRestore(hid int, params *types.HostBackup) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/restore", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostRecipeRun run recipe on host
func (a *Api) HostRecipeRun(hid int, params *types.Recipe) (*types.RecipeTask, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/runrecipe", hid),
requestTypePost,
DefaultService)
var t *types.RecipeTask
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostStart host start
func (a *Api) HostStart(hid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/start", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostStop stop host
func (a *Api) HostStop(hid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/stop", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostHAMetadataSync sync host metadata
func (a *Api) HostHAMetadataSync(hid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/sync_ha_metadata", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostVNCSettings returns host VNC settings
func (a *Api) HostVNCSettings(hid int) ([]byte, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/host/%d/vnc_settings", hid),
requestTypeGet,
DefaultService)
return bodyResp, err
}
// HostVNCSettingsUpdate update host VNC settings
func (a *Api) HostVNCSettingsUpdate(hid int, params *types.Password) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/vnc_settings", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostVNCPortsUpdate update host VNC ports
func (a *Api) HostVNCPortsUpdate(hid int, params *types.VNCPortUpdateRequest) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/vnc_ports", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// IPs returns IPs
func (a *Api) IPs(where *ParamsQuery) (*types.IPList, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/ip%s", where),
requestTypeGet,
DefaultService)
var h *types.IPList
json.Unmarshal(bodyResp, &h)
return h, err
}
// IPUpdate update IP params
func (a *Api) IPUpdate(iid int, params *types.UpdateIPResponse) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/ip/%d", iid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// IPDelete delete IP
func (a *Api) IPDelete(iid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/ip/%d", iid),
requestTypeDelete,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// IPPTRNew add PTR to IP
func (a *Api) IPPTRNew(hid int, params *types.Domain) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/ip/%d/ptr", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// HostSchedules returns host schedules
func (a *Api) HostSchedules() (*types.ScheduleListResponse, error) {
bodyResp, err := a.NewRequest(
NilPayload,
"/schedule_list",
requestTypeGet,
DefaultService)
var t *types.ScheduleListResponse
json.Unmarshal(bodyResp, &t)
return t, err
}