forked from rancher/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
281 lines (266 loc) · 8.96 KB
/
flags.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package vmwarevsphere
import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/mcnflag"
"github.com/vmware/govmomi/vim25/types"
)
var creationTypes = map[string]bool{
"vm": true,
"template": true,
"library": true,
"legacy": true,
}
func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return []mcnflag.Flag{
mcnflag.IntFlag{
EnvVar: "VSPHERE_CPU_COUNT",
Name: "vmwarevsphere-cpu-count",
Usage: "vSphere CPU number for docker VM",
Value: defaultCpus,
},
mcnflag.IntFlag{
EnvVar: "VSPHERE_MEMORY_SIZE",
Name: "vmwarevsphere-memory-size",
Usage: "vSphere size of memory for docker VM (in MB)",
Value: defaultMemory,
},
mcnflag.IntFlag{
EnvVar: "VSPHERE_DISK_SIZE",
Name: "vmwarevsphere-disk-size",
Usage: "vSphere size of disk for docker VM (in MB)",
Value: defaultDiskSize,
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_BOOT2DOCKER_URL",
Name: "vmwarevsphere-boot2docker-url",
Usage: "vSphere URL for boot2docker image",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_VCENTER",
Name: "vmwarevsphere-vcenter",
Usage: "vSphere IP/hostname for vCenter",
},
mcnflag.IntFlag{
EnvVar: "VSPHERE_VCENTER_PORT",
Name: "vmwarevsphere-vcenter-port",
Usage: "vSphere Port for vCenter",
Value: defaultSDKPort,
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_USERNAME",
Name: "vmwarevsphere-username",
Usage: "vSphere username",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_PASSWORD",
Name: "vmwarevsphere-password",
Usage: "vSphere password",
},
mcnflag.StringSliceFlag{
EnvVar: "VSPHERE_NETWORK",
Name: "vmwarevsphere-network",
Usage: "vSphere network where the virtual machine will be attached",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_DATASTORE",
Name: "vmwarevsphere-datastore",
Usage: "vSphere datastore for virtual machine",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_DATASTORE_CLUSTER",
Name: "vmwarevsphere-datastore-cluster",
Usage: "vSphere datastore cluster for virtual machine",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_DATACENTER",
Name: "vmwarevsphere-datacenter",
Usage: "vSphere datacenter for virtual machine",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_FOLDER",
Name: "vmwarevsphere-folder",
Usage: "vSphere folder for the docker VM. This folder must already exist in the datacenter",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_POOL",
Name: "vmwarevsphere-pool",
Usage: "vSphere resource pool for docker VM",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_HOSTSYSTEM",
Name: "vmwarevsphere-hostsystem",
Usage: "vSphere compute resource where the docker VM will be instantiated. This can be omitted if using a cluster with DRS",
},
mcnflag.StringSliceFlag{
EnvVar: "VSPHERE_CFGPARAM",
Name: "vmwarevsphere-cfgparam",
Usage: "vSphere vm configuration parameters (used for guestinfo)",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_CLOUDINIT",
Name: "vmwarevsphere-cloudinit",
Usage: "vSphere cloud-init filepath or url to add to guestinfo, filepath will be read and base64 encoded before adding",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_CLOUD_CONFIG",
Name: "vmwarevsphere-cloud-config",
Usage: "Filepath to a cloud-config yaml file to put into the ISO user-data",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_VAPP_IPPROTOCOL",
Name: "vmwarevsphere-vapp-ipprotocol",
Usage: "vSphere vApp IP protocol for this deployment. Supported values are: IPv4 and IPv6",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_VAPP_IPALLOCATIONPOLICY",
Name: "vmwarevsphere-vapp-ipallocationpolicy",
Usage: "vSphere vApp IP allocation policy. Supported values are: dhcp, fixed, transient and fixedAllocated",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_VAPP_TRANSPORT",
Name: "vmwarevsphere-vapp-transport",
Usage: "vSphere OVF environment transports to use for properties. Supported values are: iso and com.vmware.guestInfo",
},
mcnflag.StringSliceFlag{
EnvVar: "VSPHERE_VAPP_PROPERTY",
Name: "vmwarevsphere-vapp-property",
Usage: "vSphere vApp properties",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_CREATION_TYPE",
Name: "vmwarevsphere-creation-type",
Usage: "Creation type when creating a new virtual machine. Supported values: vm, template, library, legacy",
Value: defaultCreationType,
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_CLONE_FROM",
Name: "vmwarevsphere-clone-from",
Usage: "If you choose creation type clone a name of what you want to clone is required",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_CONTENT_LIBRARY",
Name: "vmwarevsphere-content-library",
Usage: "If you choose to clone from a content library template specify the name of the library",
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_SSH_USER",
Name: "vmwarevsphere-ssh-user",
Usage: "If using a non-B2D image you can specify the ssh user",
Value: defaultSSHUser,
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_SSH_PASSWORD",
Name: "vmwarevsphere-ssh-password",
Usage: "If using a non-B2D image you can specify the ssh password",
Value: defaultSSHPass,
},
mcnflag.IntFlag{
EnvVar: "VSPHERE_SSH_PORT",
Name: "vmwarevsphere-ssh-port",
Usage: "If using a non-B2D image you can specify the ssh port",
Value: drivers.DefaultSSHPort,
},
mcnflag.StringFlag{
EnvVar: "VSPHERE_SSH_USER_GROUP",
Name: "vmwarevsphere-ssh-user-group",
Usage: "If using a non-B2D image the uploaded keys will need chown'ed, defaults to staff e.g. docker:staff",
Value: defaultSSHUserGroup,
},
mcnflag.StringSliceFlag{
EnvVar: "",
Name: "vmwarevsphere-tag",
Usage: "vSphere tag id e.g. urn:xxx",
},
mcnflag.StringSliceFlag{
EnvVar: "",
Name: "vmwarevsphere-custom-attribute",
Usage: "vSphere custom attribute, format key/value e.g. '200=my custom value'",
},
}
}
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SSHUser = flags.String("vmwarevsphere-ssh-user")
d.SSHPassword = flags.String("vmwarevsphere-ssh-password")
d.SSHPort = flags.Int("vmwarevsphere-ssh-port")
d.SSHUserGroup = flags.String("vmwarevsphere-ssh-user-group")
d.CPU = flags.Int("vmwarevsphere-cpu-count")
d.Memory = flags.Int("vmwarevsphere-memory-size")
d.DiskSize = flags.Int("vmwarevsphere-disk-size")
d.Boot2DockerURL = flags.String("vmwarevsphere-boot2docker-url")
d.IP = flags.String("vmwarevsphere-vcenter")
d.Port = flags.Int("vmwarevsphere-vcenter-port")
d.Username = flags.String("vmwarevsphere-username")
d.Password = flags.String("vmwarevsphere-password")
d.Networks = flags.StringSlice("vmwarevsphere-network")
d.Tags = flags.StringSlice("vmwarevsphere-tag")
d.CustomAttributes = flags.StringSlice("vmwarevsphere-custom-attribute")
d.Datastore = flags.String("vmwarevsphere-datastore")
d.DatastoreCluster = flags.String("vmwarevsphere-datastore-cluster")
d.Datacenter = flags.String("vmwarevsphere-datacenter")
// Sanitize input on ingress.
d.Folder = strings.Trim(flags.String("vmwarevsphere-folder"), "/")
d.Pool = flags.String("vmwarevsphere-pool")
d.HostSystem = flags.String("vmwarevsphere-hostsystem")
d.CfgParams = flags.StringSlice("vmwarevsphere-cfgparam")
d.CloudInit = flags.String("vmwarevsphere-cloudinit")
d.CloudConfig = flags.String("vmwarevsphere-cloud-config")
if d.CloudConfig != "" {
if _, err := os.Stat(d.CloudConfig); err != nil {
return err
}
ud, err := ioutil.ReadFile(d.CloudConfig)
if err != nil {
return err
}
d.CloudConfig = string(ud)
}
d.VAppIpProtocol = flags.String("vmwarevsphere-vapp-ipprotocol")
d.VAppIpAllocationPolicy = flags.String("vmwarevsphere-vapp-ipallocationpolicy")
d.VAppTransport = flags.String("vmwarevsphere-vapp-transport")
d.VAppProperties = flags.StringSlice("vmwarevsphere-vapp-property")
d.SetSwarmConfigFromFlags(flags)
d.ISO = d.ResolveStorePath(isoFilename)
d.CreationType = flags.String("vmwarevsphere-creation-type")
if _, ok := creationTypes[d.CreationType]; !ok {
return fmt.Errorf("Creation type %s not supported", d.CreationType)
}
d.ContentLibrary = flags.String("vmwarevsphere-content-library")
if d.CreationType != "legacy" {
d.CloneFrom = flags.String("vmwarevsphere-clone-from")
if d.CloneFrom == "" {
return fmt.Errorf("creation type clone needs a VM name to clone from, use --vmwarevsphere-clone-from")
}
}
return nil
}
type AuthFlag struct {
auth types.NamePasswordAuthentication
}
func NewAuthFlag(u, p string) *AuthFlag {
return &AuthFlag{
auth: types.NamePasswordAuthentication{
Username: u,
Password: p,
},
}
}
func (f *AuthFlag) Auth() types.BaseGuestAuthentication {
return &f.auth
}
type FileAttrFlag struct {
types.GuestPosixFileAttributes
}
func (f *FileAttrFlag) SetPerms(owner, group, perms int) {
owner32 := int32(owner)
group32 := int32(group)
f.OwnerId = &owner32
f.GroupId = &group32
f.Permissions = int64(perms)
}
func (f *FileAttrFlag) Attr() types.BaseGuestFileAttributes {
return &f.GuestPosixFileAttributes
}