-
Notifications
You must be signed in to change notification settings - Fork 24
/
winrm.rb
49 lines (45 loc) · 1.28 KB
/
winrm.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module Kitchen
module Transport
class Winrm < Kitchen::Transport::Base
# Monkey patch of test-kitchen winrm transport
# that returns stdout
class Connection < Kitchen::Transport::Base::Connection
def node_execute(command, &block)
unelevated_session.run(command, &block)
end
end
end
end
module Provisioner
module Finder
# WinRM implementation for returning active non-localhost IPs
class Winrm
Finder.register_finder(Kitchen::Transport::Winrm, self)
def initialize(connection)
@connection = connection
end
def find_ips
out = @connection.node_execute(
'(ipconfig) -match \'IPv[46] Address\''
)
data = []
out.stdout.lines.each do |line|
data << Regexp.last_match[1] if line.chomp =~ /:\s*(\S+)/
end
data
end
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
end
end
end
end