2016-05-31 03:17:02 +00:00
|
|
|
require "tempfile"
|
|
|
|
|
2016-05-29 03:17:40 +00:00
|
|
|
require_relative "../../../../lib/vagrant/util/template_renderer"
|
2013-04-04 19:09:40 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
2013-05-07 09:38:46 +00:00
|
|
|
module GuestGentoo
|
2013-04-04 19:09:40 +00:00
|
|
|
module Cap
|
2013-05-07 09:38:46 +00:00
|
|
|
class ConfigureNetworks
|
2013-04-08 17:47:19 +00:00
|
|
|
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")
|
2014-08-29 08:51:31 +00:00
|
|
|
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]}",
|
2014-05-22 16:35:12 +00:00
|
|
|
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|
|
2016-05-31 03:17:02 +00:00
|
|
|
f.binmode
|
2016-05-29 03:17:40 +00:00
|
|
|
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]}")
|
2016-06-06 16:59:51 +00:00
|
|
|
comm.sudo("/etc/init.d/net.eth#{network[:interface]} stop")
|
2013-04-04 19:09:40 +00:00
|
|
|
comm.sudo("cat /tmp/vagrant-network-entry >> /etc/conf.d/net")
|
2014-08-29 08:51:31 +00:00
|
|
|
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
|