Skip to content

Commit 29c3df2

Browse files
feat: add auto feature on boottype flag (#542)
* Add auto feature on boottype flag * Remove default value from flag desc * Fix: add missing legacy instance types
1 parent 8b5c280 commit 29c3df2

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

pkg/api/helpers.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,31 @@ func OfferNameFromName(name string, products *ScalewayProductsServers) (*Product
341341
return nil, fmt.Errorf("Unknow commercial type: %v", name)
342342
}
343343

344+
var legacyInstantTypes = map[string]struct{}{
345+
"START1-XS": {},
346+
"START1-S": {},
347+
"START1-M": {},
348+
"START1-L": {},
349+
"C1": {},
350+
"C2S": {},
351+
"C2M": {},
352+
"C2L": {},
353+
"ARM64-2GB": {},
354+
"ARM64-4GB": {},
355+
"ARM64-8GB": {},
356+
"ARM64-16GB": {},
357+
"ARM64-32GB": {},
358+
"ARM64-64GB": {},
359+
"ARM64-128GB": {},
360+
"X64-15GB": {},
361+
"X64-30GB": {},
362+
"X64-60GB": {},
363+
"X64-120GB": {},
364+
"VC1S": {},
365+
"VC1M": {},
366+
"VC1L": {},
367+
}
368+
344369
// CreateServer creates a server using API based on typical server fields
345370
func CreateServer(api *ScalewayAPI, c *ConfigCreateServer) (string, error) {
346371
commercialType := os.Getenv("SCW_COMMERCIAL_TYPE")
@@ -350,6 +375,15 @@ func CreateServer(api *ScalewayAPI, c *ConfigCreateServer) (string, error) {
350375
if len(commercialType) < 2 {
351376
return "", errors.New("Invalid commercial type")
352377
}
378+
commercialType = strings.ToUpper(commercialType)
379+
380+
if c.BootType == "auto" {
381+
if _, exist := legacyInstantTypes[commercialType]; exist {
382+
c.BootType = "bootscript"
383+
} else {
384+
c.BootType = "local"
385+
}
386+
}
353387

354388
if c.BootType != "local" && c.BootType != "bootscript" {
355389
return "", errors.New("Invalid boot type")
@@ -361,7 +395,7 @@ func CreateServer(api *ScalewayAPI, c *ConfigCreateServer) (string, error) {
361395

362396
var server ScalewayServerDefinition
363397

364-
server.CommercialType = strings.ToUpper(commercialType)
398+
server.CommercialType = commercialType
365399
server.Volumes = make(map[string]string)
366400
server.DynamicIPRequired = &c.DynamicIPRequired
367401
server.EnableIPV6 = c.EnableIPV6

pkg/cli/cmd_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +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")
35+
cmdCreate.Flag.StringVar(&createBootType, []string{"-boot-type"}, "auto", "Choose between 'local' and 'bootscript' boot")
3636
cmdCreate.Flag.BoolVar(&createHelp, []string{"h", "-help"}, false, "Print usage")
3737
cmdCreate.Flag.BoolVar(&createIPV6, []string{"-ipv6"}, false, "Enable IPV6")
3838
cmdCreate.Flag.BoolVar(&createTmpSSHKey, []string{"-tmp-ssh-key"}, false, "Access your server without uploading your SSH key to your account")

pkg/cli/cmd_run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +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")
49+
cmdRun.Flag.StringVar(&runBootType, []string{"-boot-type"}, "auto", "Choose between 'local' and 'bootscript' boot")
5050
cmdRun.Flag.StringVar(&runSSHUser, []string{"-user"}, "root", "Specify SSH User")
5151
cmdRun.Flag.BoolVar(&runAutoRemove, []string{"-rm"}, false, "Automatically remove the server when it exits")
5252
cmdRun.Flag.BoolVar(&runIPV6, []string{"-ipv6"}, false, "Enable IPV6")

0 commit comments

Comments
 (0)