Class: Kitchen::Provisioner::Finder::Winrm

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/provisioner/finder/winrm.rb

Overview

WinRM implementation for returning active non-localhost IPs

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Winrm

Returns a new instance of Winrm.


20
21
22
# File 'lib/kitchen/provisioner/finder/winrm.rb', line 20

def initialize(connection)
  @connection = connection
end

Instance Method Details

#find_fqdnObject


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/kitchen/provisioner/finder/winrm.rb', line 36

def find_fqdn
  out = @connection.node_execute <<-EOS
    [System.Net.Dns]::GetHostByName($env:computername) |
      FL HostName |
      Out-String |
      % { \"{0}\" -f $_.Split(':')[1].Trim() }
  EOS
  data = ''
  data = out.stdout.chomp unless out.stdout.nil?
  data
end

#find_ipsObject


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kitchen/provisioner/finder/winrm.rb', line 24

def find_ips
  out = @connection.node_execute(
    '(ipconfig) -match \'IPv[46] Address\''
  )
  data = []
  out[:data].each do |out_data|
    stdout = out_data[:stdout]
    data << Regexp.last_match[1] if stdout.chomp =~ /:\s*(\S+)/
  end
  data
end