From fe6930d46b7882bbe4e29e2b02e03ad1e2ccc1ad Mon Sep 17 00:00:00 2001 From: Jesse Hu Date: Fri, 18 Jan 2019 18:28:59 +0800 Subject: [PATCH] Fix issue when checking guest IP of the VM with docker running When docker daemon runs in the VM, there will be a nic created by docker and usually has IP like 172.x.x.x. When VM is booting up, VM Tools sometimes reports this IP to vCenter, although the real IP of the non-docker nic will be reported later. So we add a check for this case and filter out the docker IP. --- lib/chef/provisioning/vsphere_driver/driver.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/chef/provisioning/vsphere_driver/driver.rb b/lib/chef/provisioning/vsphere_driver/driver.rb index 6140615..3683ba5 100644 --- a/lib/chef/provisioning/vsphere_driver/driver.rb +++ b/lib/chef/provisioning/vsphere_driver/driver.rb @@ -647,8 +647,7 @@ def wait_until_ready(action_handler, machine_spec, machine_options, vm) if vm.guest.toolsRunningStatus != "guestToolsRunning" if action_handler.should_perform_actions action_handler.report_progress "waiting for #{machine_spec.name} (#{vm.config.instanceUuid} on #{driver_url}) to be ready ..." - until remaining_wait_time(machine_spec, machine_options) < 0 || - (vm.guest.toolsRunningStatus == "guestToolsRunning" && vm.guest.ipAddress && !vm.guest.ipAddress.empty?) + until remaining_wait_time(machine_spec, machine_options) < 0 || vm_guest_ip?(vm) print "." sleep 5 end @@ -948,7 +947,9 @@ def wait_for_ipv4(timeout_seconds, vm) # # @param [Object] vm The VM object from Chef-Provisioning def vm_guest_ip?(vm) - vm.guest.guestState == "running" && vm.guest.toolsRunningStatus == "guestToolsRunning" && !vm.guest.ipAddress.nil? + # The docker interface usually has IP like 172.x.x.x, so need to filter it out. + vm.guest.guestState == "running" && vm.guest.toolsRunningStatus == "guestToolsRunning" && + !vm.guest.ipAddress.nil? && !vm.guest.ipAddress.empty? && !vm.guest.ipAddress.start_with?("172") end end end