1
1
package serverscom
2
2
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ )
7
+
3
8
const (
4
9
locationListPath = "/locations"
10
+ locationPath = "/locations/%d"
5
11
6
12
serverModelOptionListPath = "/locations/%d/order_options/server_models"
13
+ serverModelOptionPath = "/locations/%d/order_options/server_models/%d"
7
14
8
15
ramOptionListPath = "/locations/%d/order_options/server_models/%d/ram"
9
16
10
17
operatingSystemOptionListPath = "/locations/%d/order_options/server_models/%d/operating_systems"
18
+ operatingSystemOptionPath = "/locations/%d/order_options/server_models/%d/operating_systems/%d"
11
19
12
20
driveModelListPath = "/locations/%d/order_options/server_models/%d/drive_models"
21
+ driveModelPath = "/locations/%d/order_options/server_models/%d/drive_models/%d"
13
22
14
23
uplinkOptionListPath = "/locations/%d/order_options/server_models/%d/uplink_models"
24
+ uplinkOptionPath = "/locations/%d/order_options/server_models/%d/uplink_models/%d"
15
25
16
26
bandwidthOptionListPath = "/locations/%d/order_options/server_models/%d/uplink_models/%d/bandwidth"
27
+ bandwidthOptionPath = "/locations/%d/order_options/server_models/%d/uplink_models/%d/bandwidth/%d"
17
28
18
- sbmFlavorOptionListPath = "/locations/%d/order_options/sbm_flavor_models"
19
-
29
+ sbmFlavorOptionListPath = "/locations/%d/order_options/sbm_flavor_models"
30
+ sbmFlavorOptionPath = "/locations/%d/order_options/sbm_flavor_models/%d"
20
31
sbmOperatingSystemOptionListPath = "/locations/%d/order_options/sbm_flavor_models/%d/operating_systems"
32
+ sbmOperatingSystemOptionPath = "/locations/%d/order_options/sbm_flavor_models/%d/operating_systems/%d"
21
33
)
22
34
23
35
// LocationsService is an interface to interfacing with the Location and Order options endpoints
24
36
// API documentation:
25
37
// https://developers.servers.com/api-documentation/v1/#tag/Location
26
38
// https://developers.servers.com/api-documentation/v1/#tag/Server-Model-Option
39
+ // https://developers.servers.com/api-documentation/v1/#tag/SBM-Flavor-Model-Option
27
40
// https://developers.servers.com/api-documentation/v1/#tag/Drive-Model-Option
28
41
// https://developers.servers.com/api-documentation/v1/#tag/Ram-Option
29
42
// https://developers.servers.com/api-documentation/v1/#tag/Operating-System-Option
@@ -34,14 +47,22 @@ type LocationsService interface {
34
47
Collection () Collection [Location ]
35
48
36
49
// Generic operations
37
- ServerModelOptions (LocationID int64 ) Collection [ServerModelOption ]
38
- RAMOptions (LocationID , ServerModelID int64 ) Collection [RAMOption ]
39
- OperatingSystemOptions (LocationID , ServerModelID int64 ) Collection [OperatingSystemOption ]
40
- DriveModelOptions (LocationID , ServerModelID int64 ) Collection [DriveModel ]
41
- UplinkOptions (LocationID , ServerModelID int64 ) Collection [UplinkOption ]
42
- BandwidthOptions (LocationID , ServerModelID , uplinkID int64 ) Collection [BandwidthOption ]
43
- SBMFlavorOptions (LocationID int64 ) Collection [SBMFlavor ]
44
- SBMOperatingSystemOptions (LocationID , sbmFlavorModelID int64 ) Collection [OperatingSystemOption ]
50
+ GetLocation (ctx context.Context , locationID int64 ) (* Location , error )
51
+ ServerModelOptions (locationID int64 ) Collection [ServerModelOption ]
52
+ GetServerModelOption (ctx context.Context , locationID , serverModelID int64 ) (* ServerModelOptionDetail , error )
53
+ RAMOptions (locationID , serverModelID int64 ) Collection [RAMOption ]
54
+ OperatingSystemOptions (locationID , serverModelID int64 ) Collection [OperatingSystemOption ]
55
+ GetOperatingSystemOption (ctx context.Context , locationID , serverModelID , operatingSystemID int64 ) (* OperatingSystemOption , error )
56
+ DriveModelOptions (locationID , serverModelID int64 ) Collection [DriveModel ]
57
+ GetDriveModelOption (ctx context.Context , locationID , serverModelID , driveModelID int64 ) (* DriveModel , error )
58
+ UplinkOptions (locationID , serverModelID int64 ) Collection [UplinkOption ]
59
+ GetUplinkOption (ctx context.Context , locationID , serverModelID , uplinkModelID int64 ) (* UplinkOption , error )
60
+ BandwidthOptions (locationID , serverModelID , uplinkID int64 ) Collection [BandwidthOption ]
61
+ GetBandwidthOption (ctx context.Context , locationID , serverModelID , uplinkModelID , bandwidthID int64 ) (* BandwidthOption , error )
62
+ SBMFlavorOptions (locationID int64 ) Collection [SBMFlavor ]
63
+ GetSBMFlavorOption (ctx context.Context , locationID , sbmFlavorModelID int64 ) (* SBMFlavor , error )
64
+ SBMOperatingSystemOptions (locationID , sbmFlavorModelID int64 ) Collection [OperatingSystemOption ]
65
+ GetSBMOperatingSystemOption (ctx context.Context , locationID , sbmFlavorModelID , operatingSystemID int64 ) (* OperatingSystemOption , error )
45
66
}
46
67
47
68
// LocationsHandler handles operations around cloud instances
@@ -54,13 +75,47 @@ func (h *LocationsHandler) Collection() Collection[Location] {
54
75
return NewCollection [Location ](h .client , locationListPath )
55
76
}
56
77
78
+ // GetLocation returns a location
79
+ func (h * LocationsHandler ) GetLocation (ctx context.Context , id int64 ) (* Location , error ) {
80
+ url := h .client .buildURL (locationPath , id )
81
+
82
+ body , err := h .client .buildAndExecRequest (ctx , "GET" , url , nil )
83
+ if err != nil {
84
+ return nil , err
85
+ }
86
+
87
+ location := new (Location )
88
+ if err := json .Unmarshal (body , location ); err != nil {
89
+ return nil , err
90
+ }
91
+
92
+ return location , nil
93
+ }
94
+
57
95
// ServerModelOptions builds a new Collection[ServerModelOption interface
58
96
func (h * LocationsHandler ) ServerModelOptions (LocationID int64 ) Collection [ServerModelOption ] {
59
97
path := h .client .buildPath (serverModelOptionListPath , []interface {}{LocationID }... )
60
98
61
99
return NewCollection [ServerModelOption ](h .client , path )
62
100
}
63
101
102
+ // GetServerModelOption returns a server model option
103
+ func (h * LocationsHandler ) GetServerModelOption (ctx context.Context , locationID , serverModelID int64 ) (* ServerModelOptionDetail , error ) {
104
+ url := h .client .buildURL (serverModelOptionPath , locationID , serverModelID )
105
+
106
+ body , err := h .client .buildAndExecRequest (ctx , "GET" , url , nil )
107
+ if err != nil {
108
+ return nil , err
109
+ }
110
+
111
+ serverModelOption := new (ServerModelOptionDetail )
112
+ if err := json .Unmarshal (body , serverModelOption ); err != nil {
113
+ return nil , err
114
+ }
115
+
116
+ return serverModelOption , nil
117
+ }
118
+
64
119
// RAMOptions builds a new Collection[RAMOption] interface
65
120
func (h * LocationsHandler ) RAMOptions (LocationID , ServerModelID int64 ) Collection [RAMOption ] {
66
121
path := h .client .buildPath (ramOptionListPath , []interface {}{LocationID , ServerModelID }... )
@@ -75,37 +130,139 @@ func (h *LocationsHandler) OperatingSystemOptions(LocationID, ServerModelID int6
75
130
return NewCollection [OperatingSystemOption ](h .client , path )
76
131
}
77
132
133
+ // GetOperatingSystemOption returns an operating system option
134
+ func (h * LocationsHandler ) GetOperatingSystemOption (ctx context.Context , locationID , serverModelID , operatingSystemID int64 ) (* OperatingSystemOption , error ) {
135
+ url := h .client .buildURL (operatingSystemOptionPath , locationID , serverModelID , operatingSystemID )
136
+
137
+ body , err := h .client .buildAndExecRequest (ctx , "GET" , url , nil )
138
+ if err != nil {
139
+ return nil , err
140
+ }
141
+
142
+ operatingSystemOption := new (OperatingSystemOption )
143
+ if err := json .Unmarshal (body , operatingSystemOption ); err != nil {
144
+ return nil , err
145
+ }
146
+
147
+ return operatingSystemOption , nil
148
+ }
149
+
78
150
// DriveModelOptions builds a new Collection[DriveModel] interface
79
151
func (h * LocationsHandler ) DriveModelOptions (LocationID , ServerModelID int64 ) Collection [DriveModel ] {
80
152
path := h .client .buildPath (driveModelListPath , []interface {}{LocationID , ServerModelID }... )
81
153
82
154
return NewCollection [DriveModel ](h .client , path )
83
155
}
84
156
157
+ // GetDriveModelOption returns a drive model
158
+ func (h * LocationsHandler ) GetDriveModelOption (ctx context.Context , locationID , serverModelID , driveModelID int64 ) (* DriveModel , error ) {
159
+ url := h .client .buildURL (driveModelPath , locationID , serverModelID , driveModelID )
160
+
161
+ body , err := h .client .buildAndExecRequest (ctx , "GET" , url , nil )
162
+ if err != nil {
163
+ return nil , err
164
+ }
165
+
166
+ driveModel := new (DriveModel )
167
+ if err := json .Unmarshal (body , driveModel ); err != nil {
168
+ return nil , err
169
+ }
170
+
171
+ return driveModel , nil
172
+ }
173
+
85
174
// UplinkOptions builds a new Collection[UplinkOption] interface
86
175
func (h * LocationsHandler ) UplinkOptions (LocationID , ServerModelID int64 ) Collection [UplinkOption ] {
87
176
path := h .client .buildPath (uplinkOptionListPath , []interface {}{LocationID , ServerModelID }... )
88
177
89
178
return NewCollection [UplinkOption ](h .client , path )
90
179
}
91
180
181
+ // GetUplinkOption returns an uplink model
182
+ func (h * LocationsHandler ) GetUplinkOption (ctx context.Context , locationID , serverModelID , uplinkModelID int64 ) (* UplinkOption , error ) {
183
+ url := h .client .buildURL (uplinkOptionPath , locationID , serverModelID , uplinkModelID )
184
+
185
+ body , err := h .client .buildAndExecRequest (ctx , "GET" , url , nil )
186
+ if err != nil {
187
+ return nil , err
188
+ }
189
+
190
+ uplinkOption := new (UplinkOption )
191
+ if err := json .Unmarshal (body , uplinkOption ); err != nil {
192
+ return nil , err
193
+ }
194
+
195
+ return uplinkOption , nil
196
+ }
197
+
92
198
// BandwidthOptions builds a new Collection[BandwidthOption] interface
93
199
func (h * LocationsHandler ) BandwidthOptions (LocationID , ServerModelID , uplinkID int64 ) Collection [BandwidthOption ] {
94
200
path := h .client .buildPath (bandwidthOptionListPath , []interface {}{LocationID , ServerModelID , uplinkID }... )
95
201
96
202
return NewCollection [BandwidthOption ](h .client , path )
97
203
}
98
204
205
+ // GetBandwidthOption returns a bandwidth option
206
+ func (h * LocationsHandler ) GetBandwidthOption (ctx context.Context , locationID , serverModelID , uplinkModelID , bandwidthID int64 ) (* BandwidthOption , error ) {
207
+ url := h .client .buildURL (bandwidthOptionPath , locationID , serverModelID , uplinkModelID , bandwidthID )
208
+
209
+ body , err := h .client .buildAndExecRequest (ctx , "GET" , url , nil )
210
+ if err != nil {
211
+ return nil , err
212
+ }
213
+
214
+ bandwidthOption := new (BandwidthOption )
215
+ if err := json .Unmarshal (body , bandwidthOption ); err != nil {
216
+ return nil , err
217
+ }
218
+
219
+ return bandwidthOption , nil
220
+ }
221
+
99
222
// SBMFlavorOptions builds a new Collection[SBMFlavor] interface
100
223
func (h * LocationsHandler ) SBMFlavorOptions (LocationID int64 ) Collection [SBMFlavor ] {
101
224
path := h .client .buildPath (sbmFlavorOptionListPath , []interface {}{LocationID }... )
102
225
103
226
return NewCollection [SBMFlavor ](h .client , path )
104
227
}
105
228
229
+ // GetSBMFlavorOption returns an SBM flavor model
230
+ func (h * LocationsHandler ) GetSBMFlavorOption (ctx context.Context , locationID , sbmFlavorModelID int64 ) (* SBMFlavor , error ) {
231
+ url := h .client .buildURL (sbmFlavorOptionPath , locationID , sbmFlavorModelID )
232
+
233
+ body , err := h .client .buildAndExecRequest (ctx , "GET" , url , nil )
234
+ if err != nil {
235
+ return nil , err
236
+ }
237
+
238
+ sbmFlavor := new (SBMFlavor )
239
+ if err := json .Unmarshal (body , sbmFlavor ); err != nil {
240
+ return nil , err
241
+ }
242
+
243
+ return sbmFlavor , nil
244
+ }
245
+
106
246
// SBMOperatingSystemOptions builds a new Collection[OperatingSystemOption] interface
107
247
func (h * LocationsHandler ) SBMOperatingSystemOptions (LocationID , SBMFlavorModelID int64 ) Collection [OperatingSystemOption ] {
108
248
path := h .client .buildPath (sbmOperatingSystemOptionListPath , []interface {}{LocationID , SBMFlavorModelID }... )
109
249
110
250
return NewCollection [OperatingSystemOption ](h .client , path )
111
251
}
252
+
253
+ // GetSBMOperatingSystemOption returns an SBM operating system option
254
+ func (h * LocationsHandler ) GetSBMOperatingSystemOption (ctx context.Context , locationID , sbmFlavorModelID , operatingSystemID int64 ) (* OperatingSystemOption , error ) {
255
+ url := h .client .buildURL (sbmOperatingSystemOptionPath , locationID , sbmFlavorModelID , operatingSystemID )
256
+
257
+ body , err := h .client .buildAndExecRequest (ctx , "GET" , url , nil )
258
+ if err != nil {
259
+ return nil , err
260
+ }
261
+
262
+ operatingSystemOption := new (OperatingSystemOption )
263
+ if err := json .Unmarshal (body , operatingSystemOption ); err != nil {
264
+ return nil , err
265
+ }
266
+
267
+ return operatingSystemOption , nil
268
+ }
0 commit comments