-
Notifications
You must be signed in to change notification settings - Fork 0
/
servers.go
759 lines (637 loc) · 26.9 KB
/
servers.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
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
package lwapi
import (
"encoding/json"
"fmt"
)
// List your Dedicated Servers. This api call supports pagination.
// Use the limit and offset query string parameters to paginate through all your dedicated servers.
// Every server object in the json response lists a few properties of a server.
// Use the single resouce api call to get more details for a single server.
func (a *DSApi) Servers(queryParams map[string]interface{}) (*Servers, error) {
query := MakeQuery(queryParams)
bodyResp, err := a.NewRequest(NilPayload, "/servers"+query, "GET")
var r *Servers
json.Unmarshal(bodyResp, &r)
return r, err
}
// Use this API to get information about a single server.
func (a *DSApi) Server(serverID uint64) (*Server, error) {
uri := fmt.Sprintf("/servers/%d", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Server
json.Unmarshal(bodyResp, &r)
return r, err
}
// Update the reference for a server.
func (a *DSApi) ServerReferenceUpdate(serverID uint64, params *Reference) (*Server, error) {
uri := fmt.Sprintf("/servers/%d", serverID)
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(payload, uri, "PUT")
var r *Server
json.Unmarshal(bodyResp, &r)
return r, err
}
// This information is generated when running a hardware scan for your server.
// A hardware scan collects hardware information about your system.
func (a *DSApi) ServerHardwareInformation(serverID uint64) (*HardwareInformation, error) {
uri := fmt.Sprintf("/servers/%d/hardwareInfo", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *HardwareInformation
json.Unmarshal(bodyResp, &r)
return r, err
}
// List all IP Addresses associated with this server. Optionally filtered.
func (a *DSApi) ServerIPList(
serverID uint64, queryParams map[string]interface{}) (*ServerIPs, error) {
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/servers/%d/ips%s", serverID, query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *ServerIPs
json.Unmarshal(bodyResp, &r)
return r, err
}
// Get a single IP address associated with this server.
func (a *DSApi) ServerIP(serverID uint64, serverIP string) (*ServerIP, error) {
uri := fmt.Sprintf("/servers/%d/ips/%s", serverID, serverIP)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *ServerIP
json.Unmarshal(bodyResp, &r)
return r, err
}
// Update the reverse lookup or DDoS detection profile for the ip address.
// DDoS detection profiles can only be changed if the IP address is protected using
// Advanced DDoS protection.
func (a *DSApi) ServerIPUpdate(serverID uint64, serverIP string, params *UpdateIPRequest) (
*ServerIP, error) {
if err := params.Validate(); err != nil {
return nil, err
}
uri := fmt.Sprintf("/servers/%d/ips/%s", serverID, serverIP)
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(payload, uri, "PUT")
var r *ServerIP
json.Unmarshal(bodyResp, &r)
return r, err
}
// Null the given IP address.
// It might take a few minutes before the change is propagated across the network.
func (a *DSApi) ServerIPNull(serverID uint64, serverIP string) (*ServerIP, error) {
uri := fmt.Sprintf("/servers/%d/ips/%s/null", serverID, serverIP)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *ServerIP
json.Unmarshal(bodyResp, &r)
return r, err
}
// Remove an existing null route for the given IP address.
// It might take a few minutes before the change is propagated across the network.
func (a *DSApi) ServerIPUnNull(serverID uint64, serverIP string) (*ServerIP, error) {
uri := fmt.Sprintf("/servers/%d/ips/%s/unnull", serverID, serverIP)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *ServerIP
json.Unmarshal(bodyResp, &r)
return r, err
}
// Show all null route history for any ips associated with this server.
func (a *DSApi) ServerIPNullHistory(
serverID uint64, serverIP string, queryParams map[string]interface{}) (
*NullHistory, error) {
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/servers/%d/ips/%s/nullRouteHistory%s", serverID, serverIP, query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *NullHistory
json.Unmarshal(bodyResp, &r)
return r, err
}
// List all network interfaces for this server, including their current status.
func (a *DSApi) ServerNetworkInterfaces(serverID uint64) (*NetworkInterfacesList, error) {
uri := fmt.Sprintf("/servers/%d/networkInterfaces", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *NetworkInterfacesList
json.Unmarshal(bodyResp, &r)
return r, err
}
// Close all network interfaces for this server.
func (a *DSApi) ServerNetworkInterfacesClose(serverID uint64) (*NetworkInterfacesList, error) {
uri := fmt.Sprintf("/servers/%d/networkInterfaces/close", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *NetworkInterfacesList
json.Unmarshal(bodyResp, &r)
return r, err
}
// Open all network interfaces of this server.
func (a *DSApi) ServerNetworkInterfacesOpen(serverID uint64) (*NetworkInterfacesList, error) {
uri := fmt.Sprintf("/servers/%d/networkInterfaces/open", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *NetworkInterfacesList
json.Unmarshal(bodyResp, &r)
return r, err
}
// List the network interfaces of the given type of this server, including their status.
func (a *DSApi) ServerNetworkInterface(serverID uint64, networkType NetworkType) (*NetworkInterface, error) {
if err := networkType.Validate(); err != nil {
return nil, err
}
uri := fmt.Sprintf("/servers/%d/networkInterfaces/%s", serverID, networkType)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *NetworkInterface
json.Unmarshal(bodyResp, &r)
return r, err
}
// Close all network interfaces of this server.
func (a *DSApi) ServerNetworkInterfaceClose(serverID uint64, networkType NetworkType) (*Error, error) {
if err := networkType.Validate(); err != nil {
return nil, err
}
uri := fmt.Sprintf("/servers/%d/networkInterfaces/%s/close", serverID, networkType)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// Open all network interfaces of the given type for this server.
func (a *DSApi) ServerNetworkInterfaceOpen(serverID uint64, networkType NetworkType) (*Error, error) {
if err := networkType.Validate(); err != nil {
return nil, err
}
uri := fmt.Sprintf("/servers/%d/networkInterfaces/%s/open", serverID, networkType)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// This API call will remove the dedicated server from the private network.
// It takes a few minutes before the server has been removed from the private network.
//To get the current status of the server you can call /bareMetals/v2/servers/{serverId}.
// While the server is being removed the status changes to REMOVING.
func (a *DSApi) ServerPrivateNetworkDelete(serverID uint64, privateNetworkID int) (*Error, error) {
uri := fmt.Sprintf("/servers/%d/privateNetworks/%d", serverID, privateNetworkID)
bodyResp, err := a.NewRequest(NilPayload, uri, "DELETE")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// It takes a few minutes before the server has access to the private network.
// To get the current status of the server you can call api.Server(ID).
// Once the server is added to the private network the status changes from CONFIGURING to CONFIGURED.
func (a *DSApi) ServerPrivateNetworkAdd(serverID uint64, privateNetworkID int, linkSpeed int) (*Error, error) {
ls := &LinkSpeed{
LinkSpeed: linkSpeed,
}
if err := ls.Validate(); err != nil {
return nil, err
}
payload, _ := json.Marshal(ls)
uri := fmt.Sprintf("/servers/%d/privateNetworks/%d", serverID, privateNetworkID)
bodyResp, err := a.NewRequest(payload, uri, "PUT")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// Delete a DHCP reservation for this server.
func (a *DSApi) ServerDHCPLeaseDelete(serverID uint64) (*Error, error) {
uri := fmt.Sprintf("/servers/%d/leases", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "DELETE")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// Please note that this will only show reservations for the public network interface.
func (a *DSApi) ServerDHCPLeases(serverID uint64) (*ServerDHCPLeases, error) {
uri := fmt.Sprintf("/servers/%d/leases", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *ServerDHCPLeases
json.Unmarshal(bodyResp, &r)
return r, err
}
// After rebooting your server it will acquire this DHCP reservation and boot from the specified bootfile url.
// Please note that this API call will not reboot or power cycle your server.
func (a *DSApi) ServerDHCPLeaseNew(serverID uint64, params *ServerDHCPLeaseNew) (*Error, error) {
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/leases", serverID)
bodyResp, err := a.NewRequest(payload, uri, "POST")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// Canceling an active job will trigger the onfail flow
// of the current job often resulting in a server reboot.
// If you do not want the server state to change expire the active job instead.
func (a *DSApi) ServerActiveJobCancel(serverID uint64) (*Job, error) {
uri := fmt.Sprintf("/servers/%d/cancelActiveJob", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *Job
json.Unmarshal(bodyResp, &r)
return r, err
}
// Expiring an active job will not have any influence on the current state
// of the server and is merely an administrative action.
// Often you want to cancel the job, resulting in a server reboot.
// In that case\nuse the /cancelActiveJob API call instead.
func (a *DSApi) ServerActiveJobExpire(serverID uint64) (*Job, error) {
uri := fmt.Sprintf("/servers/%d/expireActiveJob", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *Job
json.Unmarshal(bodyResp, &r)
return r, err
}
// A hardware scan collects hardware related information from your server.
// A hardware scan will require a reboot of your server.
// The contents of your hard drive won't be altered in any way.
// After a successful hardware scan your server is booted back into the original operating system.
func (a *DSApi) ServerHardwareScan(serverID uint64, powerCycle bool, callbackUrl string) (*Job, error) {
payload, _ := json.Marshal(&HardwareScanJob{
PowerCycle: powerCycle,
CallbackUrl: callbackUrl,
})
uri := fmt.Sprintf("/servers/%d/hardwareScan", serverID)
bodyResp, err := a.NewRequest(payload, uri, "POST")
var r *Job
json.Unmarshal(bodyResp, &r)
return r, err
}
// Install your server with an Operating System and optional Control Panel.
// The default device / partitions to be used are operating system depended
// and can be retrieved via the /v2/operatingSystems/{operatingSystemId} endpoint.
// You are now able to target a specific diskset, like SATA1TB, SATA2TB, SSD256GB, etc.
// To see which disksets are available in your server check the /v2/servers/{serverId} endpoint
// and look for the corresponding diskset id from the hdd array.
func (a *DSApi) ServerInstallationLaunch(serverID uint64, params *InstallationJob) (*Job, error) {
if err := params.Validate(); err != nil {
return nil, err
}
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/install", serverID)
bodyResp, err := a.NewRequest(payload, uri, "POST")
var r *Job
json.Unmarshal(bodyResp, &r)
return r, err
}
// A reset makes sure that your IPMI interface of your server is compatible with Leaseweb automation.
// An IPMI reset will require a reboot of your server.
// The contents of your hard drive won't be altered in any way.
// After a successful IPMI reset your server is booted back into the original operating system."
func (a *DSApi) ServerIPMIReset(serverID uint64, params *CallbackURL) (*Job, error) {
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/ipmiReset", serverID)
bodyResp, err := a.NewRequest(payload, uri, "POST")
var r *Job
json.Unmarshal(bodyResp, &r)
return r, err
}
// List all jobs for this server.
func (a *DSApi) ServerJobs(serverID uint64) (*Jobs, error) {
uri := fmt.Sprintf("/servers/%d/jobs", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Jobs
json.Unmarshal(bodyResp, &r)
return r, err
}
// Get a single job for this server.
func (a *DSApi) ServerJob(serverID uint64, jobID int) (*Job, error) {
uri := fmt.Sprintf("/servers/%d/jobs/%d", serverID, jobID)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Job
json.Unmarshal(bodyResp, &r)
return r, err
}
// Rescue mode allows you to trouble shoot your server in case your installed
// operating system is no longer reachable.
// You can supply a postInstallScript key in the body of the request which should contain
// a base64 encoded string with a valid script.
// This script will be executed as soon as rescue mode is launched and can be used to further automate
// the process. A requirement for the post install script is that it starts with a shebang
// line like #!/usr/bin/env bash.
// After a rescue mode is launched you can manually reboot the server.
// After this reboot the server will boot into the existing operating system.
// To get a list of available rescue images,
// you could do so by sending a GET request to /bareMetals/v2/rescueImages.
func (a *DSApi) ServerRescueMode(serverID uint64, params *RescueModeJob) (*Job, error) {
if err := params.Validate(); err != nil {
return nil, err
}
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/rescueMode", serverID)
bodyResp, err := a.NewRequest(payload, uri, "POST")
var r *Job
json.Unmarshal(bodyResp, &r)
return r, err
}
// The credentials API allows you to store usernames and passwords securely.
// During (re)installations, rescue modes and ipmi resets the newly generated passwords
// are stored and can be retrieved using this API.
func (a *DSApi) ServerCredentials(
serverID uint64, queryParams map[string]interface{}) (*Credentials, error) {
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/servers/%d/credentials%s", serverID, query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Credentials
json.Unmarshal(bodyResp, &r)
return r, err
}
// Password will NOT be updated on the server.
// The ability to update credentials is for convenience only.
// It provides a secure way to communicate passwords with Leaseweb engineers in case support is required.
func (a *DSApi) ServerCredentialNew(serverID uint64, params *Credential) (*Credential, error) {
if err := params.Validate(); err != nil {
return nil, err
}
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/credentials", serverID)
bodyResp, err := a.NewRequest(payload, uri, "POST")
var r *Credential
json.Unmarshal(bodyResp, &r)
return r, err
}
// List all the credentials filtered by the specified type that are associated with this server.
func (a *DSApi) ServerTypedCredentials(
serverID uint64, credType CredType, queryParams map[string]interface{}) (*Credentials, error) {
if err := credType.Validate(); err != nil {
return nil, err
}
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/servers/%d/credentials/%s%s", serverID, credType, query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Credentials
json.Unmarshal(bodyResp, &r)
return r, err
}
// This action is purely administrative and will only remove the username
// and password associated with this resource from our database.
func (a *DSApi) ServerUsernameCredentialDelete(
serverID uint64, credType CredType, username string) (*Error, error) {
if err := credType.Validate(); err != nil {
return nil, err
}
uri := fmt.Sprintf("/servers/%d/credentials/%s/%s", serverID, credType, username)
bodyResp, err := a.NewRequest(NilPayload, uri, "DELETE")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// View the password for the given credential, identified by type and username.
// Auto generated credentials (during a re-install, rescue mode or ipmi reset can be found here).
func (a *DSApi) ServerUsernameTypedCredentials(
serverID uint64, credType CredType, username string) (*Credential, error) {
if err := credType.Validate(); err != nil {
return nil, err
}
uri := fmt.Sprintf("/servers/%d/credentials/%s/%s", serverID, credType, username)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Credential
json.Unmarshal(bodyResp, &r)
return r, err
}
// The usernames or types cannot be changed.
// In order to change those remove this credentials and create a new one.
// This action is purely administrative and will only update the password
// associated with this resource in our database.
func (a *DSApi) ServerCredentialUpdate(
serverID uint64, credType CredType, username string, params *Password) (*Credential, error) {
if err := credType.Validate(); err != nil {
return nil, err
}
if err := params.Validate(); err != nil {
return nil, err
}
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/credentials/%s/%s", serverID, credType, username)
bodyResp, err := a.NewRequest(payload, uri, "POST")
var r *Credential
json.Unmarshal(bodyResp, &r)
return r, err
}
// At this moment only bandwidth information for the public interface is supported.
func (a *DSApi) ServerBandwidthMetrics(serverID uint64, params *BandwidthMetrics) (*Metrics, error) {
var queryParams map[string]interface{}
if ok, err := params.Validate(); err != nil {
return nil, err
} else {
queryParams = ok
}
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/servers/%d/metrics/bandwidth%s", serverID, query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Metrics
json.Unmarshal(bodyResp, &r)
return r, err
}
// At this moment only bandwidth information for the public interface is supported.
func (a *DSApi) ServerDatatraficMetrics(serverID uint64, params *DatatrafficMetrics) (*Metrics, error) {
var queryParams map[string]interface{}
if ok, err := params.Validate(); err != nil {
return nil, err
} else {
queryParams = ok
}
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/servers/%d/metrics/datatraffic%s", serverID, query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Metrics
json.Unmarshal(bodyResp, &r)
return r, err
}
// List all bandwidth notification settings for this server.
func (a *DSApi) ServerBandwidthNotifications(
serverID uint64, queryParams map[string]interface{}) (*BandwidthNotification, error) {
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/servers/%d/notificationSettings/bandwidth%s", serverID, query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *BandwidthNotification
json.Unmarshal(bodyResp, &r)
return r, err
}
// Create a new bandwidth notification setting for this server.
func (a *DSApi) ServerBandwidthNotificationNew(
serverID uint64, params *NotificationRequest) (*NotificationResponse, error) {
if err := params.Validete(); err != nil {
return nil, err
}
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/notificationSettings/bandwidth", serverID)
bodyResp, err := a.NewRequest(payload, uri, "POST")
var r *NotificationResponse
json.Unmarshal(bodyResp, &r)
return r, err
}
// Remove a Bandwidth Notification setting for this server.
func (a *DSApi) ServerBandwidthNotificationDelete(serverID uint64, notificationSettingId int) (*Error, error) {
uri := fmt.Sprintf("/servers/%d/notificationSettings/bandwidth/%d", serverID, notificationSettingId)
bodyResp, err := a.NewRequest(NilPayload, uri, "DELETE")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// Get a bandwidth notification setting for this server.
func (a *DSApi) ServerBandwidthNotification(
serverID uint64, notificationSettingId int) (*NotificationResponse, error) {
uri := fmt.Sprintf("/servers/%d/notificationSettings/bandwidth/%d", serverID, notificationSettingId)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *NotificationResponse
json.Unmarshal(bodyResp, &r)
return r, err
}
// Update an existing bandwidth notification setting for this server.
func (a *DSApi) ServerBandwidthNotificationUpdate(
serverID uint64, notificationSettingId int, params *NotificationRequest) (*NotificationResponse, error) {
if err := params.Validete(); err != nil {
return nil, err
}
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/notificationSettings/bandwidth/%d", serverID, notificationSettingId)
bodyResp, err := a.NewRequest(payload, uri, "PUT")
var r *NotificationResponse
json.Unmarshal(bodyResp, &r)
return r, err
}
// List all datatraffic notification settings for this server.
func (a *DSApi) ServerDatatrafficNotifications(
serverID uint64, queryParams map[string]interface{}) (*DatatrafficNotification, error) {
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/servers/%d/notificationSettings/datatraffic%s", serverID, query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *DatatrafficNotification
json.Unmarshal(bodyResp, &r)
return r, err
}
// Create a new datatraffic notification setting for this server.
func (a *DSApi) ServerDatatrafficNotificationNew(
serverID uint64, params *DataTrafficNotificationRequest) (*NotificationResponse, error) {
if err := params.Validete(); err != nil {
return nil, err
}
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/notificationSettings/datatraffic", serverID)
bodyResp, err := a.NewRequest(payload, uri, "POST")
var r *NotificationResponse
json.Unmarshal(bodyResp, &r)
return r, err
}
// Delete the given datatraffic notification setting for this server.
func (a *DSApi) ServerDatatrafficNotificationDelete(serverID uint64, notificationSettingId int) (*Error, error) {
uri := fmt.Sprintf("/servers/%d/notificationSettings/datatraffic/%d", serverID, notificationSettingId)
bodyResp, err := a.NewRequest(NilPayload, uri, "DELETE")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// Get a datatraffic notification setting for this server.
func (a *DSApi) ServerDatatrafficNotification(
serverID uint64, notificationSettingId int) (*NotificationResponse, error) {
uri := fmt.Sprintf("/servers/%d/notificationSettings/datatraffic/%d", serverID, notificationSettingId)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *NotificationResponse
json.Unmarshal(bodyResp, &r)
return r, err
}
// Update an existing datatraffic notification setting for this server.
func (a *DSApi) ServerDatatrafficNotificationUpdate(
serverID uint64,
notificationSettingId int,
params *DataTrafficNotificationRequest) (*NotificationResponse, error) {
if err := params.Validete(); err != nil {
return nil, err
}
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/notificationSettings/datatraffic/%d", serverID, notificationSettingId)
bodyResp, err := a.NewRequest(payload, uri, "PUT")
var r *NotificationResponse
json.Unmarshal(bodyResp, &r)
return r, err
}
// Show all DDoS Protection related notification settings for this server.
// These settings control if you want to be notified via email in case a DDoS was mitigated.
func (a *DSApi) ServerDDoSNotification(serverID uint64) (*DDoSStatus, error) {
uri := fmt.Sprintf("/servers/%d/notificationSettings/ddos", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *DDoSStatus
json.Unmarshal(bodyResp, &r)
return r, err
}
// Update your DDoS notification settings for this server.
func (a *DSApi) ServerDDoSNotificationUpdate(serverID uint64, params *DDoSStatus) (*Error, error) {
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/servers/%d/notificationSettings/ddos", serverID)
bodyResp, err := a.NewRequest(payload, uri, "PUT")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// Powercyle the server.
func (a *DSApi) ServerPowerCycle(serverID uint64) (*Error, error) {
uri := fmt.Sprintf("/servers/%d/powerCycle", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// The server can either be ON or OFF.
// Servers can be powered on or off by using the respective /powerOn and /powerOff API calls.
// In addition servers can also be rebooted using the /powerCycle API call.
// The pdu object describes the power status from the power distribution unit (PDU) point of view.
// If your server is connected to multiple PDU ports the status property will report
// on if at least one PDU port has power.
// The ipmi object describes the power status by quering the remote management interface of your server.
// Note that pdu.status can report on but your server can still be powered off if
// it was shutdown via IPMI for example.
func (a *DSApi) ServerPowerStatus(serverID uint64) (*PowerStatus, error) {
uri := fmt.Sprintf("/servers/%d/powerCycle", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *PowerStatus
json.Unmarshal(bodyResp, &r)
return r, err
}
// Power off the given server.
func (a *DSApi) ServerPowerOff(serverID uint64) (*Error, error) {
uri := fmt.Sprintf("/servers/%d/powerOff", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// Power on the given server.
func (a *DSApi) ServerPowerOn(serverID uint64) (*Error, error) {
uri := fmt.Sprintf("/servers/%d/powerOn", serverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// An id of a operating system can be supplied when (re)installing a dedicated server
// (for more information on how to install dedicated servers via the API refer to the API documentation).
func (a *DSApi) OSes(queryParams map[string]interface{}) (*OperatingSystems, error) {
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/operatingSystems%s", query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *OperatingSystems
json.Unmarshal(bodyResp, &r)
return r, err
}
// This detailed information shows default options when
// installing the given operating system on a dedicated server.
// For some operating systems these defaults can be adjusted when making the POST request to /install.
// If the configurable parameter is true these defaults can be adjusted by the client
func (a *DSApi) OS(operatingSystemId string, controlPanelId string) (*OSParams, error) {
uri := fmt.Sprintf("/operatingSystems/%s?controlPanelId=%s", operatingSystemId, controlPanelId)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *OSParams
json.Unmarshal(bodyResp, &r)
return r, err
}
// An id of a control panel can be supplied when (re)installing a dedicated server
// (for more information on how to install dedicated servers via the API refer to the API documentation).
func (a *DSApi) ControlPanels(queryParams map[string]interface{}) (*ControlPanels, error) {
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/controlPanels%s", query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *ControlPanels
json.Unmarshal(bodyResp, &r)
return r, err
}
func (a *DSApi) RescueImages(queryParams map[string]interface{}) (*RescueImages, error) {
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/rescueImages%s", query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *RescueImages
json.Unmarshal(bodyResp, &r)
return r, err
}