From 0046815f27e7a125d64b43eba9fb5218f646d4e6 Mon Sep 17 00:00:00 2001 From: Oleg Isakov Date: Mon, 28 Apr 2025 19:00:12 +0300 Subject: [PATCH 1/2] add missing fields&models --- pkg/types.go | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/pkg/types.go b/pkg/types.go index fb3b64b..5d22c99 100644 --- a/pkg/types.go +++ b/pkg/types.go @@ -11,9 +11,14 @@ const ( // Location represents location type Location struct { - ID int64 `json:"id"` - Name string `json:"name"` - Code string `json:"code"` + ID int64 `json:"id"` + Name string `json:"name"` + Status string `json:"status"` + Code string `json:"code"` + SupportedFeatures []string `json:"supported_features"` + L2SegmentsEnabled bool `json:"l2_segments_enabled"` + PrivateRacksEnabled bool `json:"private_racks_enabled"` + LoadBalancersEnabled bool `json:"load_balancers_enabled"` } // SSLCertificate represents ssl certificate @@ -322,9 +327,43 @@ type SBMServerCreateInput struct { // ServerModelOption represents server model option type ServerModelOption struct { - ID int64 `json:"id"` - Name string `json:"name"` - RAM int `json:"ram"` + ID int64 `json:"id"` + Name string `json:"name"` + CPUName string `json:"cpu_name"` + CPUCount int `json:"cpu_count"` + CPUCoresCount int `json:"cpu_cores_count"` + CPUFrequency int `json:"cpu_frequency"` + RAM int `json:"ram"` + RAMType string `json:"ram_type"` + MaxRAM int `json:"max_ram"` + HasRAIDController bool `json:"has_raid_controller"` + RAIDControllerName string `json:"raid_controller_name"` + DriveSlotsCount int `json:"drive_slots_count"` +} + +// ServerModelOptionDetail represents full server model option +type ServerModelOptionDetail struct { + ID int64 `json:"id"` + Name string `json:"name"` + CPUName string `json:"cpu_name"` + CPUCount int `json:"cpu_count"` + CPUCoresCount int `json:"cpu_cores_count"` + CPUFrequency int `json:"cpu_frequency"` + RAM int `json:"ram"` + RAMType string `json:"ram_type"` + MaxRAM int `json:"max_ram"` + HasRAIDController bool `json:"has_raid_controller"` + RAIDControllerName string `json:"raid_controller_name"` + DriveSlotsCount int `json:"drive_slots_count"` + DriveSlots []ServerModelDriveSlot `json:"drive_slots"` +} + +type ServerModelDriveSlot struct { + Position int `json:"position"` + Interface string `json:"interface"` + FormFactor string `json:"form_factor"` + DriveModelID int64 `json:"drive_model_id"` + HotSwappable bool `json:"hot_swappable"` } // RAMOption represents ram option From 5385a7fc21b8aef8bf4e9a05e977426507254e49 Mon Sep 17 00:00:00 2001 From: Oleg Isakov Date: Mon, 28 Apr 2025 19:00:31 +0300 Subject: [PATCH 2/2] add missing methods for location service --- .../bandwidth_option_get_response.json | 6 + .../locations/drive_model_get_response.json | 8 + pkg/fixtures/locations/get_response.json | 18 ++ .../operating_system_option_get_response.json | 14 + .../locations/sbm_flavor_get_response.json | 16 ++ .../server_model_option_get_response.json | 30 +++ .../locations/uplink_option_get_response.json | 7 + pkg/locations.go | 177 +++++++++++- pkg/locations_test.go | 251 ++++++++++++++++++ 9 files changed, 517 insertions(+), 10 deletions(-) create mode 100644 pkg/fixtures/locations/bandwidth_option_get_response.json create mode 100644 pkg/fixtures/locations/drive_model_get_response.json create mode 100644 pkg/fixtures/locations/get_response.json create mode 100644 pkg/fixtures/locations/operating_system_option_get_response.json create mode 100644 pkg/fixtures/locations/sbm_flavor_get_response.json create mode 100644 pkg/fixtures/locations/server_model_option_get_response.json create mode 100644 pkg/fixtures/locations/uplink_option_get_response.json diff --git a/pkg/fixtures/locations/bandwidth_option_get_response.json b/pkg/fixtures/locations/bandwidth_option_get_response.json new file mode 100644 index 0000000..48f4e6e --- /dev/null +++ b/pkg/fixtures/locations/bandwidth_option_get_response.json @@ -0,0 +1,6 @@ +{ + "id": 348, + "name": "20002 GB", + "type": "bytes", + "commit": 20002000000 +} \ No newline at end of file diff --git a/pkg/fixtures/locations/drive_model_get_response.json b/pkg/fixtures/locations/drive_model_get_response.json new file mode 100644 index 0000000..1e09414 --- /dev/null +++ b/pkg/fixtures/locations/drive_model_get_response.json @@ -0,0 +1,8 @@ +{ + "id": 369, + "name": "ssd-model-504", + "capacity": 100, + "interface": "SATA3", + "form_factor": "2.5", + "media_type": "SSD" +} \ No newline at end of file diff --git a/pkg/fixtures/locations/get_response.json b/pkg/fixtures/locations/get_response.json new file mode 100644 index 0000000..f7bf30b --- /dev/null +++ b/pkg/fixtures/locations/get_response.json @@ -0,0 +1,18 @@ +{ + "id": 1108, + "name": "location2251", + "status": "active", + "code": "location2251", + "supported_features": [ + "disaggregated_public_ports", + "disaggregated_private_ports", + "no_public_network", + "no_private_ip", + "no_public_ip_address", + "host_rescue_mode", + "oob_public_access" + ], + "l2_segments_enabled": false, + "private_racks_enabled": false, + "load_balancers_enabled": false +} \ No newline at end of file diff --git a/pkg/fixtures/locations/operating_system_option_get_response.json b/pkg/fixtures/locations/operating_system_option_get_response.json new file mode 100644 index 0000000..45cba22 --- /dev/null +++ b/pkg/fixtures/locations/operating_system_option_get_response.json @@ -0,0 +1,14 @@ +{ + "id": 50, + "full_name": "Ubuntu 18.04-server x86_64", + "name": "Ubuntu", + "version": "18.04-server", + "arch": "x86_64", + "filesystems": [ + "ext2", + "ext4", + "swap", + "xfs", + "reiser" + ] +} \ No newline at end of file diff --git a/pkg/fixtures/locations/sbm_flavor_get_response.json b/pkg/fixtures/locations/sbm_flavor_get_response.json new file mode 100644 index 0000000..885c307 --- /dev/null +++ b/pkg/fixtures/locations/sbm_flavor_get_response.json @@ -0,0 +1,16 @@ +{ + "id": 119, + "name": "P-101", + "cpu_name": "cpu_name", + "cpu_count": 1, + "cpu_cores_count": 2, + "cpu_frequency": "3.8", + "ram_size": 4096, + "drives_configuration": "", + "public_uplink_model_id": 117, + "public_uplink_model_name": "uplink-model-name-36", + "private_uplink_model_id": 116, + "private_uplink_model_name": "uplink-model-name-35", + "bandwidth_id": 118, + "bandwidth_name": "public-bandwidth-model-21" +} \ No newline at end of file diff --git a/pkg/fixtures/locations/server_model_option_get_response.json b/pkg/fixtures/locations/server_model_option_get_response.json new file mode 100644 index 0000000..5d97c81 --- /dev/null +++ b/pkg/fixtures/locations/server_model_option_get_response.json @@ -0,0 +1,30 @@ +{ + "id": 231, + "name": "server-model-469", + "cpu_name": "cpu-model-model-468", + "cpu_count": 2, + "cpu_cores_count": 16, + "cpu_frequency": 1970, + "ram": 32, + "ram_type": "DDR3", + "max_ram": 384, + "has_raid_controller": true, + "raid_controller_name": "AHCI controller", + "drive_slots_count": 8, + "drive_slots": [ + { + "position": 0, + "interface": "SAS", + "form_factor": "2_5", + "drive_model_id": 234, + "hot_swappable": false + }, + { + "position": 1, + "interface": "SAS", + "form_factor": "2_5", + "drive_model_id": 235, + "hot_swappable": false + } + ] +} \ No newline at end of file diff --git a/pkg/fixtures/locations/uplink_option_get_response.json b/pkg/fixtures/locations/uplink_option_get_response.json new file mode 100644 index 0000000..da29781 --- /dev/null +++ b/pkg/fixtures/locations/uplink_option_get_response.json @@ -0,0 +1,7 @@ +{ + "id": 294, + "name": "Private 1 Gbps without redundancy", + "type": "private", + "speed": 1000, + "redundancy": false +} \ No newline at end of file diff --git a/pkg/locations.go b/pkg/locations.go index 109b0a1..497cb5e 100644 --- a/pkg/locations.go +++ b/pkg/locations.go @@ -1,29 +1,42 @@ package serverscom +import ( + "context" + "encoding/json" +) + const ( locationListPath = "/locations" + locationPath = "/locations/%d" serverModelOptionListPath = "/locations/%d/order_options/server_models" + serverModelOptionPath = "/locations/%d/order_options/server_models/%d" ramOptionListPath = "/locations/%d/order_options/server_models/%d/ram" operatingSystemOptionListPath = "/locations/%d/order_options/server_models/%d/operating_systems" + operatingSystemOptionPath = "/locations/%d/order_options/server_models/%d/operating_systems/%d" driveModelListPath = "/locations/%d/order_options/server_models/%d/drive_models" + driveModelPath = "/locations/%d/order_options/server_models/%d/drive_models/%d" uplinkOptionListPath = "/locations/%d/order_options/server_models/%d/uplink_models" + uplinkOptionPath = "/locations/%d/order_options/server_models/%d/uplink_models/%d" bandwidthOptionListPath = "/locations/%d/order_options/server_models/%d/uplink_models/%d/bandwidth" + bandwidthOptionPath = "/locations/%d/order_options/server_models/%d/uplink_models/%d/bandwidth/%d" - sbmFlavorOptionListPath = "/locations/%d/order_options/sbm_flavor_models" - + sbmFlavorOptionListPath = "/locations/%d/order_options/sbm_flavor_models" + sbmFlavorOptionPath = "/locations/%d/order_options/sbm_flavor_models/%d" sbmOperatingSystemOptionListPath = "/locations/%d/order_options/sbm_flavor_models/%d/operating_systems" + sbmOperatingSystemOptionPath = "/locations/%d/order_options/sbm_flavor_models/%d/operating_systems/%d" ) // LocationsService is an interface to interfacing with the Location and Order options endpoints // API documentation: // https://developers.servers.com/api-documentation/v1/#tag/Location // https://developers.servers.com/api-documentation/v1/#tag/Server-Model-Option +// https://developers.servers.com/api-documentation/v1/#tag/SBM-Flavor-Model-Option // https://developers.servers.com/api-documentation/v1/#tag/Drive-Model-Option // https://developers.servers.com/api-documentation/v1/#tag/Ram-Option // https://developers.servers.com/api-documentation/v1/#tag/Operating-System-Option @@ -34,14 +47,22 @@ type LocationsService interface { Collection() Collection[Location] // Generic operations - ServerModelOptions(LocationID int64) Collection[ServerModelOption] - RAMOptions(LocationID, ServerModelID int64) Collection[RAMOption] - OperatingSystemOptions(LocationID, ServerModelID int64) Collection[OperatingSystemOption] - DriveModelOptions(LocationID, ServerModelID int64) Collection[DriveModel] - UplinkOptions(LocationID, ServerModelID int64) Collection[UplinkOption] - BandwidthOptions(LocationID, ServerModelID, uplinkID int64) Collection[BandwidthOption] - SBMFlavorOptions(LocationID int64) Collection[SBMFlavor] - SBMOperatingSystemOptions(LocationID, sbmFlavorModelID int64) Collection[OperatingSystemOption] + GetLocation(ctx context.Context, locationID int64) (*Location, error) + ServerModelOptions(locationID int64) Collection[ServerModelOption] + GetServerModelOption(ctx context.Context, locationID, serverModelID int64) (*ServerModelOptionDetail, error) + RAMOptions(locationID, serverModelID int64) Collection[RAMOption] + OperatingSystemOptions(locationID, serverModelID int64) Collection[OperatingSystemOption] + GetOperatingSystemOption(ctx context.Context, locationID, serverModelID, operatingSystemID int64) (*OperatingSystemOption, error) + DriveModelOptions(locationID, serverModelID int64) Collection[DriveModel] + GetDriveModelOption(ctx context.Context, locationID, serverModelID, driveModelID int64) (*DriveModel, error) + UplinkOptions(locationID, serverModelID int64) Collection[UplinkOption] + GetUplinkOption(ctx context.Context, locationID, serverModelID, uplinkModelID int64) (*UplinkOption, error) + BandwidthOptions(locationID, serverModelID, uplinkID int64) Collection[BandwidthOption] + GetBandwidthOption(ctx context.Context, locationID, serverModelID, uplinkModelID, bandwidthID int64) (*BandwidthOption, error) + SBMFlavorOptions(locationID int64) Collection[SBMFlavor] + GetSBMFlavorOption(ctx context.Context, locationID, sbmFlavorModelID int64) (*SBMFlavor, error) + SBMOperatingSystemOptions(locationID, sbmFlavorModelID int64) Collection[OperatingSystemOption] + GetSBMOperatingSystemOption(ctx context.Context, locationID, sbmFlavorModelID, operatingSystemID int64) (*OperatingSystemOption, error) } // LocationsHandler handles operations around cloud instances @@ -54,6 +75,23 @@ func (h *LocationsHandler) Collection() Collection[Location] { return NewCollection[Location](h.client, locationListPath) } +// GetLocation returns a location +func (h *LocationsHandler) GetLocation(ctx context.Context, id int64) (*Location, error) { + url := h.client.buildURL(locationPath, id) + + body, err := h.client.buildAndExecRequest(ctx, "GET", url, nil) + if err != nil { + return nil, err + } + + location := new(Location) + if err := json.Unmarshal(body, location); err != nil { + return nil, err + } + + return location, nil +} + // ServerModelOptions builds a new Collection[ServerModelOption interface func (h *LocationsHandler) ServerModelOptions(LocationID int64) Collection[ServerModelOption] { path := h.client.buildPath(serverModelOptionListPath, []interface{}{LocationID}...) @@ -61,6 +99,23 @@ func (h *LocationsHandler) ServerModelOptions(LocationID int64) Collection[Serve return NewCollection[ServerModelOption](h.client, path) } +// GetServerModelOption returns a server model option +func (h *LocationsHandler) GetServerModelOption(ctx context.Context, locationID, serverModelID int64) (*ServerModelOptionDetail, error) { + url := h.client.buildURL(serverModelOptionPath, locationID, serverModelID) + + body, err := h.client.buildAndExecRequest(ctx, "GET", url, nil) + if err != nil { + return nil, err + } + + serverModelOption := new(ServerModelOptionDetail) + if err := json.Unmarshal(body, serverModelOption); err != nil { + return nil, err + } + + return serverModelOption, nil +} + // RAMOptions builds a new Collection[RAMOption] interface func (h *LocationsHandler) RAMOptions(LocationID, ServerModelID int64) Collection[RAMOption] { path := h.client.buildPath(ramOptionListPath, []interface{}{LocationID, ServerModelID}...) @@ -75,6 +130,23 @@ func (h *LocationsHandler) OperatingSystemOptions(LocationID, ServerModelID int6 return NewCollection[OperatingSystemOption](h.client, path) } +// GetOperatingSystemOption returns an operating system option +func (h *LocationsHandler) GetOperatingSystemOption(ctx context.Context, locationID, serverModelID, operatingSystemID int64) (*OperatingSystemOption, error) { + url := h.client.buildURL(operatingSystemOptionPath, locationID, serverModelID, operatingSystemID) + + body, err := h.client.buildAndExecRequest(ctx, "GET", url, nil) + if err != nil { + return nil, err + } + + operatingSystemOption := new(OperatingSystemOption) + if err := json.Unmarshal(body, operatingSystemOption); err != nil { + return nil, err + } + + return operatingSystemOption, nil +} + // DriveModelOptions builds a new Collection[DriveModel] interface func (h *LocationsHandler) DriveModelOptions(LocationID, ServerModelID int64) Collection[DriveModel] { path := h.client.buildPath(driveModelListPath, []interface{}{LocationID, ServerModelID}...) @@ -82,6 +154,23 @@ func (h *LocationsHandler) DriveModelOptions(LocationID, ServerModelID int64) Co return NewCollection[DriveModel](h.client, path) } +// GetDriveModelOption returns a drive model +func (h *LocationsHandler) GetDriveModelOption(ctx context.Context, locationID, serverModelID, driveModelID int64) (*DriveModel, error) { + url := h.client.buildURL(driveModelPath, locationID, serverModelID, driveModelID) + + body, err := h.client.buildAndExecRequest(ctx, "GET", url, nil) + if err != nil { + return nil, err + } + + driveModel := new(DriveModel) + if err := json.Unmarshal(body, driveModel); err != nil { + return nil, err + } + + return driveModel, nil +} + // UplinkOptions builds a new Collection[UplinkOption] interface func (h *LocationsHandler) UplinkOptions(LocationID, ServerModelID int64) Collection[UplinkOption] { path := h.client.buildPath(uplinkOptionListPath, []interface{}{LocationID, ServerModelID}...) @@ -89,6 +178,23 @@ func (h *LocationsHandler) UplinkOptions(LocationID, ServerModelID int64) Collec return NewCollection[UplinkOption](h.client, path) } +// GetUplinkOption returns an uplink model +func (h *LocationsHandler) GetUplinkOption(ctx context.Context, locationID, serverModelID, uplinkModelID int64) (*UplinkOption, error) { + url := h.client.buildURL(uplinkOptionPath, locationID, serverModelID, uplinkModelID) + + body, err := h.client.buildAndExecRequest(ctx, "GET", url, nil) + if err != nil { + return nil, err + } + + uplinkOption := new(UplinkOption) + if err := json.Unmarshal(body, uplinkOption); err != nil { + return nil, err + } + + return uplinkOption, nil +} + // BandwidthOptions builds a new Collection[BandwidthOption] interface func (h *LocationsHandler) BandwidthOptions(LocationID, ServerModelID, uplinkID int64) Collection[BandwidthOption] { path := h.client.buildPath(bandwidthOptionListPath, []interface{}{LocationID, ServerModelID, uplinkID}...) @@ -96,6 +202,23 @@ func (h *LocationsHandler) BandwidthOptions(LocationID, ServerModelID, uplinkID return NewCollection[BandwidthOption](h.client, path) } +// GetBandwidthOption returns a bandwidth option +func (h *LocationsHandler) GetBandwidthOption(ctx context.Context, locationID, serverModelID, uplinkModelID, bandwidthID int64) (*BandwidthOption, error) { + url := h.client.buildURL(bandwidthOptionPath, locationID, serverModelID, uplinkModelID, bandwidthID) + + body, err := h.client.buildAndExecRequest(ctx, "GET", url, nil) + if err != nil { + return nil, err + } + + bandwidthOption := new(BandwidthOption) + if err := json.Unmarshal(body, bandwidthOption); err != nil { + return nil, err + } + + return bandwidthOption, nil +} + // SBMFlavorOptions builds a new Collection[SBMFlavor] interface func (h *LocationsHandler) SBMFlavorOptions(LocationID int64) Collection[SBMFlavor] { path := h.client.buildPath(sbmFlavorOptionListPath, []interface{}{LocationID}...) @@ -103,9 +226,43 @@ func (h *LocationsHandler) SBMFlavorOptions(LocationID int64) Collection[SBMFlav return NewCollection[SBMFlavor](h.client, path) } +// GetSBMFlavorOption returns an SBM flavor model +func (h *LocationsHandler) GetSBMFlavorOption(ctx context.Context, locationID, sbmFlavorModelID int64) (*SBMFlavor, error) { + url := h.client.buildURL(sbmFlavorOptionPath, locationID, sbmFlavorModelID) + + body, err := h.client.buildAndExecRequest(ctx, "GET", url, nil) + if err != nil { + return nil, err + } + + sbmFlavor := new(SBMFlavor) + if err := json.Unmarshal(body, sbmFlavor); err != nil { + return nil, err + } + + return sbmFlavor, nil +} + // SBMOperatingSystemOptions builds a new Collection[OperatingSystemOption] interface func (h *LocationsHandler) SBMOperatingSystemOptions(LocationID, SBMFlavorModelID int64) Collection[OperatingSystemOption] { path := h.client.buildPath(sbmOperatingSystemOptionListPath, []interface{}{LocationID, SBMFlavorModelID}...) return NewCollection[OperatingSystemOption](h.client, path) } + +// GetSBMOperatingSystemOption returns an SBM operating system option +func (h *LocationsHandler) GetSBMOperatingSystemOption(ctx context.Context, locationID, sbmFlavorModelID, operatingSystemID int64) (*OperatingSystemOption, error) { + url := h.client.buildURL(sbmOperatingSystemOptionPath, locationID, sbmFlavorModelID, operatingSystemID) + + body, err := h.client.buildAndExecRequest(ctx, "GET", url, nil) + if err != nil { + return nil, err + } + + operatingSystemOption := new(OperatingSystemOption) + if err := json.Unmarshal(body, operatingSystemOption); err != nil { + return nil, err + } + + return operatingSystemOption, nil +} diff --git a/pkg/locations_test.go b/pkg/locations_test.go index f4335cf..801ea5a 100644 --- a/pkg/locations_test.go +++ b/pkg/locations_test.go @@ -33,6 +33,43 @@ func TestLocationsCollection(t *testing.T) { g.Expect(collection.HasLastPage()).To(Equal(false)) } +func TestLocationsGetLocation(t *testing.T) { + g := NewGomegaWithT(t) + + ts, client := newFakeServer(). + WithRequestPath("/locations/1108"). + WithRequestMethod("GET"). + WithResponseBodyStubFile("fixtures/locations/get_response.json"). + WithResponseCode(200). + Build() + + defer ts.Close() + + ctx := context.TODO() + + location, err := client.Locations.GetLocation(ctx, 1108) + + g.Expect(err).To(BeNil()) + g.Expect(location).ToNot(BeNil()) + + g.Expect(location.ID).To(Equal(int64(1108))) + g.Expect(location.Name).To(Equal("location2251")) + g.Expect(location.Status).To(Equal("active")) + g.Expect(location.Code).To(Equal("location2251")) + g.Expect(location.SupportedFeatures).To(Equal([]string{ + "disaggregated_public_ports", + "disaggregated_private_ports", + "no_public_network", + "no_private_ip", + "no_public_ip_address", + "host_rescue_mode", + "oob_public_access", + })) + g.Expect(location.L2SegmentsEnabled).To(BeFalse()) + g.Expect(location.PrivateRacksEnabled).To(BeFalse()) + g.Expect(location.LoadBalancersEnabled).To(BeFalse()) +} + func TestServerModelOptionsCollection(t *testing.T) { g := NewGomegaWithT(t) @@ -59,6 +96,53 @@ func TestServerModelOptionsCollection(t *testing.T) { g.Expect(collection.HasLastPage()).To(Equal(false)) } +func TestLocationsGetServerModelOption(t *testing.T) { + g := NewGomegaWithT(t) + + ts, client := newFakeServer(). + WithRequestPath("/locations/1108/order_options/server_models/231"). + WithRequestMethod("GET"). + WithResponseBodyStubFile("fixtures/locations/server_model_option_get_response.json"). + WithResponseCode(200). + Build() + + defer ts.Close() + + ctx := context.TODO() + + serverModel, err := client.Locations.GetServerModelOption(ctx, 1108, 231) + + g.Expect(err).To(BeNil()) + g.Expect(serverModel).ToNot(BeNil()) + + g.Expect(serverModel.ID).To(Equal(int64(231))) + g.Expect(serverModel.Name).To(Equal("server-model-469")) + g.Expect(serverModel.CPUName).To(Equal("cpu-model-model-468")) + g.Expect(serverModel.CPUCount).To(Equal(2)) + g.Expect(serverModel.CPUCoresCount).To(Equal(16)) + g.Expect(serverModel.CPUFrequency).To(Equal(1970)) + g.Expect(serverModel.RAM).To(Equal(32)) + g.Expect(serverModel.RAMType).To(Equal("DDR3")) + g.Expect(serverModel.MaxRAM).To(Equal(384)) + g.Expect(serverModel.HasRAIDController).To(BeTrue()) + g.Expect(serverModel.RAIDControllerName).To(Equal("AHCI controller")) + g.Expect(serverModel.DriveSlotsCount).To(Equal(8)) + + g.Expect(serverModel.DriveSlots).To(HaveLen(2)) + + g.Expect(serverModel.DriveSlots[0].Position).To(Equal(0)) + g.Expect(serverModel.DriveSlots[0].Interface).To(Equal("SAS")) + g.Expect(serverModel.DriveSlots[0].FormFactor).To(Equal("2_5")) + g.Expect(serverModel.DriveSlots[0].DriveModelID).To(Equal(int64(234))) + g.Expect(serverModel.DriveSlots[0].HotSwappable).To(BeFalse()) + + g.Expect(serverModel.DriveSlots[1].Position).To(Equal(1)) + g.Expect(serverModel.DriveSlots[1].Interface).To(Equal("SAS")) + g.Expect(serverModel.DriveSlots[1].FormFactor).To(Equal("2_5")) + g.Expect(serverModel.DriveSlots[1].DriveModelID).To(Equal(int64(235))) + g.Expect(serverModel.DriveSlots[1].HotSwappable).To(BeFalse()) +} + func TestRAMOptionsCollection(t *testing.T) { g := NewGomegaWithT(t) @@ -111,6 +195,33 @@ func TestOperatingSystemOptionsCollection(t *testing.T) { g.Expect(collection.HasLastPage()).To(Equal(false)) } +func TestLocationsGetOperatingSystemOption(t *testing.T) { + g := NewGomegaWithT(t) + + ts, client := newFakeServer(). + WithRequestPath("/locations/1108/order_options/server_models/231/operating_systems/50"). + WithRequestMethod("GET"). + WithResponseBodyStubFile("fixtures/locations/operating_system_option_get_response.json"). + WithResponseCode(200). + Build() + + defer ts.Close() + + ctx := context.TODO() + + osOption, err := client.Locations.GetOperatingSystemOption(ctx, 1108, 231, 50) + + g.Expect(err).To(BeNil()) + g.Expect(osOption).ToNot(BeNil()) + + g.Expect(osOption.ID).To(Equal(int64(50))) + g.Expect(osOption.FullName).To(Equal("Ubuntu 18.04-server x86_64")) + g.Expect(osOption.Name).To(Equal("Ubuntu")) + g.Expect(osOption.Version).To(Equal("18.04-server")) + g.Expect(osOption.Arch).To(Equal("x86_64")) + g.Expect(osOption.Filesystems).To(ContainElements("ext2", "ext4", "swap", "xfs", "reiser")) +} + func TestDriveModelOptionsCollection(t *testing.T) { g := NewGomegaWithT(t) @@ -137,6 +248,33 @@ func TestDriveModelOptionsCollection(t *testing.T) { g.Expect(collection.HasLastPage()).To(Equal(false)) } +func TestLocationsGetDriveModel(t *testing.T) { + g := NewGomegaWithT(t) + + ts, client := newFakeServer(). + WithRequestPath("/locations/1108/order_options/server_models/231/drive_models/369"). + WithRequestMethod("GET"). + WithResponseBodyStubFile("fixtures/locations/drive_model_get_response.json"). + WithResponseCode(200). + Build() + + defer ts.Close() + + ctx := context.TODO() + + driveModel, err := client.Locations.GetDriveModelOption(ctx, 1108, 231, 369) + + g.Expect(err).To(BeNil()) + g.Expect(driveModel).ToNot(BeNil()) + + g.Expect(driveModel.ID).To(Equal(int64(369))) + g.Expect(driveModel.Name).To(Equal("ssd-model-504")) + g.Expect(driveModel.Capacity).To(Equal(100)) + g.Expect(driveModel.Interface).To(Equal("SATA3")) + g.Expect(driveModel.FormFactor).To(Equal("2.5")) + g.Expect(driveModel.MediaType).To(Equal("SSD")) +} + func TestUplinkOptionsCollection(t *testing.T) { g := NewGomegaWithT(t) @@ -163,6 +301,32 @@ func TestUplinkOptionsCollection(t *testing.T) { g.Expect(collection.HasLastPage()).To(Equal(false)) } +func TestLocationsGetUplinkOption(t *testing.T) { + g := NewGomegaWithT(t) + + ts, client := newFakeServer(). + WithRequestPath("/locations/1108/order_options/server_models/231/uplink_models/294"). + WithRequestMethod("GET"). + WithResponseBodyStubFile("fixtures/locations/uplink_option_get_response.json"). + WithResponseCode(200). + Build() + + defer ts.Close() + + ctx := context.TODO() + + uplinkOption, err := client.Locations.GetUplinkOption(ctx, 1108, 231, 294) + + g.Expect(err).To(BeNil()) + g.Expect(uplinkOption).ToNot(BeNil()) + + g.Expect(uplinkOption.ID).To(Equal(int64(294))) + g.Expect(uplinkOption.Name).To(Equal("Private 1 Gbps without redundancy")) + g.Expect(uplinkOption.Type).To(Equal("private")) + g.Expect(uplinkOption.Speed).To(Equal(1000)) + g.Expect(uplinkOption.Redundancy).To(BeFalse()) +} + func TestBandwidthOptionsCollection(t *testing.T) { g := NewGomegaWithT(t) @@ -189,6 +353,31 @@ func TestBandwidthOptionsCollection(t *testing.T) { g.Expect(collection.HasLastPage()).To(Equal(false)) } +func TestLocationsGetBandwidthOption(t *testing.T) { + g := NewGomegaWithT(t) + + ts, client := newFakeServer(). + WithRequestPath("/locations/1108/order_options/server_models/231/uplink_models/294/bandwidth/348"). + WithRequestMethod("GET"). + WithResponseBodyStubFile("fixtures/locations/bandwidth_option_get_response.json"). + WithResponseCode(200). + Build() + + defer ts.Close() + + ctx := context.TODO() + + bandwidthOption, err := client.Locations.GetBandwidthOption(ctx, 1108, 231, 294, 348) + + g.Expect(err).To(BeNil()) + g.Expect(bandwidthOption).ToNot(BeNil()) + + g.Expect(bandwidthOption.ID).To(Equal(int64(348))) + g.Expect(bandwidthOption.Name).To(Equal("20002 GB")) + g.Expect(bandwidthOption.Type).To(Equal("bytes")) + g.Expect(*bandwidthOption.Commit).To(Equal(int64(20002000000))) +} + func TestSBMFlavorOptionsCollection(t *testing.T) { g := NewGomegaWithT(t) @@ -215,6 +404,41 @@ func TestSBMFlavorOptionsCollection(t *testing.T) { g.Expect(collection.HasLastPage()).To(Equal(false)) } +func TestLocationsGetSBMFlavor(t *testing.T) { + g := NewGomegaWithT(t) + + ts, client := newFakeServer(). + WithRequestPath("/locations/1108/order_options/sbm_flavor_models/119"). + WithRequestMethod("GET"). + WithResponseBodyStubFile("fixtures/locations/sbm_flavor_get_response.json"). + WithResponseCode(200). + Build() + + defer ts.Close() + + ctx := context.TODO() + + sbmFlavor, err := client.Locations.GetSBMFlavorOption(ctx, 1108, 119) + + g.Expect(err).To(BeNil()) + g.Expect(sbmFlavor).ToNot(BeNil()) + + g.Expect(sbmFlavor.ID).To(Equal(int64(119))) + g.Expect(sbmFlavor.Name).To(Equal("P-101")) + g.Expect(sbmFlavor.CPUName).To(Equal("cpu_name")) + g.Expect(sbmFlavor.CPUCount).To(Equal(1)) + g.Expect(sbmFlavor.CPUCoresCount).To(Equal(2)) + g.Expect(sbmFlavor.CPUFrequency).To(Equal("3.8")) + g.Expect(sbmFlavor.RAMSize).To(Equal(4096)) + g.Expect(sbmFlavor.DrivesConfiguration).To(Equal("")) + g.Expect(sbmFlavor.PublicUplinkModelID).To(Equal(117)) + g.Expect(sbmFlavor.PublicUplinkModelName).To(Equal("uplink-model-name-36")) + g.Expect(sbmFlavor.PrivateUplinkModelID).To(Equal(116)) + g.Expect(sbmFlavor.PrivateUplinkModelName).To(Equal("uplink-model-name-35")) + g.Expect(sbmFlavor.BandwidthID).To(Equal(118)) + g.Expect(sbmFlavor.BandwidthName).To(Equal("public-bandwidth-model-21")) +} + func TestSBMOperatingSystemOptionsCollection(t *testing.T) { g := NewGomegaWithT(t) @@ -240,3 +464,30 @@ func TestSBMOperatingSystemOptionsCollection(t *testing.T) { g.Expect(collection.HasFirstPage()).To(Equal(false)) g.Expect(collection.HasLastPage()).To(Equal(false)) } + +func TestLocationsGetSBMOperatingSystemOption(t *testing.T) { + g := NewGomegaWithT(t) + + ts, client := newFakeServer(). + WithRequestPath("/locations/1108/order_options/sbm_flavor_models/119/operating_systems/50"). + WithRequestMethod("GET"). + WithResponseBodyStubFile("fixtures/locations/operating_system_option_get_response.json"). + WithResponseCode(200). + Build() + + defer ts.Close() + + ctx := context.TODO() + + osOption, err := client.Locations.GetSBMOperatingSystemOption(ctx, 1108, 119, 50) + + g.Expect(err).To(BeNil()) + g.Expect(osOption).ToNot(BeNil()) + + g.Expect(osOption.ID).To(Equal(int64(50))) + g.Expect(osOption.FullName).To(Equal("Ubuntu 18.04-server x86_64")) + g.Expect(osOption.Name).To(Equal("Ubuntu")) + g.Expect(osOption.Version).To(Equal("18.04-server")) + g.Expect(osOption.Arch).To(Equal("x86_64")) + g.Expect(osOption.Filesystems).To(ContainElements("ext2", "ext4", "swap", "xfs", "reiser")) +}