plugins/guests/arch/cap/configure_networks.rb in vagrant-unbundled-2.2.9.0 vs plugins/guests/arch/cap/configure_networks.rb in vagrant-unbundled-2.2.10.0

- old
+ new

@@ -7,14 +7,16 @@ module VagrantPlugins module GuestArch module Cap class ConfigureNetworks include Vagrant::Util + extend Vagrant::Util::GuestInspection::Linux def self.configure_networks(machine, networks) comm = machine.communicate commands = [] + uses_systemd_networkd = systemd_networkd?(comm) interfaces = machine.guest.capability(:network_interfaces) networks.each.with_index do |network, i| network[:device] = interfaces[network[:interface]] @@ -23,13 +25,19 @@ # the netmask to the proper value. if network[:netmask] && network[:netmask].to_s.include?(".") network[:netmask] = (32-Math.log2((IPAddr.new(network[:netmask], Socket::AF_INET).to_i^0xffffffff)+1)).to_i end - entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}", - options: network, - ) + if uses_systemd_networkd + entry = TemplateRenderer.render("guests/arch/systemd_networkd/network_#{network[:type]}", + options: network, + ) + else + entry = TemplateRenderer.render("guests/arch/default_network/network_#{network[:type]}", + options: network, + ) + end remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now.to_i}-#{i}" Tempfile.open("vagrant-arch-configure-networks") do |f| f.binmode @@ -37,16 +45,25 @@ f.fsync f.close comm.upload(f.path, remote_path) end - commands << <<-EOH.gsub(/^ {14}/, '').rstrip - # 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 + if uses_systemd_networkd + commands << <<-EOH.gsub(/^ {16}/, '').rstrip + # Configure #{network[:device]} + chmod 0644 '#{remote_path}' && + mv '#{remote_path}' '/etc/systemd/network/#{network[:device]}.network' && + networkctl reload + EOH + else + commands << <<-EOH.gsub(/^ {16}/, '').rstrip + # 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 end # Run all the network modification commands in one communicator call. comm.sudo(commands.join(" && \n")) end