Skip to content

Commit

Permalink
feat(baremetal): enable settings code generation on cli (#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Jan 6, 2023
1 parent 4d10fe2 commit 86a569d
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Return all settings for a project ID.

USAGE:
scw baremetal settings list [arg=value ...]

ARGS:
[order-by] Order the response (created_at_asc | created_at_desc)
project-id ID of the project
[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)

FLAGS:
-h, --help help for list

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Update a setting for a project ID (enable or disable).

USAGE:
scw baremetal settings update [arg=value ...]

ARGS:
setting-id ID of the setting
[enabled] Enable/Disable the setting
[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)

FLAGS:
-h, --help help for update

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
21 changes: 21 additions & 0 deletions cmd/scw/testdata/test-all-usage-baremetal-settings-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Allows to configure the general settings for your elastic metal server.

USAGE:
scw baremetal settings <command>

AVAILABLE COMMANDS:
list List all settings
update Update setting

FLAGS:
-h, --help help for settings

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

Use "scw baremetal settings [command] --help" for more information about a command.
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-baremetal-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AVAILABLE COMMANDS:
os Operating System (OS) management commands
private-network Private network management command
server Server management commands
settings Settings management commands

FLAGS:
-h, --help help for baremetal
Expand Down
51 changes: 51 additions & 0 deletions docs/commands/baremetal.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Elastic metal API
- [Stop an elastic metal server](#stop-an-elastic-metal-server)
- [Update an elastic metal server](#update-an-elastic-metal-server)
- [Wait for a server to reach a stable state (delivery and installation)](#wait-for-a-server-to-reach-a-stable-state-(delivery-and-installation))
- [Settings management commands](#settings-management-commands)
- [List all settings](#list-all-settings)
- [Update setting](#update-setting)


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



## Settings management commands

Allows to configure the general settings for your elastic metal server.



### List all settings

Return all settings for a project ID.

**Usage:**

```
scw baremetal settings list [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| order-by | One of: `created_at_asc`, `created_at_desc` | Order the response |
| project-id | Required | ID of the project |
| 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 |



### Update setting

Update a setting for a project ID (enable or disable).

**Usage:**

```
scw baremetal settings update [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| setting-id | Required | ID of the setting |
| enabled | | Enable/Disable the setting |
| 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 |



2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98
github.com/mattn/go-colorable v0.1.13
github.com/mattn/go-isatty v0.0.17
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20221228142400-b21744e9949a
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20230103165509-d6c644cc2594
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20221228142400-b21744e9949a h1:AN3KX9UupxrBlNe6YE5SUE2IP2jNdy47OyT2Pvv+2mc=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20221228142400-b21744e9949a/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20230103165509-d6c644cc2594 h1:JrC3fyD72XdTIZR2oIjYOGu9gzBiedXzFiPLhb4W7vg=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.10.0.20230103165509-d6c644cc2594/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
Expand Down
97 changes: 97 additions & 0 deletions internal/namespaces/baremetal/v1/baremetal_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func GetGeneratedCommands() *core.Commands {
baremetalOs(),
baremetalBmc(),
baremetalOptions(),
baremetalSettings(),
baremetalPrivateNetwork(),
baremetalServerList(),
baremetalServerGet(),
Expand All @@ -44,6 +45,8 @@ func GetGeneratedCommands() *core.Commands {
baremetalOfferGet(),
baremetalOptionsGet(),
baremetalOptionsList(),
baremetalSettingsList(),
baremetalSettingsUpdate(),
baremetalOsList(),
baremetalOsGet(),
baremetalPrivateNetworkAdd(),
Expand Down Expand Up @@ -113,6 +116,16 @@ func baremetalOptions() *core.Command {
}
}

func baremetalSettings() *core.Command {
return &core.Command{
Short: `Settings management commands`,
Long: `Allows to configure the general settings for your elastic metal server.
`,
Namespace: "baremetal",
Resource: "settings",
}
}

func baremetalPrivateNetwork() *core.Command {
return &core.Command{
Short: `Private network management command`,
Expand Down Expand Up @@ -1065,6 +1078,90 @@ func baremetalOptionsList() *core.Command {
}
}

func baremetalSettingsList() *core.Command {
return &core.Command{
Short: `List all settings`,
Long: `Return all settings for a project ID.`,
Namespace: "baremetal",
Resource: "settings",
Verb: "list",
// Deprecated: false,
ArgsType: reflect.TypeOf(baremetal.ListSettingsRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "order-by",
Short: `Order the response`,
Required: false,
Deprecated: false,
Positional: false,
EnumValues: []string{"created_at_asc", "created_at_desc"},
},
{
Name: "project-id",
Short: `ID of the project`,
Required: true,
Deprecated: false,
Positional: false,
},
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1, scw.Zone(core.AllLocalities)),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*baremetal.ListSettingsRequest)

client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
opts := []scw.RequestOption{scw.WithAllPages()}
if request.Zone == scw.Zone(core.AllLocalities) {
opts = append(opts, scw.WithZones(api.Zones()...))
request.Zone = ""
}
resp, err := api.ListSettings(request, opts...)
if err != nil {
return nil, err
}
return resp.Settings, nil

},
}
}

func baremetalSettingsUpdate() *core.Command {
return &core.Command{
Short: `Update setting`,
Long: `Update a setting for a project ID (enable or disable).`,
Namespace: "baremetal",
Resource: "settings",
Verb: "update",
// Deprecated: false,
ArgsType: reflect.TypeOf(baremetal.UpdateSettingRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "setting-id",
Short: `ID of the setting`,
Required: true,
Deprecated: false,
Positional: false,
},
{
Name: "enabled",
Short: `Enable/Disable the setting`,
Required: false,
Deprecated: false,
Positional: false,
},
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*baremetal.UpdateSettingRequest)

client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
return api.UpdateSetting(request)

},
}
}

func baremetalOsList() *core.Command {
return &core.Command{
Short: `List all available OS that can be install on an elastic metal server`,
Expand Down

0 comments on commit 86a569d

Please sign in to comment.