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
@@ -260,6 +260,7 @@ style of Cisco Packet Tracer:
|
|||||||
- **Scope**: *entire network* (one page per site), *location overview* and/or *per rack* (one page per rack). In the rack view, directly connected devices outside the rack appear faded and dashed, with their rack.
|
- **Scope**: *entire network* (one page per site), *location overview* and/or *per rack* (one page per rack). In the rack view, directly connected devices outside the rack appear faded and dashed, with their rack.
|
||||||
- The **location overview** draws one diagram per site with the **locations as nodes** (server room, halls, sub-distributions …). Lines are the physical cables between locations, labelled with count and cable type (e.g. `2× SMF, 4× CAT6a`), so you can follow the cabling from the server room to the last sub-distribution. Locations containing firewalls, routers or core switches are placed at the top; each node shows its parent location and the number of racks and devices. Devices without a location (e.g. radio bridges on the roof) are grouped in a node for their site ("without location").
|
- The **location overview** draws one diagram per site with the **locations as nodes** (server room, halls, sub-distributions …). Lines are the physical cables between locations, labelled with count and cable type (e.g. `2× SMF, 4× CAT6a`), so you can follow the cabling from the server room to the last sub-distribution. Locations containing firewalls, routers or core switches are placed at the top; each node shows its parent location and the number of racks and devices. Devices without a location (e.g. radio bridges on the roof) are grouped in a node for their site ("without location").
|
||||||
- The **cross-site location overview** puts all locations of all sites in scope into **one diagram**; each node shows its site (and parent location), so you can see how buildings and their locations are connected to each other.
|
- The **cross-site location overview** puts all locations of all sites in scope into **one diagram**; each node shows its site (and parent location), so you can see how buildings and their locations are connected to each other.
|
||||||
|
- The **technician version** is meant for third parties (other IT companies, electricians): one diagram per site in which every link is labelled with connection numbers (`#1`, `#2–4`), followed by a table listing **every single connection** with number, device A / port A, cable (label, type, colour, length), patch panels on the way, and device B / port B.
|
||||||
- Each topology gets its **own landscape page** (PDF and Word) and is scaled as large as possible.
|
- Each topology gets its **own landscape page** (PDF and Word) and is scaled as large as possible.
|
||||||
- Provider circuits appear as a cloud, devices of other sites dashed (can be disabled).
|
- Provider circuits appear as a cloud, devices of other sites dashed (can be disabled).
|
||||||
- **Wireless links** (NetBox *Wireless links*, e.g. point-to-point radio bridges) appear as blue dotted lines labelled "Wireless", in the network view as well as in the location overviews.
|
- **Wireless links** (NetBox *Wireless links*, e.g. point-to-point radio bridges) appear as blue dotted lines labelled "Wireless", in the network view as well as in the location overviews.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class CustomerExportConfig(PluginConfig):
|
|||||||
name = "netbox_customer_export"
|
name = "netbox_customer_export"
|
||||||
verbose_name = _("Customer Export")
|
verbose_name = _("Customer Export")
|
||||||
description = _("Export customer documentation as PDF or Word")
|
description = _("Export customer documentation as PDF or Word")
|
||||||
version = "0.19.1"
|
version = "0.20.0"
|
||||||
author = "Claude"
|
author = "Claude"
|
||||||
base_url = "customer-export"
|
base_url = "customer-export"
|
||||||
min_version = "4.6.8"
|
min_version = "4.6.8"
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ class ExportForm(forms.Form):
|
|||||||
("locations", _("Location overview (connections between locations)")),
|
("locations", _("Location overview (connections between locations)")),
|
||||||
("locations_all", _("Cross-site location overview (all locations in one diagram)")),
|
("locations_all", _("Cross-site location overview (all locations in one diagram)")),
|
||||||
("rack", _("Per rack")),
|
("rack", _("Per rack")),
|
||||||
|
("technician", _("Technician version (numbered connections + port list)")),
|
||||||
),
|
),
|
||||||
initial=["site"],
|
initial=["site"],
|
||||||
required=False,
|
required=False,
|
||||||
|
|||||||
Binary file not shown.
@@ -1554,3 +1554,33 @@ msgstr "Einstellungen"
|
|||||||
|
|
||||||
msgid "without location"
|
msgid "without location"
|
||||||
msgstr "ohne Lokation"
|
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")
|
racks = build_graphs(scope, opts, per="rack")
|
||||||
# Rack-Seiten unter einer gemeinsamen Zwischenüberschrift, Racks selbst eine Ebene tiefer (kürzeres Inhaltsverzeichnis)
|
# 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)]
|
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."))
|
return _empty(opts, [title], _("No cabled devices found."))
|
||||||
# Die Abschnittsüberschrift steht mit auf der ersten Seite
|
# Die Abschnittsüberschrift steht mit auf der ersten Seite
|
||||||
return [
|
blocks = [
|
||||||
LANDSCAPE(([title] if i == 0 else []) + headings, render_png(g, show_ports=ports))
|
LANDSCAPE(([title] if i == 0 else []) + headings, render_png(g, show_ports=ports))
|
||||||
for i, (headings, g) in enumerate(pages)
|
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)
|
labels: list = field(default_factory=list)
|
||||||
summary: str = "" # feste Beschriftung statt Port-Namen (z.B. Lokationsübersicht)
|
summary: str = "" # feste Beschriftung statt Port-Namen (z.B. Lokationsübersicht)
|
||||||
wireless: bool = False # nur Funkstrecken (WirelessLink) – blau gepunktet
|
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
|
@dataclass
|
||||||
@@ -91,7 +93,7 @@ def build_graphs(scope, opts, per="site"):
|
|||||||
cache = getattr(scope, "_topology_cache", None)
|
cache = getattr(scope, "_topology_cache", None)
|
||||||
if cache is None:
|
if cache is None:
|
||||||
cache = scope._topology_cache = _collect(scope, opts)
|
cache = scope._topology_cache = _collect(scope, opts)
|
||||||
by_pk, drawn, links, external, wireless = cache
|
by_pk, drawn, links, external, wireless, conns = cache
|
||||||
|
|
||||||
groups = OrderedDict()
|
groups = OrderedDict()
|
||||||
for pk in drawn:
|
for pk in drawn:
|
||||||
@@ -131,7 +133,7 @@ def build_graphs(scope, opts, per="site"):
|
|||||||
kind, icon = drawn[d.pk]
|
kind, icon = drawn[d.pk]
|
||||||
other = Node(nid, d.name or str(d), kind, icon, context(d), external=True)
|
other = Node(nid, d.name or str(d), kind, icon, context(d), external=True)
|
||||||
nodes[nid] = Node(**{**other.__dict__})
|
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"):
|
if not opts.get("topo_isolated"):
|
||||||
linked = {n for e in edges for n in (e.a, e.b)}
|
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)
|
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
|
# Verbindungen: vollständige Kabelpfade (auch über Patchpanels) und Funkstrecken zwischen Interfaces
|
||||||
links = defaultdict(list) # (a, b) -> ["Gi1/0/1 – eth0", …]
|
links = defaultdict(list) # (a, b) -> ["Gi1/0/1 – eth0", …]
|
||||||
kinds = defaultdict(set) # (a, b) -> {"cable", "wireless"}
|
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
|
external = {} # node_id -> Node-Vorlage
|
||||||
ifaces = scope.restrict(
|
ifaces = scope.restrict(
|
||||||
Interface.objects.filter(Q(cable__isnull=False) | Q(wireless_link__isnull=False), device_id__in=list(drawn))
|
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(" – ")))
|
label = " – ".join(reversed(label.split(" – ")))
|
||||||
if label not in links[key]:
|
if label not in links[key]:
|
||||||
links[key].append(label)
|
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")
|
kinds[key].add("cable" if iface.cable_id else "wireless")
|
||||||
|
|
||||||
wireless = {k for k, v in kinds.items() if v == {"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):
|
def build_location_graphs(scope, opts, combined=False):
|
||||||
@@ -460,6 +549,8 @@ def _oriented(graph, e):
|
|||||||
|
|
||||||
|
|
||||||
def _edge_text(graph, e, show_ports):
|
def _edge_text(graph, e, show_ports):
|
||||||
|
if e.numbers:
|
||||||
|
return "#" + _number_text(e.numbers)
|
||||||
if e.summary:
|
if e.summary:
|
||||||
return e.summary
|
return e.summary
|
||||||
if show_ports:
|
if show_ports:
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "netbox-customer-export"
|
name = "netbox-customer-export"
|
||||||
version = "0.19.1"
|
version = "0.20.0"
|
||||||
description = "NetBox plugin: customer documentation (PDF/Word) for sites, locations, tenants and tenant groups"
|
description = "NetBox plugin: customer documentation (PDF/Word) for sites, locations, tenants and tenant groups"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
|
|||||||
Reference in new issue
Block a user