Sha256: 686c359ffc92e4736c7dc32b61a8c39c5d999b791d1dacf70bbd4caecf0ec587

Contents?: true

Size: 1.44 KB

Versions: 22

Compression:

Stored size: 1.44 KB

Contents

require "ipaddr"
require "timeout"

module VagrantPlugins
  module HyperV
    module Action
      class WaitForIPAddress
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new("vagrant::hyperv::wait_for_ip_addr")
        end

        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
            while true
              # If a ctrl-c came through, break out
              return if env[:interrupted]

              # Try to get the IP
              network_info = env[:machine].provider.driver.read_guest_ip
              guest_ip = network_info["ip"]

              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::IPAddrTimeout
        end
      end
    end
  end
end

Version data entries

22 entries across 19 versions & 5 rubygems

Version Path
vagrant-unbundled-1.9.7.1 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-1.9.5.1 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-1.9.1.1 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-1.8.5.2 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-1.8.5.1 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-1.8.4.2 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-1.8.4.1 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-1.8.1.2 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-1.8.1.1 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/plugins/providers/hyperv/action/wait_for_ip_address.rb