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

45 lines
1.4 KiB
Ruby
Raw Normal View History

2013-12-05 15:01:44 +00:00
# -*- coding: utf-8 -*-
require "tempfile"
require "vagrant/util/template_renderer"
2013-04-04 18:39:58 +00:00
module VagrantPlugins
module GuestArch
module Cap
class ConfigureNetworks
include Vagrant::Util
2013-04-04 18:39:58 +00:00
def self.configure_networks(machine, networks)
interfaces = Array.new
machine.communicate.sudo("ip -o -0 addr | grep -v LOOPBACK | awk
'{print $2}' | sed 's/://'") do |_, result|
interfaces = result.split("\n")
end
2013-04-04 18:39:58 +00:00
networks.each do |network|
# We use :device in the template instead of
# eth#{network[:interface]} in order to support Predictable
# Network Interfaces
network[:device] = interfaces[network[:interface]]
entry =
TemplateRenderer.render("guests/arch/network_#{network[:type]}",
options: network)
2013-04-04 18:39:58 +00:00
temp = Tempfile.new("vagrant")
temp.binmode
temp.write(entry)
temp.close
machine.communicate.upload(temp.path, "/tmp/vagrant_network")
machine.communicate.sudo("mv /tmp/vagrant_network
/etc/netctl/#{network[:device]}")
machine.communicate.sudo("ip link set #{network[:device]} down &&
netctl start #{network[:device]}")
2013-04-04 18:39:58 +00:00
end
end
end
end
end
end