Sha256: acf4d4c68ad43904942fa94b163fea59b48788084272d584340dd847555a49d3

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

require "tempfile"

require_relative "../../../../lib/vagrant/util/template_renderer"

module VagrantPlugins
  module GuestGentoo
    module Cap
      class ConfigureNetworks
        include Vagrant::Util

        def self.configure_networks(machine, networks)
          machine.communicate.tap do |comm|
            # Remove any previous host only network additions to the interface file
            comm.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/conf.d/net > /tmp/vagrant-network-interfaces")
            comm.sudo("cat /tmp/vagrant-network-interfaces > /etc/conf.d/net")
            comm.sudo("rm -f /tmp/vagrant-network-interfaces")

            # Configure each network interface
            networks.each do |network|
              entry = TemplateRenderer.render("guests/gentoo/network_#{network[:type]}",
                                              options: network)

              # Upload the entry to a temporary location
              Tempfile.open("vagrant-gentoo-configure-networks") do |f|
                f.binmode
                f.write(entry)
                f.fsync
                f.close
                comm.upload(f.path, "/tmp/vagrant-network-entry")
              end

              # Configure the interface
              comm.sudo("ln -fs /etc/init.d/net.lo /etc/init.d/net.eth#{network[:interface]}")
              comm.sudo("/etc/init.d/net.eth#{network[:interface]} stop")
              comm.sudo("cat /tmp/vagrant-network-entry >> /etc/conf.d/net")
              comm.sudo("rm -f /tmp/vagrant-network-entry")
              comm.sudo("/etc/init.d/net.eth#{network[:interface]} start")
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/gentoo/cap/configure_networks.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/gentoo/cap/configure_networks.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/gentoo/cap/configure_networks.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/guests/gentoo/cap/configure_networks.rb
vagrant-unbundled-1.8.4.2 plugins/guests/gentoo/cap/configure_networks.rb
vagrant-unbundled-1.8.4.1 plugins/guests/gentoo/cap/configure_networks.rb