Skip to content

Commit 8118b2e

Browse files
authored
fix(baremetal): better rendering get offer (#3666)
1 parent 47965e4 commit 8118b2e

File tree

6 files changed

+355
-0
lines changed

6 files changed

+355
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Get details of an offer identified by its offer ID.
4+
5+
USAGE:
6+
scw baremetal offer get <offer-id ...> [arg=value ...]
7+
8+
EXAMPLES:
9+
Get a server offer with the ID
10+
scw baremetal offer get 11111111-1111-1111-1111-111111111111 zone=fr-par-1
11+
12+
ARGS:
13+
offer-id ID of the researched Offer
14+
[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)
15+
16+
FLAGS:
17+
-h, --help help for get
18+
19+
GLOBAL FLAGS:
20+
-c, --config string The path to the config file
21+
-D, --debug Enable debug mode
22+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
23+
-p, --profile string The config profile to use

internal/namespaces/baremetal/v1/custom.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ func GetCommands() *core.Commands {
1717
human.RegisterMarshalerFunc(baremetal.OfferStock(""), human.EnumMarshalFunc(offerAvailabilityMarshalSpecs))
1818
human.RegisterMarshalerFunc(baremetal.Server{}, serverMarshalerFunc)
1919

20+
human.RegisterMarshalerFunc(baremetal.Offer{}, listOfferMarshalerFunc)
21+
2022
cmds.MustFind("baremetal", "server", "create").Override(serverCreateBuilder)
2123
cmds.MustFind("baremetal", "server", "install").Override(serverInstallBuilder)
2224
cmds.MustFind("baremetal", "server", "delete").Override(serverDeleteBuilder)

internal/namespaces/baremetal/v1/custom_offer.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,41 @@ var (
1313
baremetal.OfferStockAvailable: &human.EnumMarshalSpec{Attribute: color.FgGreen, Value: "available"},
1414
}
1515
)
16+
17+
func listOfferMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
18+
type tmp baremetal.Offer
19+
baremetalOffer := tmp(i.(baremetal.Offer))
20+
opt.Sections = []*human.MarshalSection{
21+
{
22+
FieldName: "Disks",
23+
Title: "Disks",
24+
},
25+
{
26+
FieldName: "CPUs",
27+
Title: "CPUs",
28+
},
29+
{
30+
FieldName: "Memories",
31+
Title: "Memories",
32+
},
33+
{
34+
FieldName: "Options",
35+
Title: "Options",
36+
},
37+
{
38+
FieldName: "Bandwidth",
39+
Title: "Bandwidth(Mbit/s)",
40+
},
41+
{
42+
FieldName: "PrivateBandwidth",
43+
Title: "PrivateBandwidth(Mbit/s)",
44+
},
45+
}
46+
baremetalOffer.PrivateBandwidth = baremetalOffer.PrivateBandwidth / 1000000
47+
baremetalOffer.Bandwidth = baremetalOffer.Bandwidth / 1000000
48+
str, err := human.Marshal(baremetalOffer, opt)
49+
if err != nil {
50+
return "", err
51+
}
52+
return str, nil
53+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package baremetal
2+
3+
import (
4+
"testing"
5+
6+
"github.com/scaleway/scaleway-cli/v2/internal/core"
7+
)
8+
9+
func Test_baremetalGetOffer(t *testing.T) {
10+
offerID := "c5853302-63e4-40c7-a711-4a91629565c8"
11+
t.Run("Simple", core.Test(&core.TestConfig{
12+
Commands: GetCommands(),
13+
Cmd: "scw baremetal offer get " + offerID,
14+
Check: core.TestCheckGolden(),
15+
}))
16+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: '{"id":"c5853302-63e4-40c7-a711-4a91629565c8", "name":"EM-L105X-SATA", "stock":"available",
6+
"bandwidth":1000000000, "commercial_range":"lithium", "disks":[{"capacity":6000000000000,
7+
"type":"HDD"}, {"capacity":6000000000000, "type":"HDD"}, {"capacity":6000000000000,
8+
"type":"HDD"}, {"capacity":6000000000000, "type":"HDD"}], "enable":true, "cpus":[{"name":"Intel
9+
Xeon E5 1410 v2", "core_count":4, "thread_count":8, "frequency":2800, "benchmark":""}],
10+
"memories":[{"capacity":96000000000, "type":"DDR3", "frequency":1600, "is_ecc":true}],
11+
"quota_name":"EM_L105X_SATA", "price_per_hour":{"currency_code":"EUR", "units":0,
12+
"nanos":213000000}, "price_per_month":null, "persistent_memories":[], "raid_controllers":[],
13+
"incompatible_os_ids":[], "subscription_period":"hourly", "operation_path":"",
14+
"fee":{"currency_code":"EUR", "units":0, "nanos":0}, "options":[{"id":"c498071f-4f8d-49f3-bc52-afc219a48fe0",
15+
"name":"Windows 2022 datacenter", "price":{"currency_code":"EUR", "units":143,
16+
"nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false,
17+
"os_id":"3422ae02-d6d7-4980-8a00-eb38c262fb41"}, {"id":"931df052-d713-4674-8b58-96a63244c8e2",
18+
"name":"Remote Access", "price":{"currency_code":"EUR", "units":0, "nanos":990000000},
19+
"enabled":false, "subscription_period":"hourly", "manageable":true, "os_id":"00000000-0000-0000-0000-000000000000"},
20+
{"id":"cd4158d7-2d65-49be-8803-c4b8ab6f760c", "name":"Private Network", "price":{"currency_code":"EUR",
21+
"units":0, "nanos":30000000}, "enabled":false, "subscription_period":"hourly",
22+
"manageable":true, "os_id":"00000000-0000-0000-0000-000000000000"}, {"id":"f42a040b-6c91-4b11-beb0-b0b21e641fda",
23+
"name":"Windows 2019 standard", "price":{"currency_code":"EUR", "units":22,
24+
"nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false,
25+
"os_id":"7c70ff80-dbfa-4e07-be73-1de0e60fe175"}, {"id":"f74a6322-070e-41dd-a13f-8165ea63aca8",
26+
"name":"Windows 2019 datacenter", "price":{"currency_code":"EUR", "units":143,
27+
"nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false,
28+
"os_id":"e04414b9-16d4-4ffb-8ba1-6b80704c7d2a"}, {"id":"83a8fb91-47b4-4c20-82f9-84c31d79bfd8",
29+
"name":"Windows 2022 standard", "price":{"currency_code":"EUR", "units":22,
30+
"nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false,
31+
"os_id":"bf705b90-1548-4368-98ca-d17dbd8dd860"}], "private_bandwidth":1000000000,
32+
"shared_bandwidth":true, "tags":[]}'
33+
form: {}
34+
headers:
35+
User-Agent:
36+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.7; darwin; amd64) cli-e2e-test
37+
url: https://api.scaleway.com/baremetal/v1/zones/fr-par-1/offers/c5853302-63e4-40c7-a711-4a91629565c8
38+
method: GET
39+
response:
40+
body: '{"id":"c5853302-63e4-40c7-a711-4a91629565c8", "name":"EM-L105X-SATA", "stock":"available",
41+
"bandwidth":1000000000, "commercial_range":"lithium", "disks":[{"capacity":6000000000000,
42+
"type":"HDD"}, {"capacity":6000000000000, "type":"HDD"}, {"capacity":6000000000000,
43+
"type":"HDD"}, {"capacity":6000000000000, "type":"HDD"}], "enable":true, "cpus":[{"name":"Intel
44+
Xeon E5 1410 v2", "core_count":4, "thread_count":8, "frequency":2800, "benchmark":""}],
45+
"memories":[{"capacity":96000000000, "type":"DDR3", "frequency":1600, "is_ecc":true}],
46+
"quota_name":"EM_L105X_SATA", "price_per_hour":{"currency_code":"EUR", "units":0,
47+
"nanos":213000000}, "price_per_month":null, "persistent_memories":[], "raid_controllers":[],
48+
"incompatible_os_ids":[], "subscription_period":"hourly", "operation_path":"",
49+
"fee":{"currency_code":"EUR", "units":0, "nanos":0}, "options":[{"id":"c498071f-4f8d-49f3-bc52-afc219a48fe0",
50+
"name":"Windows 2022 datacenter", "price":{"currency_code":"EUR", "units":143,
51+
"nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false,
52+
"os_id":"3422ae02-d6d7-4980-8a00-eb38c262fb41"}, {"id":"931df052-d713-4674-8b58-96a63244c8e2",
53+
"name":"Remote Access", "price":{"currency_code":"EUR", "units":0, "nanos":990000000},
54+
"enabled":false, "subscription_period":"hourly", "manageable":true, "os_id":"00000000-0000-0000-0000-000000000000"},
55+
{"id":"cd4158d7-2d65-49be-8803-c4b8ab6f760c", "name":"Private Network", "price":{"currency_code":"EUR",
56+
"units":0, "nanos":30000000}, "enabled":false, "subscription_period":"hourly",
57+
"manageable":true, "os_id":"00000000-0000-0000-0000-000000000000"}, {"id":"f42a040b-6c91-4b11-beb0-b0b21e641fda",
58+
"name":"Windows 2019 standard", "price":{"currency_code":"EUR", "units":22,
59+
"nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false,
60+
"os_id":"7c70ff80-dbfa-4e07-be73-1de0e60fe175"}, {"id":"f74a6322-070e-41dd-a13f-8165ea63aca8",
61+
"name":"Windows 2019 datacenter", "price":{"currency_code":"EUR", "units":143,
62+
"nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false,
63+
"os_id":"e04414b9-16d4-4ffb-8ba1-6b80704c7d2a"}, {"id":"83a8fb91-47b4-4c20-82f9-84c31d79bfd8",
64+
"name":"Windows 2022 standard", "price":{"currency_code":"EUR", "units":22,
65+
"nanos":0}, "enabled":false, "subscription_period":"monthly", "manageable":false,
66+
"os_id":"bf705b90-1548-4368-98ca-d17dbd8dd860"}], "private_bandwidth":1000000000,
67+
"shared_bandwidth":true, "tags":[]}'
68+
headers:
69+
Content-Length:
70+
- "2441"
71+
Content-Security-Policy:
72+
- default-src 'none'; frame-ancestors 'none'
73+
Content-Type:
74+
- application/json
75+
Date:
76+
- Mon, 26 Feb 2024 14:40:02 GMT
77+
Server:
78+
- Scaleway API Gateway (fr-par-1;edge02)
79+
Strict-Transport-Security:
80+
- max-age=63072000
81+
X-Content-Type-Options:
82+
- nosniff
83+
X-Frame-Options:
84+
- DENY
85+
X-Request-Id:
86+
- 47c191fd-956f-4f2a-b123-dc543ef4dc07
87+
status: 200 OK
88+
code: 200
89+
duration: ""
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
3+
ID c5853302-63e4-40c7-a711-4a91629565c8
4+
Name EM-L105X-SATA
5+
Stock available
6+
CommercialRange lithium
7+
PricePerHour € 0.213
8+
Enable true
9+
QuotaName EM_L105X_SATA
10+
SubscriptionPeriod hourly
11+
OperationPath -
12+
Fee € 0.00
13+
SharedBandwidth true
14+
15+
Disks:
16+
CAPACITY TYPE
17+
6.0 TB HDD
18+
6.0 TB HDD
19+
6.0 TB HDD
20+
6.0 TB HDD
21+
22+
CPUs:
23+
NAME CORE COUNT THREAD COUNT FREQUENCY BENCHMARK
24+
Intel Xeon E5 1410 v2 4 8 2800 -
25+
26+
Memories:
27+
CAPACITY TYPE FREQUENCY IS ECC
28+
96 GB DDR3 1600 true
29+
30+
Options:
31+
ID NAME ENABLED SUBSCRIPTION PERIOD PRICE MANAGEABLE OS ID
32+
c498071f-4f8d-49f3-bc52-afc219a48fe0 Windows 2022 datacenter false monthly € 143.00 false 3422ae02-d6d7-4980-8a00-eb38c262fb41
33+
931df052-d713-4674-8b58-96a63244c8e2 Remote Access false hourly € 0.99 true 00000000-0000-0000-0000-000000000000
34+
cd4158d7-2d65-49be-8803-c4b8ab6f760c Private Network false hourly € 0.03 true 00000000-0000-0000-0000-000000000000
35+
f42a040b-6c91-4b11-beb0-b0b21e641fda Windows 2019 standard false monthly € 22.00 false 7c70ff80-dbfa-4e07-be73-1de0e60fe175
36+
f74a6322-070e-41dd-a13f-8165ea63aca8 Windows 2019 datacenter false monthly € 143.00 false e04414b9-16d4-4ffb-8ba1-6b80704c7d2a
37+
83a8fb91-47b4-4c20-82f9-84c31d79bfd8 Windows 2022 standard false monthly € 22.00 false bf705b90-1548-4368-98ca-d17dbd8dd860
38+
39+
Bandwidth(Mbit/s):
40+
1000
41+
42+
PrivateBandwidth(Mbit/s):
43+
1000
44+
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
45+
{
46+
"id": "c5853302-63e4-40c7-a711-4a91629565c8",
47+
"name": "EM-L105X-SATA",
48+
"stock": "available",
49+
"bandwidth": 1000000000,
50+
"commercial_range": "lithium",
51+
"price_per_hour": {
52+
"currency_code": "EUR",
53+
"units": 0,
54+
"nanos": 213000000
55+
},
56+
"price_per_month": null,
57+
"disks": [
58+
{
59+
"capacity": 6000000000000,
60+
"type": "HDD"
61+
},
62+
{
63+
"capacity": 6000000000000,
64+
"type": "HDD"
65+
},
66+
{
67+
"capacity": 6000000000000,
68+
"type": "HDD"
69+
},
70+
{
71+
"capacity": 6000000000000,
72+
"type": "HDD"
73+
}
74+
],
75+
"enable": true,
76+
"cpus": [
77+
{
78+
"name": "Intel Xeon E5 1410 v2",
79+
"core_count": 4,
80+
"thread_count": 8,
81+
"frequency": 2800,
82+
"benchmark": ""
83+
}
84+
],
85+
"memories": [
86+
{
87+
"capacity": 96000000000,
88+
"type": "DDR3",
89+
"frequency": 1600,
90+
"is_ecc": true
91+
}
92+
],
93+
"quota_name": "EM_L105X_SATA",
94+
"persistent_memories": [],
95+
"raid_controllers": [],
96+
"incompatible_os_ids": [],
97+
"subscription_period": "hourly",
98+
"operation_path": "",
99+
"fee": {
100+
"currency_code": "EUR",
101+
"units": 0,
102+
"nanos": 0
103+
},
104+
"options": [
105+
{
106+
"id": "c498071f-4f8d-49f3-bc52-afc219a48fe0",
107+
"name": "Windows 2022 datacenter",
108+
"enabled": false,
109+
"subscription_period": "monthly",
110+
"price": {
111+
"currency_code": "EUR",
112+
"units": 143,
113+
"nanos": 0
114+
},
115+
"manageable": false,
116+
"os_id": "3422ae02-d6d7-4980-8a00-eb38c262fb41"
117+
},
118+
{
119+
"id": "931df052-d713-4674-8b58-96a63244c8e2",
120+
"name": "Remote Access",
121+
"enabled": false,
122+
"subscription_period": "hourly",
123+
"price": {
124+
"currency_code": "EUR",
125+
"units": 0,
126+
"nanos": 990000000
127+
},
128+
"manageable": true,
129+
"os_id": "00000000-0000-0000-0000-000000000000"
130+
},
131+
{
132+
"id": "cd4158d7-2d65-49be-8803-c4b8ab6f760c",
133+
"name": "Private Network",
134+
"enabled": false,
135+
"subscription_period": "hourly",
136+
"price": {
137+
"currency_code": "EUR",
138+
"units": 0,
139+
"nanos": 30000000
140+
},
141+
"manageable": true,
142+
"os_id": "00000000-0000-0000-0000-000000000000"
143+
},
144+
{
145+
"id": "f42a040b-6c91-4b11-beb0-b0b21e641fda",
146+
"name": "Windows 2019 standard",
147+
"enabled": false,
148+
"subscription_period": "monthly",
149+
"price": {
150+
"currency_code": "EUR",
151+
"units": 22,
152+
"nanos": 0
153+
},
154+
"manageable": false,
155+
"os_id": "7c70ff80-dbfa-4e07-be73-1de0e60fe175"
156+
},
157+
{
158+
"id": "f74a6322-070e-41dd-a13f-8165ea63aca8",
159+
"name": "Windows 2019 datacenter",
160+
"enabled": false,
161+
"subscription_period": "monthly",
162+
"price": {
163+
"currency_code": "EUR",
164+
"units": 143,
165+
"nanos": 0
166+
},
167+
"manageable": false,
168+
"os_id": "e04414b9-16d4-4ffb-8ba1-6b80704c7d2a"
169+
},
170+
{
171+
"id": "83a8fb91-47b4-4c20-82f9-84c31d79bfd8",
172+
"name": "Windows 2022 standard",
173+
"enabled": false,
174+
"subscription_period": "monthly",
175+
"price": {
176+
"currency_code": "EUR",
177+
"units": 22,
178+
"nanos": 0
179+
},
180+
"manageable": false,
181+
"os_id": "bf705b90-1548-4368-98ca-d17dbd8dd860"
182+
}
183+
],
184+
"private_bandwidth": 1000000000,
185+
"shared_bandwidth": true,
186+
"tags": []
187+
}

0 commit comments

Comments
 (0)