Skip to content

Commit 8c4d96c

Browse files
committed
add more methods for sbm
1 parent b98bf13 commit 8c4d96c

File tree

7 files changed

+268
-1
lines changed

7 files changed

+268
-1
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
"id": "xkazYeJ0",
4+
"title": "example.aa",
5+
"location_id": 1,
6+
"status": "init",
7+
"configuration": "Dell chassis-9015 / 2 GB RAM / 2 x hdd-model-404",
8+
"private_ipv4_address": null,
9+
"public_ipv4_address": null,
10+
"lease_start_at": null,
11+
"scheduled_release_at": null,
12+
"type": "sbm_server",
13+
"created_at": "2020-04-22T06:22:04Z",
14+
"updated_at": "2020-04-22T06:22:04Z"
15+
},
16+
{
17+
"id": "w9aAOdvM",
18+
"title": "example.bb",
19+
"location_id": 1,
20+
"status": "init",
21+
"configuration": "Dell chassis-9015 / 2 GB RAM / 2 x hdd-model-404",
22+
"private_ipv4_address": null,
23+
"public_ipv4_address": null,
24+
"lease_start_at": null,
25+
"scheduled_release_at": null,
26+
"type": "sbm_server",
27+
"created_at": "2020-04-22T06:22:04Z",
28+
"updated_at": "2020-04-22T06:22:04Z"
29+
}
30+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": "xkazYeJ0",
3+
"title": "example.aa",
4+
"location_id": 1,
5+
"status": "active",
6+
"configuration": "REMM R123",
7+
"private_ipv4_address": "10.0.0.1",
8+
"public_ipv4_address": "169.254.0.1",
9+
"lease_start_at": "2020-04-20",
10+
"scheduled_release_at": null,
11+
"type": "sbm_server",
12+
"created_at": "2020-04-22T06:22:02Z",
13+
"updated_at": "2020-04-22T06:22:02Z"
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": "xkazYeJ0",
3+
"title": "example.aa",
4+
"location_id": 1,
5+
"status": "active",
6+
"configuration": "REMM R123",
7+
"private_ipv4_address": "10.0.0.1",
8+
"public_ipv4_address": "169.254.0.1",
9+
"lease_start_at": "2020-04-20",
10+
"scheduled_release_at": null,
11+
"type": "sbm_server",
12+
"created_at": "2020-04-22T06:22:02Z",
13+
"updated_at": "2020-04-22T06:22:02Z"
14+
}

pkg/hosts_test.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,123 @@ func TestDedicatedServerPTRRecordsCollection(t *testing.T) {
548548
g.Expect(collection.HasFirstPage()).To(Equal(false))
549549
g.Expect(collection.HasLastPage()).To(Equal(false))
550550
}
551+
552+
func TestHostsCreateSBMServers(t *testing.T) {
553+
g := NewGomegaWithT(t)
554+
555+
ts, client := newFakeServer().
556+
WithRequestPath("/hosts/sbm_servers").
557+
WithRequestMethod("POST").
558+
WithResponseBodyStubFile("fixtures/hosts/sbm_servers/create_response.json").
559+
WithResponseCode(201).
560+
Build()
561+
562+
defer ts.Close()
563+
564+
input := SBMServerCreateInput{
565+
LocationID: int64(1),
566+
FlavorModelID: int64(1),
567+
Hosts: []SBMServerHostInput{
568+
{Hostname: "example.aa"},
569+
{Hostname: "example.bb"},
570+
},
571+
}
572+
573+
ctx := context.TODO()
574+
575+
sbmServers, err := client.Hosts.CreateSBMServers(ctx, input)
576+
577+
g.Expect(err).To(BeNil())
578+
g.Expect(len(sbmServers)).To(Equal(2))
579+
580+
sbmServer := sbmServers[0]
581+
582+
g.Expect(sbmServer.ID).To(Equal("xkazYeJ0"))
583+
g.Expect(sbmServer.Title).To(Equal("example.aa"))
584+
g.Expect(sbmServer.Type).To(Equal("sbm_server"))
585+
g.Expect(sbmServer.LocationID).To(Equal(int64(1)))
586+
g.Expect(sbmServer.Status).To(Equal("init"))
587+
g.Expect(sbmServer.Configuration).To(Equal("Dell chassis-9015 / 2 GB RAM / 2 x hdd-model-404"))
588+
g.Expect(sbmServer.PrivateIPv4Address).To(BeNil())
589+
g.Expect(sbmServer.PublicIPv4Address).To(BeNil())
590+
g.Expect(sbmServer.ScheduledRelease).To(BeNil())
591+
g.Expect(sbmServer.Created.String()).To(Equal("2020-04-22 06:22:04 +0000 UTC"))
592+
g.Expect(sbmServer.Updated.String()).To(Equal("2020-04-22 06:22:04 +0000 UTC"))
593+
594+
sbmServer = sbmServers[1]
595+
596+
g.Expect(sbmServer.ID).To(Equal("w9aAOdvM"))
597+
g.Expect(sbmServer.Title).To(Equal("example.bb"))
598+
g.Expect(sbmServer.Type).To(Equal("sbm_server"))
599+
g.Expect(sbmServer.LocationID).To(Equal(int64(1)))
600+
g.Expect(sbmServer.Status).To(Equal("init"))
601+
g.Expect(sbmServer.Configuration).To(Equal("Dell chassis-9015 / 2 GB RAM / 2 x hdd-model-404"))
602+
g.Expect(sbmServer.PrivateIPv4Address).To(BeNil())
603+
g.Expect(sbmServer.PublicIPv4Address).To(BeNil())
604+
g.Expect(sbmServer.ScheduledRelease).To(BeNil())
605+
g.Expect(sbmServer.Created.String()).To(Equal("2020-04-22 06:22:04 +0000 UTC"))
606+
g.Expect(sbmServer.Updated.String()).To(Equal("2020-04-22 06:22:04 +0000 UTC"))
607+
}
608+
609+
func TestHostsGetSBMServer(t *testing.T) {
610+
g := NewGomegaWithT(t)
611+
612+
ts, client := newFakeServer().
613+
WithRequestPath("/hosts/sbm_servers/xkazYeJ0").
614+
WithRequestMethod("GET").
615+
WithResponseBodyStubFile("fixtures/hosts/sbm_servers/get_response.json").
616+
WithResponseCode(200).
617+
Build()
618+
619+
defer ts.Close()
620+
621+
ctx := context.TODO()
622+
623+
sbmServer, err := client.Hosts.GetSBMServer(ctx, "xkazYeJ0")
624+
625+
g.Expect(err).To(BeNil())
626+
g.Expect(sbmServer).ToNot(BeNil())
627+
628+
g.Expect(sbmServer.ID).To(Equal("xkazYeJ0"))
629+
g.Expect(sbmServer.Title).To(Equal("example.aa"))
630+
g.Expect(sbmServer.Type).To(Equal("sbm_server"))
631+
g.Expect(sbmServer.LocationID).To(Equal(int64(1)))
632+
g.Expect(sbmServer.Status).To(Equal("active"))
633+
g.Expect(sbmServer.Configuration).To(Equal("REMM R123"))
634+
g.Expect(*sbmServer.PrivateIPv4Address).To(Equal("10.0.0.1"))
635+
g.Expect(*sbmServer.PublicIPv4Address).To(Equal("169.254.0.1"))
636+
g.Expect(sbmServer.ScheduledRelease).To(BeNil())
637+
g.Expect(sbmServer.Created.String()).To(Equal("2020-04-22 06:22:02 +0000 UTC"))
638+
g.Expect(sbmServer.Updated.String()).To(Equal("2020-04-22 06:22:02 +0000 UTC"))
639+
}
640+
641+
func TestHostsReleaseSBMServer(t *testing.T) {
642+
g := NewGomegaWithT(t)
643+
644+
ts, client := newFakeServer().
645+
WithRequestPath("/hosts/sbm_servers/xkazYeJ0").
646+
WithRequestMethod("DELETE").
647+
WithResponseBodyStubFile("fixtures/hosts/sbm_servers/release_response.json").
648+
WithResponseCode(200).
649+
Build()
650+
651+
defer ts.Close()
652+
653+
ctx := context.TODO()
654+
655+
sbmServer, err := client.Hosts.ReleaseSBMServer(ctx, "xkazYeJ0")
656+
657+
g.Expect(err).To(BeNil())
658+
g.Expect(sbmServer).ToNot(BeNil())
659+
660+
g.Expect(sbmServer.ID).To(Equal("xkazYeJ0"))
661+
g.Expect(sbmServer.Title).To(Equal("example.aa"))
662+
g.Expect(sbmServer.Type).To(Equal("sbm_server"))
663+
g.Expect(sbmServer.LocationID).To(Equal(int64(1)))
664+
g.Expect(sbmServer.Status).To(Equal("active"))
665+
g.Expect(sbmServer.Configuration).To(Equal("REMM R123"))
666+
g.Expect(*sbmServer.PrivateIPv4Address).To(Equal("10.0.0.1"))
667+
g.Expect(*sbmServer.PublicIPv4Address).To(Equal("169.254.0.1"))
668+
g.Expect(sbmServer.Created.String()).To(Equal("2020-04-22 06:22:02 +0000 UTC"))
669+
g.Expect(sbmServer.Updated.String()).To(Equal("2020-04-22 06:22:02 +0000 UTC"))
670+
}

pkg/locations.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const (
1414
uplinkOptionListPath = "/locations/%d/order_options/server_models/%d/uplink_models"
1515

1616
bandwidthOptionListPath = "/locations/%d/order_options/server_models/%d/uplink_models/%d/bandwidth"
17+
18+
sbmFlavorOptionListPath = "/locations/%d/order_options/sbm_flavor_models"
19+
20+
sbmOperatingSystemOptionListPath = "/locations/%d/order_options/sbm_flavor_models/%d/operating_systems"
1721
)
1822

1923
// LocationsService is an interface to interfacing with the Location and Order options endpoints
@@ -36,6 +40,8 @@ type LocationsService interface {
3640
DriveModelOptions(LocationID, ServerModelID int64) Collection[DriveModel]
3741
UplinkOptions(LocationID, ServerModelID int64) Collection[UplinkOption]
3842
BandwidthOptions(LocationID, ServerModelID, uplinkID int64) Collection[BandwidthOption]
43+
SBMFlavorOptions(LocationID int64) Collection[SBMFlavor]
44+
SBMOperatingSystemOptions(LocationID, sbmFlavorModelID int64) Collection[OperatingSystemOption]
3945
}
4046

4147
// LocationsHandler handles operations around cloud instances
@@ -89,3 +95,17 @@ func (h *LocationsHandler) BandwidthOptions(LocationID, ServerModelID, uplinkID
8995

9096
return NewCollection[BandwidthOption](h.client, path)
9197
}
98+
99+
// SBMFlavorOptions builds a new Collection[SBMFlavor] interface
100+
func (h *LocationsHandler) SBMFlavorOptions(LocationID int64) Collection[SBMFlavor] {
101+
path := h.client.buildPath(sbmFlavorOptionListPath, []interface{}{LocationID}...)
102+
103+
return NewCollection[SBMFlavor](h.client, path)
104+
}
105+
106+
// SBMOperatingSystemOptions builds a new Collection[OperatingSystemOption] interface
107+
func (h *LocationsHandler) SBMOperatingSystemOptions(LocationID, SBMFlavorModelID int64) Collection[OperatingSystemOption] {
108+
path := h.client.buildPath(sbmOperatingSystemOptionListPath, []interface{}{LocationID, SBMFlavorModelID}...)
109+
110+
return NewCollection[OperatingSystemOption](h.client, path)
111+
}

pkg/locations_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,55 @@ func TestBandwidthOptionsCollection(t *testing.T) {
188188
g.Expect(collection.HasFirstPage()).To(Equal(false))
189189
g.Expect(collection.HasLastPage()).To(Equal(false))
190190
}
191+
192+
func TestSBMFlavorOptionsCollection(t *testing.T) {
193+
g := NewGomegaWithT(t)
194+
195+
ts, client := newFakeServer().
196+
WithRequestPath("/locations/1/order_options/sbm_flavor_models").
197+
WithRequestMethod("GET").
198+
WithResponseBodyStubInline(`[]`).
199+
WithResponseCode(200).
200+
Build()
201+
202+
defer ts.Close()
203+
204+
collection := client.Locations.SBMFlavorOptions(int64(1))
205+
206+
ctx := context.TODO()
207+
208+
list, err := collection.List(ctx)
209+
210+
g.Expect(err).To(BeNil())
211+
g.Expect(list).To(BeEmpty())
212+
g.Expect(collection.HasNextPage()).To(Equal(false))
213+
g.Expect(collection.HasPreviousPage()).To(Equal(false))
214+
g.Expect(collection.HasFirstPage()).To(Equal(false))
215+
g.Expect(collection.HasLastPage()).To(Equal(false))
216+
}
217+
218+
func TestSBMOperatingSystemOptionsCollection(t *testing.T) {
219+
g := NewGomegaWithT(t)
220+
221+
ts, client := newFakeServer().
222+
WithRequestPath("/locations/1/order_options/sbm_flavor_models/1/operating_systems").
223+
WithRequestMethod("GET").
224+
WithResponseBodyStubInline(`[]`).
225+
WithResponseCode(200).
226+
Build()
227+
228+
defer ts.Close()
229+
230+
collection := client.Locations.SBMOperatingSystemOptions(int64(1), int64(1))
231+
232+
ctx := context.TODO()
233+
234+
list, err := collection.List(ctx)
235+
236+
g.Expect(err).To(BeNil())
237+
g.Expect(list).To(BeEmpty())
238+
g.Expect(collection.HasNextPage()).To(Equal(false))
239+
g.Expect(collection.HasPreviousPage()).To(Equal(false))
240+
g.Expect(collection.HasFirstPage()).To(Equal(false))
241+
g.Expect(collection.HasLastPage()).To(Equal(false))
242+
}

pkg/types.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ type SBMServerHostInput struct {
255255
// },
256256
// }
257257
type SBMServerCreateInput struct {
258-
SBMFlavorModelID int64 `json:"sbm_flavor_model_id"`
258+
FlavorModelID int64 `json:"sbm_flavor_model_id"`
259259
LocationID int64 `json:"location_id"`
260260
Hosts []SBMServerHostInput `json:"hosts"`
261261
OperatingSystemID *int64 `json:"operating_system_id"`
@@ -749,3 +749,20 @@ type L7LoadBalancerCreateInput struct {
749749
VHostZones []L7VHostZoneInput `json:"vhost_zones"`
750750
UpstreamZones []L7UpstreamZoneInput `json:"upstream_zones"`
751751
}
752+
753+
type SBMFlavor struct {
754+
ID int64 `json:"id"`
755+
Name string `json:"name"`
756+
CPUName string `json:"cpu_name"`
757+
CPUCount int `json:"cpu_count"`
758+
CPUCoresCount int `json:"cpu_cores_count"`
759+
CPUFrequency string `json:"cpu_frequency"`
760+
RAMSize int `json:"ram_size"`
761+
DrivesConfiguration string `json:"drives_configuration"`
762+
PublicUplinkModelID int `json:"public_uplink_model_id"`
763+
PublicUplinkModelName string `json:"public_uplink_model_name"`
764+
PrivateUplinkModelID int `json:"private_uplink_model_id"`
765+
PrivateUplinkModelName string `json:"private_uplink_model_name"`
766+
BandwidthID int `json:"bandwidth_id"`
767+
BandwidthName string `json:"bandwidth_name"`
768+
}

0 commit comments

Comments
 (0)