Method: Vagrant::Action::VM::Network#assign_interface_numbers

Defined in:
lib/vagrant/action/vm/network.rb

#assign_interface_numbers(networks, adapters) ⇒ Object

Assigns the actual interface number of a network based on the enabled NICs on the virtual machine.

This interface number is used by the guest to configure the NIC on the guest VM.

The networks are modified in place by adding an ":interface" field to each.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/vagrant/action/vm/network.rb', line 132

def assign_interface_numbers(networks, adapters)
  current = 0
  adapter_to_interface = {}

  # Make a first pass to assign interface numbers by adapter location
  vm_adapters = @env[:vm].driver.read_network_interfaces
  vm_adapters.sort.each do |number, adapter|
    if adapter[:type] != :none
      # Not used, so assign the interface number and increment
      adapter_to_interface[number] = current
      current += 1
    end
  end

  # Make a pass through the adapters to assign the :interface
  # key to each network configuration.
  adapters.each_index do |i|
    adapter = adapters[i]
    network = networks[i]

    # Figure out the interface number by simple lookup
    network[:interface] = adapter_to_interface[adapter[:adapter]]
  end
end