feat: per-location cabling topology including patch panels
Draws every cable hop by hop (interfaces, front and rear ports) per top-level location, so trunks from switches over patch panels to sub-distributions become visible. Adds a patch panel symbol. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
cd4357f417
commit
59ffd2a4b5
8 files changed
+153
-8
No files matched your search
@@ -255,7 +255,8 @@ style of Cisco Packet Tracer:
|
||||
- Links come from NetBox **cable paths**; paths through patch panels are traced to the end device.
|
||||
- The top-to-bottom layout follows the cabling: provider → firewall/router → core → access → end devices, with ordering optimised for as few crossings as possible.
|
||||
- Lines are routed **orthogonally** on bus bars, coloured per upstream device. Port names sit at the target device; multiple uplinks are drawn thicker and marked "2×".
|
||||
- **Scope**: *entire network* (one page per site) 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), *per location* 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.
|
||||
- **Per location** shows the **physical cabling hop by hop** instead of end-to-end paths: every cable is a line and patch panels appear as their own nodes, so you see switch → patch panel → trunk → patch panel of the sub-distribution → switch. One diagram per top-level location includes its child locations; each device shows its sub-location and rack.
|
||||
- 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).
|
||||
- Selectable labels: management IP, model, ports on links.
|
||||
@@ -269,12 +270,12 @@ button on device type and device role pages):
|
||||
3. otherwise **automatic**, first by role, then by model and manufacturer
|
||||
|
||||
Built-in symbols: internet/provider, modem/NTU, firewall, router, layer-3
|
||||
switch, switch, radio link, WLAN controller, PoE injector, access point, server,
|
||||
switch, switch, radio link, patch panel, WLAN controller, PoE injector, access point, server,
|
||||
storage/SAN, NAS, tape library, UPS/ATS, PBX, IP phone, PC/client, printer,
|
||||
camera and "other".
|
||||
|
||||
Patch panels, power strips, PDUs, cable management and rooms are hidden
|
||||
automatically; further device types or roles can be hidden via "Hide in
|
||||
automatically (in the per-location view, devices with front/rear ports are drawn as patch panels); further device types or roles can be hidden via "Hide in
|
||||
topology". Custom icons are stored under `MEDIA_ROOT/customer-export/symbols/`.
|
||||
Permissions: object type *Customer Export | Topology symbol*, analogous to
|
||||
branding profiles.
|
||||
|
||||
@@ -5,7 +5,7 @@ class CustomerExportConfig(PluginConfig):
|
||||
name = "netbox_customer_export"
|
||||
verbose_name = "Kunden-Export"
|
||||
description = "Kundendokumentation als PDF oder Word exportieren"
|
||||
version = "0.12.1"
|
||||
version = "0.13.0"
|
||||
author = "Claude"
|
||||
base_url = "customer-export"
|
||||
min_version = "4.6.8"
|
||||
|
||||
@@ -76,7 +76,11 @@ class ExportForm(forms.Form):
|
||||
label="Beschriftung",
|
||||
)
|
||||
topo_scope = forms.MultipleChoiceField(
|
||||
choices=(("site", "Gesamtes Netzwerk (je Standort)"), ("rack", "Je Rack")),
|
||||
choices=(
|
||||
("site", "Gesamtes Netzwerk (je Standort)"),
|
||||
("location", "Je Lokation (Verkabelung inkl. Patchfelder)"),
|
||||
("rack", "Je Rack"),
|
||||
),
|
||||
initial=["site"],
|
||||
required=False,
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
|
||||
@@ -554,7 +554,7 @@ def licenses(scope, opts):
|
||||
|
||||
@section("topology", "Netzwerk-Topologie", "Netzwerk", default=False, hint="Diagramm mit Symbolen, wie Packet Tracer")
|
||||
def topology(scope, opts):
|
||||
from .topology import build_graphs, render_png
|
||||
from .topology import build_graphs, build_location_graphs, render_png
|
||||
|
||||
title = H(1, "Netzwerk-Topologie")
|
||||
scopes = opts.get("topo_scope") or ["site"]
|
||||
@@ -562,6 +562,9 @@ def topology(scope, opts):
|
||||
pages = [] # (Überschriften, Graph) – je eine Querformat-Seite
|
||||
if "site" in scopes:
|
||||
pages += [([H(2, g.title)], g) for g in build_graphs(scope, opts, per="site")]
|
||||
if "location" in scopes:
|
||||
locs = build_location_graphs(scope, opts)
|
||||
pages += [(([H(2, "Verkabelung je Lokation")] if i == 0 else []) + [H(3, g.title)], g) for i, g in enumerate(locs)]
|
||||
if "rack" in scopes:
|
||||
racks = build_graphs(scope, opts, per="rack")
|
||||
# Rack-Seiten unter einer gemeinsamen Zwischenüberschrift, Racks selbst eine Ebene tiefer (kürzeres Inhaltsverzeichnis)
|
||||
|
||||
@@ -14,6 +14,7 @@ KINDS = OrderedDict(
|
||||
("l3switch", ("Layer-3-Switch / Core", 2)),
|
||||
("switch", ("Switch", 3)),
|
||||
("radio", ("Funkstrecke / Richtfunk", 3)),
|
||||
("patchpanel", ("Patchfeld / Rangierverteiler", 3)),
|
||||
("wlc", ("WLAN-Controller", 3)),
|
||||
("poe", ("PoE-Injektor", 4)),
|
||||
("ap", ("Access Point", 4)),
|
||||
@@ -286,6 +287,14 @@ def _draw_ups(d):
|
||||
d.polygon([(62, 70), (50, 88), (58, 88), (54, 102), (70, 82), (62, 82), (68, 70)], fill=(250, 200, 40))
|
||||
|
||||
|
||||
def _draw_patchpanel(d):
|
||||
# flaches 19"-Feld mit zwei Portreihen, bewusst nüchtern (passives Element)
|
||||
_iso_box(d, 8, 58, 104, 92, 14, (96, 104, 114), (150, 158, 168), (74, 82, 92))
|
||||
for row in (64, 78):
|
||||
for i in range(12):
|
||||
d.rectangle([14 + i * 7.5, row, 19 + i * 7.5, row + 7], fill=(40, 46, 54))
|
||||
|
||||
|
||||
def _draw_pbx(d):
|
||||
# Anlage (Box) mit Hörer-Symbol
|
||||
_iso_box(d, 12, 50, 104, 104, 12, (62, 70, 80), (126, 136, 148), (44, 52, 60))
|
||||
@@ -319,6 +328,7 @@ _DRAWERS = {
|
||||
"tape": _draw_tape,
|
||||
"ups": _draw_ups,
|
||||
"pbx": _draw_pbx,
|
||||
"patchpanel": _draw_patchpanel,
|
||||
}
|
||||
|
||||
|
||||
@@ -366,6 +376,11 @@ class SymbolResolver:
|
||||
pass
|
||||
self._icons = {}
|
||||
|
||||
def is_hidden(self, device):
|
||||
"""Per Symbolzuordnung ausdrücklich ausgeblendet?"""
|
||||
sym = self.by_type.get(device.device_type_id) or self.by_role.get(device.role_id)
|
||||
return bool(sym and sym.kind == HIDDEN)
|
||||
|
||||
def resolve(self, device):
|
||||
"""(kind, icon_png_bytes) oder (None, None), wenn das Gerät nicht gezeichnet wird."""
|
||||
sym = self.by_type.get(device.device_type_id) or self.by_role.get(device.role_id)
|
||||
|
||||
@@ -175,7 +175,7 @@
|
||||
<div class="card-body">
|
||||
<div class="ce-label mt-0">Umfang</div>
|
||||
{% include 'netbox_customer_export/_pills.html' with field=form.topo_scope %}
|
||||
<div class="form-text mb-2">„Je Rack“ zeigt zusätzlich jedes Rack einzeln; verbundene Geräte außerhalb erscheinen gestrichelt.</div>
|
||||
<div class="form-text mb-2">„Je Lokation“ zeigt jedes Kabel einzeln, also auch Patchfelder und Trunks zu Unterverteilungen. „Je Rack“ zeigt jedes Rack einzeln. Verbundene Geräte außerhalb erscheinen gestrichelt.</div>
|
||||
<div class="ce-label">Beschriftung</div>
|
||||
{% include 'netbox_customer_export/_pills.html' with field=form.topo_details %}
|
||||
<div class="ce-label">Weiteres</div>
|
||||
|
||||
@@ -206,6 +206,128 @@ def _collect(scope, opts):
|
||||
return by_pk, drawn, links, external
|
||||
|
||||
|
||||
def build_location_graphs(scope, opts):
|
||||
"""Ein Graph je Lokation (inkl. Unterlokationen) mit der physischen Verkabelung Hop für Hop.
|
||||
|
||||
Anders als die Standort-Topologie (vollständige Kabelpfade) zeigt diese Ansicht jedes einzelne Kabel –
|
||||
Patchfelder erscheinen als eigene Knoten, so sieht man Switch → Patchfeld → Trunk → Unterverteilung.
|
||||
"""
|
||||
from dcim.models import FrontPort, Interface, RearPort
|
||||
|
||||
resolver = SymbolResolver()
|
||||
devices = list(
|
||||
scope.devices().filter(location__isnull=False).select_related(
|
||||
"role", "device_type__manufacturer", "site", "location", "rack", "primary_ip4", "primary_ip6"
|
||||
).order_by("location__name", "rack__name", "name")
|
||||
)
|
||||
if not devices:
|
||||
return []
|
||||
ids = [d.pk for d in devices]
|
||||
passive = set(FrontPort.objects.filter(device_id__in=ids).values_list("device_id", flat=True))
|
||||
passive |= set(RearPort.objects.filter(device_id__in=ids).values_list("device_id", flat=True))
|
||||
|
||||
def root_of(d):
|
||||
if scope.kind == "location":
|
||||
return scope.obj
|
||||
return d.location.get_root() if d.location.parent_id else d.location
|
||||
|
||||
def where(d, root):
|
||||
parts = [str(d.location)] if d.location_id != root.pk else []
|
||||
if d.rack_id:
|
||||
parts.append(f"Rack {d.rack.name}")
|
||||
return " · ".join(parts)
|
||||
|
||||
drawn, group_of = {}, {} # pk -> (kind, icon); pk -> Wurzel-Lokation
|
||||
by_pk = {d.pk: d for d in devices}
|
||||
groups = OrderedDict()
|
||||
for d in devices:
|
||||
kind, icon = resolver.resolve(d)
|
||||
if not kind and d.pk in passive and not resolver.is_hidden(d):
|
||||
kind, icon = "patchpanel", builtin_icon("patchpanel")
|
||||
if not kind:
|
||||
continue
|
||||
drawn[d.pk] = (kind, icon)
|
||||
root = root_of(d)
|
||||
group_of[d.pk] = root
|
||||
groups.setdefault(root, []).append(d.pk)
|
||||
|
||||
# Kabel: jedes Kabel wird von beiden Enden gefunden, daher je Knotenpaar sammeln und doppelte Labels verwerfen
|
||||
links = defaultdict(list)
|
||||
outside = {} # node_id -> Node-Vorlage (Gerät/Leitung außerhalb der Lokation)
|
||||
for model in (Interface, FrontPort, RearPort):
|
||||
ports = scope.restrict(model.objects.filter(device_id__in=list(drawn), cable__isnull=False)).select_related("device")
|
||||
for port in ports:
|
||||
try:
|
||||
peers = port.link_peers or []
|
||||
except Exception: # noqa: BLE001
|
||||
continue
|
||||
for peer in peers:
|
||||
a = f"d{port.device_id}"
|
||||
peer_dev = getattr(peer, "device", None)
|
||||
if peer_dev is not None:
|
||||
if peer_dev.pk == port.device_id:
|
||||
continue
|
||||
b = f"d{peer_dev.pk}"
|
||||
if peer_dev.pk not in drawn:
|
||||
if not opts.get("topo_external"):
|
||||
continue
|
||||
kind, icon = resolver.resolve(peer_dev)
|
||||
if not kind:
|
||||
kind, icon = "patchpanel", builtin_icon("patchpanel")
|
||||
loc = getattr(peer_dev, "location", None)
|
||||
outside[b] = Node(b, peer_dev.name or str(peer_dev), kind, icon, [str(loc or peer_dev.site)], external=True)
|
||||
label = f"{port.name} – {peer.name}"
|
||||
elif peer._meta.model_name == "circuittermination":
|
||||
if not opts.get("topo_external"):
|
||||
continue
|
||||
circuit = peer.circuit
|
||||
b = f"c{circuit.pk}"
|
||||
outside[b] = Node(b, str(circuit.provider), "cloud", builtin_icon("cloud"), [str(circuit.cid)], external=True)
|
||||
label = port.name
|
||||
else:
|
||||
continue
|
||||
key = tuple(sorted((a, b)))
|
||||
if key[0] != a:
|
||||
label = " – ".join(reversed(label.split(" – ")))
|
||||
if label not in links[key]:
|
||||
links[key].append(label)
|
||||
|
||||
graphs = []
|
||||
for root, pks in groups.items():
|
||||
nodes = OrderedDict()
|
||||
for pk in pks:
|
||||
d = by_pk[pk]
|
||||
kind, icon = drawn[pk]
|
||||
sub = [w] if (w := where(d, root)) else []
|
||||
nodes[f"d{pk}"] = Node(f"d{pk}", d.name or str(d), kind, icon, sub + _device_sub(d, opts))
|
||||
members = set(nodes)
|
||||
edges = []
|
||||
for (a, b), labels in links.items():
|
||||
in_a, in_b = a in members, b in members
|
||||
if not (in_a or in_b):
|
||||
continue
|
||||
for nid, inside in ((a, in_a), (b, in_b)):
|
||||
if inside:
|
||||
continue
|
||||
tpl = outside.get(nid)
|
||||
if tpl is None: # Gerät im Scope, aber in einer anderen Lokation
|
||||
if not opts.get("topo_external"):
|
||||
break
|
||||
d = by_pk[int(nid[1:])]
|
||||
kind, icon = drawn[d.pk]
|
||||
tpl = Node(nid, d.name or str(d), kind, icon, [str(d.location)], external=True)
|
||||
nodes[nid] = Node(**{**tpl.__dict__})
|
||||
else:
|
||||
edges.append(Edge(a, b, labels))
|
||||
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)
|
||||
if nodes:
|
||||
_layout(nodes, edges)
|
||||
graphs.append(Graph(f"Lokation {root} ({root.site})", nodes, edges))
|
||||
return graphs
|
||||
|
||||
|
||||
# --- Layout -------------------------------------------------------------------
|
||||
|
||||
CELL_W = 174 # Spaltenbreite (enger = Symbole und Schrift im Dokument größer)
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "netbox-customer-export"
|
||||
version = "0.12.1"
|
||||
version = "0.13.0"
|
||||
description = "NetBox-Plugin: Kundendokumentation (PDF/Word) für Standorte, Lokationen, Mandanten und Mandantengruppen"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
Reference in new issue
Block a user