Class: VagrantPlugins::GuestCumulus::Cap::ConfigureNetworks

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util
Defined in:
lib/vagrant-cumulus/cap/configure_networks.rb

Overview

Configure Cumulus Linux mgmt and front panel ports

Class Method Summary collapse

Class Method Details

.configure_networks(machine, networks) ⇒ Object



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
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vagrant-cumulus/cap/configure_networks.rb', line 17

def self.configure_networks(machine, networks)
  machine.communicate.tap do |comm|
    # First, remove any previous network modifications
    # from the interface file.
    comm.sudo("sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre")
    comm.sudo("sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tail -n +2 > /tmp/vagrant-network-interfaces.post")

    # Accumulate the configurations to add to the interfaces file as
    # well as what interfaces we're actually configuring since we use that
    # later.
    interfaces = Set.new
    entries = []
    networks.each do |network|
      interfaces.add(network[:interface])

      type, config = vm_network_config(machine, network[:interface])
      if config[:cumulus__intname]
        network[:name] = config[:cumulus__intname]
      else
        network[:name] = network[:interface] == 0 ? 'eth0' : "swp#{network[:interface]}"
      end

      entry = TemplateRenderer.render("guests/cumulus/network_#{network[:type]}",
                                      options: network,
                                      template_root: "#{VagrantPlugins::GuestCumulus.source_root}/templates")

      entries << entry
    end

    # Perform the careful dance necessary to reconfigure
    # the network interfaces
    temp = Tempfile.new("vagrant")
    temp.binmode
    temp.write(entries.join("\n"))
    temp.close

    comm.upload(temp.path, "/tmp/vagrant-network-entry")

    comm.sudo('cat /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post > /etc/network/interfaces')
    comm.sudo('rm -f /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post')

    # ifreload will reload the interfaces correctly
    comm.sudo("/sbin/ifreload -a")
  end
end

.vm_network_config(machine, interface) ⇒ Object



13
14
15
# File 'lib/vagrant-cumulus/cap/configure_networks.rb', line 13

def self.vm_network_config(machine, interface)
  machine.config.vm.networks[interface-1]
end