From 71361290d2131359769fca3c20897a74ff7230ef Mon Sep 17 00:00:00 2001 From: "Vladimir Sharshov (warpc)" Date: Tue, 10 Nov 2015 16:40:54 +0300 Subject: [PATCH] New way to get list of all physical ethernet interfaces Changes: * support predictable network interfaces naming based [0] * better and more reliable way to detect non-virtual, not a wireless ethernet interfaces. * support old and new Ruby version (1.8.7+) [0] http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames Co-Authored-By: Alexei Sheplyakov Change-Id: Ia61b23beaef38d3d74bf195d58c1e30dac690b7f Closes-Bug: #1502198 (cherry picked from commit 3e9d17211d65c80bf97c8d83979979f6c7feb687) --- agent | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/agent b/agent index 3bbe102..b5ae4e2 100755 --- a/agent +++ b/agent @@ -28,6 +28,8 @@ require 'ipaddr' require 'rethtool' require 'digest' require 'timeout' +# TODO(vsharshov): replace below lines by this string after excluding Ruby 1.8 +require 'pathname' unless Process.euid == 0 puts "You must be root" @@ -268,11 +270,15 @@ class NodeAgent begin (@os[:network][:interfaces] or {} rescue {}).each do |int, intinfo| # Send info about physical interfaces only - next if intinfo[:type] !~ /^eth.*/ - # Exception: eth0.0(example) have "type" => "eth" but it is not physical interface - next if int =~ /\d+\.\d+$/ or int =~ /vlan\d+$/ - # Remove interfaces like eth0.101-hapr, eth1-hapr - next if int =~ /\d+-.+/ + + next if intinfo[:encapsulation] !~ /^Ethernet.*/ + # Avoid virtual devices like loopback, tunnels, bonding, vlans ... + # TODO(vsharshov): replace below lines by this string after excluding Ruby 1.8 + # next if File.realpath("/sys/class/net/#{int}") =~ /virtual/ + next if Pathname.new("/sys/class/net/#{int}").realpath.to_s =~ /virtual/ + # Avoid wireless + next if File.exist?("/sys/class/net/#{int}/phy80211") || + File.exist?("/sys/class/net/#{int}/wireless") int_meta = {:name => int} int_meta[:state] = intinfo[:state]