From 59474f80fd4f060e0941632d84b9653d13cf38bf Mon Sep 17 00:00:00 2001 From: Trey Tabner Date: Wed, 30 May 2018 10:10:36 -0500 Subject: [PATCH 1/2] Increase priority and support multiple networks --- .../guests/debian/cap/configure_networks.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/guests/debian/cap/configure_networks.rb b/plugins/guests/debian/cap/configure_networks.rb index 6ba4c2ca9..e8bf24e95 100644 --- a/plugins/guests/debian/cap/configure_networks.rb +++ b/plugins/guests/debian/cap/configure_networks.rb @@ -82,11 +82,10 @@ module VagrantPlugins # Configure guest networking using networkd def self.configure_networkd(machine, interfaces, comm, networks) - net_conf = [] - root_device = interfaces.first networks.each do |network| dev_name = interfaces[network[:interface]] + net_conf = [] net_conf << "[Match]" net_conf << "Name=#{dev_name}" net_conf << "[Network]" @@ -106,15 +105,16 @@ module VagrantPlugins else net_conf << "DHCP=yes" end + + remote_path = upload_tmp_file(comm, net_conf.join("\n")) + dest_path = "#{NETWORKD_DIRECTORY}/10-vagrant-#{dev_name}.network" + comm.sudo(["mkdir -p #{NETWORKD_DIRECTORY}", + "mv -f '#{remote_path}' '#{dest_path}'", + "chown root:root '#{dest_path}'", + "chmod 0644 '#{dest_path}'"].join("\n")) end - remote_path = upload_tmp_file(comm, net_conf.join("\n")) - dest_path = "#{NETWORKD_DIRECTORY}/99-vagrant.network" - comm.sudo(["mkdir -p #{NETWORKD_DIRECTORY}", - "mv -f '#{remote_path}' '#{dest_path}'", - "chown root:root '#{dest_path}'", - "chmod 0644 '#{dest_path}'", - "systemctl restart systemd-networkd.service"].join("\n")) + comm.sudo(["systemctl restart systemd-networkd.service"].join("\n")) end # Configure guest networking using net-tools From 91970364992e2bd1dd57f5fe1afc296701617888 Mon Sep 17 00:00:00 2001 From: Trey Tabner Date: Wed, 30 May 2018 11:00:58 -0500 Subject: [PATCH 2/2] The restart command was moved to after the loop --- test/unit/plugins/guests/debian/cap/configure_networks_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/plugins/guests/debian/cap/configure_networks_test.rb b/test/unit/plugins/guests/debian/cap/configure_networks_test.rb index 13ccea1b6..c0a0a91a7 100644 --- a/test/unit/plugins/guests/debian/cap/configure_networks_test.rb +++ b/test/unit/plugins/guests/debian/cap/configure_networks_test.rb @@ -111,7 +111,7 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do expect(comm.received_commands[0]).to match("mv -f '/tmp/vagrant-network-entry.*' '/etc/systemd/network/.*network'") expect(comm.received_commands[0]).to match("chown") expect(comm.received_commands[0]).to match("chmod") - expect(comm.received_commands[0]).to match("systemctl restart") + expect(comm.received_commands[2]).to match("systemctl restart") end end