mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-03 06:13:02 +02:00
statd: add speed to op data store and cli
Signed-off-by: Richard Alpe <richard@bit42.se>
This commit is contained in:
committed by
Joachim Wiberg
parent
9ccb6bfd2d
commit
d6928b933c
@@ -51,6 +51,7 @@ class Iface:
|
||||
self.autoneg = self.get_json_data('unknown', 'ieee802-ethernet-interface:ethernet',
|
||||
'auto-negotiation', 'enable')
|
||||
self.duplex = self.get_json_data('', 'ieee802-ethernet-interface:ethernet', 'duplex')
|
||||
self.speed = self.get_json_data('', 'ieee802-ethernet-interface:ethernet', 'speed')
|
||||
self.phys_address = data.get('phys-address', '')
|
||||
|
||||
if data.get('statistics'):
|
||||
@@ -193,6 +194,10 @@ class Iface:
|
||||
if self.duplex:
|
||||
print(f"{'duplex':<{20}}: {self.duplex}")
|
||||
|
||||
if self.speed:
|
||||
mbs = float(self.speed) * 1000
|
||||
print(f"{'speed':<{20}}: {int(mbs)}")
|
||||
|
||||
if self.phys_address:
|
||||
print(f"{'physical address':<{20}}: {self.phys_address}")
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ def add_ethtool_groups(ifname, iface_out):
|
||||
|
||||
def add_ethtool_std(ifname, iface_out):
|
||||
cmd = ['ethtool', ifname]
|
||||
keys = ['Duplex', 'Auto-negotiation']
|
||||
keys = ['Speed', 'Duplex', 'Auto-negotiation']
|
||||
result = {}
|
||||
|
||||
lines = run_cmd(cmd)
|
||||
@@ -315,6 +315,13 @@ def add_ethtool_std(ifname, iface_out):
|
||||
else:
|
||||
insert(iface_out, "ieee802-ethernet-interface:ethernet", "duplex", "unknown")
|
||||
|
||||
if "Speed" in result and result['Speed'] != "Unknown!":
|
||||
# Avoid importing re (performance)
|
||||
num = ''.join(filter(str.isdigit, result['Speed']))
|
||||
if num:
|
||||
num = round((int(num) / 1000), 3)
|
||||
insert(iface_out, "ieee802-ethernet-interface:ethernet", "speed", str(num))
|
||||
|
||||
if __name__ == "__main__":
|
||||
yang_data = {
|
||||
"ietf-interfaces:interfaces": {
|
||||
|
||||
Reference in New Issue
Block a user