Skip to content

Commit 86a569d

Browse files
authored
feat(baremetal): enable settings code generation on cli (#2716)
1 parent 4d10fe2 commit 86a569d

File tree

8 files changed

+213
-3
lines changed

8 files changed

+213
-3
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Return all settings for a project ID.
4+
5+
USAGE:
6+
scw baremetal settings list [arg=value ...]
7+
8+
ARGS:
9+
[order-by] Order the response (created_at_asc | created_at_desc)
10+
project-id ID of the project
11+
[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 | all)
12+
13+
FLAGS:
14+
-h, --help help for list
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
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Update a setting for a project ID (enable or disable).
4+
5+
USAGE:
6+
scw baremetal settings update [arg=value ...]
7+
8+
ARGS:
9+
setting-id ID of the setting
10+
[enabled] Enable/Disable the setting
11+
[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)
12+
13+
FLAGS:
14+
-h, --help help for update
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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Allows to configure the general settings for your elastic metal server.
4+
5+
USAGE:
6+
scw baremetal settings <command>
7+
8+
AVAILABLE COMMANDS:
9+
list List all settings
10+
update Update setting
11+
12+
FLAGS:
13+
-h, --help help for settings
14+
15+
GLOBAL FLAGS:
16+
-c, --config string The path to the config file
17+
-D, --debug Enable debug mode
18+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
19+
-p, --profile string The config profile to use
20+
21+
Use "scw baremetal settings [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
@@ -12,6 +12,7 @@ AVAILABLE COMMANDS:
1212
os Operating System (OS) management commands
1313
private-network Private network management command
1414
server Server management commands
15+
settings Settings management commands
1516

1617
FLAGS:
1718
-h, --help help for baremetal

docs/commands/baremetal.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Elastic metal API
3333
- [Stop an elastic metal server](#stop-an-elastic-metal-server)
3434
- [Update an elastic metal server](#update-an-elastic-metal-server)
3535
- [Wait for a server to reach a stable state (delivery and installation)](#wait-for-a-server-to-reach-a-stable-state-(delivery-and-installation))
36+
- [Settings management commands](#settings-management-commands)
37+
- [List all settings](#list-all-settings)
38+
- [Update setting](#update-setting)
3639

3740

3841
## Baseboard Management Controller (BMC) management commands
@@ -809,3 +812,51 @@ scw baremetal server wait 11111111-1111-1111-1111-111111111111
809812

810813

811814

815+
## Settings management commands
816+
817+
Allows to configure the general settings for your elastic metal server.
818+
819+
820+
821+
### List all settings
822+
823+
Return all settings for a project ID.
824+
825+
**Usage:**
826+
827+
```
828+
scw baremetal settings list [arg=value ...]
829+
```
830+
831+
832+
**Args:**
833+
834+
| Name | | Description |
835+
|------|---|-------------|
836+
| order-by | One of: `created_at_asc`, `created_at_desc` | Order the response |
837+
| project-id | Required | ID of the project |
838+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `nl-ams-1`, `all` | Zone to target. If none is passed will use default zone from the config |
839+
840+
841+
842+
### Update setting
843+
844+
Update a setting for a project ID (enable or disable).
845+
846+
**Usage:**
847+
848+
```
849+
scw baremetal settings update [arg=value ...]
850+
```
851+
852+
853+
**Args:**
854+
855+
| Name | | Description |
856+
|------|---|-------------|
857+
| setting-id | Required | ID of the setting |
858+
| enabled | | Enable/Disable the setting |
859+
| 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 |
860+
861+
862+

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98
1919
github.com/mattn/go-colorable v0.1.13
2020
github.com/mattn/go-isatty v0.0.17
21-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20221228142400-b21744e9949a
21+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20230103165509-d6c644cc2594
2222
github.com/spf13/cobra v1.6.1
2323
github.com/spf13/pflag v1.0.5
2424
github.com/stretchr/testify v1.8.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw
7272
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7373
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7474
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
75-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20221228142400-b21744e9949a h1:AN3KX9UupxrBlNe6YE5SUE2IP2jNdy47OyT2Pvv+2mc=
76-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20221228142400-b21744e9949a/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
75+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20230103165509-d6c644cc2594 h1:JrC3fyD72XdTIZR2oIjYOGu9gzBiedXzFiPLhb4W7vg=
76+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20230103165509-d6c644cc2594/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
7777
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
7878
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
7979
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=

internal/namespaces/baremetal/v1/baremetal_cli.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func GetGeneratedCommands() *core.Commands {
2525
baremetalOs(),
2626
baremetalBmc(),
2727
baremetalOptions(),
28+
baremetalSettings(),
2829
baremetalPrivateNetwork(),
2930
baremetalServerList(),
3031
baremetalServerGet(),
@@ -44,6 +45,8 @@ func GetGeneratedCommands() *core.Commands {
4445
baremetalOfferGet(),
4546
baremetalOptionsGet(),
4647
baremetalOptionsList(),
48+
baremetalSettingsList(),
49+
baremetalSettingsUpdate(),
4750
baremetalOsList(),
4851
baremetalOsGet(),
4952
baremetalPrivateNetworkAdd(),
@@ -113,6 +116,16 @@ func baremetalOptions() *core.Command {
113116
}
114117
}
115118

119+
func baremetalSettings() *core.Command {
120+
return &core.Command{
121+
Short: `Settings management commands`,
122+
Long: `Allows to configure the general settings for your elastic metal server.
123+
`,
124+
Namespace: "baremetal",
125+
Resource: "settings",
126+
}
127+
}
128+
116129
func baremetalPrivateNetwork() *core.Command {
117130
return &core.Command{
118131
Short: `Private network management command`,
@@ -1065,6 +1078,90 @@ func baremetalOptionsList() *core.Command {
10651078
}
10661079
}
10671080

1081+
func baremetalSettingsList() *core.Command {
1082+
return &core.Command{
1083+
Short: `List all settings`,
1084+
Long: `Return all settings for a project ID.`,
1085+
Namespace: "baremetal",
1086+
Resource: "settings",
1087+
Verb: "list",
1088+
// Deprecated: false,
1089+
ArgsType: reflect.TypeOf(baremetal.ListSettingsRequest{}),
1090+
ArgSpecs: core.ArgSpecs{
1091+
{
1092+
Name: "order-by",
1093+
Short: `Order the response`,
1094+
Required: false,
1095+
Deprecated: false,
1096+
Positional: false,
1097+
EnumValues: []string{"created_at_asc", "created_at_desc"},
1098+
},
1099+
{
1100+
Name: "project-id",
1101+
Short: `ID of the project`,
1102+
Required: true,
1103+
Deprecated: false,
1104+
Positional: false,
1105+
},
1106+
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1, scw.Zone(core.AllLocalities)),
1107+
},
1108+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
1109+
request := args.(*baremetal.ListSettingsRequest)
1110+
1111+
client := core.ExtractClient(ctx)
1112+
api := baremetal.NewAPI(client)
1113+
opts := []scw.RequestOption{scw.WithAllPages()}
1114+
if request.Zone == scw.Zone(core.AllLocalities) {
1115+
opts = append(opts, scw.WithZones(api.Zones()...))
1116+
request.Zone = ""
1117+
}
1118+
resp, err := api.ListSettings(request, opts...)
1119+
if err != nil {
1120+
return nil, err
1121+
}
1122+
return resp.Settings, nil
1123+
1124+
},
1125+
}
1126+
}
1127+
1128+
func baremetalSettingsUpdate() *core.Command {
1129+
return &core.Command{
1130+
Short: `Update setting`,
1131+
Long: `Update a setting for a project ID (enable or disable).`,
1132+
Namespace: "baremetal",
1133+
Resource: "settings",
1134+
Verb: "update",
1135+
// Deprecated: false,
1136+
ArgsType: reflect.TypeOf(baremetal.UpdateSettingRequest{}),
1137+
ArgSpecs: core.ArgSpecs{
1138+
{
1139+
Name: "setting-id",
1140+
Short: `ID of the setting`,
1141+
Required: true,
1142+
Deprecated: false,
1143+
Positional: false,
1144+
},
1145+
{
1146+
Name: "enabled",
1147+
Short: `Enable/Disable the setting`,
1148+
Required: false,
1149+
Deprecated: false,
1150+
Positional: false,
1151+
},
1152+
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1),
1153+
},
1154+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
1155+
request := args.(*baremetal.UpdateSettingRequest)
1156+
1157+
client := core.ExtractClient(ctx)
1158+
api := baremetal.NewAPI(client)
1159+
return api.UpdateSetting(request)
1160+
1161+
},
1162+
}
1163+
}
1164+
10681165
func baremetalOsList() *core.Command {
10691166
return &core.Command{
10701167
Short: `List all available OS that can be install on an elastic metal server`,

0 commit comments

Comments
 (0)