knife-vsphere 2.1.1 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/chef/knife/base_vsphere_command.rb +69 -70
- data/lib/chef/knife/customization_helper.rb +4 -4
- data/lib/chef/knife/search_helper.rb +16 -7
- data/lib/chef/knife/vsphere_cluster_list.rb +8 -8
- data/lib/chef/knife/vsphere_cpu_ratio.rb +4 -4
- data/lib/chef/knife/vsphere_customization_list.rb +3 -3
- data/lib/chef/knife/vsphere_datastore_file.rb +17 -17
- data/lib/chef/knife/vsphere_datastore_list.rb +11 -11
- data/lib/chef/knife/vsphere_datastore_maxfree.rb +14 -14
- data/lib/chef/knife/vsphere_datastorecluster_list.rb +7 -7
- data/lib/chef/knife/vsphere_datastorecluster_maxfree.rb +10 -10
- data/lib/chef/knife/vsphere_folder_list.rb +4 -4
- data/lib/chef/knife/vsphere_hosts_list.rb +10 -10
- data/lib/chef/knife/vsphere_pool_list.rb +5 -5
- data/lib/chef/knife/vsphere_pool_query.rb +7 -7
- data/lib/chef/knife/vsphere_pool_show.rb +8 -8
- data/lib/chef/knife/vsphere_template_list.rb +7 -7
- data/lib/chef/knife/vsphere_vlan_create.rb +8 -8
- data/lib/chef/knife/vsphere_vlan_list.rb +3 -3
- data/lib/chef/knife/vsphere_vm_cdrom.rb +27 -27
- data/lib/chef/knife/vsphere_vm_clone.rb +224 -214
- data/lib/chef/knife/vsphere_vm_config.rb +6 -6
- data/lib/chef/knife/vsphere_vm_delete.rb +17 -17
- data/lib/chef/knife/vsphere_vm_disk_extend.rb +11 -11
- data/lib/chef/knife/vsphere_vm_disk_list.rb +6 -6
- data/lib/chef/knife/vsphere_vm_execute.rb +14 -14
- data/lib/chef/knife/vsphere_vm_find.rb +87 -87
- data/lib/chef/knife/vsphere_vm_list.rb +12 -12
- data/lib/chef/knife/vsphere_vm_markastemplate.rb +5 -5
- data/lib/chef/knife/vsphere_vm_migrate.rb +20 -25
- data/lib/chef/knife/vsphere_vm_move.rb +17 -17
- data/lib/chef/knife/vsphere_vm_net.rb +8 -8
- data/lib/chef/knife/vsphere_vm_network_add.rb +22 -24
- data/lib/chef/knife/vsphere_vm_network_delete.rb +8 -8
- data/lib/chef/knife/vsphere_vm_network_list.rb +5 -5
- data/lib/chef/knife/vsphere_vm_network_set.rb +10 -10
- data/lib/chef/knife/vsphere_vm_property_get.rb +7 -7
- data/lib/chef/knife/vsphere_vm_property_set.rb +16 -16
- data/lib/chef/knife/vsphere_vm_show.rb +8 -8
- data/lib/chef/knife/vsphere_vm_snapshot.rb +35 -35
- data/lib/chef/knife/vsphere_vm_state.rb +31 -31
- data/lib/chef/knife/vsphere_vm_toolsconfig.rb +11 -11
- data/lib/chef/knife/vsphere_vm_vmdk_add.rb +32 -32
- data/lib/chef/knife/vsphere_vm_vnc_set.rb +15 -15
- data/lib/chef/knife/vsphere_vm_wait_sysprep.rb +10 -11
- data/lib/knife-vsphere/version.rb +1 -1
- metadata +5 -89
@@ -3,15 +3,15 @@
|
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
6
|
+
require "chef/knife"
|
7
|
+
require "chef/knife/base_vsphere_command"
|
8
|
+
require "chef/knife/search_helper"
|
9
9
|
|
10
10
|
# Lists all known VM templates in the configured datacenter
|
11
11
|
# VsphereTemplatelist extends the BaseVspherecommand
|
12
12
|
class Chef::Knife::VsphereTemplateList < Chef::Knife::BaseVsphereCommand
|
13
13
|
include SearchHelper
|
14
|
-
banner
|
14
|
+
banner "knife vsphere template list"
|
15
15
|
|
16
16
|
common_options
|
17
17
|
|
@@ -25,11 +25,11 @@ class Chef::Knife::VsphereTemplateList < Chef::Knife::BaseVsphereCommand
|
|
25
25
|
|
26
26
|
vms = get_all_vm_objects(
|
27
27
|
folder: get_config(:folder),
|
28
|
-
properties: [
|
29
|
-
).select { |vm| vm[
|
28
|
+
properties: ["name", "config.template"]
|
29
|
+
).select { |vm| vm["config.template"] == true }
|
30
30
|
|
31
31
|
vm_list = vms.map do |vm|
|
32
|
-
{
|
32
|
+
{ "Template Name" => vm["name"] }
|
33
33
|
end
|
34
34
|
|
35
35
|
ui.output(vm_list)
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "chef/knife"
|
2
|
+
require "chef/knife/base_vsphere_command"
|
3
3
|
|
4
4
|
# Lists all known data stores in datacenter with sizes
|
5
5
|
# VsphereVlanCreate extends BaseVspherecommand
|
6
6
|
class Chef::Knife::VsphereVlanCreate < Chef::Knife::BaseVsphereCommand
|
7
|
-
banner
|
7
|
+
banner "knife vsphere vlan create NAME VID"
|
8
8
|
|
9
9
|
common_options
|
10
10
|
|
11
11
|
option :switch,
|
12
|
-
long:
|
13
|
-
description:
|
12
|
+
long: "--switch DVSNAME",
|
13
|
+
description: "The DVSwitch that will hold this VLAN"
|
14
14
|
|
15
15
|
# The main run method for vlan_create
|
16
16
|
#
|
@@ -24,11 +24,11 @@ class Chef::Knife::VsphereVlanCreate < Chef::Knife::BaseVsphereCommand
|
|
24
24
|
switch = if config[:switch]
|
25
25
|
switches.find { |s| s.name == config[:switch] }
|
26
26
|
else
|
27
|
-
ui.warn
|
27
|
+
ui.warn "Multiple switches found. Choosing the first switch. Use --switch to select a switch." if switches.count > 1
|
28
28
|
switches.first
|
29
29
|
end
|
30
30
|
|
31
|
-
fatal_exit
|
31
|
+
fatal_exit "No switches found." if switch.nil?
|
32
32
|
|
33
33
|
ui.info "Found #{switch.name}" if log_verbose?
|
34
34
|
switch.AddDVPortgroup_Task(spec: [add_port_spec(@name_args[0], @name_args[1])])
|
@@ -46,7 +46,7 @@ class Chef::Knife::VsphereVlanCreate < Chef::Knife::BaseVsphereCommand
|
|
46
46
|
),
|
47
47
|
name: name,
|
48
48
|
numPorts: 128,
|
49
|
-
type:
|
49
|
+
type: "earlyBinding"
|
50
50
|
)
|
51
51
|
pp spec if log_verbose?
|
52
52
|
spec
|
@@ -14,13 +14,13 @@
|
|
14
14
|
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
15
15
|
# PERFORMANCE OF THIS SOFTWARE
|
16
16
|
|
17
|
-
require
|
18
|
-
require
|
17
|
+
require "chef/knife"
|
18
|
+
require "chef/knife/base_vsphere_command"
|
19
19
|
|
20
20
|
# Lists all known data stores in datacenter with sizes
|
21
21
|
# VsphereVlanlist extends the BaseVspherecommand
|
22
22
|
class Chef::Knife::VsphereVlanList < Chef::Knife::BaseVsphereCommand
|
23
|
-
banner
|
23
|
+
banner "knife vsphere vlan list"
|
24
24
|
|
25
25
|
common_options
|
26
26
|
|
@@ -1,50 +1,50 @@
|
|
1
1
|
# License:: Apache License, Version 2.0
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "chef/knife"
|
4
|
+
require "chef/knife/base_vsphere_command"
|
5
|
+
require "chef/knife/search_helper"
|
6
6
|
|
7
7
|
# VsphereVmCdrom extends the BaseVspherecommand
|
8
8
|
class Chef::Knife::VsphereVmCdrom < Chef::Knife::BaseVsphereCommand
|
9
9
|
include SearchHelper
|
10
|
-
banner
|
10
|
+
banner "knife vsphere vm cdrom VMNAME (options)"
|
11
11
|
|
12
12
|
# The empty device name.
|
13
|
-
EMPTY_DEVICE_NAME =
|
13
|
+
EMPTY_DEVICE_NAME = "".freeze
|
14
14
|
|
15
15
|
common_options
|
16
16
|
|
17
17
|
option :datastore,
|
18
|
-
long:
|
19
|
-
description:
|
18
|
+
long: "--datastore STORE",
|
19
|
+
description: "The datastore for an iso source"
|
20
20
|
|
21
21
|
option :iso,
|
22
|
-
long:
|
23
|
-
description:
|
22
|
+
long: "--iso ISO",
|
23
|
+
description: "The name and path of the ISO to attach"
|
24
24
|
|
25
25
|
option :attach,
|
26
|
-
short:
|
27
|
-
long:
|
28
|
-
description:
|
26
|
+
short: "-a",
|
27
|
+
long: "--attach",
|
28
|
+
description: "Attach the virtual cdrom to the VM",
|
29
29
|
boolean: true
|
30
30
|
|
31
31
|
option :disconnect,
|
32
|
-
long:
|
33
|
-
description:
|
32
|
+
long: "--disconnect",
|
33
|
+
description: "Disconnect the virtual cdrom from the VM",
|
34
34
|
boolean: true
|
35
35
|
|
36
36
|
option :on_boot,
|
37
|
-
long:
|
38
|
-
description:
|
37
|
+
long: "--on_boot ONBOOT",
|
38
|
+
description: "False for Detached on boot or True for Attached on boot"
|
39
39
|
|
40
40
|
option :client_device,
|
41
|
-
long:
|
42
|
-
description:
|
41
|
+
long: "--client_device",
|
42
|
+
description: "Set the backing store to client-device"
|
43
43
|
|
44
44
|
option :recursive,
|
45
|
-
short:
|
46
|
-
long:
|
47
|
-
description:
|
45
|
+
short: "-r",
|
46
|
+
long: "--recursive",
|
47
|
+
description: "Search all folders"
|
48
48
|
|
49
49
|
# The main run method for vm_cdrom
|
50
50
|
#
|
@@ -54,20 +54,20 @@ class Chef::Knife::VsphereVmCdrom < Chef::Knife::BaseVsphereCommand
|
|
54
54
|
vmname = @name_args[0]
|
55
55
|
if vmname.nil?
|
56
56
|
show_usage
|
57
|
-
fatal_exit(
|
57
|
+
fatal_exit("You must specify a virtual machine name")
|
58
58
|
end
|
59
59
|
|
60
60
|
unless get_config(:attach) ^ get_config(:disconnect)
|
61
|
-
fatal_exit(
|
61
|
+
fatal_exit("You must specify one of --attach or --disconnect")
|
62
62
|
end
|
63
63
|
|
64
|
-
fatal_exit
|
65
|
-
fatal_exit
|
64
|
+
fatal_exit "You must specify the name and path of an ISO with --iso" if get_config(:attach) && !get_config(:iso)
|
65
|
+
fatal_exit "You must specify the datastore containing the ISO with --datastore" if get_config(:attach) && !get_config(:datastore)
|
66
66
|
|
67
67
|
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
68
68
|
|
69
69
|
cdrom_obj = vm.config.hardware.device.find { |hw| hw.class == RbVmomi::VIM::VirtualCdrom }
|
70
|
-
fatal_exit
|
70
|
+
fatal_exit "Could not find a cd drive" unless cdrom_obj
|
71
71
|
|
72
72
|
backing = if get_config(:attach)
|
73
73
|
RbVmomi::VIM::VirtualCdromIsoBackingInfo(
|
@@ -97,7 +97,7 @@ class Chef::Knife::VsphereVmCdrom < Chef::Knife::BaseVsphereCommand
|
|
97
97
|
connected: get_config(:attach) || false,
|
98
98
|
allowGuestControl: true
|
99
99
|
)
|
100
|
-
)
|
100
|
+
),
|
101
101
|
}]
|
102
102
|
)
|
103
103
|
end
|
@@ -6,225 +6,225 @@
|
|
6
6
|
# License:: Apache License, Version 2.0
|
7
7
|
#
|
8
8
|
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
9
|
+
require "chef/knife"
|
10
|
+
require "chef/knife/base_vsphere_command"
|
11
|
+
require "chef/knife/customization_helper"
|
12
|
+
require "chef/knife/search_helper"
|
13
|
+
require "chef/knife/winrm_base"
|
14
|
+
require "ipaddr"
|
15
|
+
require "netaddr"
|
16
|
+
require "securerandom"
|
17
17
|
|
18
18
|
# VsphereVmClone extends the BaseVspherecommand
|
19
19
|
class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
20
|
-
banner
|
20
|
+
banner "knife vsphere vm clone VMNAME (options)"
|
21
21
|
|
22
22
|
# A AUTO_MAC for NIC?
|
23
|
-
AUTO_MAC =
|
23
|
+
AUTO_MAC = "auto".freeze
|
24
24
|
# A NO IP for you to use!
|
25
|
-
NO_IPS =
|
25
|
+
NO_IPS = "".freeze
|
26
26
|
# a linklayer origin is an actual nic
|
27
|
-
ORIGIN_IS_REAL_NIC =
|
27
|
+
ORIGIN_IS_REAL_NIC = "linklayer".freeze
|
28
28
|
|
29
29
|
include Chef::Knife::WinrmBase
|
30
30
|
include CustomizationHelper
|
31
31
|
include SearchHelper
|
32
32
|
deps do
|
33
|
-
require
|
34
|
-
require
|
33
|
+
require "chef/json_compat"
|
34
|
+
require "chef/knife/bootstrap"
|
35
35
|
Chef::Knife::Bootstrap.load_deps
|
36
36
|
end
|
37
37
|
|
38
38
|
common_options
|
39
39
|
|
40
40
|
option :dest_folder,
|
41
|
-
long:
|
42
|
-
description:
|
41
|
+
long: "--dest-folder FOLDER",
|
42
|
+
description: "The folder into which to put the cloned VM"
|
43
43
|
|
44
44
|
option :datastore,
|
45
|
-
long:
|
46
|
-
description:
|
45
|
+
long: "--datastore STORE",
|
46
|
+
description: "The datastore into which to put the cloned VM"
|
47
47
|
|
48
48
|
option :datastorecluster,
|
49
|
-
long:
|
50
|
-
description:
|
49
|
+
long: "--datastorecluster STORE",
|
50
|
+
description: "The datastorecluster into which to put the cloned VM"
|
51
51
|
|
52
52
|
option :host,
|
53
|
-
long:
|
54
|
-
description:
|
53
|
+
long: "--host HOST",
|
54
|
+
description: "The host into which to put the cloned VM"
|
55
55
|
|
56
56
|
option :resource_pool,
|
57
|
-
long:
|
58
|
-
description:
|
57
|
+
long: "--resource-pool POOL",
|
58
|
+
description: "The resource pool or cluster into which to put the cloned VM"
|
59
59
|
|
60
60
|
option :source_vm,
|
61
|
-
long:
|
62
|
-
description:
|
61
|
+
long: "--template TEMPLATE",
|
62
|
+
description: "The source VM / Template to clone from"
|
63
63
|
|
64
64
|
option :linked_clone,
|
65
|
-
long:
|
66
|
-
description:
|
65
|
+
long: "--linked-clone",
|
66
|
+
description: "Indicates whether to use linked clones.",
|
67
67
|
boolean: false
|
68
68
|
|
69
69
|
option :thin_provision,
|
70
|
-
long:
|
71
|
-
description:
|
70
|
+
long: "--thin-provision",
|
71
|
+
description: "Indicates whether disk should be thin provisioned.",
|
72
72
|
boolean: true
|
73
73
|
|
74
74
|
option :annotation,
|
75
|
-
long:
|
76
|
-
description:
|
75
|
+
long: "--annotation TEXT",
|
76
|
+
description: "Add TEXT in Notes field from annotation"
|
77
77
|
|
78
78
|
option :customization_spec,
|
79
|
-
long:
|
80
|
-
description:
|
79
|
+
long: "--cspec CUST_SPEC",
|
80
|
+
description: "The name of any customization specification to apply"
|
81
81
|
|
82
82
|
option :customization_plugin,
|
83
|
-
long:
|
84
|
-
description:
|
83
|
+
long: "--cplugin CUST_PLUGIN_PATH",
|
84
|
+
description: "Path to plugin that implements KnifeVspherePlugin.customize_clone_spec and/or KnifeVspherePlugin.reconfig_vm"
|
85
85
|
|
86
86
|
option :customization_plugin_data,
|
87
|
-
long:
|
88
|
-
description:
|
87
|
+
long: "--cplugin-data CUST_PLUGIN_DATA",
|
88
|
+
description: "String of data to pass to the plugin. Use any format you wish."
|
89
89
|
|
90
90
|
option :customization_vlan,
|
91
|
-
long:
|
92
|
-
description:
|
91
|
+
long: "--cvlan CUST_VLANS",
|
92
|
+
description: "Comma-delimited list of VLAN names for network adapters to join"
|
93
93
|
|
94
94
|
option :customization_sw_uuid,
|
95
|
-
long:
|
95
|
+
long: "--sw-uuid SWITCH_UUIDS",
|
96
96
|
description: "Comma-delimited list of distributed virtual switch UUIDs for network adapter to connect, use 'auto' to automatically assign"
|
97
97
|
|
98
98
|
option :customization_macs,
|
99
|
-
long:
|
100
|
-
description:
|
99
|
+
long: "--cmacs CUST_MACS",
|
100
|
+
description: "Comma-delimited list of MAC addresses for network adapters",
|
101
101
|
default: AUTO_MAC
|
102
102
|
|
103
103
|
option :customization_ips,
|
104
|
-
long:
|
105
|
-
description:
|
104
|
+
long: "--cips CUST_IPS",
|
105
|
+
description: "Comma-delimited list of CIDR IPs for customization",
|
106
106
|
default: NO_IPS
|
107
107
|
|
108
108
|
option :customization_dns_ips,
|
109
|
-
long:
|
110
|
-
description:
|
109
|
+
long: "--cdnsips CUST_DNS_IPS",
|
110
|
+
description: "Comma-delimited list of DNS IP addresses"
|
111
111
|
|
112
112
|
option :customization_dns_suffixes,
|
113
|
-
long:
|
114
|
-
description:
|
113
|
+
long: "--cdnssuffix CUST_DNS_SUFFIXES",
|
114
|
+
description: "Comma-delimited list of DNS search suffixes"
|
115
115
|
|
116
116
|
option :customization_gw,
|
117
|
-
long:
|
118
|
-
description:
|
117
|
+
long: "--cgw CUST_GW",
|
118
|
+
description: "CIDR IP of gateway for customization"
|
119
119
|
|
120
120
|
option :customization_hostname,
|
121
|
-
long:
|
122
|
-
description:
|
121
|
+
long: "--chostname CUST_HOSTNAME",
|
122
|
+
description: "Unqualified hostname for customization"
|
123
123
|
|
124
124
|
option :customization_domain,
|
125
|
-
long:
|
126
|
-
description:
|
125
|
+
long: "--cdomain CUST_DOMAIN",
|
126
|
+
description: "Domain name for customization"
|
127
127
|
|
128
128
|
option :customization_tz,
|
129
|
-
long:
|
129
|
+
long: "--ctz CUST_TIMEZONE",
|
130
130
|
description: "Timezone invalid 'Area/Location' format"
|
131
131
|
|
132
132
|
option :customization_cpucount,
|
133
|
-
long:
|
134
|
-
description:
|
133
|
+
long: "--ccpu CUST_CPU_COUNT",
|
134
|
+
description: "Number of CPUs"
|
135
135
|
|
136
136
|
option :customization_corespersocket,
|
137
|
-
long:
|
138
|
-
description:
|
137
|
+
long: "--ccorespersocket CUST_CPU_CORES_PER_SOCKET",
|
138
|
+
description: "Number of CPU Cores per Socket"
|
139
139
|
|
140
140
|
option :customization_memory,
|
141
|
-
long:
|
142
|
-
description:
|
141
|
+
long: "--cram CUST_MEMORY_GB",
|
142
|
+
description: "Gigabytes of RAM"
|
143
143
|
|
144
144
|
option :customization_memory_reservation,
|
145
|
-
long:
|
146
|
-
description:
|
145
|
+
long: "--cram_reservation CUST_MEMORY_RESERVATION_GB",
|
146
|
+
description: "Gigabytes of RAM"
|
147
147
|
|
148
148
|
option :power,
|
149
|
-
long:
|
150
|
-
description:
|
149
|
+
long: "--start",
|
150
|
+
description: "Indicates whether to start the VM after a successful clone",
|
151
151
|
boolean: false
|
152
152
|
|
153
153
|
option :bootstrap,
|
154
|
-
long:
|
155
|
-
description:
|
154
|
+
long: "--bootstrap",
|
155
|
+
description: "Indicates whether to bootstrap the VM",
|
156
156
|
boolean: false
|
157
157
|
|
158
158
|
option :environment,
|
159
|
-
long:
|
160
|
-
description:
|
159
|
+
long: "--environment ENVIRONMENT",
|
160
|
+
description: "Environment to add the node to for bootstrapping"
|
161
161
|
|
162
162
|
option :fqdn,
|
163
|
-
long:
|
164
|
-
description:
|
163
|
+
long: "--fqdn SERVER_FQDN",
|
164
|
+
description: "Fully qualified hostname for bootstrapping"
|
165
165
|
|
166
166
|
option :bootstrap_msi_url,
|
167
|
-
long:
|
168
|
-
description:
|
167
|
+
long: "--bootstrap-msi-url URL",
|
168
|
+
description: "Location of the Chef Client MSI. The default templates will prefer to download from this location."
|
169
169
|
|
170
170
|
option :bootstrap_protocol,
|
171
|
-
long:
|
172
|
-
description:
|
171
|
+
long: "--bootstrap-protocol protocol",
|
172
|
+
description: "Protocol to bootstrap windows servers. options: winrm/ssh",
|
173
173
|
proc: proc { |key| Chef::Config[:knife][:bootstrap_protocol] = key },
|
174
174
|
default: nil
|
175
175
|
|
176
176
|
option :ssh_user,
|
177
|
-
short:
|
178
|
-
long:
|
179
|
-
description:
|
180
|
-
default:
|
177
|
+
short: "-x USERNAME",
|
178
|
+
long: "--ssh-user USERNAME",
|
179
|
+
description: "The ssh username",
|
180
|
+
default: "root"
|
181
181
|
|
182
182
|
option :ssh_password,
|
183
|
-
short:
|
184
|
-
long:
|
185
|
-
description:
|
183
|
+
short: "-P PASSWORD",
|
184
|
+
long: "--ssh-password PASSWORD",
|
185
|
+
description: "The ssh password"
|
186
186
|
|
187
187
|
option :ssh_port,
|
188
|
-
short:
|
189
|
-
long:
|
190
|
-
description:
|
191
|
-
default:
|
188
|
+
short: "-p PORT",
|
189
|
+
long: "--ssh-port PORT",
|
190
|
+
description: "The ssh port",
|
191
|
+
default: "22"
|
192
192
|
|
193
193
|
option :identity_file,
|
194
|
-
short:
|
195
|
-
long:
|
196
|
-
description:
|
194
|
+
short: "-i IDENTITY_FILE",
|
195
|
+
long: "--identity-file IDENTITY_FILE",
|
196
|
+
description: "The SSH identity file used for authentication"
|
197
197
|
|
198
198
|
option :chef_node_name,
|
199
|
-
short:
|
200
|
-
long:
|
201
|
-
description:
|
199
|
+
short: "-N NAME",
|
200
|
+
long: "--node-name NAME",
|
201
|
+
description: "The Chef node name for your new node"
|
202
202
|
|
203
203
|
option :prerelease,
|
204
|
-
long:
|
205
|
-
description:
|
204
|
+
long: "--prerelease",
|
205
|
+
description: "Install the pre-release chef gems",
|
206
206
|
boolean: false
|
207
207
|
|
208
208
|
option :bootstrap_version,
|
209
|
-
long:
|
210
|
-
description:
|
209
|
+
long: "--bootstrap-version VERSION",
|
210
|
+
description: "The version of Chef to install",
|
211
211
|
proc: proc { |v| Chef::Config[:knife][:bootstrap_version] = v }
|
212
212
|
|
213
213
|
option :bootstrap_proxy,
|
214
|
-
long:
|
215
|
-
description:
|
214
|
+
long: "--bootstrap-proxy PROXY_URL",
|
215
|
+
description: "The proxy server for the node being bootstrapped",
|
216
216
|
proc: proc { |p| Chef::Config[:knife][:bootstrap_proxy] = p }
|
217
217
|
|
218
218
|
option :bootstrap_vault_file,
|
219
|
-
long:
|
220
|
-
description:
|
219
|
+
long: "--bootstrap-vault-file VAULT_FILE",
|
220
|
+
description: "A JSON file with a list of vault(s) and item(s) to be updated"
|
221
221
|
|
222
222
|
option :bootstrap_vault_json,
|
223
|
-
long:
|
224
|
-
description:
|
223
|
+
long: "--bootstrap-vault-json VAULT_JSON",
|
224
|
+
description: "A JSON string with the vault(s) and item(s) to be updated"
|
225
225
|
|
226
226
|
option :bootstrap_vault_item,
|
227
|
-
long:
|
227
|
+
long: "--bootstrap-vault-item VAULT_ITEM",
|
228
228
|
description: 'A single vault and item to update as "vault:item"',
|
229
229
|
proc: proc { |i|
|
230
230
|
(vault, item) = i.split(/:/)
|
@@ -235,102 +235,113 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
235
235
|
}
|
236
236
|
|
237
237
|
option :distro,
|
238
|
-
short:
|
239
|
-
long:
|
240
|
-
description:
|
241
|
-
proc:
|
242
|
-
|
238
|
+
short: "-d DISTRO",
|
239
|
+
long: "--distro DISTRO",
|
240
|
+
description: "Bootstrap a distro using a template. [DEPRECATED] Use -t / --bootstrap-template option instead.",
|
241
|
+
proc: Proc.new { |v|
|
242
|
+
Chef::Log.fatal("[DEPRECATED] -d / --distro option is deprecated. Use --bootstrap-template option instead.")
|
243
|
+
v
|
244
|
+
}
|
243
245
|
|
244
246
|
option :tags,
|
245
|
-
long:
|
246
|
-
description:
|
247
|
+
long: "--tags TAGS",
|
248
|
+
description: "Comma separated list of tags to apply to the node",
|
247
249
|
proc: ->(tags) { tags.split(/[\s,]+/) },
|
248
250
|
default: []
|
249
251
|
|
252
|
+
option :bootstrap_template,
|
253
|
+
short: "-t TEMPLATE",
|
254
|
+
long: "--bootstrap-template TEMPLATE",
|
255
|
+
description: "Bootstrap Chef using a built-in or custom template. Set to the full path of an erb template or use one of the built-in templates."
|
256
|
+
|
250
257
|
option :template_file,
|
251
|
-
long:
|
252
|
-
description:
|
258
|
+
long: "--template-file TEMPLATE",
|
259
|
+
description: "Full path to location of template to use. [DEPRECATED] Use -t / --bootstrap-template option",
|
260
|
+
proc: Proc.new { |v|
|
261
|
+
Chef::Log.fatal("[DEPRECATED] --template-file option is deprecated. Use --bootstrap-template option instead.")
|
262
|
+
v
|
263
|
+
}
|
253
264
|
|
254
265
|
option :run_list,
|
255
|
-
short:
|
256
|
-
long:
|
257
|
-
description:
|
258
|
-
proc: ->
|
266
|
+
short: "-r RUN_LIST",
|
267
|
+
long: "--run-list RUN_LIST",
|
268
|
+
description: "Comma separated list of roles/recipes to apply",
|
269
|
+
proc: ->(o) { o.split(/[\s,]+/) },
|
259
270
|
default: []
|
260
271
|
|
261
272
|
option :secret_file,
|
262
|
-
long:
|
263
|
-
description:
|
273
|
+
long: "--secret-file SECRET_FILE",
|
274
|
+
description: "A file containing the secret key to use to encrypt data bag item values",
|
264
275
|
proc: ->(secret_file) { Chef::Config[:knife][:secret_file] = secret_file }
|
265
276
|
|
266
277
|
# rubocop:disable Style/Blocks
|
267
278
|
option :hint,
|
268
|
-
long:
|
269
|
-
description:
|
279
|
+
long: "--hint HINT_NAME[=HINT_FILE]",
|
280
|
+
description: "Specify Ohai Hint to be set on the bootstrap target. Use multiple --hint options to specify multiple hints.",
|
270
281
|
proc: proc { |h|
|
271
282
|
Chef::Config[:knife][:hints] ||= {}
|
272
|
-
name, path = h.split(
|
283
|
+
name, path = h.split("=")
|
273
284
|
Chef::Config[:knife][:hints][name] = path ? JSON.parse(::File.read(path)) : {}
|
274
285
|
},
|
275
|
-
default:
|
286
|
+
default: ""
|
276
287
|
# rubocop:enable Style/Blocks
|
277
288
|
|
278
289
|
option :no_host_key_verify,
|
279
|
-
long:
|
280
|
-
description:
|
290
|
+
long: "--no-host-key-verify",
|
291
|
+
description: "Disable host key verification",
|
281
292
|
boolean: true
|
282
293
|
|
283
294
|
option :node_ssl_verify_mode,
|
284
|
-
long:
|
285
|
-
description:
|
295
|
+
long: "--node-ssl-verify-mode [peer|none]",
|
296
|
+
description: "Whether or not to verify the SSL cert for all HTTPS requests when bootstrapping"
|
286
297
|
|
287
298
|
option :first_boot_attributes,
|
288
|
-
short:
|
289
|
-
long:
|
290
|
-
description:
|
299
|
+
short: "-j JSON_ATTRIBS",
|
300
|
+
long: "--json-attributes",
|
301
|
+
description: "A JSON string to be added to the first run of chef-client",
|
291
302
|
proc: ->(o) { JSON.parse(o) },
|
292
303
|
default: {}
|
293
304
|
|
294
305
|
option :disable_customization,
|
295
|
-
long:
|
296
|
-
description:
|
306
|
+
long: "--disable-customization",
|
307
|
+
description: "Disable default customization",
|
297
308
|
boolean: true,
|
298
309
|
default: false
|
299
310
|
|
300
311
|
option :log_level,
|
301
|
-
short:
|
302
|
-
long:
|
303
|
-
description:
|
312
|
+
short: "-l LEVEL",
|
313
|
+
long: "--log_level",
|
314
|
+
description: "Set the log level (debug, info, warn, error, fatal) for chef-client",
|
304
315
|
proc: ->(l) { l.to_sym }
|
305
316
|
|
306
317
|
option :mark_as_template,
|
307
|
-
long:
|
308
|
-
description:
|
318
|
+
long: "--mark_as_template",
|
319
|
+
description: "Indicates whether to mark the new vm as a template",
|
309
320
|
boolean: false
|
310
321
|
|
311
322
|
option :random_vmname,
|
312
|
-
long:
|
313
|
-
description:
|
323
|
+
long: "--random-vmname",
|
324
|
+
description: "Creates a random VMNAME starts with vm-XXXXXXXX",
|
314
325
|
boolean: false
|
315
326
|
|
316
327
|
option :random_vmname_prefix,
|
317
|
-
long:
|
318
|
-
description:
|
319
|
-
default:
|
328
|
+
long: "--random-vmname-prefix PREFIX",
|
329
|
+
description: "Change the VMNAME prefix",
|
330
|
+
default: "vm-"
|
320
331
|
|
321
332
|
option :sysprep_timeout,
|
322
|
-
long:
|
323
|
-
description:
|
333
|
+
long: "--sysprep_timeout TIMEOUT",
|
334
|
+
description: "Wait TIMEOUT seconds for sysprep event before continuing with bootstrap",
|
324
335
|
default: 600
|
325
336
|
|
326
337
|
option :bootstrap_nic,
|
327
|
-
long:
|
328
|
-
description:
|
338
|
+
long: "--bootstrap-nic INTEGER",
|
339
|
+
description: "Network interface to use when multiple NICs are defined on a template.",
|
329
340
|
default: 0
|
330
341
|
|
331
342
|
option :bootstrap_ipv4,
|
332
|
-
long:
|
333
|
-
description:
|
343
|
+
long: "--bootstrap-ipv4",
|
344
|
+
description: "Force using an IPv4 address when a NIC has both IPv4 and IPv6 addresses.",
|
334
345
|
default: false
|
335
346
|
|
336
347
|
def run
|
@@ -338,13 +349,13 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
338
349
|
|
339
350
|
unless using_supplied_hostname? ^ using_random_hostname?
|
340
351
|
show_usage
|
341
|
-
fatal_exit(
|
352
|
+
fatal_exit("You must specify a virtual machine name OR use --random-vmname")
|
342
353
|
end
|
343
354
|
|
344
|
-
abort
|
355
|
+
abort "--template or knife[:source_vm] must be specified" unless config[:source_vm]
|
345
356
|
|
346
357
|
if get_config(:datastore) && get_config(:datastorecluster)
|
347
|
-
abort
|
358
|
+
abort "Please select either datastore or datastorecluster"
|
348
359
|
end
|
349
360
|
|
350
361
|
if get_config(:customization_macs) != AUTO_MAC && get_config(:customization_ips) == NO_IPS
|
@@ -358,7 +369,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
358
369
|
|
359
370
|
dc = datacenter
|
360
371
|
|
361
|
-
src_vm = get_vm_by_name(get_config(:source_vm), get_config(:folder)) || fatal_exit("Could not find template #{
|
372
|
+
src_vm = get_vm_by_name(get_config(:source_vm), get_config(:folder)) || fatal_exit("Could not find template #{get_config(:source_vm)}")
|
362
373
|
|
363
374
|
create_delta_disk(src_vm) if get_config(:linked_clone)
|
364
375
|
|
@@ -380,7 +391,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
380
391
|
if fault.class == RbVmomi::VIM::NicSettingMismatch
|
381
392
|
abort "There is a mismatch in the number of NICs on the template (#{fault.numberOfNicsInVM}) and what you've passed on the command line with --cips (#{fault.numberOfNicsInSpec}). The VM has been cloned but not customized."
|
382
393
|
elsif fault.class == RbVmomi::VIM::DuplicateName
|
383
|
-
ui.info
|
394
|
+
ui.info "VM already exists, proceeding to bootstrap"
|
384
395
|
else
|
385
396
|
raise e
|
386
397
|
end
|
@@ -409,14 +420,12 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
409
420
|
connect_port = get_config(:ssh_port)
|
410
421
|
protocol = get_config(:bootstrap_protocol)
|
411
422
|
if windows?(src_vm.config)
|
412
|
-
protocol ||=
|
413
|
-
# Set distro to windows-chef-client-msi
|
414
|
-
config[:distro] = 'windows-chef-client-msi' if config[:distro].nil? || config[:distro] == 'chef-full'
|
423
|
+
protocol ||= "winrm"
|
415
424
|
unless config[:disable_customization]
|
416
425
|
# Wait for customization to complete
|
417
|
-
puts
|
426
|
+
puts "Waiting for customization to complete..."
|
418
427
|
CustomizationHelper.wait_for_sysprep(vm, vim, Integer(get_config(:sysprep_timeout)), 10)
|
419
|
-
puts
|
428
|
+
puts "Customization Complete"
|
420
429
|
end
|
421
430
|
connect_host = guest_address(vm)
|
422
431
|
Chef::Log.debug("Connect Host for winrm Bootstrap: #{connect_host}")
|
@@ -426,7 +435,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
426
435
|
else
|
427
436
|
connect_host = guest_address(vm)
|
428
437
|
Chef::Log.debug("Connect Host for SSH Bootstrap: #{connect_host}")
|
429
|
-
protocol ||=
|
438
|
+
protocol ||= "ssh"
|
430
439
|
wait_for_access(connect_host, connect_port, protocol)
|
431
440
|
ssh_override_winrm
|
432
441
|
bootstrap_for_node.run
|
@@ -434,7 +443,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
434
443
|
end
|
435
444
|
|
436
445
|
def ipv4_address(vm)
|
437
|
-
puts
|
446
|
+
puts "Waiting for a valid IPv4 address..."
|
438
447
|
# Multiple reboots occur during guest customization in which a link-local
|
439
448
|
# address is assigned. As such, we need to wait until a routable IP address
|
440
449
|
# becomes available. This is most commonly an issue with Windows instances.
|
@@ -448,7 +457,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
448
457
|
end
|
449
458
|
|
450
459
|
def guest_address(vm)
|
451
|
-
puts
|
460
|
+
puts "Waiting for network interfaces to become available..."
|
452
461
|
sleep 2 while vm.guest.net.empty? || !vm.guest.ipAddress
|
453
462
|
ui.info "Found address #{vm.guest.ipAddress}" if log_verbose?
|
454
463
|
config[:fqdn] = if config[:bootstrap_ipv4]
|
@@ -460,28 +469,28 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
460
469
|
# This is the closest thing to vm.guest.ipAddress but
|
461
470
|
# allows specifying a NIC.
|
462
471
|
vm.guest.net[bootstrap_nic_index].ipConfig.ipAddress.detect do |addr|
|
463
|
-
addr.origin !=
|
472
|
+
addr.origin != "linklayer"
|
464
473
|
end.ipAddress
|
465
474
|
end
|
466
475
|
end
|
467
476
|
|
468
477
|
def wait_for_access(connect_host, connect_port, protocol)
|
469
|
-
if protocol ==
|
478
|
+
if protocol == "winrm"
|
470
479
|
load_winrm_deps
|
471
|
-
if get_config(:winrm_transport) ==
|
472
|
-
config[:winrm_port] =
|
480
|
+
if get_config(:winrm_transport) == "ssl" && get_config(:winrm_port) == "5985"
|
481
|
+
config[:winrm_port] = "5986"
|
473
482
|
end
|
474
483
|
connect_port = get_config(:winrm_port)
|
475
484
|
print "\n#{ui.color("Waiting for winrm access to become available on #{connect_host}:#{connect_port}", :magenta)}"
|
476
|
-
print(
|
485
|
+
print(".") until tcp_test_winrm(connect_host, connect_port) do
|
477
486
|
sleep 10
|
478
|
-
puts(
|
487
|
+
puts("done")
|
479
488
|
end
|
480
489
|
else
|
481
490
|
print "\n#{ui.color("Waiting for sshd access to become available on #{connect_host}:#{connect_port}", :magenta)}"
|
482
|
-
print(
|
491
|
+
print(".") until tcp_test_ssh(connect_host, connect_port) do
|
483
492
|
sleep 10
|
484
|
-
puts(
|
493
|
+
puts("done")
|
485
494
|
end
|
486
495
|
end
|
487
496
|
connect_port
|
@@ -494,7 +503,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
494
503
|
deviceChange: [
|
495
504
|
{
|
496
505
|
operation: :remove,
|
497
|
-
device: disk
|
506
|
+
device: disk,
|
498
507
|
},
|
499
508
|
{
|
500
509
|
operation: :add,
|
@@ -503,9 +512,9 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
503
512
|
new_disk.backing = new_disk.backing.dup
|
504
513
|
new_disk.backing.fileName = "[#{disk.backing.datastore.name}]"
|
505
514
|
new_disk.backing.parent = disk.backing
|
506
|
-
end
|
515
|
+
end,
|
507
516
|
}
|
508
|
-
]
|
517
|
+
],
|
509
518
|
}
|
510
519
|
src_vm.ReconfigVM_Task(spec: spec).wait_for_completion
|
511
520
|
end
|
@@ -513,10 +522,10 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
513
522
|
|
514
523
|
def find_available_hosts
|
515
524
|
hosts = traverse_folders_for_computeresources(datacenter.hostFolder)
|
516
|
-
fatal_exit(
|
525
|
+
fatal_exit("No ComputeResource found - Use --resource-pool to specify a resource pool or a cluster") if hosts.empty?
|
517
526
|
hosts.reject!(&:nil?)
|
518
527
|
hosts.reject! { |host| host.host.all? { |h| h.runtime.inMaintenanceMode } }
|
519
|
-
fatal_exit
|
528
|
+
fatal_exit "All hosts in maintenance mode!" if hosts.empty?
|
520
529
|
if get_config(:datastore)
|
521
530
|
hosts.reject! { |host| !host.datastore.include?(find_datastore(get_config(:datastore))) }
|
522
531
|
end
|
@@ -530,7 +539,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
530
539
|
fatal_exit "No hosts have the requested DatastoreCluster available! #{get_config(:datastorecluster)}" if hosts.empty?
|
531
540
|
|
532
541
|
if get_config(:customization_vlan)
|
533
|
-
vlan_list = get_config(:customization_vlan).split(
|
542
|
+
vlan_list = get_config(:customization_vlan).split(",")
|
534
543
|
vlan_list.each do |network|
|
535
544
|
hosts.reject! { |host| !host.network.include?(find_network(network)) }
|
536
545
|
end
|
@@ -619,24 +628,24 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
619
628
|
end
|
620
629
|
|
621
630
|
mac_list = if get_config(:customization_macs) == AUTO_MAC
|
622
|
-
[AUTO_MAC] * get_config(:customization_ips).split(
|
631
|
+
[AUTO_MAC] * get_config(:customization_ips).split(",").length
|
623
632
|
else
|
624
|
-
get_config(:customization_macs).split(
|
633
|
+
get_config(:customization_macs).split(",")
|
625
634
|
end
|
626
635
|
|
627
636
|
if get_config(:customization_sw_uuid)
|
628
637
|
unless get_config(:customization_vlan)
|
629
|
-
abort(
|
638
|
+
abort("Must specify VLANs with --cvlan when specifying switch UUIDs with --sw-uuids")
|
630
639
|
end
|
631
|
-
swuuid_list = if get_config(:customization_sw_uuid) ==
|
632
|
-
[
|
640
|
+
swuuid_list = if get_config(:customization_sw_uuid) == "auto"
|
641
|
+
["auto"] * get_config(:customization_ips).split(",").length
|
633
642
|
else
|
634
|
-
get_config(:customization_sw_uuid).split(
|
643
|
+
get_config(:customization_sw_uuid).split(",").map { |swuuid| swuuid.gsub(/((\w+\s+){7})(\w+)\s+(.+)/, '\1\3-\4') }
|
635
644
|
end
|
636
645
|
end
|
637
646
|
|
638
647
|
if get_config(:customization_vlan)
|
639
|
-
vlan_list = get_config(:customization_vlan).split(
|
648
|
+
vlan_list = get_config(:customization_vlan).split(",")
|
640
649
|
sw_uuid = get_config(:customization_sw_uuid)
|
641
650
|
networks = vlan_list.map { |vlan| find_network(vlan, sw_uuid) }
|
642
651
|
|
@@ -645,7 +654,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
645
654
|
networks.each_with_index do |network, index|
|
646
655
|
card = cards[index] || abort("Can't find source network card to customize for vlan #{vlan_list[index]}")
|
647
656
|
begin
|
648
|
-
if get_config(:customization_sw_uuid) && (swuuid_list[index] !=
|
657
|
+
if get_config(:customization_sw_uuid) && (swuuid_list[index] != "auto")
|
649
658
|
switch_port = RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
|
650
659
|
switchUuid: swuuid_list[index], portgroupKey: network.key
|
651
660
|
)
|
@@ -660,7 +669,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
660
669
|
card.backing = RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo(network: network, deviceName: network.name)
|
661
670
|
end
|
662
671
|
card.macAddress = mac_list[index] if get_config(:customization_macs) && mac_list[index] != AUTO_MAC
|
663
|
-
dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(device: card, operation:
|
672
|
+
dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(device: card, operation: "edit")
|
664
673
|
clone_spec.config.deviceChange.push dev_spec
|
665
674
|
end
|
666
675
|
end
|
@@ -682,15 +691,15 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
682
691
|
end
|
683
692
|
|
684
693
|
if get_config(:customization_dns_ips)
|
685
|
-
cust_spec.globalIPSettings.dnsServerList = get_config(:customization_dns_ips).split(
|
694
|
+
cust_spec.globalIPSettings.dnsServerList = get_config(:customization_dns_ips).split(",")
|
686
695
|
end
|
687
696
|
|
688
697
|
if get_config(:customization_dns_suffixes)
|
689
|
-
cust_spec.globalIPSettings.dnsSuffixList = get_config(:customization_dns_suffixes).split(
|
698
|
+
cust_spec.globalIPSettings.dnsSuffixList = get_config(:customization_dns_suffixes).split(",")
|
690
699
|
end
|
691
700
|
|
692
701
|
if config[:customization_ips] != NO_IPS
|
693
|
-
cust_spec.nicSettingMap = config[:customization_ips].split(
|
702
|
+
cust_spec.nicSettingMap = config[:customization_ips].split(",").map.with_index { |cust_ip, index|
|
694
703
|
generate_adapter_map(cust_ip, get_config(:customization_gw), mac_list[index])
|
695
704
|
}
|
696
705
|
end
|
@@ -704,13 +713,15 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
704
713
|
|
705
714
|
if windows?(src_config)
|
706
715
|
# We should get here with the customizations set, either by a plugin or a --cspec
|
707
|
-
fatal_exit
|
716
|
+
fatal_exit "Windows clones need a customization identity. Try passing a --cspec or making a --cplugin" if cust_spec.identity.props.empty?
|
708
717
|
|
709
718
|
identification = identification_for_spec(cust_spec)
|
710
719
|
|
711
|
-
|
712
|
-
|
713
|
-
|
720
|
+
if cust_spec.identity.licenseFilePrintData
|
721
|
+
license_file_print_data = RbVmomi::VIM.CustomizationLicenseFilePrintData(
|
722
|
+
autoMode: cust_spec.identity.licenseFilePrintData.autoMode
|
723
|
+
)
|
724
|
+
end # optional param
|
714
725
|
|
715
726
|
user_data = RbVmomi::VIM.CustomizationUserData(
|
716
727
|
fullName: cust_spec.identity.userData.fullName,
|
@@ -729,7 +740,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
729
740
|
timeZone: cust_spec.identity.guiUnattended.timeZone
|
730
741
|
)
|
731
742
|
runonce = RbVmomi::VIM.CustomizationGuiRunOnce(
|
732
|
-
commandList: [
|
743
|
+
commandList: ["cust_spec.identity.guiUnattended.commandList"]
|
733
744
|
)
|
734
745
|
ident = RbVmomi::VIM.CustomizationSysprep
|
735
746
|
ident.guiRunOnce = runonce
|
@@ -745,11 +756,11 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
745
756
|
ident.domain = if get_config(:customization_domain)
|
746
757
|
get_config(:customization_domain)
|
747
758
|
else
|
748
|
-
|
759
|
+
""
|
749
760
|
end
|
750
761
|
cust_spec.identity = ident
|
751
762
|
else
|
752
|
-
ui.error(
|
763
|
+
ui.error("Customization only supports Linux and Windows currently.")
|
753
764
|
exit 1
|
754
765
|
end
|
755
766
|
end
|
@@ -773,14 +784,14 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
773
784
|
abort "Customization plugin could not be found at #{cplugin_path}"
|
774
785
|
end
|
775
786
|
|
776
|
-
if Object.const_defined?
|
777
|
-
@customization_plugin = Object.const_get(
|
787
|
+
if Object.const_defined? "KnifeVspherePlugin"
|
788
|
+
@customization_plugin = Object.const_get("KnifeVspherePlugin").new
|
778
789
|
cplugin_data = get_config(:customization_plugin_data)
|
779
790
|
if cplugin_data
|
780
791
|
if @customization_plugin.respond_to?(:data=)
|
781
792
|
@customization_plugin.data = cplugin_data
|
782
793
|
else
|
783
|
-
abort
|
794
|
+
abort "Customization plugin has no :data= accessor to receive the --cplugin-data argument. Define both or neither."
|
784
795
|
end
|
785
796
|
end
|
786
797
|
else
|
@@ -807,7 +818,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
807
818
|
def generate_adapter_map(ip = nil, gw = nil, mac = nil)
|
808
819
|
settings = RbVmomi::VIM.CustomizationIPSettings
|
809
820
|
|
810
|
-
if ip.nil? || ip.
|
821
|
+
if ip.nil? || ip.casecmp("dhcp") == 0
|
811
822
|
settings.ip = RbVmomi::VIM::CustomizationDhcpIpGenerator.new
|
812
823
|
else
|
813
824
|
cidr_ip = NetAddr::CIDR.create(ip)
|
@@ -816,7 +827,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
816
827
|
|
817
828
|
# TODO: want to confirm gw/ip are in same subnet?
|
818
829
|
# Only set gateway on first IP.
|
819
|
-
if config[:customization_ips].split(
|
830
|
+
if config[:customization_ips].split(",").first == ip
|
820
831
|
if gw.nil?
|
821
832
|
settings.gateway = [cidr_ip.network(Objectify: true).next_ip]
|
822
833
|
else
|
@@ -835,8 +846,6 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
835
846
|
def bootstrap_common_params(bootstrap)
|
836
847
|
bootstrap.config[:run_list] = config[:run_list]
|
837
848
|
bootstrap.config[:bootstrap_version] = get_config(:bootstrap_version)
|
838
|
-
bootstrap.config[:distro] = get_config(:distro)
|
839
|
-
bootstrap.config[:template_file] = get_config(:template_file)
|
840
849
|
bootstrap.config[:environment] = get_config(:environment)
|
841
850
|
bootstrap.config[:prerelease] = get_config(:prerelease)
|
842
851
|
bootstrap.config[:first_boot_attributes] = get_config(:first_boot_attributes)
|
@@ -854,20 +863,20 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
854
863
|
|
855
864
|
def bootstrap_for_windows_node
|
856
865
|
Chef::Knife::Bootstrap.load_deps
|
857
|
-
if get_config(:bootstrap_protocol) ==
|
866
|
+
if get_config(:bootstrap_protocol) == "winrm" || get_config(:bootstrap_protocol).nil?
|
858
867
|
bootstrap = Chef::Knife::BootstrapWindowsWinrm.new
|
859
868
|
bootstrap.name_args = [config[:fqdn]]
|
860
869
|
bootstrap.config[:winrm_user] = get_config(:winrm_user)
|
861
870
|
bootstrap.config[:winrm_password] = get_config(:winrm_password)
|
862
871
|
bootstrap.config[:winrm_transport] = get_config(:winrm_transport)
|
863
872
|
bootstrap.config[:winrm_port] = get_config(:winrm_port)
|
864
|
-
elsif get_config(:bootstrap_protocol) ==
|
873
|
+
elsif get_config(:bootstrap_protocol) == "ssh"
|
865
874
|
bootstrap = Chef::Knife::BootstrapWindowsSsh.new
|
866
875
|
bootstrap.config[:ssh_user] = get_config(:ssh_user)
|
867
876
|
bootstrap.config[:ssh_password] = get_config(:ssh_password)
|
868
877
|
bootstrap.config[:ssh_port] = get_config(:ssh_port)
|
869
878
|
else
|
870
|
-
ui.error(
|
879
|
+
ui.error("Unsupported Bootstrapping Protocol. Supports : winrm, ssh")
|
871
880
|
exit 1
|
872
881
|
end
|
873
882
|
bootstrap.config[:msi_url] = get_config(:bootstrap_msi_url)
|
@@ -878,13 +887,14 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
878
887
|
Chef::Knife::Bootstrap.load_deps
|
879
888
|
bootstrap = Chef::Knife::Bootstrap.new
|
880
889
|
bootstrap.name_args = [config[:fqdn]]
|
890
|
+
bootstrap.config[:bootstrap_template] = get_config(:bootstrap_template)
|
881
891
|
bootstrap.config[:secret_file] = get_config(:secret_file)
|
882
892
|
bootstrap.config[:ssh_user] = get_config(:ssh_user)
|
883
893
|
bootstrap.config[:ssh_password] = get_config(:ssh_password)
|
884
894
|
bootstrap.config[:ssh_port] = get_config(:ssh_port)
|
885
895
|
bootstrap.config[:identity_file] = get_config(:identity_file)
|
886
|
-
bootstrap.config[:use_sudo] = true unless get_config(:ssh_user) ==
|
887
|
-
bootstrap.config[:use_sudo_password] = true unless get_config(:ssh_user) ==
|
896
|
+
bootstrap.config[:use_sudo] = true unless get_config(:ssh_user) == "root"
|
897
|
+
bootstrap.config[:use_sudo_password] = true unless get_config(:ssh_user) == "root"
|
888
898
|
bootstrap.config[:log_level] = get_config(:log_level)
|
889
899
|
bootstrap_common_params(bootstrap)
|
890
900
|
end
|
@@ -892,19 +902,19 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
892
902
|
def ssh_override_winrm
|
893
903
|
# unchanged ssh_user and changed winrm_user, override ssh_user
|
894
904
|
if get_config(:ssh_user).eql?(options[:ssh_user][:default]) &&
|
895
|
-
|
905
|
+
!get_config(:winrm_user).eql?(options[:winrm_user][:default])
|
896
906
|
config[:ssh_user] = get_config(:winrm_user)
|
897
907
|
end
|
898
908
|
|
899
909
|
# unchanged ssh_port and changed winrm_port, override ssh_port
|
900
910
|
if get_config(:ssh_port).eql?(options[:ssh_port][:default]) &&
|
901
|
-
|
911
|
+
!get_config(:winrm_port).eql?(options[:winrm_port][:default])
|
902
912
|
config[:ssh_port] = get_config(:winrm_port)
|
903
913
|
end
|
904
914
|
|
905
915
|
# unset ssh_password and set winrm_password, override ssh_password
|
906
916
|
if get_config(:ssh_password).nil? &&
|
907
|
-
|
917
|
+
!get_config(:winrm_password).nil?
|
908
918
|
config[:ssh_password] = get_config(:winrm_password)
|
909
919
|
end
|
910
920
|
|
@@ -969,11 +979,11 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
969
979
|
end
|
970
980
|
|
971
981
|
def load_winrm_deps
|
972
|
-
require
|
973
|
-
require
|
974
|
-
require
|
975
|
-
require
|
976
|
-
require
|
982
|
+
require "winrm"
|
983
|
+
require "chef/knife/winrm"
|
984
|
+
require "chef/knife/bootstrap_windows_winrm"
|
985
|
+
require "chef/knife/bootstrap_windows_ssh"
|
986
|
+
require "chef/knife/core/windows_bootstrap_context"
|
977
987
|
end
|
978
988
|
|
979
989
|
private
|