Sha256: 4b1664b41180c58eb337855e2fba19cf772f85632aeb86c291d76480c6919723

Contents?: true

Size: 922 Bytes

Versions: 3

Compression:

Stored size: 922 Bytes

Contents

require_relative 'base'

# Base class for retrieving network facts from Windows
#
# @since 2.8.0
class VagrantHosts::Cap::Facts::Windows < VagrantHosts::Cap::Facts::Base

  def load_facts
    facts = {}
    facts['networking'] = {}
    facts['networking']['interfaces'] = parse_ifconfig

    iface = get_default_iface
    facts['networking']['ip'] = iface

    facts
  end

  private

  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

  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

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-hosts-2.8.2 lib/vagrant-hosts/cap/facts/windows.rb
vagrant-hosts-2.8.1 lib/vagrant-hosts/cap/facts/windows.rb
vagrant-hosts-2.8.0 lib/vagrant-hosts/cap/facts/windows.rb