Prune links a scanned switch no longer reports

Dept scans don't clear links first, so when a port was re-cabled (e.g. a
new switch inserted on an existing uplink) the old link stayed alongside
the new one. After storing a switch's neighbors, prune_stale_links() now
deletes any link on that switch that its own LLDP table doesn't back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dcstephenson
2026-10-01 14:56:10 -05:00
parent a84c09d9cd
commit e589f76387
2 changed files with 35 additions and 1 deletions
+5 -1
View File
@@ -4,7 +4,7 @@ import threading
from nocodb_client import get_switches
from ssh_client import scan_all_switches
from db import (
upsert_switch, upsert_link, clear_links,
upsert_switch, upsert_link, clear_links, prune_stale_links,
log_scan_start, log_scan_finish, merge_duplicate_switches
)
from parser import parse_neighbor_description
@@ -126,6 +126,10 @@ def run_scan(dept: str = None, workers: int = 5, login_delay: int = 3):
chassis_b=neighbor["chassis_id"],
port_b=neighbor["remote_port"],
)
prune_stale_links(
result["chassis_id"],
{(n["local_port"], n["chassis_id"]) for n in result["neighbors"]},
)
else:
scan_state["fail"] += 1
error = result.get("error", "Unknown error")