Skip to content

Commit 75e3bfa

Browse files
authored
Merge branch 'master' into qa_missing_example
2 parents c718310 + 45018f1 commit 75e3bfa

31 files changed

+2091
-396
lines changed

MAINTAINERS.md

-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ routing PRs, questions, etc. to the right place.
99
| :------------- | :-------------- |
1010
| Jérôme Quéré | @jerome-quere |
1111
| Quentin Brosse | @QuentinBrosse |
12-
| Loïc Bourgois | @loicbourgois |
1312
| Olivier Cano | @kindermoumoute |
1413
| Rémy Léone | @remyleone |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Get the BMC (Baseboard Management Controller) access associated with the given ID.
4+
5+
USAGE:
6+
scw baremetal bmc get [arg=value ...]
7+
8+
ARGS:
9+
server-id ID of the server
10+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-2)
11+
12+
FLAGS:
13+
-h, --help help for get
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Start BMC (Baseboard Management Controller) access associated with the given ID.
4+
The BMC (Baseboard Management Controller) access is available one hour after the installation of the server.
5+
6+
USAGE:
7+
scw baremetal bmc start [arg=value ...]
8+
9+
ARGS:
10+
server-id ID of the server
11+
ip The IP authorized to connect to the given server
12+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-2)
13+
14+
FLAGS:
15+
-h, --help help for start
16+
17+
GLOBAL FLAGS:
18+
-c, --config string The path to the config file
19+
-D, --debug Enable debug mode
20+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
21+
-p, --profile string The config profile to use
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Stop BMC (Baseboard Management Controller) access associated with the given ID.
4+
5+
USAGE:
6+
scw baremetal bmc stop [arg=value ...]
7+
8+
ARGS:
9+
server-id ID of the server
10+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-2)
11+
12+
FLAGS:
13+
-h, --help help for stop
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Baseboard Management Controller (BMC) allows you to remotely access the low-level parameters of your dedicated server.
4+
For instance, your KVM-IP management console could be accessed with it.
5+
6+
USAGE:
7+
scw baremetal bmc <command>
8+
9+
AVAILABLE COMMANDS:
10+
get Get BMC (Baseboard Management Controller) access for a given baremetal server
11+
start Start BMC (Baseboard Management Controller) access for a given baremetal server
12+
stop Stop BMC (Baseboard Management Controller) access for a given baremetal server
13+
14+
FLAGS:
15+
-h, --help help for bmc
16+
17+
GLOBAL FLAGS:
18+
-c, --config string The path to the config file
19+
-D, --debug Enable debug mode
20+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
21+
-p, --profile string The config profile to use
22+
23+
Use "scw baremetal bmc [command] --help" for more information about a command.

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

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ USAGE:
66
scw baremetal <command>
77

88
AVAILABLE COMMANDS:
9+
bmc Baseboard Management Controller (BMC) management commands
910
os Operating System (OS) management commands
1011
server Server management commands
1112

cmd/scw/testdata/test-all-usage-lblb-create-usage.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ARGS:
1010
[description] Resource description
1111
[ip-id] Just like for compute instances, when you destroy a load balancer, you can keep its highly available IP address and reuse it for another load balancer later
1212
[tags.{index}] List of keyword
13-
[type] Load balancer offer type
13+
[type=LB-S] Load balancer offer type (LB-S | LB-GP-M | LB-GP-L)
1414
[ssl-compatibility-level] (ssl_compatibility_level_unknown | ssl_compatibility_level_intermediate | ssl_compatibility_level_modern | ssl_compatibility_level_old)
1515
[organization-id] Organization ID to use. If none is passed will use default organization ID from the config
1616
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams)

cmd/scw/testdata/test-all-usage-lblb-migrate-usage.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ USAGE:
77

88
ARGS:
99
lb-id Load balancer ID
10-
type Load balancer type (check /lb-types to list all type)
10+
type Load balancer type (check /lb-types to list all type) (LB-S | LB-GP-M | LB-GP-L)
1111
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams)
1212

1313
FLAGS:

internal/namespaces/baremetal/v1/baremetal_cli.go

+113
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func GetGeneratedCommands() *core.Commands {
2222
baremetalRoot(),
2323
baremetalServer(),
2424
baremetalOs(),
25+
baremetalBmc(),
2526
baremetalServerList(),
2627
baremetalServerGet(),
2728
baremetalServerCreate(),
@@ -31,6 +32,9 @@ func GetGeneratedCommands() *core.Commands {
3132
baremetalServerReboot(),
3233
baremetalServerStart(),
3334
baremetalServerStop(),
35+
baremetalBmcStart(),
36+
baremetalBmcGet(),
37+
baremetalBmcStop(),
3438
baremetalOsList(),
3539
baremetalOsGet(),
3640
)
@@ -61,6 +65,17 @@ func baremetalOs() *core.Command {
6165
}
6266
}
6367

68+
func baremetalBmc() *core.Command {
69+
return &core.Command{
70+
Short: `Baseboard Management Controller (BMC) management commands`,
71+
Long: `Baseboard Management Controller (BMC) allows you to remotely access the low-level parameters of your dedicated server.
72+
For instance, your KVM-IP management console could be accessed with it.
73+
`,
74+
Namespace: "baremetal",
75+
Resource: "bmc",
76+
}
77+
}
78+
6479
func baremetalServerList() *core.Command {
6580
return &core.Command{
6681
Short: `List baremetal servers`,
@@ -496,6 +511,104 @@ func baremetalServerStop() *core.Command {
496511
}
497512
}
498513

514+
func baremetalBmcStart() *core.Command {
515+
return &core.Command{
516+
Short: `Start BMC (Baseboard Management Controller) access for a given baremetal server`,
517+
Long: `Start BMC (Baseboard Management Controller) access associated with the given ID.
518+
The BMC (Baseboard Management Controller) access is available one hour after the installation of the server.
519+
`,
520+
Namespace: "baremetal",
521+
Resource: "bmc",
522+
Verb: "start",
523+
ArgsType: reflect.TypeOf(baremetal.StartBMCAccessRequest{}),
524+
ArgSpecs: core.ArgSpecs{
525+
{
526+
Name: "server-id",
527+
Short: `ID of the server`,
528+
Required: true,
529+
Positional: false,
530+
},
531+
{
532+
Name: "ip",
533+
Short: `The IP authorized to connect to the given server`,
534+
Required: true,
535+
Positional: false,
536+
},
537+
core.ZoneArgSpec(scw.ZoneFrPar2),
538+
},
539+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
540+
request := args.(*baremetal.StartBMCAccessRequest)
541+
542+
client := core.ExtractClient(ctx)
543+
api := baremetal.NewAPI(client)
544+
return api.StartBMCAccess(request)
545+
546+
},
547+
}
548+
}
549+
550+
func baremetalBmcGet() *core.Command {
551+
return &core.Command{
552+
Short: `Get BMC (Baseboard Management Controller) access for a given baremetal server`,
553+
Long: `Get the BMC (Baseboard Management Controller) access associated with the given ID.`,
554+
Namespace: "baremetal",
555+
Resource: "bmc",
556+
Verb: "get",
557+
ArgsType: reflect.TypeOf(baremetal.GetBMCAccessRequest{}),
558+
ArgSpecs: core.ArgSpecs{
559+
{
560+
Name: "server-id",
561+
Short: `ID of the server`,
562+
Required: true,
563+
Positional: false,
564+
},
565+
core.ZoneArgSpec(scw.ZoneFrPar2),
566+
},
567+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
568+
request := args.(*baremetal.GetBMCAccessRequest)
569+
570+
client := core.ExtractClient(ctx)
571+
api := baremetal.NewAPI(client)
572+
return api.GetBMCAccess(request)
573+
574+
},
575+
}
576+
}
577+
578+
func baremetalBmcStop() *core.Command {
579+
return &core.Command{
580+
Short: `Stop BMC (Baseboard Management Controller) access for a given baremetal server`,
581+
Long: `Stop BMC (Baseboard Management Controller) access associated with the given ID.`,
582+
Namespace: "baremetal",
583+
Resource: "bmc",
584+
Verb: "stop",
585+
ArgsType: reflect.TypeOf(baremetal.StopBMCAccessRequest{}),
586+
ArgSpecs: core.ArgSpecs{
587+
{
588+
Name: "server-id",
589+
Short: `ID of the server`,
590+
Required: true,
591+
Positional: false,
592+
},
593+
core.ZoneArgSpec(scw.ZoneFrPar2),
594+
},
595+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
596+
request := args.(*baremetal.StopBMCAccessRequest)
597+
598+
client := core.ExtractClient(ctx)
599+
api := baremetal.NewAPI(client)
600+
e = api.StopBMCAccess(request)
601+
if e != nil {
602+
return nil, e
603+
}
604+
return &core.SuccessResult{
605+
Resource: "bmc",
606+
Verb: "stop",
607+
}, nil
608+
},
609+
}
610+
}
611+
499612
func baremetalOsList() *core.Command {
500613
return &core.Command{
501614
Short: `List all available OS that can be install on a baremetal server`,

internal/namespaces/instance/v1/custom.go

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func GetCommands() *core.Commands {
158158
cmds.MustFind("instance", "user-data", "delete").Override(userDataDeleteBuilder)
159159
cmds.MustFind("instance", "user-data", "set").Override(userDataSetBuilder)
160160
cmds.MustFind("instance", "user-data", "get").Override(userDataGetBuilder)
161+
cmds.MustFind("instance", "user-data", "list").Override(userDataListBuilder)
161162

162163
return cmds
163164
}

internal/namespaces/instance/v1/custom_user_data.go

+37
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package instance
33
import (
44
"context"
55
"fmt"
6+
"io"
67
"net/http"
8+
"strings"
79

810
"github.com/scaleway/scaleway-cli/internal/core"
911
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
@@ -53,3 +55,38 @@ func userDataGetBuilder(c *core.Command) *core.Command {
5355

5456
return c
5557
}
58+
59+
func userDataListBuilder(c *core.Command) *core.Command {
60+
type userDataRow struct {
61+
Key string `json:"key"`
62+
Value string `json:"value"`
63+
}
64+
c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (interface{}, error) {
65+
client := core.ExtractClient(ctx)
66+
api := instance.NewAPI(client)
67+
args := argsI.(*instance.ListServerUserDataRequest)
68+
res, err := api.GetAllServerUserData(&instance.GetAllServerUserDataRequest{
69+
Zone: args.Zone,
70+
ServerID: args.ServerID,
71+
})
72+
if err != nil {
73+
return nil, err
74+
}
75+
var r []userDataRow
76+
for a, v := range res.UserData {
77+
buf := new(strings.Builder)
78+
_, err := io.Copy(buf, v)
79+
if err != nil {
80+
return nil, err
81+
}
82+
r = append(r, userDataRow{
83+
Key: a,
84+
Value: buf.String(),
85+
})
86+
}
87+
88+
return r, nil
89+
})
90+
91+
return c
92+
}

internal/namespaces/instance/v1/custom_user_data_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,20 @@ func Test_UserDataGet(t *testing.T) {
3232
),
3333
}))
3434
}
35+
36+
func Test_UserDataList(t *testing.T) {
37+
t.Run("Simple", core.Test(&core.TestConfig{
38+
BeforeFunc: core.BeforeFuncCombine(
39+
createServer("Server"),
40+
core.ExecBeforeCmd("scw instance user-data set {{ .Server.ID }} key=foo content=bar"),
41+
core.ExecBeforeCmd("scw instance user-data set {{ .Server.ID }} key=bar content=foo"),
42+
),
43+
Commands: GetCommands(),
44+
Cmd: "scw instance user-data list server-id={{ .Server.ID }}",
45+
AfterFunc: deleteServer("Server"),
46+
Check: core.TestCheckCombine(
47+
core.TestCheckGolden(),
48+
core.TestCheckExitCode(0),
49+
),
50+
}))
51+
}

0 commit comments

Comments
 (0)