Skip to content

Commit

Permalink
Merge pull request #8 from chef-partners/metalseargolid-feature/ipv4_…
Browse files Browse the repository at this point in the history
…bootstrap

Metalseargolid feature/ipv4 bootstrap
  • Loading branch information
JJ Asghar authored Apr 20, 2017
2 parents 38c790e + 9798b13 commit 1bb6134
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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 @@ -730,8 +730,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

0 comments on commit 1bb6134

Please sign in to comment.