Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ipv4_bootstrap #96

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions lib/chef/provisioning/vsphere_driver/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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