Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion pkg/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,31 @@ func OfferNameFromName(name string, products *ScalewayProductsServers) (*Product
return nil, fmt.Errorf("Unknow commercial type: %v", name)
}

var legacyInstantTypes = map[string]struct{}{
"START1-XS": {},
"START1-S": {},
"START1-M": {},
"START1-L": {},
"C1": {},
"C2S": {},
"C2M": {},
"C2L": {},
"ARM64-2GB": {},
"ARM64-4GB": {},
"ARM64-8GB": {},
"ARM64-16GB": {},
"ARM64-32GB": {},
"ARM64-64GB": {},
"ARM64-128GB": {},
"X64-15GB": {},
"X64-30GB": {},
"X64-60GB": {},
"X64-120GB": {},
"VC1S": {},
"VC1M": {},
"VC1L": {},
}

// CreateServer creates a server using API based on typical server fields
func CreateServer(api *ScalewayAPI, c *ConfigCreateServer) (string, error) {
commercialType := os.Getenv("SCW_COMMERCIAL_TYPE")
Expand All @@ -350,6 +375,15 @@ func CreateServer(api *ScalewayAPI, c *ConfigCreateServer) (string, error) {
if len(commercialType) < 2 {
return "", errors.New("Invalid commercial type")
}
commercialType = strings.ToUpper(commercialType)

if c.BootType == "auto" {
if _, exist := legacyInstantTypes[commercialType]; exist {
c.BootType = "bootscript"
} else {
c.BootType = "local"
}
}

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

var server ScalewayServerDefinition

server.CommercialType = strings.ToUpper(commercialType)
server.CommercialType = commercialType
server.Volumes = make(map[string]string)
server.DynamicIPRequired = &c.DynamicIPRequired
server.EnableIPV6 = c.EnableIPV6
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
cmdCreate.Flag.StringVar(&createVolume, []string{"v", "-volume"}, "", "Attach additional volume (i.e., 50G)")
cmdCreate.Flag.StringVar(&createIPAddress, []string{"-ip-address"}, "dynamic", "Assign a reserved public IP, a 'dynamic' one or 'none'")
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")
cmdCreate.Flag.StringVar(&createBootType, []string{"-boot-type"}, "local", "Choose between 'local' and 'bootscript' boot")
cmdCreate.Flag.StringVar(&createBootType, []string{"-boot-type"}, "auto", "Choose between 'local' and 'bootscript' boot")
cmdCreate.Flag.BoolVar(&createHelp, []string{"h", "-help"}, false, "Print usage")
cmdCreate.Flag.BoolVar(&createIPV6, []string{"-ipv6"}, false, "Enable IPV6")
cmdCreate.Flag.BoolVar(&createTmpSSHKey, []string{"-tmp-ssh-key"}, false, "Access your server without uploading your SSH key to your account")
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func init() {
cmdRun.Flag.StringVar(&runGateway, []string{"g", "-gateway"}, "", "Use a SSH gateway")
cmdRun.Flag.StringVar(&runUserdatas, []string{"u", "-userdata"}, "", "Start a server with userdata predefined")
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")
cmdRun.Flag.StringVar(&runBootType, []string{"-boot-type"}, "local", "Choose between 'local' and 'bootscript' boot")
cmdRun.Flag.StringVar(&runBootType, []string{"-boot-type"}, "auto", "Choose between 'local' and 'bootscript' boot")
cmdRun.Flag.StringVar(&runSSHUser, []string{"-user"}, "root", "Specify SSH User")
cmdRun.Flag.BoolVar(&runAutoRemove, []string{"-rm"}, false, "Automatically remove the server when it exits")
cmdRun.Flag.BoolVar(&runIPV6, []string{"-ipv6"}, false, "Enable IPV6")
Expand Down