knife-vsphere 1.2.10 → 1.2.11
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 +4 -4
- data/lib/chef/knife/vsphere_vm_clone.rb +40 -4
- data/lib/knife-vsphere/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 041173b0bb8d4791d22c9834ff1759992ef9143f
|
4
|
+
data.tar.gz: 2ab04c24568487e1a624bbed1338faef8f5b219b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c08fffec7d372bc2f5011d1d9aef0e4cf83d01a9976eae560fc8b196430379e75f7c765047127fb325dcd54b30738aeb5dcbb4a1d6cf8513f50792a35e458adf
|
7
|
+
data.tar.gz: 7f8323b13c044d45b9ad926fa1626d2f12efcc1f48a3aaa7e31a612b98049942115a03c41ba507dbbec9557fc752148ea1e520f1f7eb5a54a82daba67f59273b
|
@@ -3,6 +3,7 @@
|
|
3
3
|
# Contributor:: Jesse Campbell (<hikeit@gmail.com>)
|
4
4
|
# Contributor:: Bethany Erskine (<bethany@paperlesspost.com>)
|
5
5
|
# Contributor:: Adrian Stanila (https://github.com/sacx)
|
6
|
+
# Contributor:: Ryan Hass (rhass@chef.io)
|
6
7
|
# License:: Apache License, Version 2.0
|
7
8
|
#
|
8
9
|
|
@@ -13,6 +14,7 @@ require 'netaddr'
|
|
13
14
|
require 'securerandom'
|
14
15
|
require 'chef/knife/winrm_base'
|
15
16
|
require 'chef/knife/customization_helper'
|
17
|
+
require 'ipaddr'
|
16
18
|
|
17
19
|
# Clone an existing template into a new VM, optionally applying a customization specification.
|
18
20
|
# usage:
|
@@ -282,6 +284,16 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
282
284
|
description: 'Wait TIMEOUT seconds for sysprep event before continuing with bootstrap',
|
283
285
|
default: 600
|
284
286
|
|
287
|
+
option :bootstrap_nic,
|
288
|
+
long: '--bootstrap-nic INTEGER',
|
289
|
+
description: 'Network interface to use when multiple NICs are defined on a template.',
|
290
|
+
default: 0
|
291
|
+
|
292
|
+
option :bootstrap_ipv4,
|
293
|
+
long: '--bootstrap-ipv4',
|
294
|
+
description: 'Force using an IPv4 address when a NIC has both IPv4 and IPv6 addresses.',
|
295
|
+
default: false
|
296
|
+
|
285
297
|
def run
|
286
298
|
$stdout.sync = true
|
287
299
|
|
@@ -332,9 +344,8 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
332
344
|
end
|
333
345
|
|
334
346
|
return unless get_config(:bootstrap)
|
335
|
-
sleep 2 until vm.guest.ipAddress
|
336
347
|
|
337
|
-
connect_host =
|
348
|
+
connect_host = guest_address(vm)
|
338
349
|
Chef::Log.debug("Connect Host for Bootstrap: #{connect_host}")
|
339
350
|
connect_port = get_config(:ssh_port)
|
340
351
|
protocol = get_config(:bootstrap_protocol)
|
@@ -347,8 +358,6 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
347
358
|
puts 'Waiting for customization to complete...'
|
348
359
|
CustomizationHelper.wait_for_sysprep(vm, vim, Integer(get_config(:sysprep_timeout)), 10)
|
349
360
|
puts 'Customization Complete'
|
350
|
-
sleep 2 until vm.guest.ipAddress
|
351
|
-
connect_host = config[:fqdn] = config[:fqdn] ? get_config(:fqdn) : vm.guest.ipAddress
|
352
361
|
end
|
353
362
|
wait_for_access(connect_host, connect_port, protocol)
|
354
363
|
ssh_override_winrm
|
@@ -361,6 +370,33 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
361
370
|
end
|
362
371
|
end
|
363
372
|
|
373
|
+
def ipv4_address(vm)
|
374
|
+
puts 'Waiting for a valid IPv4 address...'
|
375
|
+
# Multiple reboots occur during guest customization in which a link-local
|
376
|
+
# address is assigned. As such, we need to wait until a routable IP address
|
377
|
+
# becomes available. This is most commonly an issue with Windows instances.
|
378
|
+
sleep 2 while vm.guest.net[config[:bootstrap_nic]].ipConfig.ipAddress.detect { |addr| IPAddr.new(addr.ipAddress).ipv4? }.origin == 'linklayer'
|
379
|
+
vm.guest.net[config[:bootstrap_nic]].ipAddress.detect { |addr| IPAddr.new(addr).ipv4? }
|
380
|
+
end
|
381
|
+
|
382
|
+
def guest_address(vm)
|
383
|
+
puts 'Waiting for network interfaces to become available...'
|
384
|
+
sleep 2 while vm.guest.net.empty? && !vm.guest.ipAddress
|
385
|
+
guest_address ||=
|
386
|
+
config[:fqdn] = if config[:bootstrap_ipv4]
|
387
|
+
ipv4_address(vm)
|
388
|
+
elsif config[:fqdn]
|
389
|
+
get_config(:fqdn)
|
390
|
+
else
|
391
|
+
# Use the first IP which is not a link-local address.
|
392
|
+
# This is the closest thing to vm.guest.ipAddress but
|
393
|
+
# allows specifying a NIC.
|
394
|
+
vm.guest.net[config[:bootstrap_nic]].ipConfig.ipAddress.detect do |addr|
|
395
|
+
addr.origin != 'linklayer'
|
396
|
+
end.ipAddress
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
364
400
|
def wait_for_access(connect_host, connect_port, protocol)
|
365
401
|
if protocol == 'winrm'
|
366
402
|
load_winrm_deps
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-vsphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ezra Pagel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: filesize
|