Correctly detect bonded slave interface state
Bonded slave interfaces under Linux were incorrectly being detected as always up. We now check sysfs directly to determine their state.
This commit is contained in:
parent
00c230f4f8
commit
18eaeb45be
@ -59,6 +59,15 @@ def get_bonded_slaves():
|
|||||||
return slaves
|
return slaves
|
||||||
|
|
||||||
|
|
||||||
|
def sysfs_interface_up(interface):
|
||||||
|
try:
|
||||||
|
with open("/sys/class/net/{}/operstate".format(interface)) as f:
|
||||||
|
status = f.read().strip()
|
||||||
|
except FileNotFoundError:
|
||||||
|
raise RuntimeError("Unknown interface {iface}!".format(iface=interface))
|
||||||
|
return status == "up"
|
||||||
|
|
||||||
|
|
||||||
class Network(IntervalModule):
|
class Network(IntervalModule):
|
||||||
"""
|
"""
|
||||||
Display network information about a interface.
|
Display network information about a interface.
|
||||||
@ -113,12 +122,13 @@ class Network(IntervalModule):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
master_info = netifaces.ifaddresses(master)
|
if sysfs_interface_up(self.interface):
|
||||||
for af in (netifaces.AF_INET, netifaces.AF_INET6):
|
master_info = netifaces.ifaddresses(master)
|
||||||
try:
|
for af in (netifaces.AF_INET, netifaces.AF_INET6):
|
||||||
info[af] = master_info[af]
|
try:
|
||||||
except KeyError:
|
info[af] = master_info[af]
|
||||||
pass
|
except KeyError:
|
||||||
|
pass
|
||||||
up = netifaces.AF_INET in info or netifaces.AF_INET6 in info
|
up = netifaces.AF_INET in info or netifaces.AF_INET6 in info
|
||||||
fdict = dict(
|
fdict = dict(
|
||||||
zip_longest(["v4", "v4mask", "v4cidr", "v6", "v6mask", "v6cidr"], [], fillvalue=""))
|
zip_longest(["v4", "v4mask", "v4cidr", "v6", "v6mask", "v6cidr"], [], fillvalue=""))
|
||||||
|
Loading…
Reference in New Issue
Block a user