Class: VagrantPlugins::VSphereDDNS::Action::WaitForIPAddress
- Inherits:
-
Object
- Object
- VagrantPlugins::VSphereDDNS::Action::WaitForIPAddress
- Defined in:
- lib/vagrant-vsphere-ddns/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.
9 10 11 12 |
# File 'lib/vagrant-vsphere-ddns/action/wait_for_ip_address.rb', line 9 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant::vsphere-ddns::wait_for_ip_address") end |
Instance Method Details
#call(env) ⇒ Object
14 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 |
# File 'lib/vagrant-vsphere-ddns/action/wait_for_ip_address.rb', line 14 def call(env) return if env[:machine_ssh_info].nil? host = env[:machine_ssh_info][:host] timeout = env[:machine].config.ddns.ssh_timeout @logger.info("Trying to resolve #{host} (timeout #{timeout} seconds)") Timeout.timeout(timeout) do while true # If a ctrl-c came through, break out return if env[:interrupted] begin ip_address = Resolv.getaddress(host) @logger.info("Host #{host} resolved to #{ip_address}") break rescue Resolv::ResolvError @logger.warn("Could not resolve: #{host}") end sleep 1 end end return if env[:interrupted] @app.call(env) rescue Timeout::Error raise Errors::IPAddrTimeout, host: host, timeout: timeout end |