diff --git a/napalm_linux/linux.py b/napalm_linux/linux.py index c2a4ac9..8fa5c34 100644 --- a/napalm_linux/linux.py +++ b/napalm_linux/linux.py @@ -38,6 +38,7 @@ from napalm_device_types import ( HostStatusMixin, KernelFactsMixin, ListeningSocketsMixin, + LldpNeighborDict, OpenSshServerMixin, OSDriver, ServiceClustersMixin, @@ -47,6 +48,7 @@ from napalm_device_types import ( SystemdUnavailable, SystemIdentityMixin, VirtualIpsMixin, + lldp_neighbors, open_stream_on_transport, parse_apt_upgradable, 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. #: lldpd's neighbours; a failure prints nothing and reads as none, as before (#58). _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 2>&1 &'" #: Why ``run_command`` refuses stdin to a privileged command while a sudo @@ -765,7 +765,7 @@ class LinuxDriver( except (IndexError, ValueError): 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. Uses ``lldpctl -f keyvalue``, parsed by napalm-device-types: every @@ -786,14 +786,7 @@ class LinuxDriver( if "active" not in running: return {} - output = 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 + return lldp_neighbors(parse_lldpctl_keyvalue(self._send(_LLDPCTL_COMMAND))) def get_interfaces(self) -> dict[str, Any]: """Return interface operational data.""" diff --git a/tests/quality_baseline.json b/tests/quality_baseline.json index b0037df..804a6f3 100644 --- a/tests/quality_baseline.json +++ b/tests/quality_baseline.json @@ -21,7 +21,7 @@ "napalm_linux.linux" ], "python_file_lines": { - "napalm_linux/linux.py": 2129 + "napalm_linux/linux.py": 2122 }, "untyped_public": [] }