github.com/scaleway/scaleway-cli@v1.11.1/pkg/cli/cmd_create.go (about) 1 // Copyright (C) 2015 Scaleway. All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE.md file. 4 5 package cli 6 7 import ( 8 "strings" 9 10 "github.com/scaleway/scaleway-cli/pkg/commands" 11 ) 12 13 var cmdCreate = &Command{ 14 Exec: runCreate, 15 UsageLine: "create [OPTIONS] IMAGE", 16 Description: "Create a new server but do not start it", 17 Help: "Create a new server but do not start it.", 18 Examples: ` 19 $ scw create docker 20 $ scw create 10GB 21 $ scw create --bootscript=3.2.34 --env="boot=live rescue_image=http://j.mp/scaleway-ubuntu-trusty-tarball" 50GB 22 $ scw inspect $(scw create 1GB --bootscript=rescue --volume=50GB) 23 $ scw create $(scw tag my-snapshot my-image) 24 $ scw create --tmp-ssh-key 10GB 25 `, 26 } 27 28 func init() { 29 cmdCreate.Flag.StringVar(&createName, []string{"-name"}, "", "Assign a name") 30 cmdCreate.Flag.StringVar(&createBootscript, []string{"-bootscript"}, "", "Assign a bootscript") 31 cmdCreate.Flag.StringVar(&createEnv, []string{"e", "-env"}, "", "Provide metadata tags passed to initrd (i.e., boot=rescue INITRD_DEBUG=1)") 32 cmdCreate.Flag.StringVar(&createVolume, []string{"v", "-volume"}, "", "Attach additional volume (i.e., 50G)") 33 cmdCreate.Flag.StringVar(&createIPAddress, []string{"-ip-address"}, "dynamic", "Assign a reserved public IP, a 'dynamic' one or 'none'") 34 cmdCreate.Flag.StringVar(&createCommercialType, []string{"-commercial-type"}, "VC1S", "Create a server with specific commercial-type C1, VC1[S|M|L], C2[S|M|L]") 35 cmdCreate.Flag.BoolVar(&createHelp, []string{"h", "-help"}, false, "Print usage") 36 cmdCreate.Flag.BoolVar(&createIPV6, []string{"-ipv6"}, false, "Enable IPV6") 37 cmdCreate.Flag.BoolVar(&createTmpSSHKey, []string{"-tmp-ssh-key"}, false, "Access your server without uploading your SSH key to your account") 38 } 39 40 // Flags 41 var createName string // --name flag 42 var createBootscript string // --bootscript flag 43 var createEnv string // -e, --env flag 44 var createVolume string // -v, --volume flag 45 var createHelp bool // -h, --help flag 46 var createTmpSSHKey bool // --tmp-ssh-key flag 47 var createIPAddress string // --ip-address flag 48 var createCommercialType string // --commercial-type flag 49 var createIPV6 bool // --ipv6 flag 50 51 func runCreate(cmd *Command, rawArgs []string) error { 52 if createHelp { 53 return cmd.PrintUsage() 54 } 55 if len(rawArgs) != 1 { 56 return cmd.PrintShortUsage() 57 } 58 59 args := commands.CreateArgs{ 60 Name: createName, 61 Bootscript: createBootscript, 62 Image: rawArgs[0], 63 TmpSSHKey: createTmpSSHKey, 64 IP: createIPAddress, 65 CommercialType: createCommercialType, 66 IPV6: createIPV6, 67 } 68 69 if len(createEnv) > 0 { 70 args.Tags = strings.Split(createEnv, " ") 71 } 72 if len(createVolume) > 0 { 73 args.Volumes = strings.Split(createVolume, " ") 74 } 75 ctx := cmd.GetContext(rawArgs) 76 return commands.RunCreate(ctx, args) 77 }