Class: VagrantWindows::Guest::Cap::ConfigureNetworks

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-windows/guest/cap/configure_networks.rb

Constant Summary collapse

@@logger =
Log4r::Logger.new("vagrant_windows::guest::cap::configure_networks")

Class Method Summary collapse

Class Method Details

.configure_networks(machine, networks) ⇒ Object



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
# File 'lib/vagrant-windows/guest/cap/configure_networks.rb', line 15

def self.configure_networks(machine, networks)
  @@logger.debug("networks: #{networks.inspect}")
  
  windows_machine = VagrantWindows::WindowsMachine.new(machine)
  guest_network = VagrantWindows::Communication::GuestNetwork.new(windows_machine.winrmshell)
  if windows_machine.is_vmware?()
    @@logger.warn('Configuring secondary network adapters through VMware is not yet supported.')
    @@logger.warn('You will need to manually configure the network adapter.')
  else
    vm_interface_map = create_vm_interface_map(windows_machine, guest_network)          
    networks.each do |network|
      interface = vm_interface_map[network[:interface]+1]
      if interface.nil?
        @@logger.warn("Could not find interface for network #{network.inspect}")
        next
      end
      network_type = network[:type].to_sym
      if network_type == :static
        guest_network.configure_static_interface(
          interface[:index],
          interface[:net_connection_id],
          network[:ip],
          network[:netmask])
      elsif network_type == :dhcp
        guest_network.configure_dhcp_interface(
          interface[:index],
          interface[:net_connection_id])
      else
        raise WindowsError, "#{network_type} network type is not supported, try static or dhcp"
      end
    end
  end
  guest_network.set_all_networks_to_work() if windows_machine.windows_config.set_work_network
end

.create_vm_interface_map(windows_machine, guest_network) ⇒ Object

Area Connection”, :mac_address=>“0800275FAC5B”, :interface_index=>“11”, :index=>“7”}



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vagrant-windows/guest/cap/configure_networks.rb', line 51

def self.create_vm_interface_map(windows_machine, guest_network)
  vm_interface_map = {}
  driver_mac_address = windows_machine.read_mac_addresses.invert
  @@logger.debug("mac addresses: #{driver_mac_address.inspect}")
  guest_network.network_adapters().each do |nic|
    @@logger.debug("nic: #{nic.inspect}")
    naked_mac = nic[:mac_address].gsub(':','')
    if driver_mac_address[naked_mac]
      vm_interface_map[driver_mac_address[naked_mac]] = {
        :net_connection_id => nic[:net_connection_id],
        :mac_address => naked_mac,
        :interface_index => nic[:interface_index],
        :index => nic[:index] }
    end
  end
  @@logger.debug("vm_interface_map: #{vm_interface_map.inspect}")
  vm_interface_map
end