[Kimchi-devel] [PATCH] Change function that verifies network interface status
Ramon Medeiros
ramonn at linux.vnet.ibm.com
Wed Aug 20 14:58:31 UTC 2014
LTC Bugzilla #115031 - LTCTest: build-8: List interfaces which are
active
The old way does just consider if the interface has connectivity, not
the interface status. The new file can determine if the interface is up
or down and if cable is connected or not.
Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
---
src/kimchi/netinfo.py | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/netinfo.py b/src/kimchi/netinfo.py
index 5fd6130..276c0b7 100644
--- a/src/kimchi/netinfo.py
+++ b/src/kimchi/netinfo.py
@@ -29,7 +29,7 @@ BONDING_PATH = '/sys/class/net/*/bonding'
WLAN_PATH = '/sys/class/net/*/wireless'
NET_BRPORT = '/sys/class/net/%s/brport'
NET_MASTER = '/sys/class/net/%s/master'
-NET_STATE = '/sys/class/net/%s/operstate'
+NET_STATE = '/sys/class/net/%s/carrier'
PROC_NET_VLAN = '/proc/net/vlan/'
BONDING_SLAVES = '/sys/class/net/%s/bonding/slaves'
BRIDGE_PORTS = '/sys/class/net/%s/brif'
@@ -101,8 +101,21 @@ def is_bondlave(nic):
def operstate(dev):
- return open(NET_STATE % dev).readline().strip()
+ status = None
+
+ # try to read interface status
+ try:
+ status = open(NET_STATE % dev).readline().strip()
+ except IOError:
+ pass
+
+ # when IOError is raised, interface is down
+ if status == None:
+ return "down"
+ # if value is 1, cable is connected
+ # 0 corresponds to no interface up with no cable
+ return "up"
def get_vlan_device(vlan):
""" Return the device of the given VLAN. """
--
1.8.3.1
More information about the Kimchi-devel
mailing list