Skip to content

Commit 5385a7f

Browse files
committed
add missing methods for location service
1 parent 0046815 commit 5385a7f

9 files changed

+517
-10
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": 348,
3+
"name": "20002 GB",
4+
"type": "bytes",
5+
"commit": 20002000000
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": 369,
3+
"name": "ssd-model-504",
4+
"capacity": 100,
5+
"interface": "SATA3",
6+
"form_factor": "2.5",
7+
"media_type": "SSD"
8+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"id": 1108,
3+
"name": "location2251",
4+
"status": "active",
5+
"code": "location2251",
6+
"supported_features": [
7+
"disaggregated_public_ports",
8+
"disaggregated_private_ports",
9+
"no_public_network",
10+
"no_private_ip",
11+
"no_public_ip_address",
12+
"host_rescue_mode",
13+
"oob_public_access"
14+
],
15+
"l2_segments_enabled": false,
16+
"private_racks_enabled": false,
17+
"load_balancers_enabled": false
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": 50,
3+
"full_name": "Ubuntu 18.04-server x86_64",
4+
"name": "Ubuntu",
5+
"version": "18.04-server",
6+
"arch": "x86_64",
7+
"filesystems": [
8+
"ext2",
9+
"ext4",
10+
"swap",
11+
"xfs",
12+
"reiser"
13+
]
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"id": 119,
3+
"name": "P-101",
4+
"cpu_name": "cpu_name",
5+
"cpu_count": 1,
6+
"cpu_cores_count": 2,
7+
"cpu_frequency": "3.8",
8+
"ram_size": 4096,
9+
"drives_configuration": "",
10+
"public_uplink_model_id": 117,
11+
"public_uplink_model_name": "uplink-model-name-36",
12+
"private_uplink_model_id": 116,
13+
"private_uplink_model_name": "uplink-model-name-35",
14+
"bandwidth_id": 118,
15+
"bandwidth_name": "public-bandwidth-model-21"
16+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"id": 231,
3+
"name": "server-model-469",
4+
"cpu_name": "cpu-model-model-468",
5+
"cpu_count": 2,
6+
"cpu_cores_count": 16,
7+
"cpu_frequency": 1970,
8+
"ram": 32,
9+
"ram_type": "DDR3",
10+
"max_ram": 384,
11+
"has_raid_controller": true,
12+
"raid_controller_name": "AHCI controller",
13+
"drive_slots_count": 8,
14+
"drive_slots": [
15+
{
16+
"position": 0,
17+
"interface": "SAS",
18+
"form_factor": "2_5",
19+
"drive_model_id": 234,
20+
"hot_swappable": false
21+
},
22+
{
23+
"position": 1,
24+
"interface": "SAS",
25+
"form_factor": "2_5",
26+
"drive_model_id": 235,
27+
"hot_swappable": false
28+
}
29+
]
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"id": 294,
3+
"name": "Private 1 Gbps without redundancy",
4+
"type": "private",
5+
"speed": 1000,
6+
"redundancy": false
7+
}

pkg/locations.go

Lines changed: 167 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
package serverscom
22

3+
import (
4+
"context"
5+
"encoding/json"
6+
)
7+
38
const (
49
locationListPath = "/locations"
10+
locationPath = "/locations/%d"
511

612
serverModelOptionListPath = "/locations/%d/order_options/server_models"
13+
serverModelOptionPath = "/locations/%d/order_options/server_models/%d"
714

815
ramOptionListPath = "/locations/%d/order_options/server_models/%d/ram"
916

1017
operatingSystemOptionListPath = "/locations/%d/order_options/server_models/%d/operating_systems"
18+
operatingSystemOptionPath = "/locations/%d/order_options/server_models/%d/operating_systems/%d"
1119

1220
driveModelListPath = "/locations/%d/order_options/server_models/%d/drive_models"
21+
driveModelPath = "/locations/%d/order_options/server_models/%d/drive_models/%d"
1322

1423
uplinkOptionListPath = "/locations/%d/order_options/server_models/%d/uplink_models"
24+
uplinkOptionPath = "/locations/%d/order_options/server_models/%d/uplink_models/%d"
1525

1626
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"
1728

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"
2031
sbmOperatingSystemOptionListPath = "/locations/%d/order_options/sbm_flavor_models/%d/operating_systems"
32+
sbmOperatingSystemOptionPath = "/locations/%d/order_options/sbm_flavor_models/%d/operating_systems/%d"
2133
)
2234

2335
// LocationsService is an interface to interfacing with the Location and Order options endpoints
2436
// API documentation:
2537
// https://developers.servers.com/api-documentation/v1/#tag/Location
2638
// https://developers.servers.com/api-documentation/v1/#tag/Server-Model-Option
39+
// https://developers.servers.com/api-documentation/v1/#tag/SBM-Flavor-Model-Option
2740
// https://developers.servers.com/api-documentation/v1/#tag/Drive-Model-Option
2841
// https://developers.servers.com/api-documentation/v1/#tag/Ram-Option
2942
// https://developers.servers.com/api-documentation/v1/#tag/Operating-System-Option
@@ -34,14 +47,22 @@ type LocationsService interface {
3447
Collection() Collection[Location]
3548

3649
// 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)
4566
}
4667

4768
// LocationsHandler handles operations around cloud instances
@@ -54,13 +75,47 @@ func (h *LocationsHandler) Collection() Collection[Location] {
5475
return NewCollection[Location](h.client, locationListPath)
5576
}
5677

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+
5795
// ServerModelOptions builds a new Collection[ServerModelOption interface
5896
func (h *LocationsHandler) ServerModelOptions(LocationID int64) Collection[ServerModelOption] {
5997
path := h.client.buildPath(serverModelOptionListPath, []interface{}{LocationID}...)
6098

6199
return NewCollection[ServerModelOption](h.client, path)
62100
}
63101

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+
64119
// RAMOptions builds a new Collection[RAMOption] interface
65120
func (h *LocationsHandler) RAMOptions(LocationID, ServerModelID int64) Collection[RAMOption] {
66121
path := h.client.buildPath(ramOptionListPath, []interface{}{LocationID, ServerModelID}...)
@@ -75,37 +130,139 @@ func (h *LocationsHandler) OperatingSystemOptions(LocationID, ServerModelID int6
75130
return NewCollection[OperatingSystemOption](h.client, path)
76131
}
77132

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+
78150
// DriveModelOptions builds a new Collection[DriveModel] interface
79151
func (h *LocationsHandler) DriveModelOptions(LocationID, ServerModelID int64) Collection[DriveModel] {
80152
path := h.client.buildPath(driveModelListPath, []interface{}{LocationID, ServerModelID}...)
81153

82154
return NewCollection[DriveModel](h.client, path)
83155
}
84156

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+
85174
// UplinkOptions builds a new Collection[UplinkOption] interface
86175
func (h *LocationsHandler) UplinkOptions(LocationID, ServerModelID int64) Collection[UplinkOption] {
87176
path := h.client.buildPath(uplinkOptionListPath, []interface{}{LocationID, ServerModelID}...)
88177

89178
return NewCollection[UplinkOption](h.client, path)
90179
}
91180

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+
92198
// BandwidthOptions builds a new Collection[BandwidthOption] interface
93199
func (h *LocationsHandler) BandwidthOptions(LocationID, ServerModelID, uplinkID int64) Collection[BandwidthOption] {
94200
path := h.client.buildPath(bandwidthOptionListPath, []interface{}{LocationID, ServerModelID, uplinkID}...)
95201

96202
return NewCollection[BandwidthOption](h.client, path)
97203
}
98204

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+
99222
// SBMFlavorOptions builds a new Collection[SBMFlavor] interface
100223
func (h *LocationsHandler) SBMFlavorOptions(LocationID int64) Collection[SBMFlavor] {
101224
path := h.client.buildPath(sbmFlavorOptionListPath, []interface{}{LocationID}...)
102225

103226
return NewCollection[SBMFlavor](h.client, path)
104227
}
105228

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+
106246
// SBMOperatingSystemOptions builds a new Collection[OperatingSystemOption] interface
107247
func (h *LocationsHandler) SBMOperatingSystemOptions(LocationID, SBMFlavorModelID int64) Collection[OperatingSystemOption] {
108248
path := h.client.buildPath(sbmOperatingSystemOptionListPath, []interface{}{LocationID, SBMFlavorModelID}...)
109249

110250
return NewCollection[OperatingSystemOption](h.client, path)
111251
}
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

Comments
 (0)