driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 28s
driver / types (pull_request) Failing after 30s
driver / test (3.13) (pull_request) Failing after 15s
driver / test (3.12) (pull_request) Failing after 17s
driver / lowest (pull_request) Failing after 18s
driver / build (pull_request) Successful in 35s
driver / security (pull_request) Failing after 40s
CI / driver (pull_request) Failing after 1m41s
driver / publish (pull_request) Skipped
lldpd tells the chassis MAC, but get_lldp_neighbors reported only name and port, so netOrk, which matches a neighbour by MAC first, could match OpenWrt's neighbours by name only. napalm-device-types' lldp_neighbors projection now carries mac (lower case) when the chassis id is a MAC address, as napalm-linux reports it. Closes #31
64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
# 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.
|
|
|
|
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 OpenWrtLLDPMixin:
|
|
"""Mixin providing LLDP NAPALM getters."""
|
|
|
|
def get_lldp_neighbors(self) -> dict[str, list[LldpNeighborDict]]:
|
|
"""Return LLDP neighbors (requires ``lldpd`` installed and running on the device).
|
|
|
|
A neighbour that names its chassis by a MAC address carries it as ``mac``.
|
|
|
|
Uses ``lldpctl -f keyvalue`` output::
|
|
|
|
lldp.eth0.port.ifname=eth1
|
|
lldp.eth0.chassis.name=router-core
|
|
"""
|
|
return lldp_neighbors(self._get_lldp_table())
|
|
|
|
def _get_lldp_table(self) -> list[LldpNeighborRow]:
|
|
"""``lldpctl -f keyvalue`` as one row per neighbour.
|
|
|
|
Reads only: lldpd is neither started nor reconfigured here. Installing,
|
|
starting and configuring it are the caller's (``ensure_package``,
|
|
``manage_service``).
|
|
|
|
:raises ValueError: when lldpctl failed (not installed, lldpd not
|
|
running): that is no answer, not a port without neighbours.
|
|
"""
|
|
return parse_lldpctl_keyvalue(self._send_command(LLDPCTL_KEYVALUE_COMMAND))
|
|
|
|
def get_lldp_neighbors_detail(
|
|
self, interface: str = ""
|
|
) -> dict[str, list[LLDPNeighborDetailDict]]:
|
|
"""Return detailed LLDP neighbor info."""
|
|
return lldp_neighbors_detail(self._get_lldp_table(), interface)
|
|
|
|
if TYPE_CHECKING: # pragma: no cover - the driver's
|
|
|
|
def _send_command(self, command: str | list[str]) -> str: ...
|