Skip to content

Commit 03b3a98

Browse files
authored
feat: enable generation for getservermetrics and listserverevents (#2921)
1 parent 2303f73 commit 03b3a98

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Get the ping status of the server associated with the ID.
4+
5+
USAGE:
6+
scw baremetal server get-metrics [arg=value ...]
7+
8+
ARGS:
9+
server-id Server ID to get the metrics
10+
[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)
11+
12+
FLAGS:
13+
-h, --help help for get-metrics
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
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+
List event (i.e. start/stop/reboot) associated to the server ID.
4+
5+
USAGE:
6+
scw baremetal server list-events [arg=value ...]
7+
8+
ARGS:
9+
server-id ID of the server events searched
10+
[order-by] Order of the server events (created_at_asc | created_at_desc)
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-events
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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ AVAILABLE COMMANDS:
99
create Create an Elastic Metal server
1010
delete Delete an Elastic Metal server
1111
get Get a specific Elastic Metal server
12+
get-metrics Return server metrics
1213
install Install an Elastic Metal server
1314
list List Elastic Metal servers for an organization
15+
list-events List server events
1416
reboot Reboot an Elastic Metal server
1517
start Start an Elastic Metal server
1618
stop Stop an Elastic Metal server

docs/commands/baremetal.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ Elastic Metal API.
2626
- [Create an Elastic Metal server](#create-an-elastic-metal-server)
2727
- [Delete an Elastic Metal server](#delete-an-elastic-metal-server)
2828
- [Get a specific Elastic Metal server](#get-a-specific-elastic-metal-server)
29+
- [Return server metrics](#return-server-metrics)
2930
- [Install an Elastic Metal server](#install-an-elastic-metal-server)
3031
- [List Elastic Metal servers for an organization](#list-elastic-metal-servers-for-an-organization)
32+
- [List server events](#list-server-events)
3133
- [Reboot an Elastic Metal server](#reboot-an-elastic-metal-server)
3234
- [Start an Elastic Metal server](#start-an-elastic-metal-server)
3335
- [Stop an Elastic Metal server](#stop-an-elastic-metal-server)
@@ -582,6 +584,26 @@ scw baremetal server get 11111111-1111-1111-1111-111111111111
582584

583585

584586

587+
### Return server metrics
588+
589+
Get the ping status of the server associated with the ID.
590+
591+
**Usage:**
592+
593+
```
594+
scw baremetal server get-metrics [arg=value ...]
595+
```
596+
597+
598+
**Args:**
599+
600+
| Name | | Description |
601+
|------|---|-------------|
602+
| server-id | Required | Server ID to get the metrics |
603+
| 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 |
604+
605+
606+
585607
### Install an Elastic Metal server
586608

587609
Install an Operating System (OS) on the Elastic Metal server with a specific ID.
@@ -656,6 +678,27 @@ scw baremetal server list
656678

657679

658680

681+
### List server events
682+
683+
List event (i.e. start/stop/reboot) associated to the server ID.
684+
685+
**Usage:**
686+
687+
```
688+
scw baremetal server list-events [arg=value ...]
689+
```
690+
691+
692+
**Args:**
693+
694+
| Name | | Description |
695+
|------|---|-------------|
696+
| server-id | Required | ID of the server events searched |
697+
| order-by | One of: `created_at_asc`, `created_at_desc` | Order of the server events |
698+
| 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 |
699+
700+
701+
659702
### Reboot an Elastic Metal server
660703

661704
Reboot the Elastic Metal server associated with the ID, use the `boot_type` `rescue` to reboot the server in rescue mode.

internal/namespaces/baremetal/v1/baremetal_cli.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ func GetGeneratedCommands() *core.Commands {
3232
baremetalServerCreate(),
3333
baremetalServerUpdate(),
3434
baremetalServerInstall(),
35+
baremetalServerGetMetrics(),
3536
baremetalServerDelete(),
3637
baremetalServerReboot(),
3738
baremetalServerStart(),
3839
baremetalServerStop(),
40+
baremetalServerListEvents(),
3941
baremetalBmcStart(),
4042
baremetalBmcGet(),
4143
baremetalBmcStop(),
@@ -532,6 +534,36 @@ func baremetalServerInstall() *core.Command {
532534
}
533535
}
534536

537+
func baremetalServerGetMetrics() *core.Command {
538+
return &core.Command{
539+
Short: `Return server metrics`,
540+
Long: `Get the ping status of the server associated with the ID.`,
541+
Namespace: "baremetal",
542+
Resource: "server",
543+
Verb: "get-metrics",
544+
// Deprecated: false,
545+
ArgsType: reflect.TypeOf(baremetal.GetServerMetricsRequest{}),
546+
ArgSpecs: core.ArgSpecs{
547+
{
548+
Name: "server-id",
549+
Short: `Server ID to get the metrics`,
550+
Required: true,
551+
Deprecated: false,
552+
Positional: false,
553+
},
554+
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1),
555+
},
556+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
557+
request := args.(*baremetal.GetServerMetricsRequest)
558+
559+
client := core.ExtractClient(ctx)
560+
api := baremetal.NewAPI(client)
561+
return api.GetServerMetrics(request)
562+
563+
},
564+
}
565+
}
566+
535567
func baremetalServerDelete() *core.Command {
536568
return &core.Command{
537569
Short: `Delete an Elastic Metal server`,
@@ -700,6 +732,53 @@ func baremetalServerStop() *core.Command {
700732
}
701733
}
702734

735+
func baremetalServerListEvents() *core.Command {
736+
return &core.Command{
737+
Short: `List server events`,
738+
Long: `List event (i.e. start/stop/reboot) associated to the server ID.`,
739+
Namespace: "baremetal",
740+
Resource: "server",
741+
Verb: "list-events",
742+
// Deprecated: false,
743+
ArgsType: reflect.TypeOf(baremetal.ListServerEventsRequest{}),
744+
ArgSpecs: core.ArgSpecs{
745+
{
746+
Name: "server-id",
747+
Short: `ID of the server events searched`,
748+
Required: true,
749+
Deprecated: false,
750+
Positional: false,
751+
},
752+
{
753+
Name: "order-by",
754+
Short: `Order of the server events`,
755+
Required: false,
756+
Deprecated: false,
757+
Positional: false,
758+
EnumValues: []string{"created_at_asc", "created_at_desc"},
759+
},
760+
core.ZoneArgSpec(scw.ZoneFrPar1, scw.ZoneFrPar2, scw.ZoneNlAms1, scw.Zone(core.AllLocalities)),
761+
},
762+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
763+
request := args.(*baremetal.ListServerEventsRequest)
764+
765+
client := core.ExtractClient(ctx)
766+
api := baremetal.NewAPI(client)
767+
opts := []scw.RequestOption{scw.WithAllPages()}
768+
if request.Zone == scw.Zone(core.AllLocalities) {
769+
opts = append(opts, scw.WithZones(api.Zones()...))
770+
request.Zone = ""
771+
}
772+
resp, err := api.ListServerEvents(request, opts...)
773+
if err != nil {
774+
return nil, err
775+
}
776+
return resp.Events, nil
777+
778+
},
779+
}
780+
}
781+
703782
func baremetalBmcStart() *core.Command {
704783
return &core.Command{
705784
Short: `Start BMC access`,

0 commit comments

Comments
 (0)