Method: Vagrant::Action::VM::Network#call

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

#call(env) ⇒ Object



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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/vagrant/action/vm/network.rb', line 22

def call(env)
  @env = env

  # First we have to get the array of adapters that we need
  # to create on the virtual machine itself, as well as the
  # driver-agnostic network configurations for each.
  @logger.debug("Determining adapters and networks...")
  adapters = []
  networks = []
  env[:vm].config.vm.networks.each do |type, args|
    # Get the normalized configuration we'll use around
    config = send("#{type}_config", args)

    # Get the virtualbox adapter configuration
    adapter = send("#{type}_adapter", config)
    adapters << adapter

    # Get the network configuration
    network = send("#{type}_network_config", config)
    network[:_auto_config] = true if config[:auto_config]
    networks << network
  end

  if !adapters.empty?
    # Automatically assign an adapter number to any adapters
    # that aren't explicitly set.
    @logger.debug("Assigning adapter locations...")
    assign_adapter_locations(adapters)

    # Verify that our adapters are good just prior to enabling them.
    verify_adapters(adapters)

    # Create all the network interfaces
    @logger.info("Enabling adapters...")
    env[:ui].info I18n.t("vagrant.actions.vm.network.preparing")
    env[:vm].driver.enable_adapters(adapters)
  end

  # Continue the middleware chain. We're done with our VM
  # setup until after it is booted.
  @app.call(env)

  if !adapters.empty? && !networks.empty?
    # Determine the interface numbers for the guest.
    assign_interface_numbers(networks, adapters)

    # Configure all the network interfaces on the guest. We only
    # want to configure the networks that have `auto_config` setup.
    networks_to_configure = networks.select { |n| n[:_auto_config] }
    env[:ui].info I18n.t("vagrant.actions.vm.network.configuring")
    env[:vm].guest.configure_networks(networks_to_configure)
  end
end