Sha256: 3c75aca88877e39cedd6e5123c577482aff7cf456b6061ce3416e792e56f0112
Contents?: true
Size: 1.63 KB
Versions: 6
Compression:
Stored size: 1.63 KB
Contents
require "tempfile" require_relative "../../../../lib/vagrant/util/template_renderer" module VagrantPlugins module GuestArch module Cap class ConfigureNetworks include Vagrant::Util def self.configure_networks(machine, networks) comm = machine.communicate commands = [] interfaces = [] # The result will be something like: # eth0\nenp0s8\nenp0s9 comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, stdout| interfaces = stdout.split("\n") end 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}" Tempfile.open("vagrant-arch-configure-networks") do |f| f.binmode f.write(entry) f.fsync f.close comm.upload(f.path, remote_path) end 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 end # Run all the network modification commands in one communicator call. comm.sudo(commands.join("\n")) end end end end end
Version data entries
6 entries across 6 versions & 2 rubygems