driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Failing after 29s
driver / test (3.12) (pull_request) Failing after 20s
driver / test (3.13) (pull_request) Failing after 17s
driver / lowest (pull_request) Failing after 18s
driver / security (pull_request) Failing after 45s
driver / build (pull_request) Successful in 35s
CI / driver (pull_request) Failing after 1m43s
driver / publish (pull_request) Skipped
lldpcli's text was read with 2>/dev/null || true, so lldpd not running, lldpctl missing or the command not running at all came back as a node without neighbours. Capabilities were lldpd's symbols lower-cased (tel, wlan, docsis) rather than NAPALM's names. The node now runs napalm-device-types' LLDPCTL_KEYVALUE_COMMAND, whose output carries lldpctl's exit status; parse_lldpctl_keyvalue raises on a failure, an empty answer raises too, and the lldp_neighbors projections give NAPALM's capability names and the chassis MAC. The module is under strict mypy now; the floor on napalm-device-types rises to 4.24.0. Closes #44
73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
# Copyright 2025 The NetOrk Authors
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
"""LLDP-related NAPALM getters for Proxmox VE nodes.
|
|
|
|
lldpd's neighbours come from ``lldpctl -f keyvalue``, parsed and projected by
|
|
napalm-device-types (``parse_lldpctl_keyvalue``, ``lldp_neighbors``,
|
|
``lldp_neighbors_detail``), as on every host that runs lldpd.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from napalm.base.models import LLDPNeighborDetailDict
|
|
from napalm_device_types import (
|
|
LLDPCTL_KEYVALUE_COMMAND,
|
|
LldpNeighborDict,
|
|
LldpNeighborRow,
|
|
lldp_neighbors,
|
|
lldp_neighbors_detail,
|
|
parse_lldpctl_keyvalue,
|
|
)
|
|
|
|
|
|
class ProxmoxLLDPMixin:
|
|
"""Mixin providing LLDP NAPALM methods."""
|
|
|
|
def get_lldp_neighbors(self) -> dict[str, list[LldpNeighborDict]]:
|
|
"""Return LLDP neighbours (requires lldpd on the Proxmox node).
|
|
|
|
Every neighbour of a port is its own entry; one that names its chassis
|
|
by a MAC address carries it as ``mac``.
|
|
|
|
:raises ValueError: when lldpctl failed or gave no answer.
|
|
"""
|
|
return lldp_neighbors(self._get_lldp_table())
|
|
|
|
def get_lldp_neighbors_detail(
|
|
self, interface: str = ""
|
|
) -> dict[str, list[LLDPNeighborDetailDict]]:
|
|
"""Return detailed LLDP neighbour information, of *interface* only when given.
|
|
|
|
:raises ValueError: when lldpctl failed or gave no answer.
|
|
"""
|
|
return lldp_neighbors_detail(self._get_lldp_table(), interface)
|
|
|
|
def _get_lldp_table(self) -> list[LldpNeighborRow]:
|
|
"""``lldpctl -f keyvalue`` on the node, one row per neighbour.
|
|
|
|
The command always prints lldpctl's exit status, so an empty answer
|
|
means it never ran: that is no answer, not a node without neighbours.
|
|
"""
|
|
raw = self._exec_ssh_command(LLDPCTL_KEYVALUE_COMMAND)
|
|
if not raw.strip():
|
|
raise ValueError("lldpctl gave no answer on the node")
|
|
return parse_lldpctl_keyvalue(raw)
|
|
|
|
if TYPE_CHECKING: # pragma: no cover - the driver's
|
|
|
|
def _exec_ssh_command(self, command: str) -> str: ...
|