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