vagrant/plugins/guests/gentoo/cap/configure_networks.rb

45 lines
1.7 KiB
Ruby
Raw Normal View History

require "tempfile"
require_relative "../../../../lib/vagrant/util/template_renderer"
2013-04-04 19:09:40 +00:00
module VagrantPlugins
module GuestGentoo
2013-04-04 19:09:40 +00:00
module Cap
class ConfigureNetworks
include Vagrant::Util
2013-04-04 19:09:40 +00:00
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")
2013-04-04 19:09:40 +00:00
# Configure each network interface
networks.each do |network|
entry = TemplateRenderer.render("guests/gentoo/network_#{network[:type]}",
options: network)
2013-04-04 19:09:40 +00:00
# Upload the entry to a temporary location
2016-05-31 04:18:16 +00:00
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
2013-04-04 19:09:40 +00:00
# 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 2> /dev/null")
comm.sudo("cat /tmp/vagrant-network-entry >> /etc/conf.d/net")
comm.sudo("rm -f /tmp/vagrant-network-entry")
2013-04-04 19:09:40 +00:00
comm.sudo("/etc/init.d/net.eth#{network[:interface]} start")
end
end
end
end
end
end
end