[PATCH] Change function that verifies network interface status v2

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@linux.vnet.ibm.com> --- src/kimchi/netinfo.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/kimchi/netinfo.py b/src/kimchi/netinfo.py index 5fd6130..2d5cf29 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,18 @@ def is_bondlave(nic): def operstate(dev): - return open(NET_STATE % dev).readline().strip() + + # try to read interface status + try: + open(NET_STATE % dev).readline().strip() + + # when IOError is raised, interface is down + except IOError: + return "down" + # if value is 1, interface up with cable connected + # 0 corresponds to interface up with cable disconnected + return "up" def get_vlan_device(vlan): """ Return the device of the given VLAN. """ -- 1.8.3.1
participants (2)
-
Aline Manera
-
Ramon Medeiros