2013-05-14 20:22:19 +00:00
|
|
|
require "tempfile"
|
|
|
|
|
|
|
|
require "vagrant/util/template_renderer"
|
|
|
|
|
2013-04-04 18:39:58 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestArch
|
|
|
|
module Cap
|
|
|
|
class ConfigureNetworks
|
2013-05-22 15:29:58 +00:00
|
|
|
include Vagrant::Util
|
|
|
|
|
2013-04-04 18:39:58 +00:00
|
|
|
def self.configure_networks(machine, networks)
|
|
|
|
networks.each do |network|
|
|
|
|
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
|
|
|
|
:options => network)
|
|
|
|
|
|
|
|
temp = Tempfile.new("vagrant")
|
|
|
|
temp.binmode
|
|
|
|
temp.write(entry)
|
|
|
|
temp.close
|
|
|
|
|
2013-12-05 14:16:59 +00:00
|
|
|
# Only consider nth line of sed's output below. There certainly is a
|
|
|
|
# better way to do this
|
|
|
|
snth = network[:interface] + 1
|
|
|
|
|
2013-04-04 18:39:58 +00:00
|
|
|
machine.communicate.upload(temp.path, "/tmp/vagrant_network")
|
2013-05-23 21:16:26 +00:00
|
|
|
machine.communicate.sudo("mv /tmp/vagrant_network /etc/netctl/eth#{network[:interface]}")
|
2013-12-05 14:16:59 +00:00
|
|
|
|
|
|
|
# A hack not to rely on udev rule 80-net-name-slot.rules masking:
|
|
|
|
# ln -sf /dev/null /etc/udev/80-net-name-slot.rules that
|
|
|
|
# I assume this to be the most portable solution because
|
|
|
|
# otherwise we would need to rely on the Virtual Machine implementation
|
|
|
|
# to provide details on the configured interfaces, e.g mac address
|
|
|
|
# to write a custom udev rule.
|
|
|
|
machine.communicate.sudo("sed -i s/eth#{network[:interface]}/`systemctl list-units -t device | sed -n 's/.*subsystem.net-devices-\\(.*\\).device.*/\\1/p' | sed -n #{snth}p`/g /etc/netctl/eth#{network[:interface]}")
|
2013-05-23 21:16:26 +00:00
|
|
|
machine.communicate.sudo("netctl start eth#{network[:interface]}")
|
2013-04-04 18:39:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|