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(windows_machine) ⇒ WinRMFinder

Returns a new instance of WinRMFinder.



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

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

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#windows_machineObject (readonly)

Returns the value of attribute windows_machine.



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

def windows_machine
  @windows_machine
end

Instance Method Details

#winrm_host_addressString

Finds the address of the Windows machine. Raises a Vagrant::Errors::SSHNotReady if WinRM is not responding yet.

Returns:

  • (String)

    The IP of the Windows machine

Raises:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-windows/communication/winrmfinder.rb', line 21

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 = @windows_machine.ssh_info
  raise VagrantWindows::Errors::WinRMNotReady if ssh_info.nil?
  
  # if the configuration has a host value, that takes precedence
  host = @windows_machine.winrm_config.host || ssh_info[:host]
  @logger.info("WinRM host: #{host}")
  host
end

#winrm_host_portString

Finds the IP port of the Windows machine’s WinRM service.

Returns:

  • (String)

    The port of the Windows machine’s WinRM service



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vagrant-windows/communication/winrmfinder.rb', line 36

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

  # Look for the forwarded port only by comparing the guest port
  @windows_machine.read_forwarded_ports().each do |_, _, hostport, guestport|
    return hostport if guestport == expected_guest_port
  end
  
  # We tried, give up and use the configured port as-is
  @windows_machine.winrm_config.port
end