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)
|
2016-06-23 01:33:59 +00:00
|
|
|
comm = machine.communicate
|
|
|
|
|
|
|
|
commands = []
|
2016-06-26 15:41:16 +00:00
|
|
|
interfaces = machine.guest.capability(:network_interfaces, "/bin/ip")
|
2016-06-23 01:33:59 +00:00
|
|
|
|
|
|
|
# Remove any previous network additions to the configuration file.
|
|
|
|
commands << "sed -i'' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/conf.d/net"
|
|
|
|
|
|
|
|
networks.each_with_index do |network, i|
|
|
|
|
network[:device] = interfaces[network[:interface]]
|
|
|
|
|
|
|
|
entry = TemplateRenderer.render("guests/gentoo/network_#{network[:type]}",
|
|
|
|
options: network,
|
|
|
|
)
|
|
|
|
|
|
|
|
remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now.to_i}-#{i}"
|
|
|
|
|
|
|
|
Tempfile.open("vagrant-gentoo-configure-networks") do |f|
|
|
|
|
f.binmode
|
|
|
|
f.write(entry)
|
|
|
|
f.fsync
|
|
|
|
f.close
|
|
|
|
comm.upload(f.path, remote_path)
|
2013-04-04 19:09:40 +00:00
|
|
|
end
|
2016-06-23 01:33:59 +00:00
|
|
|
|
|
|
|
commands << <<-EOH.gsub(/^ {14}/, '')
|
|
|
|
ln -sf /etc/init.d/net.lo /etc/init.d/net.#{network[:device]}
|
|
|
|
/etc/init.d/net.#{network[:device]} stop || true
|
|
|
|
|
|
|
|
cat '#{remote_path}' >> /etc/conf.d/net
|
|
|
|
rm -f '#{remote_path}'
|
|
|
|
|
|
|
|
/etc/init.d/net.#{network[:device]} start
|
|
|
|
EOH
|
2013-04-04 19:09:40 +00:00
|
|
|
end
|
2016-06-23 01:33:59 +00:00
|
|
|
|
|
|
|
comm.sudo(commands.join("\n"))
|
2013-04-04 19:09:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|