feat: technician topology with numbered connections and full port list
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
27673ee68f
commit
677590f52c
8 files changed
+145
-7
No files matched your search
@@ -6,7 +6,7 @@ class CustomerExportConfig(PluginConfig):
|
||||
name = "netbox_customer_export"
|
||||
verbose_name = _("Customer Export")
|
||||
description = _("Export customer documentation as PDF or Word")
|
||||
version = "0.19.1"
|
||||
version = "0.20.0"
|
||||
author = "Claude"
|
||||
base_url = "customer-export"
|
||||
min_version = "4.6.8"
|
||||
|
||||
@@ -82,6 +82,7 @@ class ExportForm(forms.Form):
|
||||
("locations", _("Location overview (connections between locations)")),
|
||||
("locations_all", _("Cross-site location overview (all locations in one diagram)")),
|
||||
("rack", _("Per rack")),
|
||||
("technician", _("Technician version (numbered connections + port list)")),
|
||||
),
|
||||
initial=["site"],
|
||||
required=False,
|
||||
|
||||
Binary file not shown.
@@ -1554,3 +1554,33 @@ msgstr "Einstellungen"
|
||||
|
||||
msgid "without location"
|
||||
msgstr "ohne Lokation"
|
||||
|
||||
msgid "Technician version (numbered connections + port list)"
|
||||
msgstr "Techniker-Version (nummerierte Verbindungen + Portliste)"
|
||||
|
||||
msgid "Technician version"
|
||||
msgstr "Techniker-Version"
|
||||
|
||||
msgid "Connections – %(name)s"
|
||||
msgstr "Verbindungen – %(name)s"
|
||||
|
||||
msgid "No."
|
||||
msgstr "Nr."
|
||||
|
||||
msgid "Device A"
|
||||
msgstr "Gerät A"
|
||||
|
||||
msgid "Port A"
|
||||
msgstr "Port A"
|
||||
|
||||
msgid "Device B"
|
||||
msgstr "Gerät B"
|
||||
|
||||
msgid "Port B"
|
||||
msgstr "Port B"
|
||||
|
||||
msgid "Via (patch panel)"
|
||||
msgstr "Über (Patchpanel)"
|
||||
|
||||
msgid "Circuit"
|
||||
msgstr "Leitung"
|
||||
@@ -624,10 +624,25 @@ def topology(scope, opts):
|
||||
racks = build_graphs(scope, opts, per="rack")
|
||||
# Rack-Seiten unter einer gemeinsamen Zwischenüberschrift, Racks selbst eine Ebene tiefer (kürzeres Inhaltsverzeichnis)
|
||||
pages += [(([H(2, _("Topology per rack"))] if i == 0 else []) + [H(3, g.title)], g) for i, g in enumerate(racks)]
|
||||
if not pages:
|
||||
tech = [] # Techniker-Ansicht: nummerierte Verbindungen + vollständige Portliste je Standort
|
||||
if "technician" in scopes:
|
||||
from .topology import number_connections
|
||||
|
||||
for i, g in enumerate(build_graphs(scope, opts, per="site")):
|
||||
rows = number_connections(g)
|
||||
head = ([H(2, _("Technician version"))] if i == 0 else []) + [H(3, g.title)]
|
||||
tech.append((head, g, rows))
|
||||
if not pages and not tech:
|
||||
return _empty(opts, [title], _("No cabled devices found."))
|
||||
# Die Abschnittsüberschrift steht mit auf der ersten Seite
|
||||
return [
|
||||
blocks = [
|
||||
LANDSCAPE(([title] if i == 0 else []) + headings, render_png(g, show_ports=ports))
|
||||
for i, (headings, g) in enumerate(pages)
|
||||
]
|
||||
headers = [_("No."), _("Device A"), _("Port A"), _("Cable"), _("Via (patch panel)"), _("Device B"), _("Port B")]
|
||||
for head, g, rows in tech:
|
||||
if not blocks:
|
||||
head = [title] + head
|
||||
blocks.append(LANDSCAPE(head, render_png(g)))
|
||||
blocks += [H(4, _("Connections – %(name)s") % {"name": g.title}), T(headers, rows)]
|
||||
return blocks
|
||||
@@ -33,6 +33,8 @@ class Edge:
|
||||
labels: list = field(default_factory=list)
|
||||
summary: str = "" # feste Beschriftung statt Port-Namen (z.B. Lokationsübersicht)
|
||||
wireless: bool = False # nur Funkstrecken (WirelessLink) – blau gepunktet
|
||||
conns: list = field(default_factory=list) # Einzelverbindungen (Techniker-Ansicht), aus Sicht von a
|
||||
numbers: list = field(default_factory=list) # laufende Nummern der Einzelverbindungen (Techniker-Ansicht)
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -91,7 +93,7 @@ def build_graphs(scope, opts, per="site"):
|
||||
cache = getattr(scope, "_topology_cache", None)
|
||||
if cache is None:
|
||||
cache = scope._topology_cache = _collect(scope, opts)
|
||||
by_pk, drawn, links, external, wireless = cache
|
||||
by_pk, drawn, links, external, wireless, conns = cache
|
||||
|
||||
groups = OrderedDict()
|
||||
for pk in drawn:
|
||||
@@ -131,7 +133,7 @@ def build_graphs(scope, opts, per="site"):
|
||||
kind, icon = drawn[d.pk]
|
||||
other = Node(nid, d.name or str(d), kind, icon, context(d), external=True)
|
||||
nodes[nid] = Node(**{**other.__dict__})
|
||||
edges.append(Edge(a, b, labels, wireless=(a, b) in wireless))
|
||||
edges.append(Edge(a, b, labels, wireless=(a, b) in wireless, conns=conns.get((a, b), [])))
|
||||
if not opts.get("topo_isolated"):
|
||||
linked = {n for e in edges for n in (e.a, e.b)}
|
||||
nodes = OrderedDict((k, v) for k, v in nodes.items() if k in linked)
|
||||
@@ -167,6 +169,7 @@ def _collect(scope, opts):
|
||||
# Verbindungen: vollständige Kabelpfade (auch über Patchpanels) und Funkstrecken zwischen Interfaces
|
||||
links = defaultdict(list) # (a, b) -> ["Gi1/0/1 – eth0", …]
|
||||
kinds = defaultdict(set) # (a, b) -> {"cable", "wireless"}
|
||||
conns = defaultdict(list) # (a, b) -> [Einzelverbindung als dict], für die Techniker-Ansicht
|
||||
external = {} # node_id -> Node-Vorlage
|
||||
ifaces = scope.restrict(
|
||||
Interface.objects.filter(Q(cable__isnull=False) | Q(wireless_link__isnull=False), device_id__in=list(drawn))
|
||||
@@ -210,10 +213,96 @@ def _collect(scope, opts):
|
||||
label = " – ".join(reversed(label.split(" – ")))
|
||||
if label not in links[key]:
|
||||
links[key].append(label)
|
||||
peer_name = label.split(" – ", 1)[1] if model == "interface" else ""
|
||||
c = _connection(iface, ep, peer_name)
|
||||
if key[0] != a:
|
||||
c = _flip(c)
|
||||
conns[key].append(c)
|
||||
kinds[key].add("cable" if iface.cable_id else "wireless")
|
||||
|
||||
wireless = {k for k, v in kinds.items() if v == {"wireless"}}
|
||||
return by_pk, drawn, links, external, wireless
|
||||
return by_pk, drawn, links, external, wireless, conns
|
||||
|
||||
|
||||
def _connection(iface, ep, peer_port):
|
||||
"""Eine Port-zu-Port-Verbindung mit Kabeldaten und Zwischenstationen (Patchpanels)."""
|
||||
cable = iface.cable
|
||||
model = ep._meta.model_name
|
||||
if model == "interface":
|
||||
peer = ep.device.name or str(ep.device)
|
||||
elif model == "circuittermination" and getattr(ep, "circuit", None):
|
||||
peer = f"{ep.circuit.provider} {ep.circuit.cid}"
|
||||
peer_port = _("Circuit")
|
||||
else:
|
||||
peer = str(ep)
|
||||
cable_parts = []
|
||||
if cable is not None:
|
||||
cable_parts.append(cable.label or f"#{cable.pk}")
|
||||
if cable.type:
|
||||
cable_parts.append(cable.get_type_display())
|
||||
if cable.color:
|
||||
cable_parts.append(cable.get_color_display() if hasattr(cable, "get_color_display") else cable.color)
|
||||
if cable.length:
|
||||
from .sections import num
|
||||
|
||||
cable_parts.append(f"{num(cable.length)} {cable.get_length_unit_display() if cable.length_unit else ''}".strip())
|
||||
elif iface.wireless_link_id:
|
||||
wl = iface.wireless_link
|
||||
cable_parts.append(_("Wireless") + (f" {wl.ssid}" if getattr(wl, "ssid", "") else ""))
|
||||
via = []
|
||||
try:
|
||||
for _near, _cables, far in iface.trace():
|
||||
for obj in far or []:
|
||||
if obj._meta.model_name in ("frontport", "rearport"):
|
||||
via.append(f"{obj.device} {obj.name}")
|
||||
except Exception: # noqa: BLE001 – Pfad nicht verfolgbar
|
||||
via = []
|
||||
return {
|
||||
"a_dev": iface.device.name or str(iface.device), "a_port": iface.name,
|
||||
"b_dev": peer, "b_port": peer_port, "cable": ", ".join(str(x) for x in cable_parts), "via": via,
|
||||
}
|
||||
|
||||
|
||||
def _flip(c):
|
||||
return {**c, "a_dev": c["b_dev"], "a_port": c["b_port"], "b_dev": c["a_dev"], "b_port": c["a_port"], "via": list(reversed(c["via"]))}
|
||||
|
||||
|
||||
def number_connections(graph):
|
||||
"""Techniker-Ansicht: alle Einzelverbindungen durchnummerieren (von oben nach unten, links nach rechts).
|
||||
|
||||
Liefert die Tabellenzeilen; jede Kante merkt sich ihre Nummern für die Beschriftung im Diagramm.
|
||||
"""
|
||||
nodes = graph.nodes
|
||||
|
||||
def pos(e):
|
||||
a, b = nodes[e.a], nodes[e.b]
|
||||
top, low = sorted(((a.row, a.x), (b.row, b.x)))
|
||||
return top, low
|
||||
|
||||
rows, n = [], 0
|
||||
for e in sorted(graph.edges, key=pos):
|
||||
a, b = nodes[e.a], nodes[e.b]
|
||||
flip = (a.row, a.x) > (b.row, b.x)
|
||||
conns = e.conns or [{"a_dev": a.label, "a_port": "", "b_dev": b.label, "b_port": "", "cable": "", "via": []}]
|
||||
e.numbers = []
|
||||
for c in conns:
|
||||
c = _flip(c) if flip else c
|
||||
n += 1
|
||||
e.numbers.append(n)
|
||||
rows.append([n, c["a_dev"], c["a_port"], c["cable"], " → ".join(c["via"]), c["b_dev"], c["b_port"]])
|
||||
return rows
|
||||
|
||||
|
||||
def _number_text(numbers):
|
||||
"""[1, 2, 3, 5] -> „1–3, 5“."""
|
||||
parts, start = [], None
|
||||
for i, n in enumerate(numbers):
|
||||
if start is None:
|
||||
start = n
|
||||
if i + 1 == len(numbers) or numbers[i + 1] != n + 1:
|
||||
parts.append(str(start) if start == n else f"{start}–{n}")
|
||||
start = None
|
||||
return ", ".join(parts)
|
||||
|
||||
|
||||
def build_location_graphs(scope, opts, combined=False):
|
||||
@@ -460,6 +549,8 @@ def _oriented(graph, e):
|
||||
|
||||
|
||||
def _edge_text(graph, e, show_ports):
|
||||
if e.numbers:
|
||||
return "#" + _number_text(e.numbers)
|
||||
if e.summary:
|
||||
return e.summary
|
||||
if show_ports:
|
||||
|
||||
Reference in new issue
Block a user