Skip to content

Commit 65d3dbe

Browse files
authored
Merge pull request #504 from scaleway/mlegarrec/boot-type_option
add boot-type option to create/run commands
2 parents 3944aab + f5540e4 commit 65d3dbe

File tree

8 files changed

+27
-0
lines changed

8 files changed

+27
-0
lines changed

pkg/api/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ type ScalewayServer struct {
545545
// State is the current status of the server
546546
State string `json:"state,omitempty"`
547547

548+
// BootType is the boot method used, can be local or bootscript
549+
BootType string `json:"boot_type,omitempty"`
550+
548551
// StateDetail is the detailed status of the server
549552
StateDetail string `json:"state_detail,omitempty"`
550553

@@ -619,6 +622,7 @@ type ScalewayServerPatchDefinition struct {
619622
Tags *[]string `json:"tags,omitempty"`
620623
IPV6 *ScalewayIPV6Definition `json:"ipv6,omitempty"`
621624
EnableIPV6 *bool `json:"enable_ipv6,omitempty"`
625+
BootType *string `json:"boot_type,omitempty"`
622626
}
623627

624628
// ScalewayServerDefinition represents a Scaleway server with image definition
@@ -652,6 +656,8 @@ type ScalewayServerDefinition struct {
652656
EnableIPV6 bool `json:"enable_ipv6,omitempty"`
653657

654658
SecurityGroup string `json:"security_group,omitempty"`
659+
660+
BootType string `json:"boot_type,omitempty"`
655661
}
656662

657663
// ScalewayOneServer represents the response of a GET /servers/UUID API call

pkg/api/helpers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ type ConfigCreateServer struct {
319319
CommercialType string
320320
DynamicIPRequired bool
321321
EnableIPV6 bool
322+
BootType string
322323
}
323324

324325
// Return offer from any of the product name or alternate names
@@ -350,6 +351,10 @@ func CreateServer(api *ScalewayAPI, c *ConfigCreateServer) (string, error) {
350351
return "", errors.New("Invalid commercial type")
351352
}
352353

354+
if c.BootType != "local" && c.BootType != "bootscript" {
355+
return "", errors.New("Invalid boot type")
356+
}
357+
353358
if c.Name == "" {
354359
c.Name = strings.Replace(namesgenerator.GetRandomName(0), "_", "-", -1)
355360
}
@@ -360,6 +365,7 @@ func CreateServer(api *ScalewayAPI, c *ConfigCreateServer) (string, error) {
360365
server.Volumes = make(map[string]string)
361366
server.DynamicIPRequired = &c.DynamicIPRequired
362367
server.EnableIPV6 = c.EnableIPV6
368+
server.BootType = c.BootType
363369
if commercialType == "" {
364370
return "", errors.New("You need to specify a commercial-type")
365371
}

pkg/cli/cmd_create.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func init() {
3232
cmdCreate.Flag.StringVar(&createVolume, []string{"v", "-volume"}, "", "Attach additional volume (i.e., 50G)")
3333
cmdCreate.Flag.StringVar(&createIPAddress, []string{"-ip-address"}, "dynamic", "Assign a reserved public IP, a 'dynamic' one or 'none'")
3434
cmdCreate.Flag.StringVar(&createCommercialType, []string{"-commercial-type"}, "X64-2GB", "Create a server with specific commercial-type C1, C2[S|M|L], X64-[2|4|8|15|30|60|120]GB, ARM64-[2|4|8]GB")
35+
cmdCreate.Flag.StringVar(&createBootType, []string{"-boot-type"}, "local", "Choose between 'local' and 'bootscript' boot")
3536
cmdCreate.Flag.BoolVar(&createHelp, []string{"h", "-help"}, false, "Print usage")
3637
cmdCreate.Flag.BoolVar(&createIPV6, []string{"-ipv6"}, false, "Enable IPV6")
3738
cmdCreate.Flag.BoolVar(&createTmpSSHKey, []string{"-tmp-ssh-key"}, false, "Access your server without uploading your SSH key to your account")
@@ -47,6 +48,7 @@ var createTmpSSHKey bool // --tmp-ssh-key flag
4748
var createIPAddress string // --ip-address flag
4849
var createCommercialType string // --commercial-type flag
4950
var createIPV6 bool // --ipv6 flag
51+
var createBootType string // --boot-type flag
5052

5153
func runCreate(cmd *Command, rawArgs []string) error {
5254
if createHelp {
@@ -64,6 +66,7 @@ func runCreate(cmd *Command, rawArgs []string) error {
6466
IP: createIPAddress,
6567
CommercialType: createCommercialType,
6668
IPV6: createIPV6,
69+
BootType: createBootType,
6770
}
6871

6972
if len(createEnv) > 0 {

pkg/cli/cmd_run.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func init() {
4646
cmdRun.Flag.StringVar(&runGateway, []string{"g", "-gateway"}, "", "Use a SSH gateway")
4747
cmdRun.Flag.StringVar(&runUserdatas, []string{"u", "-userdata"}, "", "Start a server with userdata predefined")
4848
cmdRun.Flag.StringVar(&runCommercialType, []string{"-commercial-type"}, "X64-2GB", "Start a server with specific commercial-type C1, C2[S|M|L], X64-[2|4|8|15|30|60|120]GB, ARM64-[2|4|8]GB")
49+
cmdRun.Flag.StringVar(&runBootType, []string{"-boot-type"}, "local", "Choose between 'local' and 'bootscript' boot")
4950
cmdRun.Flag.StringVar(&runSSHUser, []string{"-user"}, "root", "Specify SSH User")
5051
cmdRun.Flag.BoolVar(&runAutoRemove, []string{"-rm"}, false, "Automatically remove the server when it exits")
5152
cmdRun.Flag.BoolVar(&runIPV6, []string{"-ipv6"}, false, "Enable IPV6")
@@ -68,6 +69,7 @@ var runDetachFlag bool // -d, --detach flag
6869
var runGateway string // -g, --gateway flag
6970
var runUserdatas string // -u, --userdata flag
7071
var runCommercialType string // --commercial-type flag
72+
var runBootType string // --boot-type flag
7173
var runTmpSSHKey bool // --tmp-ssh-key flag
7274
var runShowBoot bool // --show-boot flag
7375
var runIPV6 bool // --ipv6 flag
@@ -124,6 +126,7 @@ func runRun(cmd *Command, rawArgs []string) error {
124126
IPV6: runIPV6,
125127
SSHUser: runSSHUser,
126128
SSHPort: runSSHPort,
129+
BootType: runBootType,
127130
// FIXME: Timeout
128131
}
129132

pkg/cli/x_patch.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func runPatch(cmd *Command, args []string) error {
8383
changes++
8484
payload.Bootscript = &newValue
8585
}
86+
case "boot_type":
87+
log.Debugf("%s=%s => %s=%s", fieldName, currentServer.BootType, fieldName, newValue)
88+
changes++
89+
payload.BootType = &newValue
8690
case "security_group":
8791
log.Debugf("%s=%s => %s=%s", fieldName, currentServer.SecurityGroup.Identifier, fieldName, newValue)
8892
if currentServer.SecurityGroup.Identifier != newValue {

pkg/commands/create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type CreateArgs struct {
2323
CommercialType string
2424
TmpSSHKey bool
2525
IPV6 bool
26+
BootType string
2627
}
2728

2829
// RunCreate is the handler for 'scw create'
@@ -46,6 +47,7 @@ func RunCreate(ctx CommandContext, args CreateArgs) error {
4647
IP: args.IP,
4748
CommercialType: args.CommercialType,
4849
EnableIPV6: args.IPV6,
50+
BootType: args.BootType,
4951
}
5052
if args.IP == "dynamic" || args.IP == "" {
5153
config.DynamicIPRequired = true

pkg/commands/create_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func TestRunCreate_realAPI(t *testing.T) {
6565
Image: "ubuntu-mini-xenial-25g",
6666
CommercialType: "X64-2GB",
6767
IP: "dynamic",
68+
BootType: "bootscript",
6869
}
6970

7071
scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx)

pkg/commands/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type RunArgs struct {
3232
CommercialType string
3333
State string
3434
SSHUser string
35+
BootType string
3536
Timeout int64
3637
SSHPort int
3738
AutoRemove bool
@@ -170,6 +171,7 @@ func Run(ctx CommandContext, args RunArgs) error {
170171
IP: args.IP,
171172
CommercialType: args.CommercialType,
172173
EnableIPV6: args.IPV6,
174+
BootType: args.BootType,
173175
}
174176
if args.IP == "dynamic" || (args.IP == "" && args.Gateway == "") {
175177
config.DynamicIPRequired = true

0 commit comments

Comments
 (0)