From b810e7e460869d3bb9f75b9f45fa30a4eb9490f4 Mon Sep 17 00:00:00 2001 From: Alexander Alber Date: Fri, 4 Nov 2016 13:59:29 -0400 Subject: [PATCH 1/2] If specified, wait for ipv4 address. --- .../provisioning/vsphere_driver/driver.rb | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/chef/provisioning/vsphere_driver/driver.rb b/lib/chef/provisioning/vsphere_driver/driver.rb index 3ae42d8..e5ad011 100644 --- a/lib/chef/provisioning/vsphere_driver/driver.rb +++ b/lib/chef/provisioning/vsphere_driver/driver.rb @@ -704,8 +704,40 @@ def ip_to_bootstrap(bootstrap_options, vm) bootstrap_options[:customization_spec][:ipsettings][:ip] end else + if use_ipv4_during_bootstrap?(bootstrap_options) + wait_for_ipv4(bootstrap_ip_timeout(bootstrap_options), vm) + end vm.guest.ipAddress end end + + def use_ipv4_during_bootstrap?(bootstrap_options) + if bootstrap_options.has_key?(:bootstrap_ipv4) + return bootstrap_options[:bootstrap_ipv4] == true + end + false + end + + def bootstrap_ip_timeout(bootstrap_options) + if bootstrap_options.has_key?(:ipv4_timeout) + return bootstrap_options[:ipv4_timeout].to_i + end + 30 + end + + def wait_for_ipv4(timeout, vm) + sleep_time = 5 + print 'Waiting for ipv4 address.' + tries = 0 + max_tries = timeout > sleep_time ? timeout / sleep_time : 1 + while ( vm.guest.ipAddress.nil? || ! IPAddr.new(vm.guest.ipAddress).ipv4? ) && ( tries += 1 ) <= max_tries do + print '.' + sleep sleep_time + end + raise "Timed out waiting for ipv4 address!" if tries > max_tries && ! IPAddr.new(vm.guest.ipAddress).ipv4? + puts "Found ipv4 address!" + true + end + end end From 9798b1337f272440e7074b2ee615270d0b81292c Mon Sep 17 00:00:00 2001 From: Alexander Alber Date: Fri, 4 Nov 2016 15:45:49 -0400 Subject: [PATCH 2/2] Updated README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 528f144..adfa00d 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,8 @@ This will use chef-zero and needs no chef server (only works for ssh). Note that - `[:host]` - `{cluster}`/`{host}` to use during provisioning - `[:resource_pool]` - `{cluster}`/`{resource pool}` to use during provisioning - `[:additional_disk_size_gb]` - an array of numbers, each signifying the number of gigabytes to assign to an additional disk (*this requires a datastore to be specified*) +- `[:bootstrap_ipv4]` - `true` / `false`, set to `true` to wait for an IPv4 address to become available before bootstrapping. +- `[:ipv4_timeout]` - use with `[:bootstrap_ipv4]`, set the time in seconds to wait before an IPv4 address is received (defaults to 30) - `[:ssh][:user]` user to use for ssh/winrm (defaults to root on linux/administrator on windows) - `[:ssh][:password]` - password to use for ssh/winrm - `[:ssh][:paranoid]` - specifies the strictness of the host key verification checking