Sha256: 46de8616a4ae5dcc8355803e5c1abd8833a8c36e8f4fe6142fd4092ee4829819

Contents?: true

Size: 1.64 KB

Versions: 41

Compression:

Stored size: 1.64 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
              begin
                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
              rescue Errors::PowerShellError
                # Ignore, continue looking.
                @logger.warn("Failed to read guest IP.")
              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

41 entries across 37 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.0.0 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-2.1.4.0 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-2.1.2.0 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-2.1.1.0 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-2.0.4.0 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-2.0.3.0 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-aws-detiber-0.7.2.pre.4 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-aws-detiber-0.7.2.pre.3 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-aws-detiber-0.7.2.pre.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-2.0.2.0 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-2.0.1.0 plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/plugins/providers/hyperv/action/wait_for_ip_address.rb
vagrant-unbundled-2.0.0.1 plugins/providers/hyperv/action/wait_for_ip_address.rb