Class: VagrantPlugins::VSphere::Action::WaitForIPAddress
- Inherits:
-
Object
- Object
- VagrantPlugins::VSphere::Action::WaitForIPAddress
- Defined in:
- lib/vSphere/action/wait_for_ip_address.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, _env) ⇒ WaitForIPAddress
constructor
A new instance of WaitForIPAddress.
Constructor Details
#initialize(app, _env) ⇒ WaitForIPAddress
Returns a new instance of WaitForIPAddress.
10 11 12 13 |
# File 'lib/vSphere/action/wait_for_ip_address.rb', line 10 def initialize(app, _env) @app = app @logger = Log4r::Logger.new('vagrant::vsphere::wait_for_ip_addr') end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vSphere/action/wait_for_ip_address.rb', line 15 def call(env) timeout = env[:machine].provider_config.ip_address_timeout env[:ui].output('Waiting for the machine to report its IP address...') env[:ui].detail("Timeout: #{timeout} seconds") guest_ip = nil Timeout.timeout(timeout) do loop do # If a ctrl-c came through, break out return if env[:interrupted] guest_ip = nil if env[:machine].state.id == :running ssh_info = env[:machine].ssh_info guest_ip = ssh_info[:host] unless ssh_info.nil? end if guest_ip begin IPAddr.new(guest_ip) break rescue IPAddr::InvalidAddressError # Ignore, continue looking. @logger.warn("Invalid IP address returned: #{guest_ip}") end end sleep 1 end end # If we were interrupted then return now return if env[:interrupted] env[:ui].detail("IP: #{guest_ip}") @app.call(env) rescue Timeout::Error raise Errors::VSphereError, :wait_for_ip_address_timeout end |