Sha256: b4ceba871e6b3ed651795f89022cef7dff8bacc0675cc9f95d14ed749818e1f6

Contents?: true

Size: 1.18 KB

Versions: 63

Compression:

Stored size: 1.18 KB

Contents

require "log4r"
require "timeout"

module VagrantPlugins
  module HyperV
    module Action
      # This action reads the SSH info for the machine and puts it into the
      # `:machine_ssh_info` key in the environment.
      class ReadGuestIP
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant::hyperv::connection")
        end

        def call(env)
          env[:machine_ssh_info] = read_host_ip(env)
          @app.call(env)
        end

        def read_host_ip(env)
          return nil if env[:machine].id.nil?

          # Get Network details from WMI Provider
          # Wait for 120 sec By then the machine should be ready
          host_ip = nil
          begin
            Timeout.timeout(120) do
            begin
              network_info  = env[:machine].provider.driver.read_guest_ip
              host_ip = network_info["ip"]
              sleep 10 if host_ip.empty?
              end while host_ip.empty?
            end
          rescue Timeout::Error
            @logger.info("Cannot find the IP address of the virtual machine")
          end
          return { host: host_ip } unless host_ip.nil?
        end
      end
    end
  end
end

Version data entries

63 entries across 56 versions & 8 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/providers/hyperv/action/read_guest_ip.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.3.3.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.3.2.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.19.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.18.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.16.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.14.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.10.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.9.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.8.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.7.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.6.2 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.6.1 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.6.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.5.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.4.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.3.0 plugins/providers/hyperv/action/read_guest_ip.rb
vagrant-unbundled-2.2.2.0 plugins/providers/hyperv/action/read_guest_ip.rb