Class: VagrantWindows::Communication::WinRMFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-windows/communication/winrmfinder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ WinRMFinder

Returns a new instance of WinRMFinder.



11
12
13
14
# File 'lib/vagrant-windows/communication/winrmfinder.rb', line 11

def initialize(machine)
  @machine = machine
  @logger = Log4r::Logger.new("vagrant_windows::communication::winrmfinder")
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/vagrant-windows/communication/winrmfinder.rb', line 8

def logger
  @logger
end

#machineObject (readonly)

Returns the value of attribute machine.



9
10
11
# File 'lib/vagrant-windows/communication/winrmfinder.rb', line 9

def machine
  @machine
end

Instance Method Details

#winrm_host_addressObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-windows/communication/winrmfinder.rb', line 16

def winrm_host_address
  # Get the SSH info for the machine, raise an exception if the
  # provider is saying that the machine is not ready.
  ssh_info = @machine.ssh_info
  raise VagrantWindows::Errors::WinRMNotReady if ssh_info.nil?
  
  # if the configuration has a host value, that takes precedence
  host = @machine.config.winrm.host || ssh_info[:host]
  @logger.info("WinRM host: #{host}")
  host
end

#winrm_host_portObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vagrant-windows/communication/winrmfinder.rb', line 28

def winrm_host_port
  expected_guest_port = @machine.config.winrm.guest_port
  @logger.debug("Searching for WinRM port: #{expected_guest_port.inspect}")

  # Look for the forwarded port only by comparing the guest port
  begin
    @machine.provider.driver.read_forwarded_ports.each do |_, _, hostport, guestport|
      return hostport if guestport == expected_guest_port
    end
  rescue NoMethodError => e
    # VMWare provider doesn't support read_forwarded_ports
    @logger.debug(e.message)
  end
  
  # We tried, give up and use the configured port as-is
  @machine.config.winrm.port
end