No files matched your search
@@ -48,6 +48,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- `create_vm_from_cloud_init(ssh_public_keys=...)` installs every key, one per
|
||||
line, instead of only the first; a key containing `/` or `+` is no longer
|
||||
refused by Proxmox (#23).
|
||||
- `get_lldp_neighbors()` lists every neighbour of a port: a second neighbour on
|
||||
the same port no longer overwrites the first, and a neighbour that sends no
|
||||
system name is listed with an empty `hostname` instead of being dropped (#22).
|
||||
|
||||
## [0.8.0] - 2026-10-23
|
||||
|
||||
|
||||
@@ -26,26 +26,26 @@ class ProxmoxLLDPMixin:
|
||||
"""Mixin providing LLDP NAPALM methods."""
|
||||
|
||||
def get_lldp_neighbors(self) -> dict[str, list[_JsonDict]]:
|
||||
"""Return LLDP neighbours (requires lldpd on the Proxmox node)."""
|
||||
"""Return LLDP neighbours (requires lldpd on the Proxmox node).
|
||||
|
||||
lldpcli prints one ``Interface:`` block per neighbour, so a port with
|
||||
several neighbours appears once for each of them.
|
||||
"""
|
||||
result: dict[str, list[_JsonDict]] = {}
|
||||
raw = self._exec_ssh_command("lldpcli show neighbors summary 2>/dev/null || true")
|
||||
current_iface = ""
|
||||
current: _JsonDict | None = None
|
||||
for line in raw.splitlines():
|
||||
m_iface = re.match(r"^\s*Interface:\s+(\S+?),?\s", line)
|
||||
if m_iface:
|
||||
current_iface = m_iface.group(1)
|
||||
result.setdefault(current_iface, [])
|
||||
current = {"hostname": "", "port": ""}
|
||||
result.setdefault(m_iface.group(1), []).append(current)
|
||||
continue
|
||||
m_sys = re.match(r"^\s*SysName:\s+(.+)", line)
|
||||
m_port = re.match(r"^\s*PortID:\s+\S+\s+(.+)", line)
|
||||
if m_sys and current_iface:
|
||||
hostname = m_sys.group(1).strip()
|
||||
if result[current_iface]:
|
||||
result[current_iface][-1]["hostname"] = hostname
|
||||
else:
|
||||
result[current_iface].append({"hostname": hostname, "port": ""})
|
||||
if m_port and current_iface and result[current_iface]:
|
||||
result[current_iface][-1]["port"] = m_port.group(1).strip()
|
||||
if m_sys and current is not None:
|
||||
current["hostname"] = m_sys.group(1).strip()
|
||||
if m_port and current is not None:
|
||||
current["port"] = m_port.group(1).strip()
|
||||
return result
|
||||
|
||||
def get_lldp_neighbors_detail(self, interface: str = "") -> dict[str, list[_JsonDict]]:
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"""LLDP neighbours read from lldpd's ``lldpcli show neighbors``."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from napalm_proxmox import ProxmoxDriver
|
||||
|
||||
# lldpd 1.0 output: one "Interface:" block per neighbour, so a port with two
|
||||
# neighbours (a switch and a phone behind it) appears twice. The phone sends
|
||||
# no SysName.
|
||||
TWO_NEIGHBOURS_ON_ONE_PORT = """\
|
||||
-------------------------------------------------------------------------------
|
||||
LLDP neighbors:
|
||||
-------------------------------------------------------------------------------
|
||||
Interface: eno1, via: LLDP, RID: 1, Time: 0 day, 00:10:12
|
||||
Chassis:
|
||||
ChassisID: mac 00:11:22:33:44:55
|
||||
SysName: sw1
|
||||
Port:
|
||||
PortID: ifname gi1/0/1
|
||||
PortDescr: GigabitEthernet1/0/1
|
||||
-------------------------------------------------------------------------------
|
||||
Interface: eno1, via: LLDP, RID: 2, Time: 0 day, 00:01:02
|
||||
Chassis:
|
||||
ChassisID: mac aa:bb:cc:dd:ee:ff
|
||||
Port:
|
||||
PortID: mac aa:bb:cc:dd:ee:ff
|
||||
-------------------------------------------------------------------------------
|
||||
Interface: eno2, via: LLDP, RID: 3, Time: 0 day, 00:10:12
|
||||
Chassis:
|
||||
ChassisID: mac 00:11:22:33:44:66
|
||||
SysName: sw2
|
||||
Port:
|
||||
PortID: ifname gi1/0/2
|
||||
-------------------------------------------------------------------------------
|
||||
"""
|
||||
|
||||
|
||||
def _driver(output: str) -> ProxmoxDriver:
|
||||
d = ProxmoxDriver("pve", "root@pam", "pw")
|
||||
d._exec_ssh_command = lambda command: output
|
||||
return d
|
||||
|
||||
|
||||
class TestGetLldpNeighbors:
|
||||
def test_every_neighbour_on_a_port_is_its_own_entry(self):
|
||||
result = _driver(TWO_NEIGHBOURS_ON_ONE_PORT).get_lldp_neighbors()
|
||||
|
||||
assert result == {
|
||||
"eno1": [
|
||||
{"hostname": "sw1", "port": "gi1/0/1"},
|
||||
{"hostname": "", "port": "aa:bb:cc:dd:ee:ff"},
|
||||
],
|
||||
"eno2": [{"hostname": "sw2", "port": "gi1/0/2"}],
|
||||
}
|
||||
|
||||
def test_no_lldpd_output_is_no_neighbour(self):
|
||||
assert _driver("").get_lldp_neighbors() == {}
|
||||
|
||||
|
||||
class TestGetLldpNeighborsDetail:
|
||||
def test_every_neighbour_on_a_port_is_its_own_entry(self):
|
||||
result = _driver(TWO_NEIGHBOURS_ON_ONE_PORT).get_lldp_neighbors_detail()
|
||||
|
||||
assert [e["remote_system_name"] for e in result["eno1"]] == ["sw1", ""]
|
||||
assert result["eno1"][1]["remote_chassis_id"] == "aa:bb:cc:dd:ee:ff"
|
||||
Reference in new issue
Block a user