|
| 1 | +/* |
| 2 | +Copyright 2017 The Kubernetes Authors All rights reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +/* |
| 18 | + * Copyright 2017 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. |
| 19 | + */ |
| 20 | + |
| 21 | +package vmware |
| 22 | + |
| 23 | +import ( |
| 24 | + "github.com/docker/machine/libmachine/drivers" |
| 25 | + "github.com/docker/machine/libmachine/mcnflag" |
| 26 | +) |
| 27 | + |
| 28 | +const ( |
| 29 | + defaultSSHUser = "docker" |
| 30 | + defaultSSHPass = "tcuser" |
| 31 | + defaultDiskSize = 20000 |
| 32 | + defaultCPU = 1 |
| 33 | + defaultMemory = 1024 |
| 34 | + defaultWaitIP = 30000 |
| 35 | + defaultNetworkType = "nat" |
| 36 | +) |
| 37 | + |
| 38 | +// Config specifies the configuration of driver VMware |
| 39 | +type Config struct { |
| 40 | + *drivers.BaseDriver |
| 41 | + |
| 42 | + Memory int |
| 43 | + DiskSize int |
| 44 | + CPU int |
| 45 | + ISO string |
| 46 | + Boot2DockerURL string |
| 47 | + |
| 48 | + SSHPassword string |
| 49 | + ConfigDriveISO string |
| 50 | + ConfigDriveURL string |
| 51 | + NoShare bool |
| 52 | + |
| 53 | + WaitIP int |
| 54 | + NetworkType string |
| 55 | +} |
| 56 | + |
| 57 | +// NewConfig creates a new Config |
| 58 | +func NewConfig(hostname, storePath string) *Config { |
| 59 | + return &Config{ |
| 60 | + CPU: defaultCPU, |
| 61 | + Memory: defaultMemory, |
| 62 | + DiskSize: defaultDiskSize, |
| 63 | + SSHPassword: defaultSSHPass, |
| 64 | + WaitIP: defaultWaitIP, |
| 65 | + NetworkType: defaultNetworkType, |
| 66 | + BaseDriver: &drivers.BaseDriver{ |
| 67 | + SSHUser: defaultSSHUser, |
| 68 | + MachineName: hostname, |
| 69 | + StorePath: storePath, |
| 70 | + }, |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +// GetCreateFlags registers the flags this driver adds to |
| 75 | +// "docker hosts create" |
| 76 | +func (c *Config) GetCreateFlags() []mcnflag.Flag { |
| 77 | + return []mcnflag.Flag{ |
| 78 | + mcnflag.StringFlag{ |
| 79 | + EnvVar: "VMWARE_BOOT2DOCKER_URL", |
| 80 | + Name: "vmware-boot2docker-url", |
| 81 | + Usage: "URL for boot2docker image", |
| 82 | + Value: "", |
| 83 | + }, |
| 84 | + mcnflag.StringFlag{ |
| 85 | + EnvVar: "VMWARE_CONFIGDRIVE_URL", |
| 86 | + Name: "vmware-configdrive-url", |
| 87 | + Usage: "URL for cloud-init configdrive", |
| 88 | + Value: "", |
| 89 | + }, |
| 90 | + mcnflag.IntFlag{ |
| 91 | + EnvVar: "VMWARE_CPU_COUNT", |
| 92 | + Name: "vmware-cpu-count", |
| 93 | + Usage: "number of CPUs for the machine (-1 to use the number of CPUs available)", |
| 94 | + Value: defaultCPU, |
| 95 | + }, |
| 96 | + mcnflag.IntFlag{ |
| 97 | + EnvVar: "VMWARE_MEMORY_SIZE", |
| 98 | + Name: "vmware-memory-size", |
| 99 | + Usage: "size of memory for host VM (in MB)", |
| 100 | + Value: defaultMemory, |
| 101 | + }, |
| 102 | + mcnflag.IntFlag{ |
| 103 | + EnvVar: "VMWARE_DISK_SIZE", |
| 104 | + Name: "vmware-disk-size", |
| 105 | + Usage: "size of disk for host VM (in MB)", |
| 106 | + Value: defaultDiskSize, |
| 107 | + }, |
| 108 | + mcnflag.StringFlag{ |
| 109 | + EnvVar: "VMWARE_SSH_USER", |
| 110 | + Name: "vmware-ssh-user", |
| 111 | + Usage: "SSH user", |
| 112 | + Value: defaultSSHUser, |
| 113 | + }, |
| 114 | + mcnflag.StringFlag{ |
| 115 | + EnvVar: "VMWARE_SSH_PASSWORD", |
| 116 | + Name: "vmware-ssh-password", |
| 117 | + Usage: "SSH password", |
| 118 | + Value: defaultSSHPass, |
| 119 | + }, |
| 120 | + mcnflag.BoolFlag{ |
| 121 | + EnvVar: "VMWARE_NO_SHARE", |
| 122 | + Name: "vmware-no-share", |
| 123 | + Usage: "Disable the mount of your home directory", |
| 124 | + }, |
| 125 | + mcnflag.IntFlag{ |
| 126 | + EnvVar: "VMWARE_WAIT_IP", |
| 127 | + Name: "vmware-wait-ip", |
| 128 | + Usage: "time to wait for vmrun to get an ip (in milliseconds)", |
| 129 | + Value: defaultWaitIP, |
| 130 | + }, |
| 131 | + mcnflag.StringFlag{ |
| 132 | + EnvVar: "VMWARE_NETWORK_TYPE", |
| 133 | + Name: "vmware-network-type", |
| 134 | + Usage: "Network connection type to use (e.g. 'nat', 'bridged', 'hostonly')", |
| 135 | + Value: defaultNetworkType, |
| 136 | + }, |
| 137 | + } |
| 138 | +} |
0 commit comments