Skip to content

Commit 9681ee8

Browse files
authored
feat(baremetal): enable offer support (#2499)
1 parent 6958446 commit 9681ee8

8 files changed

Lines changed: 245 additions & 3 deletions
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+
Return specific offer for the given ID.
4+
5+
USAGE:
6+
scw baremetal offer get [arg=value ...]
7+
8+
EXAMPLES:
9+
Get a server offer with the given ID
10+
scw baremetal offer get zone=fr-par-1 offer-id=11111111-1111-1111-1111-111111111111
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)
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
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
List all available server offers.
4+
5+
USAGE:
6+
scw baremetal offer list [arg=value ...]
7+
8+
EXAMPLES:
9+
List all server offers in the default zone
10+
scw baremetal offer list
11+
12+
List all server offers in fr-par-1 zone
13+
scw baremetal offer list zone=fr-par-1
14+
15+
ARGS:
16+
[subscription-period] Period of subscription to filter offers (unknown_subscription_period | hourly | monthly)
17+
[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)
18+
19+
FLAGS:
20+
-h, --help help for list
21+
22+
GLOBAL FLAGS:
23+
-c, --config string The path to the config file
24+
-D, --debug Enable debug mode
25+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
26+
-p, --profile string The config profile to use
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Server offers will answer with all different elastic metal server ranges available in a given zone.
4+
Each of them will contain all the features of the server (cpus, memories, disks) with their associated pricing.
5+
6+
USAGE:
7+
scw baremetal offer <command>
8+
9+
AVAILABLE COMMANDS:
10+
get Get offer
11+
list List offers
12+
13+
FLAGS:
14+
-h, --help help for offer
15+
16+
GLOBAL FLAGS:
17+
-c, --config string The path to the config file
18+
-D, --debug Enable debug mode
19+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
20+
-p, --profile string The config profile to use
21+
22+
Use "scw baremetal offer [command] --help" for more information about a command.

cmd/scw/testdata/test-all-usage-baremetal-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ USAGE:
77

88
AVAILABLE COMMANDS:
99
bmc Baseboard Management Controller (BMC) management commands
10+
offer Server offer management commands
1011
os Operating System (OS) management commands
1112
server Server management commands
1213

docs/commands/baremetal.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Elastic metal API
66
- [Get BMC (Baseboard Management Controller) access for a given elastic metal server](#get-bmc-(baseboard-management-controller)-access-for-a-given-elastic-metal-server)
77
- [Start BMC (Baseboard Management Controller) access for a given elastic metal server](#start-bmc-(baseboard-management-controller)-access-for-a-given-elastic-metal-server)
88
- [Stop BMC (Baseboard Management Controller) access for a given elastic metal server](#stop-bmc-(baseboard-management-controller)-access-for-a-given-elastic-metal-server)
9+
- [Server offer management commands](#server-offer-management-commands)
10+
- [Get offer](#get-offer)
11+
- [List offers](#list-offers)
912
- [Operating System (OS) management commands](#operating-system-(os)-management-commands)
1013
- [Get an OS with a given ID](#get-an-os-with-a-given-id)
1114
- [List all available OS that can be install on an elastic metal server](#list-all-available-os-that-can-be-install-on-an-elastic-metal-server)
@@ -97,6 +100,78 @@ scw baremetal bmc stop [arg=value ...]
97100

98101

99102

103+
## Server offer management commands
104+
105+
Server offers will answer with all different elastic metal server ranges available in a given zone.
106+
Each of them will contain all the features of the server (cpus, memories, disks) with their associated pricing.
107+
108+
109+
110+
### Get offer
111+
112+
Return specific offer for the given ID.
113+
114+
**Usage:**
115+
116+
```
117+
scw baremetal offer get [arg=value ...]
118+
```
119+
120+
121+
**Args:**
122+
123+
| Name | | Description |
124+
|------|---|-------------|
125+
| offer-id | Required | ID of the researched Offer |
126+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `nl-ams-1` | Zone to target. If none is passed will use default zone from the config |
127+
128+
129+
**Examples:**
130+
131+
132+
Get a server offer with the given ID
133+
```
134+
scw baremetal offer get zone=fr-par-1 offer-id=11111111-1111-1111-1111-111111111111
135+
```
136+
137+
138+
139+
140+
### List offers
141+
142+
List all available server offers.
143+
144+
**Usage:**
145+
146+
```
147+
scw baremetal offer list [arg=value ...]
148+
```
149+
150+
151+
**Args:**
152+
153+
| Name | | Description |
154+
|------|---|-------------|
155+
| subscription-period | One of: `unknown_subscription_period`, `hourly`, `monthly` | Period of subscription to filter offers |
156+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `nl-ams-1` | Zone to target. If none is passed will use default zone from the config |
157+
158+
159+
**Examples:**
160+
161+
162+
List all server offers in the default zone
163+
```
164+
scw baremetal offer list
165+
```
166+
167+
List all server offers in fr-par-1 zone
168+
```
169+
scw baremetal offer list zone=fr-par-1
170+
```
171+
172+
173+
174+
100175
## Operating System (OS) management commands
101176

102177
An Operating System (OS) is the underlying software installed on your server

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98
1818
github.com/mattn/go-colorable v0.1.13
1919
github.com/mattn/go-isatty v0.0.16
20-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220907082605-794394649db9
20+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220912091438-7eb3f47b338d
2121
github.com/spf13/cobra v1.5.0
2222
github.com/spf13/pflag v1.0.5
2323
github.com/stretchr/testify v1.8.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
5858
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5959
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6060
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
61-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220907082605-794394649db9 h1:cQE7TtLqtXqIAI1vYvhiAeIOfWr0nBEwIb234125Feg=
62-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220907082605-794394649db9/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
61+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220912091438-7eb3f47b338d h1:bm9Vc3dz8oHAZTf9XoO6hRkv1CcOZLFbxT1pGok551k=
62+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9.0.20220912091438-7eb3f47b338d/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
6363
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
6464
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
6565
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=

internal/namespaces/baremetal/v1/baremetal_cli.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func GetGeneratedCommands() *core.Commands {
2121
return core.NewCommands(
2222
baremetalRoot(),
2323
baremetalServer(),
24+
baremetalOffer(),
2425
baremetalOs(),
2526
baremetalBmc(),
2627
baremetalServerList(),
@@ -35,6 +36,8 @@ func GetGeneratedCommands() *core.Commands {
3536
baremetalBmcStart(),
3637
baremetalBmcGet(),
3738
baremetalBmcStop(),
39+
baremetalOfferList(),
40+
baremetalOfferGet(),
3841
baremetalOsList(),
3942
baremetalOsGet(),
4043
)
@@ -56,6 +59,17 @@ func baremetalServer() *core.Command {
5659
}
5760
}
5861

62+
func baremetalOffer() *core.Command {
63+
return &core.Command{
64+
Short: `Server offer management commands`,
65+
Long: `Server offers will answer with all different elastic metal server ranges available in a given zone.
66+
Each of them will contain all the features of the server (cpus, memories, disks) with their associated pricing.
67+
`,
68+
Namespace: "baremetal",
69+
Resource: "offer",
70+
}
71+
}
72+
5973
func baremetalOs() *core.Command {
6074
return &core.Command{
6175
Short: `Operating System (OS) management commands`,
@@ -738,6 +752,87 @@ func baremetalBmcStop() *core.Command {
738752
}
739753
}
740754

755+
func baremetalOfferList() *core.Command {
756+
return &core.Command{
757+
Short: `List offers`,
758+
Long: `List all available server offers.`,
759+
Namespace: "baremetal",
760+
Resource: "offer",
761+
Verb: "list",
762+
// Deprecated: false,
763+
ArgsType: reflect.TypeOf(baremetal.ListOffersRequest{}),
764+
ArgSpecs: core.ArgSpecs{
765+
{
766+
Name: "subscription-period",
767+
Short: `Period of subscription to filter offers`,
768+
Required: false,
769+
Deprecated: false,
770+
Positional: false,
771+
EnumValues: []string{"unknown_subscription_period", "hourly", "monthly"},
772+
},
773+
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1),
774+
},
775+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
776+
request := args.(*baremetal.ListOffersRequest)
777+
778+
client := core.ExtractClient(ctx)
779+
api := baremetal.NewAPI(client)
780+
resp, err := api.ListOffers(request, scw.WithAllPages())
781+
if err != nil {
782+
return nil, err
783+
}
784+
return resp.Offers, nil
785+
786+
},
787+
Examples: []*core.Example{
788+
{
789+
Short: "List all server offers in the default zone",
790+
ArgsJSON: `null`,
791+
},
792+
{
793+
Short: "List all server offers in fr-par-1 zone",
794+
ArgsJSON: `{"zone":"fr-par-1"}`,
795+
},
796+
},
797+
}
798+
}
799+
800+
func baremetalOfferGet() *core.Command {
801+
return &core.Command{
802+
Short: `Get offer`,
803+
Long: `Return specific offer for the given ID.`,
804+
Namespace: "baremetal",
805+
Resource: "offer",
806+
Verb: "get",
807+
// Deprecated: false,
808+
ArgsType: reflect.TypeOf(baremetal.GetOfferRequest{}),
809+
ArgSpecs: core.ArgSpecs{
810+
{
811+
Name: "offer-id",
812+
Short: `ID of the researched Offer`,
813+
Required: true,
814+
Deprecated: false,
815+
Positional: false,
816+
},
817+
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1),
818+
},
819+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
820+
request := args.(*baremetal.GetOfferRequest)
821+
822+
client := core.ExtractClient(ctx)
823+
api := baremetal.NewAPI(client)
824+
return api.GetOffer(request)
825+
826+
},
827+
Examples: []*core.Example{
828+
{
829+
Short: "Get a server offer with the given ID",
830+
ArgsJSON: `{"offer_id":"11111111-1111-1111-1111-111111111111","zone":"fr-par-1"}`,
831+
},
832+
},
833+
}
834+
}
835+
741836
func baremetalOsList() *core.Command {
742837
return &core.Command{
743838
Short: `List all available OS that can be install on an elastic metal server`,

0 commit comments

Comments
 (0)