refactor(lldp): take the neighbour MAC from the shared projection
napalm-device-types' lldp_neighbors now carries the chassis MAC as mac when the chassis id is a MAC address, the rule this driver applied itself. The getter uses the projection, so linux and openwrt report neighbours the same way.
This commit is contained in:
1 parent
3d2de27988
commit
a3d95d72b9
2 files changed
+5
-12
No files matched your search
+4
-11
@@ -38,6 +38,7 @@ from napalm_device_types import (
|
|||||||
HostStatusMixin,
|
HostStatusMixin,
|
||||||
KernelFactsMixin,
|
KernelFactsMixin,
|
||||||
ListeningSocketsMixin,
|
ListeningSocketsMixin,
|
||||||
|
LldpNeighborDict,
|
||||||
OpenSshServerMixin,
|
OpenSshServerMixin,
|
||||||
OSDriver,
|
OSDriver,
|
||||||
ServiceClustersMixin,
|
ServiceClustersMixin,
|
||||||
@@ -47,6 +48,7 @@ from napalm_device_types import (
|
|||||||
SystemdUnavailable,
|
SystemdUnavailable,
|
||||||
SystemIdentityMixin,
|
SystemIdentityMixin,
|
||||||
VirtualIpsMixin,
|
VirtualIpsMixin,
|
||||||
|
lldp_neighbors,
|
||||||
open_stream_on_transport,
|
open_stream_on_transport,
|
||||||
parse_apt_upgradable,
|
parse_apt_upgradable,
|
||||||
parse_dnf_security,
|
parse_dnf_security,
|
||||||
@@ -130,8 +132,6 @@ _DNF_RC_RE = re.compile(r"^__DNF_RC=(\d+)\s*$", re.MULTILINE)
|
|||||||
#: cannot take the restart with it.
|
#: cannot take the restart with it.
|
||||||
#: lldpd's neighbours; a failure prints nothing and reads as none, as before (#58).
|
#: lldpd's neighbours; a failure prints nothing and reads as none, as before (#58).
|
||||||
_LLDPCTL_COMMAND = "lldpctl -f keyvalue 2>/dev/null || true"
|
_LLDPCTL_COMMAND = "lldpctl -f keyvalue 2>/dev/null || true"
|
||||||
#: A chassis id lldpd names ``mac`` that really is one.
|
|
||||||
_MAC_RE = re.compile(r"^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$")
|
|
||||||
_REBOOT_DETACHED = "sh -c '(trap \"\" HUP; sleep 2; /sbin/reboot) </dev/null >/dev/null 2>&1 &'"
|
_REBOOT_DETACHED = "sh -c '(trap \"\" HUP; sleep 2; /sbin/reboot) </dev/null >/dev/null 2>&1 &'"
|
||||||
|
|
||||||
#: Why ``run_command`` refuses stdin to a privileged command while a sudo
|
#: Why ``run_command`` refuses stdin to a privileged command while a sudo
|
||||||
@@ -765,7 +765,7 @@ class LinuxDriver(
|
|||||||
except (IndexError, ValueError):
|
except (IndexError, ValueError):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def get_lldp_neighbors(self) -> dict[str, list[dict[str, Any]]]:
|
def get_lldp_neighbors(self) -> dict[str, list[LldpNeighborDict]]:
|
||||||
"""Return LLDP neighbors if lldpd is installed and currently running.
|
"""Return LLDP neighbors if lldpd is installed and currently running.
|
||||||
|
|
||||||
Uses ``lldpctl -f keyvalue``, parsed by napalm-device-types: every
|
Uses ``lldpctl -f keyvalue``, parsed by napalm-device-types: every
|
||||||
@@ -786,14 +786,7 @@ class LinuxDriver(
|
|||||||
if "active" not in running:
|
if "active" not in running:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
output = self._send(_LLDPCTL_COMMAND)
|
return lldp_neighbors(parse_lldpctl_keyvalue(self._send(_LLDPCTL_COMMAND)))
|
||||||
neighbors: dict[str, list[dict[str, Any]]] = {}
|
|
||||||
for row in parse_lldpctl_keyvalue(output):
|
|
||||||
entry: dict[str, Any] = {"hostname": row["system_name"], "port": row["port_id"]}
|
|
||||||
if row["chassis_id_type"] == "mac" and _MAC_RE.match(row["chassis_id"]):
|
|
||||||
entry["mac"] = row["chassis_id"].lower()
|
|
||||||
neighbors.setdefault(row["local_port"], []).append(entry)
|
|
||||||
return neighbors
|
|
||||||
|
|
||||||
def get_interfaces(self) -> dict[str, Any]:
|
def get_interfaces(self) -> dict[str, Any]:
|
||||||
"""Return interface operational data."""
|
"""Return interface operational data."""
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"napalm_linux.linux"
|
"napalm_linux.linux"
|
||||||
],
|
],
|
||||||
"python_file_lines": {
|
"python_file_lines": {
|
||||||
"napalm_linux/linux.py": 2129
|
"napalm_linux/linux.py": 2122
|
||||||
},
|
},
|
||||||
"untyped_public": []
|
"untyped_public": []
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user