Class: VagrantWindows::Communication::WinRMFinder
- Inherits:
-
Object
- Object
- VagrantWindows::Communication::WinRMFinder
- Defined in:
- lib/vagrant-windows/communication/winrmfinder.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#windows_machine ⇒ Object
readonly
Returns the value of attribute windows_machine.
Instance Method Summary collapse
-
#initialize(windows_machine) ⇒ WinRMFinder
constructor
A new instance of WinRMFinder.
-
#winrm_host_address ⇒ String
Finds the address of the Windows machine.
-
#winrm_host_port ⇒ String
Finds the IP port of the Windows machine’s WinRM service.
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
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/vagrant-windows/communication/winrmfinder.rb', line 9 def logger @logger end |
#windows_machine ⇒ Object (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_address ⇒ String
Finds the address of the Windows machine. Raises a Vagrant::Errors::SSHNotReady if WinRM is not responding yet.
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_port ⇒ String
Finds the IP 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 |