-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtualservers.go
149 lines (121 loc) · 4.29 KB
/
virtualservers.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
package lwapi
import (
"encoding/json"
"fmt"
)
func (a *VSApi) VirtualServers(queryParams map[string]interface{}) (*VirtualServers, error) {
query := MakeQuery(queryParams)
bodyResp, err := a.NewRequest(NilPayload, query, "GET")
var r *VirtualServers
json.Unmarshal(bodyResp, &r)
return r, err
}
func (a *VSApi) VirtualServer(vserverID uint64) (*VirtualServer, error) {
uri := fmt.Sprintf("/%d", vserverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *VirtualServer
json.Unmarshal(bodyResp, &r)
return r, err
}
func (a *VSApi) VirtualServerReferenceUpdate(vserverID uint64, params *Reference) (*VirtualServer, error) {
uri := fmt.Sprintf("/%d", vserverID)
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(payload, uri, "PUT")
var r *VirtualServer
json.Unmarshal(bodyResp, &r)
return r, err
}
func (a *VSApi) VirtualServerPowerOff(vserverID uint64) (*Error, error) {
uri := fmt.Sprintf("/%d/powerOff", vserverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
func (a *VSApi) VirtualServerPowerOn(vserverID uint64) (*Error, error) {
uri := fmt.Sprintf("/%d/powerOn", vserverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
func (a *VSApi) VirtualServerReboot(vserverID uint64) (*Error, error) {
uri := fmt.Sprintf("/%d/reboot", vserverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "POST")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
func (a *VSApi) VirtualServerReinstall(vserverID uint64, operatingSystemId string) (*Error, error) {
uri := fmt.Sprintf("/%d/reinstall", vserverID)
payload, _ := json.Marshal(&OperatingSystemID{
OperatingSystemID: operatingSystemId,
})
bodyResp, err := a.NewRequest(payload, uri, "POST")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// This API call will only update the password displayed for your machine in the customer portal.
// It will not make any changes to the root password of your machine.
func (a *VSApi) VirtualServerCredentialUpdate(
vserverID uint64, params *VirtualServerCredentialUpdate) (*Error, error) {
if err := params.Validate(); err != nil {
return nil, err
}
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/%d/credentials", vserverID)
bodyResp, err := a.NewRequest(payload, uri, "PUT")
var r *Error
json.Unmarshal(bodyResp, &r)
return r, err
}
// You will only be able to retrieve the last password that we configured in your server or control panel.
// If you changed it, the information retrieved by this API call will not work.
// The password is not returned in this call, you must use the endpoint to get a credential by
// the username to retrieve it.
func (a *VSApi) VirtualServerCredentials(
serverID uint64, credType VirtualCredType, queryParams map[string]interface{}) (*Credentials, error) {
if err := credType.Validate(); err != nil {
return nil, err
}
query := MakeQuery(queryParams)
uri := fmt.Sprintf("/%d/credentials/%s%s", serverID, credType, query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Credentials
json.Unmarshal(bodyResp, &r)
return r, err
}
func (a *VSApi) VirtualServerUserCredentials(
vserverID uint64, credType VirtualCredType, username string) (*Credential, error) {
if err := credType.Validate(); err != nil {
return nil, err
}
uri := fmt.Sprintf("/%d/credentials/%s/%s", vserverID, credType, username)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Credential
json.Unmarshal(bodyResp, &r)
return r, err
}
func (a *VSApi) VirtualServerDatatraficMetrics(
vserverID uint64, params *DatatrafficMetrics) (*VirtualServerDatatraficMetrics, 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("/%d/metrics/datatraffic%s", vserverID, query)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *VirtualServerDatatraficMetrics
json.Unmarshal(bodyResp, &r)
return r, err
}
func (a *VSApi) VirtualServerTemplates(vserverID uint64) (*Templates, error) {
uri := fmt.Sprintf("/%d/templates", vserverID)
bodyResp, err := a.NewRequest(NilPayload, uri, "GET")
var r *Templates
json.Unmarshal(bodyResp, &r)
return r, err
}