forked from docker/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
machine.go
215 lines (193 loc) · 5.69 KB
/
machine.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package main
import (
"fmt"
"os"
"strconv"
"path/filepath"
"github.com/codegangsta/cli"
"github.com/docker/machine/commands"
"github.com/docker/machine/commands/mcndirs"
"github.com/docker/machine/drivers/amazonec2"
"github.com/docker/machine/drivers/azure"
"github.com/docker/machine/drivers/digitalocean"
"github.com/docker/machine/drivers/exoscale"
"github.com/docker/machine/drivers/generic"
"github.com/docker/machine/drivers/google"
"github.com/docker/machine/drivers/hyperv"
"github.com/docker/machine/drivers/none"
"github.com/docker/machine/drivers/openstack"
"github.com/docker/machine/drivers/rackspace"
"github.com/docker/machine/drivers/softlayer"
"github.com/docker/machine/drivers/virtualbox"
"github.com/docker/machine/drivers/vmwarefusion"
"github.com/docker/machine/drivers/vmwarevcloudair"
"github.com/docker/machine/drivers/vmwarevsphere"
"github.com/docker/machine/libmachine/drivers/plugin"
"github.com/docker/machine/libmachine/drivers/plugin/localbinary"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/version"
)
var AppHelpTemplate = `Usage: {{.Name}} {{if .Flags}}[OPTIONS] {{end}}COMMAND [arg...]
{{.Usage}}
Version: {{.Version}}{{if or .Author .Email}}
Author:{{if .Author}}
{{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}}
{{.Email}}{{end}}{{end}}
{{if .Flags}}
Options:
{{range .Flags}}{{.}}
{{end}}{{end}}
Commands:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}
Run '{{.Name}} COMMAND --help' for more information on a command.
`
var CommandHelpTemplate = `Usage: docker-machine {{.Name}}{{if .Flags}} [OPTIONS]{{end}} [arg...]
{{.Usage}}{{if .Description}}
Description:
{{.Description}}{{end}}{{if .Flags}}
Options:
{{range .Flags}}
{{.}}{{end}}{{ end }}
`
func setDebugOutputLevel() {
// TODO: I'm not really a fan of this method and really would rather
// use -v / --verbose TBQH
for _, f := range os.Args {
if f == "-D" || f == "--debug" || f == "-debug" {
log.SetDebug(true)
}
}
debugEnv := os.Getenv("MACHINE_DEBUG")
if debugEnv != "" {
showDebug, err := strconv.ParseBool(debugEnv)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing boolean value from MACHINE_DEBUG: %s\n", err)
os.Exit(1)
}
log.SetDebug(showDebug)
}
}
func main() {
if os.Getenv(localbinary.PluginEnvKey) == localbinary.PluginEnvVal {
driverName := os.Getenv(localbinary.PluginEnvDriverName)
runDriver(driverName)
return
}
localbinary.CurrentBinaryIsDockerMachine = true
setDebugOutputLevel()
cli.AppHelpTemplate = AppHelpTemplate
cli.CommandHelpTemplate = CommandHelpTemplate
app := cli.NewApp()
app.Name = filepath.Base(os.Args[0])
app.Author = "Docker Machine Contributors"
app.Email = "https://github.com/docker/machine"
app.Commands = commands.Commands
app.CommandNotFound = cmdNotFound
app.Usage = "Create and manage machines running Docker."
app.Version = version.FullVersion()
log.Debug("Docker Machine Version: ", app.Version)
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, D",
Usage: "Enable debug mode",
},
cli.StringFlag{
EnvVar: "MACHINE_STORAGE_PATH",
Name: "storage-path, s",
Value: mcndirs.GetBaseDir(),
Usage: "Configures storage path",
},
cli.StringFlag{
EnvVar: "MACHINE_TLS_CA_CERT",
Name: "tls-ca-cert",
Usage: "CA to verify remotes against",
Value: "",
},
cli.StringFlag{
EnvVar: "MACHINE_TLS_CA_KEY",
Name: "tls-ca-key",
Usage: "Private key to generate certificates",
Value: "",
},
cli.StringFlag{
EnvVar: "MACHINE_TLS_CLIENT_CERT",
Name: "tls-client-cert",
Usage: "Client cert to use for TLS",
Value: "",
},
cli.StringFlag{
EnvVar: "MACHINE_TLS_CLIENT_KEY",
Name: "tls-client-key",
Usage: "Private key used in client TLS auth",
Value: "",
},
cli.StringFlag{
EnvVar: "MACHINE_GITHUB_API_TOKEN",
Name: "github-api-token",
Usage: "Token to use for requests to the Github API",
Value: "",
},
cli.BoolFlag{
EnvVar: "MACHINE_NATIVE_SSH",
Name: "native-ssh",
Usage: "Use the native (Go-based) SSH implementation.",
},
cli.StringFlag{
EnvVar: "MACHINE_BUGSNAG_API_TOKEN",
Name: "bugsnag-api-token",
Usage: "BugSnag API token for crash reporting",
Value: "",
},
}
if err := app.Run(os.Args); err != nil {
log.Error(err)
}
}
func runDriver(driverName string) {
switch driverName {
case "amazonec2":
plugin.RegisterDriver(amazonec2.NewDriver("", ""))
case "azure":
plugin.RegisterDriver(azure.NewDriver("", ""))
case "digitalocean":
plugin.RegisterDriver(digitalocean.NewDriver("", ""))
case "exoscale":
plugin.RegisterDriver(exoscale.NewDriver("", ""))
case "generic":
plugin.RegisterDriver(generic.NewDriver("", ""))
case "google":
plugin.RegisterDriver(google.NewDriver("", ""))
case "hyperv":
plugin.RegisterDriver(hyperv.NewDriver("", ""))
case "none":
plugin.RegisterDriver(none.NewDriver("", ""))
case "openstack":
plugin.RegisterDriver(openstack.NewDriver("", ""))
case "rackspace":
plugin.RegisterDriver(rackspace.NewDriver("", ""))
case "softlayer":
plugin.RegisterDriver(softlayer.NewDriver("", ""))
case "virtualbox":
plugin.RegisterDriver(virtualbox.NewDriver("", ""))
case "vmwarefusion":
plugin.RegisterDriver(vmwarefusion.NewDriver("", ""))
case "vmwarevcloudair":
plugin.RegisterDriver(vmwarevcloudair.NewDriver("", ""))
case "vmwarevsphere":
plugin.RegisterDriver(vmwarevsphere.NewDriver("", ""))
default:
fmt.Fprintf(os.Stderr, "Unsupported driver: %s\n", driverName)
os.Exit(1)
}
}
func cmdNotFound(c *cli.Context, command string) {
log.Errorf(
"%s: '%s' is not a %s command. See '%s --help'.",
c.App.Name,
command,
c.App.Name,
os.Args[0],
)
os.Exit(1)
}