Skip to content

Commit 97d879a

Browse files
Le Garrec Maëlizissise
authored andcommitted
add boot-type option to create command
1 parent 3944aab commit 97d879a

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

pkg/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ type ScalewayServerDefinition struct {
652652
EnableIPV6 bool `json:"enable_ipv6,omitempty"`
653653

654654
SecurityGroup string `json:"security_group,omitempty"`
655+
656+
BootType string `json:"boot_type,omitempty"`
655657
}
656658

657659
// 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/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

0 commit comments

Comments
 (0)