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

50 lines
1.4 KiB
Ruby
Raw Normal View History

require "tempfile"
require_relative "../../../../lib/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)
comm = machine.communicate
commands = ["set -e"]
interfaces = machine.guest.capability(:network_interfaces)
networks.each.with_index do |network, i|
network[:device] = interfaces[network[:interface]]
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
options: network,
)
remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now.to_i}-#{i}"
2013-04-04 18:39:58 +00:00
2016-05-31 04:18:16 +00:00
Tempfile.open("vagrant-arch-configure-networks") do |f|
f.binmode
f.write(entry)
f.fsync
f.close
comm.upload(f.path, remote_path)
end
2013-04-04 18:39:58 +00:00
commands << <<-EOH.gsub(/^ {14}/, '')
# Configure #{network[:device]}
mv '#{remote_path}' '/etc/netctl/#{network[:device]}'
ip link set '#{network[:device]}' down
netctl restart '#{network[:device]}'
netctl enable '#{network[:device]}'
EOH
2013-04-04 18:39:58 +00:00
end
# Run all the network modification commands in one communicator call.
comm.sudo(commands.join("\n"))
2013-04-04 18:39:58 +00:00
end
end
end
end
end