diff --git a/cmd/scw/testdata/test-all-usage-baremetal-offer-get-usage#01.golden b/cmd/scw/testdata/test-all-usage-baremetal-offer-get-usage#01.golden new file mode 100644 index 0000000000..d987ef9288 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-baremetal-offer-get-usage#01.golden @@ -0,0 +1,23 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +Get details of an offer identified by its offer ID. + +USAGE: + scw baremetal offer get [arg=value ...] + +EXAMPLES: + Get a server offer with the ID + scw baremetal offer get 11111111-1111-1111-1111-111111111111 zone=fr-par-1 + +ARGS: + offer-id ID of the researched Offer + [zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | nl-ams-1 | nl-ams-2) + +FLAGS: + -h, --help help for get + +GLOBAL FLAGS: + -c, --config string The path to the config file + -D, --debug Enable debug mode + -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") + -p, --profile string The config profile to use diff --git a/internal/namespaces/baremetal/v1/custom.go b/internal/namespaces/baremetal/v1/custom.go index 4d8aef08bc..2d1ee7e2f1 100644 --- a/internal/namespaces/baremetal/v1/custom.go +++ b/internal/namespaces/baremetal/v1/custom.go @@ -17,6 +17,8 @@ func GetCommands() *core.Commands { human.RegisterMarshalerFunc(baremetal.OfferStock(""), human.EnumMarshalFunc(offerAvailabilityMarshalSpecs)) human.RegisterMarshalerFunc(baremetal.Server{}, serverMarshalerFunc) + human.RegisterMarshalerFunc(baremetal.Offer{}, listOfferMarshalerFunc) + cmds.MustFind("baremetal", "server", "create").Override(serverCreateBuilder) cmds.MustFind("baremetal", "server", "install").Override(serverInstallBuilder) cmds.MustFind("baremetal", "server", "delete").Override(serverDeleteBuilder) diff --git a/internal/namespaces/baremetal/v1/custom_offer.go b/internal/namespaces/baremetal/v1/custom_offer.go index b94a6c00af..d4ae68d255 100644 --- a/internal/namespaces/baremetal/v1/custom_offer.go +++ b/internal/namespaces/baremetal/v1/custom_offer.go @@ -13,3 +13,41 @@ var ( baremetal.OfferStockAvailable: &human.EnumMarshalSpec{Attribute: color.FgGreen, Value: "available"}, } ) + +func listOfferMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) { + type tmp baremetal.Offer + baremetalOffer := tmp(i.(baremetal.Offer)) + opt.Sections = []*human.MarshalSection{ + { + FieldName: "Disks", + Title: "Disks", + }, + { + FieldName: "CPUs", + Title: "CPUs", + }, + { + FieldName: "Memories", + Title: "Memories", + }, + { + FieldName: "Options", + Title: "Options", + }, + { + FieldName: "Bandwidth", + Title: "Bandwidth(Mbit/s)", + }, + { + FieldName: "PrivateBandwidth", + Title: "PrivateBandwidth(Mbit/s)", + }, + } + baremetalOffer.PrivateBandwidth = baremetalOffer.PrivateBandwidth / 1000000 + baremetalOffer.Bandwidth = baremetalOffer.Bandwidth / 1000000 + str, err := human.Marshal(baremetalOffer, opt) + if err != nil { + return "", err + } + return str, nil +} diff --git a/internal/namespaces/baremetal/v1/custom_offer_test.go b/internal/namespaces/baremetal/v1/custom_offer_test.go new file mode 100644 index 0000000000..2bcf3dfce8 --- /dev/null +++ b/internal/namespaces/baremetal/v1/custom_offer_test.go @@ -0,0 +1,16 @@ +package baremetal + +import ( + "testing" + + "github.com/scaleway/scaleway-cli/v2/internal/core" +) + +func Test_baremetalGetOffer(t *testing.T) { + offerID := "c5853302-63e4-40c7-a711-4a91629565c8" + t.Run("Simple", core.Test(&core.TestConfig{ + Commands: GetCommands(), + Cmd: "scw baremetal offer get " + offerID, + Check: core.TestCheckGolden(), + })) +} diff --git a/internal/namespaces/baremetal/v1/testdata/test-baremetal-get-offer-simple.cassette.yaml b/internal/namespaces/baremetal/v1/testdata/test-baremetal-get-offer-simple.cassette.yaml new file mode 100644 index 0000000000..fd57936ae7 --- /dev/null +++ b/internal/namespaces/baremetal/v1/testdata/test-baremetal-get-offer-simple.cassette.yaml @@ -0,0 +1,89 @@ +--- +version: 1 +interactions: +- request: + body: '{"id":"c5853302-63e4-40c7-a711-4a91629565c8", "name":"EM-L105X-SATA", "stock":"available", + "bandwidth":1000000000, "commercial_range":"lithium", "disks":[{"capacity":6000000000000, + "type":"HDD"}, {"capacity":6000000000000, "type":"HDD"}, {"capacity":6000000000000, + "type":"HDD"}, {"capacity":6000000000000, "type":"HDD"}], "enable":true, "cpus":[{"name":"Intel + Xeon E5 1410 v2", "core_count":4, "thread_count":8, "frequency":2800, "benchmark":""}], + "memories":[{"capacity":96000000000, "type":"DDR3", "frequency":1600, "is_ecc":true}], + "quota_name":"EM_L105X_SATA", "price_per_hour":{"currency_code":"EUR", "units":0, + "nanos":213000000}, "price_per_month":null, "persistent_memories":[], "raid_controllers":[], + "incompatible_os_ids":[], "subscription_period":"hourly", "operation_path":"", + "fee":{"currency_code":"EUR", "units":0, "nanos":0}, "options":[{"id":"c498071f-4f8d-49f3-bc52-afc219a48fe0", + "name":"Windows 2022 datacenter", "price":{"currency_code":"EUR", "units":143, + "nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false, + "os_id":"3422ae02-d6d7-4980-8a00-eb38c262fb41"}, {"id":"931df052-d713-4674-8b58-96a63244c8e2", + "name":"Remote Access", "price":{"currency_code":"EUR", "units":0, "nanos":990000000}, + "enabled":false, "subscription_period":"hourly", "manageable":true, "os_id":"00000000-0000-0000-0000-000000000000"}, + {"id":"cd4158d7-2d65-49be-8803-c4b8ab6f760c", "name":"Private Network", "price":{"currency_code":"EUR", + "units":0, "nanos":30000000}, "enabled":false, "subscription_period":"hourly", + "manageable":true, "os_id":"00000000-0000-0000-0000-000000000000"}, {"id":"f42a040b-6c91-4b11-beb0-b0b21e641fda", + "name":"Windows 2019 standard", "price":{"currency_code":"EUR", "units":22, + "nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false, + "os_id":"7c70ff80-dbfa-4e07-be73-1de0e60fe175"}, {"id":"f74a6322-070e-41dd-a13f-8165ea63aca8", + "name":"Windows 2019 datacenter", "price":{"currency_code":"EUR", "units":143, + "nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false, + "os_id":"e04414b9-16d4-4ffb-8ba1-6b80704c7d2a"}, {"id":"83a8fb91-47b4-4c20-82f9-84c31d79bfd8", + "name":"Windows 2022 standard", "price":{"currency_code":"EUR", "units":22, + "nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false, + "os_id":"bf705b90-1548-4368-98ca-d17dbd8dd860"}], "private_bandwidth":1000000000, + "shared_bandwidth":true, "tags":[]}' + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/baremetal/v1/zones/fr-par-1/offers/c5853302-63e4-40c7-a711-4a91629565c8 + method: GET + response: + body: '{"id":"c5853302-63e4-40c7-a711-4a91629565c8", "name":"EM-L105X-SATA", "stock":"available", + "bandwidth":1000000000, "commercial_range":"lithium", "disks":[{"capacity":6000000000000, + "type":"HDD"}, {"capacity":6000000000000, "type":"HDD"}, {"capacity":6000000000000, + "type":"HDD"}, {"capacity":6000000000000, "type":"HDD"}], "enable":true, "cpus":[{"name":"Intel + Xeon E5 1410 v2", "core_count":4, "thread_count":8, "frequency":2800, "benchmark":""}], + "memories":[{"capacity":96000000000, "type":"DDR3", "frequency":1600, "is_ecc":true}], + "quota_name":"EM_L105X_SATA", "price_per_hour":{"currency_code":"EUR", "units":0, + "nanos":213000000}, "price_per_month":null, "persistent_memories":[], "raid_controllers":[], + "incompatible_os_ids":[], "subscription_period":"hourly", "operation_path":"", + "fee":{"currency_code":"EUR", "units":0, "nanos":0}, "options":[{"id":"c498071f-4f8d-49f3-bc52-afc219a48fe0", + "name":"Windows 2022 datacenter", "price":{"currency_code":"EUR", "units":143, + "nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false, + "os_id":"3422ae02-d6d7-4980-8a00-eb38c262fb41"}, {"id":"931df052-d713-4674-8b58-96a63244c8e2", + "name":"Remote Access", "price":{"currency_code":"EUR", "units":0, "nanos":990000000}, + "enabled":false, "subscription_period":"hourly", "manageable":true, "os_id":"00000000-0000-0000-0000-000000000000"}, + {"id":"cd4158d7-2d65-49be-8803-c4b8ab6f760c", "name":"Private Network", "price":{"currency_code":"EUR", + "units":0, "nanos":30000000}, "enabled":false, "subscription_period":"hourly", + "manageable":true, "os_id":"00000000-0000-0000-0000-000000000000"}, {"id":"f42a040b-6c91-4b11-beb0-b0b21e641fda", + "name":"Windows 2019 standard", "price":{"currency_code":"EUR", "units":22, + "nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false, + "os_id":"7c70ff80-dbfa-4e07-be73-1de0e60fe175"}, {"id":"f74a6322-070e-41dd-a13f-8165ea63aca8", + "name":"Windows 2019 datacenter", "price":{"currency_code":"EUR", "units":143, + "nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false, + "os_id":"e04414b9-16d4-4ffb-8ba1-6b80704c7d2a"}, {"id":"83a8fb91-47b4-4c20-82f9-84c31d79bfd8", + "name":"Windows 2022 standard", "price":{"currency_code":"EUR", "units":22, + "nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false, + "os_id":"bf705b90-1548-4368-98ca-d17dbd8dd860"}], "private_bandwidth":1000000000, + "shared_bandwidth":true, "tags":[]}' + headers: + Content-Length: + - "2441" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 26 Feb 2024 14:40:02 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge02) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 47c191fd-956f-4f2a-b123-dc543ef4dc07 + status: 200 OK + code: 200 + duration: "" diff --git a/internal/namespaces/baremetal/v1/testdata/test-baremetal-get-offer-simple.golden b/internal/namespaces/baremetal/v1/testdata/test-baremetal-get-offer-simple.golden new file mode 100644 index 0000000000..f9a1c030ef --- /dev/null +++ b/internal/namespaces/baremetal/v1/testdata/test-baremetal-get-offer-simple.golden @@ -0,0 +1,187 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +🟩🟩🟩 STDOUT️ 🟩🟩🟩️ +ID c5853302-63e4-40c7-a711-4a91629565c8 +Name EM-L105X-SATA +Stock available +CommercialRange lithium +PricePerHour € 0.213 +Enable true +QuotaName EM_L105X_SATA +SubscriptionPeriod hourly +OperationPath - +Fee € 0.00 +SharedBandwidth true + +Disks: +CAPACITY TYPE +6.0 TB HDD +6.0 TB HDD +6.0 TB HDD +6.0 TB HDD + +CPUs: +NAME CORE COUNT THREAD COUNT FREQUENCY BENCHMARK +Intel Xeon E5 1410 v2 4 8 2800 - + +Memories: +CAPACITY TYPE FREQUENCY IS ECC +96 GB DDR3 1600 true + +Options: +ID NAME ENABLED SUBSCRIPTION PERIOD PRICE MANAGEABLE OS ID +c498071f-4f8d-49f3-bc52-afc219a48fe0 Windows 2022 datacenter false monthly € 143.00 false 3422ae02-d6d7-4980-8a00-eb38c262fb41 +931df052-d713-4674-8b58-96a63244c8e2 Remote Access false hourly € 0.99 true 00000000-0000-0000-0000-000000000000 +cd4158d7-2d65-49be-8803-c4b8ab6f760c Private Network false hourly € 0.03 true 00000000-0000-0000-0000-000000000000 +f42a040b-6c91-4b11-beb0-b0b21e641fda Windows 2019 standard false monthly € 22.00 false 7c70ff80-dbfa-4e07-be73-1de0e60fe175 +f74a6322-070e-41dd-a13f-8165ea63aca8 Windows 2019 datacenter false monthly € 143.00 false e04414b9-16d4-4ffb-8ba1-6b80704c7d2a +83a8fb91-47b4-4c20-82f9-84c31d79bfd8 Windows 2022 standard false monthly € 22.00 false bf705b90-1548-4368-98ca-d17dbd8dd860 + +Bandwidth(Mbit/s): +1000 + +PrivateBandwidth(Mbit/s): +1000 +🟩🟩🟩 JSON STDOUT 🟩🟩🟩 +{ + "id": "c5853302-63e4-40c7-a711-4a91629565c8", + "name": "EM-L105X-SATA", + "stock": "available", + "bandwidth": 1000000000, + "commercial_range": "lithium", + "price_per_hour": { + "currency_code": "EUR", + "units": 0, + "nanos": 213000000 + }, + "price_per_month": null, + "disks": [ + { + "capacity": 6000000000000, + "type": "HDD" + }, + { + "capacity": 6000000000000, + "type": "HDD" + }, + { + "capacity": 6000000000000, + "type": "HDD" + }, + { + "capacity": 6000000000000, + "type": "HDD" + } + ], + "enable": true, + "cpus": [ + { + "name": "Intel Xeon E5 1410 v2", + "core_count": 4, + "thread_count": 8, + "frequency": 2800, + "benchmark": "" + } + ], + "memories": [ + { + "capacity": 96000000000, + "type": "DDR3", + "frequency": 1600, + "is_ecc": true + } + ], + "quota_name": "EM_L105X_SATA", + "persistent_memories": [], + "raid_controllers": [], + "incompatible_os_ids": [], + "subscription_period": "hourly", + "operation_path": "", + "fee": { + "currency_code": "EUR", + "units": 0, + "nanos": 0 + }, + "options": [ + { + "id": "c498071f-4f8d-49f3-bc52-afc219a48fe0", + "name": "Windows 2022 datacenter", + "enabled": false, + "subscription_period": "monthly", + "price": { + "currency_code": "EUR", + "units": 143, + "nanos": 0 + }, + "manageable": false, + "os_id": "3422ae02-d6d7-4980-8a00-eb38c262fb41" + }, + { + "id": "931df052-d713-4674-8b58-96a63244c8e2", + "name": "Remote Access", + "enabled": false, + "subscription_period": "hourly", + "price": { + "currency_code": "EUR", + "units": 0, + "nanos": 990000000 + }, + "manageable": true, + "os_id": "00000000-0000-0000-0000-000000000000" + }, + { + "id": "cd4158d7-2d65-49be-8803-c4b8ab6f760c", + "name": "Private Network", + "enabled": false, + "subscription_period": "hourly", + "price": { + "currency_code": "EUR", + "units": 0, + "nanos": 30000000 + }, + "manageable": true, + "os_id": "00000000-0000-0000-0000-000000000000" + }, + { + "id": "f42a040b-6c91-4b11-beb0-b0b21e641fda", + "name": "Windows 2019 standard", + "enabled": false, + "subscription_period": "monthly", + "price": { + "currency_code": "EUR", + "units": 22, + "nanos": 0 + }, + "manageable": false, + "os_id": "7c70ff80-dbfa-4e07-be73-1de0e60fe175" + }, + { + "id": "f74a6322-070e-41dd-a13f-8165ea63aca8", + "name": "Windows 2019 datacenter", + "enabled": false, + "subscription_period": "monthly", + "price": { + "currency_code": "EUR", + "units": 143, + "nanos": 0 + }, + "manageable": false, + "os_id": "e04414b9-16d4-4ffb-8ba1-6b80704c7d2a" + }, + { + "id": "83a8fb91-47b4-4c20-82f9-84c31d79bfd8", + "name": "Windows 2022 standard", + "enabled": false, + "subscription_period": "monthly", + "price": { + "currency_code": "EUR", + "units": 22, + "nanos": 0 + }, + "manageable": false, + "os_id": "bf705b90-1548-4368-98ca-d17dbd8dd860" + } + ], + "private_bandwidth": 1000000000, + "shared_bandwidth": true, + "tags": [] +}