class VagrantHosts::Cap::Facts::Windows
Base class for retrieving network facts from Windows
@since 2.8.0
Public Instance Methods
load_facts()
click to toggle source
# File lib/vagrant-hosts/cap/facts/windows.rb, line 8 def load_facts facts = {} facts['networking'] = {} facts['networking']['interfaces'] = parse_ifconfig iface = get_default_iface facts['networking']['ip'] = iface facts end
Private Instance Methods
get_default_iface()
click to toggle source
# File lib/vagrant-hosts/cap/facts/windows.rb, line 31 def get_default_iface route_table = sudo('netstat -rn')[:stdout] default = route_table.lines.find do |e| e.lstrip.start_with?('default') || e.lstrip.start_with?('0.0.0.0') end default.split[-2].chomp end
parse_ifconfig()
click to toggle source
# File lib/vagrant-hosts/cap/facts/windows.rb, line 21 def parse_ifconfig # Imagine a call to Get-WmiObject -Query that returns a combined dataset # built from Win32_NetworkAdapter (interface names) and # Win32_NetworkAdapterConfiguration (everything else, like ipaddress). # # TODO: Implement said query. Hash.new end
sudo(cmd)
click to toggle source
FIXME: de-duplicate with posix implementation after figuring out what
happens to newlines.
# File lib/vagrant-hosts/cap/facts/windows.rb, line 46 def sudo(cmd) stdout = '' stderr = '' retval = machine.communicate.sudo(cmd) do |type, data| if type == :stderr stderr << data else stdout << data end end {:stdout => stdout, :stderr => stderr, :retval => retval} end