-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
770 lines (653 loc) · 25.2 KB
/
server.go
File metadata and controls
770 lines (653 loc) · 25.2 KB
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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
package clcv1
import (
"github.com/grrtrr/clcv1/microsoft"
)
// Server Object
type Server struct {
// The full name of the Server.
Name string
// The unique identifier of the containing Group.
HardwareGroupUUID string
// The description of the Server as provided on creation.
Description string
// Modification origin
ModifiedBy string
// Modification date
DateModified microsoft.Timestamp
// The DNS name of the Server.
DnsName string
// The number of processors configured on the Server.
Cpu int
// Total GB of RAM configured on the Server.
MemoryGB int
// Total number of disks configured on the Server.
DiskCount int
// Total space across all disk configured on the Server.
TotalDiskSpaceGB int
// True if the Server is a template, else False.
IsTemplate bool
// True if the Server is a Hyperscale instance, else False.
IsHyperscale bool
// Active, Archived, Deleted, UnderConstruction, QueuedForArchive, QueuedForDelete, or QueuedForRestore
Status string
// The type of server. Standard or Premium
ServerType int
// The service level/performance for the underlying data store. Standard or Premium
ServiceLevel int
// Operating System of the server (see below).
OperatingSystem OperatingSystem
// StringThe current power state of the Server (Stopped, Started, Paused).
PowerState string
// Indicates if the Server is in Maintenance Mode.
InMaintenanceMode bool
// Home datacenter of the Server.
Location string
// The primary IP address of the Server.
IPAddress string
// A list of all IP Addresses assigned to the server (see below)
IPAddresses []IPAddress
// A list of Custom Fields associated to this server (see below)
CustomFields []CustomField
// The ID of the Server. DEPRECATED - Value is -1.
ID int
// The legacy ID of the containing Group.
// DEPRECATED - Not available after May 6, 2015. Use UUID instead.
HardwareGroupID int
}
type IPAddress struct {
// The IP Address
Address string
// The type of the IP Address:
// RIP - Real IP (internal IP configured on the VLAN)
// MIP - Mapped IP (external IP configured on the Firewall)
// VIP - Virtual IP (external IP configured on the Load Balancer)
AddressType string
}
func (i IPAddress) String() string {
return i.Address + "/" + i.AddressType
}
func (i *IPAddress) IsPublic() bool {
return i.AddressType == "MIP" || i.AddressType == "VIP"
}
type CustomField struct {
// Unique identifier that is associated with the Account Custom Field.
// Call Account/GetCustomFields for a list of all custom fields set at the account level.
ID string
// Name for the Custom Field.
Name string
// Type of custom field: Text, Option or Checkbox.
Type string
// For Text: Any value;
// For Option values, call Account/GetCustomFields to see possible values to pass in.
// Checkbox values should be "true" or "false".
Value string
// Deprecated. Value is -1. Use CustomFieldType instead.
CustomFieldID int
}
/*
* Server Lists
*/
// List all servers of a given Hardware Group.
// @hwGrpUUID: The unique identifier of the Hardware Group.
// @acctAlias:
func (c *Client) GetServers(hwGrpUUID, acctAlias string) (servers []Server, err error) {
req := struct { AccountAlias, HardwareGroupUUID string } { acctAlias, hwGrpUUID }
err = c.getResponse("/Server/GetServers/JSON", &req, &struct {
BaseResponse
Servers *[]Server
} { Servers: &servers })
return
}
// Get a deep list of all Servers for a given Hardware Group and its sub groups,
// or all Servers for a given location.
// All of the following arguments are optional (empty string):
// @acctAlias: The alias of the account that owns the servers.
// @hwGrpUUID: The unique identifier of the containing Hardware Group.
// @location: The data center location.
func (c *Client) GetAllServers(acctAlias, hwGrpUUID, location string) (servers []Server, err error) {
req := struct {
AccountAlias, HardwareGroupUUID, Location string
} { acctAlias, hwGrpUUID, location }
err = c.getResponse("/Server/GetAllServers/JSON", &req, &struct {
BaseResponse
Servers *[]Server
} { Servers: &servers })
return
}
// Like GetAllServers, but with additional begin/end dates added to query.
// @acctAlias: see GetAllServers
// @hwGrpUUID: see GetAllServers
// @location: see GetAllServers
// @beginDate: Beginning of date range for querying modified servers.
// Can be a partial DateTime (e.g. 2013-05-10) or a full DateTime (e.g. 2013:05-10T14:30:12).
// If date is missing, then the value equals today minus one day.
// @endDate: End of date range for querying modified servers. Can be a partial DateTime (e.g. 2013-05-10)
// or a full DateTime (e.g. 2013:05-10T14:30:12).
// If date is missing, then the value is set to the current date time.
func (c *Client) GetAllServersByModifiedDates(acctAlias, hwGrpUUID, location string,
beginDate, endDate string) (servers []Server, err error) {
req := struct {
AccountAlias, HardwareGroupUUID, Location string
BeginDate, EndDate string
} { acctAlias, hwGrpUUID, location, beginDate, endDate }
err = c.getResponse("/Server/GetAllServersByModifiedDates/JSON", &req, &struct {
BaseResponse
Servers *[]Server
} { Servers: &servers })
return
}
type AccountServer struct {
AccountAlias string
Servers []Server
}
// Get a deep list of all servers for a given account hierarchy within a given data center.
// Use this operation to get a full list of all servers contained within an account and all its subaccounts.
// @acctAlias: The alias of the account that contains sub-accounts with servers (optional).
// @location: The data center location. Otherwise leave blank and let it default to account's primary data center.
func (c *Client) GetAllServersForAccountHierarchy(acctAlias, location string) (servers []AccountServer, err error) {
req := struct {
AccountAlias, Location string
} { acctAlias, location }
err = c.getResponse("/Server/GetAllServersForAccountHierarchy/JSON", &req, &struct {
BaseResponse
AccountServers *[]AccountServer
} { AccountServers: &servers })
return
}
/*
* Server Templates
*/
type ServerTemplate struct {
// The ID of the Server.
// Deprecated. Value is -1.
ID int
// The full name of the Server.
Name string
// The description of the Serve.
Description string
// The number of processors.
Cpu int
// Total GB of RAM configured on the Server.
MemoryGB int
// Total number of disks configured on the Server.
DiskCount int
// Total space across all disk configured on the Server.
TotalDiskSpaceGB int
// Operating System of the server (see below).
OperatingSystem OperatingSystem
// Home datacenter of the template.
Location string
}
// Gets the list of Templates available to the account (default location)
func (c *Client) GetServerTemplates() (templates []ServerTemplate, err error) {
err = c.getResponse("/Server/GetServerTemplates/JSON", nil, &struct {
BaseResponse
Templates *[]ServerTemplate
} { Templates: &templates })
return
}
// Gets the list of Templates available to the account and location.
// @acctAlias: The alias of the account that owns the server.
// If not provided it will assume the account to which the API user is mapped.
// Providing this value gives you the ability to access servers in your sub accounts.
// @location: The data center of the server templates.
func (c *Client) ListAvailableServerTemplates(acctAlias, location string) (templates []ServerTemplate, err error) {
req := struct { AccountAlias, Location string } { acctAlias, location }
err = c.getResponse("/Server/ListAvailableServerTemplates/JSON", &req, &struct {
BaseResponse
Templates *[]ServerTemplate
} { Templates: &templates })
return
}
// Convert the server to a template.
// @name: The name of the Server.
// @password: The administrator/root password for the server to convert.
// @templAlias: The alias for the Template to create.
// @acctAlias: The alias of the account that owns the server (optional).
func (c *Client) ConvertServerToTemplate(name, password, templAlias, acctAlias string) (reqId int, err error) {
req := struct {
Name, AccountAlias string
Password string
TemplateAlias string
} { name, acctAlias, password, templAlias }
err = c.getResponse("/Server/ConvertServerToTemplate/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Convert the template to a server.
// @name: The name of the Template.
// @password: The new administrator/root password for the converted server.
// @hwGrpUUID: The unique identifier of the hardware group to add the converted server to.
// @network: The name of the network to add the converted server to.
// @acctAlias: The alias of the account that owns the server (optional).
func (c *Client) ConvertTemplateToServer(name, password, hwGrpUUID, network, acctAlias string) (reqId int, err error) {
req := struct {
Name, AccountAlias string
Password string
HardwareGroupUUID string
Network string
} { name, acctAlias, password, hwGrpUUID, network }
err = c.getResponse("/Server/ConvertTemplateToServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Delete the Template with the specified name.
// @name: The name of the Template to delete.
// @acctAlias: The alias of the account that owns the template (optional).
func (c *Client) DeleteTemplate(name, acctAlias string) (reqId int, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/DeleteTemplate/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
/*
* Invidual Servers
*/
// Gets the detail for one server.
// @name: The name of the server
// @acctAlias: The alias of the account that owns the servers (optional)
func (c *Client) GetServer(name, acctAlias string) (server Server, err error) {
req := struct { AccountAlias, Name string } { acctAlias, name }
err = c.getResponse("/Server/GetServer/JSON", &req, &struct {
BaseResponse
Server *Server
} { Server: &server })
return
}
/*
* Credentials
*/
type ServerCredentials struct {
// The administrator or root user name for the server.
Username string
// The password associated with the account.
Password string
}
// Get the credentials for the specified server.
// @name: The name of the server
// @acctAlias: The alias of the account that owns the servers (optional)
func (c *Client) GetServerCredentials(name, acctAlias string) (creds ServerCredentials, err error) {
req := struct { AccountAlias, Name string } { acctAlias, name }
err = c.getResponse("/Server/GetServerCredentials/JSON", &req, &struct {
BaseResponse
*ServerCredentials
} { ServerCredentials: &creds })
return
}
// Update the Admin/Root password for a Server.
// @name: The name of the server
// @acctAlias: The alias of the account that owns the servers (optional)
// @curPass: The existing password, for authentication.
// @newPass: The new password to apply.
func (c *Client) ServerChangePassword(name, acctAlias, curPass, newPass string) error {
req := struct {
AccountAlias, Name string
CurrentPassword string
NewPassword string
} { acctAlias, name, curPass, newPass }
return c.getResponse("/Server/ChangePassword/JSON", &req, new(BaseResponse))
}
/*
* Disk-related Functions
*/
type DiskInfo struct {
// Name assigned to the disk.
Name string
// The SCSI bus ID of the disk.
ScsiBusID string
// The SCSI device ID of the disk.
ScsiDeviceID string
// Size of the disk in GB
SizeGB int
}
// List the disks on a Server.
// @name: The name of the server
// @acctAlias: The alias of the account that owns the servers (optional)
// @diskNames: Set to true in order to retreive disk mount points / drive letters
func (c *Client) ListDisks(name, acctAlias string, diskNames bool) (hasSnapshot bool, disks []DiskInfo, err error) {
req := struct {
AccountAlias, Name string
QueryGuestDiskNames bool
} { acctAlias, name, diskNames }
err = c.getResponse("/Server/ListDisks/JSON", &req, &struct {
BaseResponse
Server string
HasSnapshot *bool
Disks *[]DiskInfo
} { HasSnapshot: &hasSnapshot, Disks: &disks })
return
}
// Delete a disk from a Server.
// @name: The name of the server
// @acctAlias: The alias of the account that owns the servers (optional)
// @busId: The SCSI bus ID of the disk.
// @devId: The SCSI device ID of the disk.
// @force: Set to true to override safety checks that prevent deleting typical primary
// operating system drives, e.g. SCSI Bus ID 0, SCSI Device ID 0 on Windows (
// typically C drive) and SCSI Bus ID 0, SCSI Device IDs 0,1,2 on Linux
// (typically boot, swap and root disks).
func (c *Client) DeleteDisk(name, acctAlias string, busId, devId string, force bool) (reqId int, err error) {
req := struct {
AccountAlias, Name string
ScsiBusID, ScsiDeviceID string
OverrideFailsafes bool
} { acctAlias, name, busId, devId, force }
err = c.getResponse("/Server/DeleteDisk/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Resize a disk on a server
// @name: The name of the server
// @acctAlias: The alias of the account that owns the servers (optional)
// @busId: The SCSI bus ID of the disk.
// @devId: The SCSI device ID of the disk.
// @newSizeGB: The expanded size of the disk. Must be greater than the existing disk size.
// @expandFS: Whether to expand the file system on the disk after the resize.
func (c *Client) ResizeDisk(name, acctAlias string, busId, devId string, newSizeGB int, expandFs bool) (reqId int, err error) {
req := struct {
AccountAlias, Name string
ScsiBusID, ScsiDeviceID string
ResizeGuestDisk bool
NewSizeGB int
} { acctAlias, name, busId, devId, expandFs, newSizeGB }
err = c.getResponse("/Server/ResizeDisk/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
/*
* Create Server
*/
type CreateServerReq struct {
// The alias of the account to own the server.
// If not provided it will assume the account to which the API user is mapped.
// Providing this value gives you the ability to create servers in your sub accounts. (optional)
AccountAlias string
// The alias of the data center in which to create the server (optional).
// If not provided, will default to the API user's default data center.
LocationAlias string
// The name of the template to create the server from (required)
Template string
// The alias for the server. Limit 6 charcters (required)
Alias string
// An optional description for the server. If none is supplied the server name will be used. (optional)
Description string
// The unique identifier of the Hardware Group to add this server to (required)
HardwareGroupUUID string
//The type of server to create (required)
// 1 = Standard
// 2 = Enterprise
ServerType int
// The service level/performance for the underlying data store (required)
// 1 = Premium
// 2 = Standard
ServiceLevel int
// The number of processors to configure the server with (required)
Cpu int
// The number of GB of memory to configure the server with (required)
MemoryGB int
// The size in GB of an additional drive to add to the server (required).
// If no additional drive is needed, pass in a 0 value.
ExtraDriveGB int
// The primary DNS to set on the server (optional)
// If not supplied the default value set on the account will be used.
PrimaryDns string
// The secondary DNS to set on the server (optional)
// If not supplied the default value set on the account will be used.
SecondaryDns string
// The name of the network to which to deploy the server.
// If your account has not yet been assigned a network, leave this blank and one will be assigned automatically.
// If one or more networks are available, the network name is required.
Network string
// The desired Admin/Root password (optional).
// Please note the password must meet the password strength policy.
// Leave blank to have the system generate a password
Password string
// A list of Custom Fields associated to this server
// ID: Unique identifier that is associated with the Account Custom Field.
// Call Account/GetCustomFields for a list of all custom fields set at the account level.
// Value:
// - For Text: Any value;
// - For Option values, call Account/GetCustomFields to see possible values to pass in.
// - Checkbox values should be "true" or "false".
CustomFields []struct { ID, Value string }
}
// Create a new Server
func (c *Client) CreateServer(req *CreateServerReq) (reqId int, err error) {
err = c.getResponse("/Server/CreateServer/JSON", req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
/*
* Configure Server
*/
type ConfigureServerReq struct {
// The name of the server.
Name string
// The unique identifier of the Hardware Group that this server belongs to (required).
HardwareGroupUUID string
// The alias of the account to own the server (optional)
AccountAlias string
// The number of processors to configure the server with (required).
Cpu int
// The number of GB of memory to configure the server with (required).
MemoryGB int
// The size in GB of an additional drive to add to the server (required).
// If no additional drive is needed, pass in a 0 value.
AdditionalStorageGB int
// A list of Custom Fields associated to this server.
// See field of identical name in above CreateServerReq
CustomFields []struct { ID, Value string }
}
// Configure the CPU, Memory, Group and additional storage for a Server.
func (c *Client) ConfigureServer(req *ConfigureServerReq) (reqId int, err error) {
err = c.getResponse("/Server/ConfigureServer/JSON", req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Power server on (or resume from a paused state).
// @name: The name of the Server to power on.
// @acctAlias: The alias of the account that owns the server.
func (c *Client) PowerOnServer(name, acctAlias string) (reqId int, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/PowerOnServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Pause the server.
// @name: The name of the Server to pause.
// @acctAlias: The alias of the account that owns the server.
func (c *Client) PauseServer(name, acctAlias string) (reqId int, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/PauseServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Power server off.
// @name: The name of the Server to power off.
// @acctAlias: The alias of the account that owns the server.
func (c *Client) PowerOffServer(name, acctAlias string) (reqId int, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/PowerOffServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Shut down the operating system and then power off server.
// @name: The name of the Server to shut down.
// @acctAlias: The alias of the account that owns the server.
func (c *Client) ShutdownServer(name, acctAlias string) (reqId int, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/ShutdownServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Reboot the server (OS reboot)
// @name: The name of the Server to reboot.
// @acctAlias: The alias of the account that owns the server.
func (c *Client) RebootServer(name, acctAlias string) (reqId int, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/RebootServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Reset server (forced power-cycle).
// @name: The name of the Server to reset.
// @acctAlias: The alias of the account that owns the server.
func (c *Client) ResetServer(name, acctAlias string) (reqId int, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/ResetServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Enable or disable maintenance mode on a Server.
// @enable: Turn maintenance mode on or off.
// @name: The name of the Server.
// @acctAlias: The alias of the account that owns the server (optional).
func (c *Client) ServerMaintenance(enable bool, name, acctAlias string) (reqId int, err error) {
req := struct {
Name, AccountAlias string
Enable bool
} { name, acctAlias, enable }
err = c.getResponse("/Server/ServerMaintenance/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Delete the machine and release all associated resources.
// @name: The name of the Server to delete.
// @acctAlias: The alias of the account that owns the server.
func (c *Client) DeleteServer(name, acctAlias string) (reqId int, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/DeleteServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
/*
* Snapshots
*/
type SnapshotAttribute struct {
// The full name of the Snapshot.
Name string
// The description of the Snapshot.
Description string
// The time (in UTC) when the Snapshot was created.
DateCreated microsoft.Timestamp
}
// Get the list of Snapshots associated with the server.
// @name: The name of the Server to list snapshots of.
// @acctAlias: The alias of the account that owns the server (optional).
func (c *Client) GetSnapshots(name, acctAlias string) (snaps []SnapshotAttribute, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/GetSnapshots/JSON", &req, &struct {
BaseResponse
Snapshots *[]SnapshotAttribute
} { Snapshots: &snaps })
return
}
// Take a server snapshot.
// @name: The name of the Server to snapshot.
// @acctAlias: The alias of the account that owns the server (optional).
func (c *Client) SnapshotServer(name, acctAlias string) (reqId int, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/SnapshotServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Revert to a named snapshot for a specified server.
// @name: The name of the Server to revert.
// @snapName: The name of the Snapshot to revert to.
// @acctAlias: The alias of the account that owns the server (optional).
// FIXME: CLC only uses 1 snapshot currently. Use GetSnapshots() to get the single snapshot
// name (if any), and drop the @snapName argument.
func (c *Client) RevertToSnapshot(name, snapName, acctAlias string) error {
req := struct { SnapshotName, Name, AccountAlias string } { snapName, name, acctAlias }
return c.getResponse("/Server/RevertToSnapshot/JSON", &req, new(BaseResponse))
}
// Delete a named snapshot for a specified server
// @snapName: The name of the Snapshot to delete.
// @name: The name of the Server to delete snapshot from.
// @acctAlias: The alias of the account that owns the server (optional).
func (c *Client) DeleteSnapshot(snapName, name, acctAlias string) error {
req := struct { SnapshotName, Name, AccountAlias string } { snapName, name, acctAlias }
return c.getResponse("/Server/DeleteSnapshot/JSON", &req, new(BaseResponse))
}
/*
* Archiving Servers
*/
type ArchivedServer struct {
// The ID of the Server.
// Deprecated. Value is -1.
ID int
// The full name of the Server.
Name string
// The description of the Server as provided on creation.
Description string
}
// List archived servers
// @acctAlias: The alias of the account that owns the server (optional).
// @location: The data center of the servers (optional).
// Note: dropped the GetArchiveServers() call, it seems deprecated (always returned an empty list).
func (c *Client) ListArchiveServers(acctAlias, location string) (servers []ArchivedServer, err error) {
req := struct { AccountAlias, Location string } { acctAlias, location }
err = c.getResponse("/Server/ListArchivedServers/JSON", &req, &struct {
BaseResponse
Servers *[]ArchivedServer
} { Servers: &servers })
return
}
// Archive a server
// @name: The name of the Server to archive.
// @acctAlias: The alias of the account that owns the server (optional).
func (c *Client) ArchiveServer(name, acctAlias string) (reqId int, err error) {
req := struct { Name, AccountAlias string } { name, acctAlias }
err = c.getResponse("/Server/ArchiveServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}
// Restore an archived server.
// @name: The name of the archived Server.
// @acctAlias: The alias of the account that owns the server (optional).
// @hwGrpUUID: The unique identifier of the hardware group to the restore the server to.
func (c *Client) RestoreServer(name, acctAlias, hwGrpUUID string) (reqId int, err error) {
req := struct {
Name, AccountAlias string
HardwareGroupUUID string
} { name, acctAlias, hwGrpUUID }
err = c.getResponse("/Server/RestoreServer/JSON", &req, &struct {
BaseResponse
RequestID *int
} { RequestID: &reqId })
return
}