2013-12-05 15:01:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
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-05-14 20:22:19 +00:00
|
|
|
|
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)
|
2016-05-29 03:17:40 +00:00
|
|
|
tempfiles = []
|
|
|
|
interfaces = []
|
|
|
|
|
2014-12-13 20:08:31 +00:00
|
|
|
machine.communicate.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, result|
|
2014-09-06 02:56:01 +00:00
|
|
|
interfaces = result.split("\n")
|
|
|
|
end
|
|
|
|
|
2016-05-29 03:17:40 +00:00
|
|
|
networks.each.with_index do |network, i|
|
2014-09-06 02:56:01 +00:00
|
|
|
network[:device] = interfaces[network[:interface]]
|
|
|
|
|
2016-05-29 03:17:40 +00:00
|
|
|
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
|
|
|
|
options: network)
|
|
|
|
|
|
|
|
remote_path = "/tmp/vagrant-network-#{Time.now.to_i}-#{i}"
|
2013-04-04 18:39:58 +00:00
|
|
|
|
2016-05-31 03:17:02 +00:00
|
|
|
Tempfile.open("arch-configure-networks") do |f|
|
|
|
|
f.binmode
|
2016-05-29 03:17:40 +00:00
|
|
|
f.write(entry)
|
|
|
|
f.fsync
|
|
|
|
f.close
|
|
|
|
machine.communicate.upload(f.path, remote_path)
|
|
|
|
end
|
2013-04-04 18:39:58 +00:00
|
|
|
|
2016-05-29 03:17:40 +00:00
|
|
|
machine.communicate.sudo("mv #{remote_path} /etc/netctl/#{network[:device]}")
|
2016-03-08 15:19:39 +00:00
|
|
|
machine.communicate.sudo("ip link set #{network[:device]} down && netctl restart #{network[:device]} && netctl enable #{network[:device]}")
|
2013-04-04 18:39:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|