From bd4d4284c473860b800906e4db889b5a04552d70 Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Tue, 5 Aug 2014 13:02:28 +1000 Subject: [PATCH] Fixes Fedora 20 network issues when virtual On Fedora 20 virtual machines biosdevname command 'Returns 4 if running in a virtual machine.' This patch: - Uses the biosdevname command return value to detect if virtual - Uses /sys/net to get interface names - Might be better solution - Leaves unchanged the original 'bare metal' case - I wonder what for though? Tested with Fedora Cloud image adapted for vagrant-libvirt Fixes issue #4104 --- .../guests/fedora/cap/configure_networks.rb | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/plugins/guests/fedora/cap/configure_networks.rb b/plugins/guests/fedora/cap/configure_networks.rb index f07c8707f..93806c025 100644 --- a/plugins/guests/fedora/cap/configure_networks.rb +++ b/plugins/guests/fedora/cap/configure_networks.rb @@ -14,25 +14,40 @@ module VagrantPlugins def self.configure_networks(machine, networks) network_scripts_dir = machine.guest.capability("network_scripts_dir") + virtual = false interface_names = Array.new - machine.communicate.sudo("/usr/sbin/biosdevname -d | grep Kernel | cut -f2 -d: | sed -e 's/ //;'") do |_, result| - interface_names = result.split("\n") + machine.communicate.sudo("/usr/sbin/biosdevname; echo $?") do |_, result| + virtual = true if result.chomp == '4' end - interface_name_pairs = Array.new - interface_names.each do |interface_name| - machine.communicate.sudo("/usr/sbin/biosdevname --policy=all_ethN -i #{interface_name}") do |_, result| - interface_name_pairs.push([interface_name, result.gsub("\n", "")]) + if virtual + machine.communicate.sudo("ls /sys/class/net | grep -v lo") do |_, result| + interface_names = result.split("\n") end - end - setting_interface_names = networks.map do |network| - "eth#{network[:interface]}" - end + interface_names = networks.map do |network| + "eth#{network[:interface]}" + end + else + machine.communicate.sudo("/usr/sbin/biosdevname -d | grep Kernel | cut -f2 -d: | sed -e 's/ //;'") do |_, result| + interface_names = result.split("\n") + end - interface_name_pairs.each do |interface_name, previous_interface_name| - if setting_interface_names.index(previous_interface_name) == nil - interface_names.delete(interface_name) + interface_name_pairs = Array.new + interface_names.each do |interface_name| + machine.communicate.sudo("/usr/sbin/biosdevname --policy=all_ethN -i #{interface_name}") do |_, result| + interface_name_pairs.push([interface_name, result.gsub("\n", "")]) + end + end + + setting_interface_names = networks.map do |network| + "eth#{network[:interface]}" + end + + interface_name_pairs.each do |interface_name, previous_interface_name| + if setting_interface_names.index(previous_interface_name) == nil + interface_names.delete(interface_name) + end end end