Compare commits
5
Commits
38b3ec2a27
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
677590f52c | ||
|
|
27673ee68f | ||
|
|
174a41e838 | ||
|
|
d7c86289b1 | ||
|
|
9735164da1 |
No files matched your search
@@ -39,7 +39,7 @@ All queries respect NetBox permissions (`.restrict(user, "view")`) — a
|
||||
technician only exports what they are allowed to see.
|
||||
|
||||
Open it via the **Customer Docs** button on site, location, tenant and tenant
|
||||
group pages, or via **Plugins → Customer Documentation**. Output formats:
|
||||
group pages, or via **Customer Export → Customer Documentation** in the main navigation. Output formats:
|
||||
**PDF**, **Word** and **HTML preview** (opens in a new tab).
|
||||
|
||||
## Compatibility
|
||||
@@ -182,7 +182,7 @@ sudo systemctl restart netbox netbox-rq
|
||||
|
||||
### Branding in NetBox (recommended)
|
||||
|
||||
Under **Plugins → Branding profiles**, admins create design profiles directly in NetBox:
|
||||
Under **Customer Export → Branding Profiles**, admins create design profiles directly in NetBox:
|
||||
|
||||
- name, company name, footer and **logo upload** (PNG/JPG)
|
||||
- colours via colour picker: primary, accent, table header text, labels, zebra stripes
|
||||
@@ -258,13 +258,16 @@ style of Cisco Packet Tracer:
|
||||
- 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), *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.
|
||||
- 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 **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.
|
||||
- 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.
|
||||
- Selectable labels: management IP, model, ports on links.
|
||||
- Device names longer than 15 characters are wrapped, preferably at `-`, `_`, `.` or spaces.
|
||||
|
||||
**Symbols** (menu **Plugins → Topology symbols**, or the "Topology symbol"
|
||||
**Symbols** (menu **Customer Export → Topology Symbols**, or the "Topology symbol"
|
||||
button on device type and device role pages):
|
||||
|
||||
1. per **device type**: choose a built-in symbol or **upload a custom icon** (PNG/JPG, ideally transparent)
|
||||
|
||||
@@ -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.17.0"
|
||||
version = "0.20.0"
|
||||
author = "Claude"
|
||||
base_url = "customer-export"
|
||||
min_version = "4.6.8"
|
||||
|
||||
@@ -80,7 +80,9 @@ class ExportForm(forms.Form):
|
||||
choices=(
|
||||
("site", _("Whole network (per site)")),
|
||||
("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.
@@ -1507,13 +1507,16 @@ msgstr "vCPU je Kern"
|
||||
|
||||
msgid ""
|
||||
"“Location overview” shows all locations of a site and the cables between "
|
||||
"them, from the server room to the last sub-distribution. “Per rack” shows "
|
||||
"each rack separately. Connected devices outside appear dashed."
|
||||
"them, from the server room to the last sub-distribution. “Cross-site” "
|
||||
"combines all sites in one diagram to show how buildings and their locations "
|
||||
"are connected. “Per rack” shows each rack separately. Connected devices "
|
||||
"outside appear dashed."
|
||||
msgstr ""
|
||||
"„Lokationsübersicht“ zeigt alle Lokationen eines Standorts und die Kabel "
|
||||
"zwischen ihnen, vom Serverraum bis zur letzten Unterverteilung. „Je Rack“ "
|
||||
"zeigt jedes Rack einzeln. Verbundene Geräte außerhalb erscheinen "
|
||||
"gestrichelt."
|
||||
"zwischen ihnen, vom Serverraum bis zur letzten Unterverteilung. "
|
||||
"„Standortübergreifend“ fasst alle Standorte in einem Diagramm zusammen, um "
|
||||
"zu sehen, wie Gebäude und ihre Lokationen verbunden sind. „Je Rack“ zeigt "
|
||||
"jedes Rack einzeln. Verbundene Geräte außerhalb erscheinen gestrichelt."
|
||||
|
||||
msgid "%(n)d device"
|
||||
msgid_plural "%(n)d devices"
|
||||
@@ -1529,3 +1532,55 @@ msgid "%(n)d rack"
|
||||
msgid_plural "%(n)d racks"
|
||||
msgstr[0] "%(n)d Rack"
|
||||
msgstr[1] "%(n)d Racks"
|
||||
|
||||
msgid "Cross-site location overview (all locations in one diagram)"
|
||||
msgstr ""
|
||||
"Lokationsübersicht standortübergreifend (alle Lokationen in einem Diagramm)"
|
||||
|
||||
msgid "Cross-site location overview"
|
||||
msgstr "Standortübergreifende Lokationsübersicht"
|
||||
|
||||
msgid "All sites"
|
||||
msgstr "Alle Standorte"
|
||||
|
||||
msgid "Wireless"
|
||||
msgstr "Funk"
|
||||
|
||||
msgid "Export"
|
||||
msgstr "Export"
|
||||
|
||||
msgid "Settings"
|
||||
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"
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from netbox.plugins import PluginMenuButton, PluginMenuItem
|
||||
from netbox.plugins import PluginMenu, PluginMenuButton, PluginMenuItem
|
||||
|
||||
menu_items = (
|
||||
_items = (
|
||||
PluginMenuItem(
|
||||
link="plugins:netbox_customer_export:select",
|
||||
link_text=_("Customer Documentation"),
|
||||
@@ -34,3 +34,13 @@ menu_items = (
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
# Eigener Eintrag im obersten Navigationsmenü statt unter „Plugins“
|
||||
menu = PluginMenu(
|
||||
label=_("Customer Export"),
|
||||
groups=(
|
||||
(_("Export"), _items[:1]),
|
||||
(_("Settings"), _items[1:]),
|
||||
),
|
||||
icon_class="mdi mdi-file-document-multiple-outline",
|
||||
)
|
||||
@@ -618,14 +618,31 @@ def topology(scope, opts):
|
||||
if "locations" in scopes:
|
||||
locs = build_location_graphs(scope, opts)
|
||||
pages += [(([H(2, _("Location overview"))] if i == 0 else []) + [H(3, g.title)], g) for i, g in enumerate(locs)]
|
||||
if "locations_all" in scopes:
|
||||
pages += [([H(2, _("Cross-site location overview"))], g) for g in build_location_graphs(scope, opts, combined=True)]
|
||||
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)
|
||||
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
|
||||
@@ -176,7 +176,7 @@
|
||||
<div class="card-body">
|
||||
<div class="ce-label mt-0">{{ form.topo_scope.label }}</div>
|
||||
{% include 'netbox_customer_export/_pills.html' with field=form.topo_scope %}
|
||||
<div class="form-text mb-2">{% trans "“Location overview” shows all locations of a site and the cables between them, from the server room to the last sub-distribution. “Per rack” shows each rack separately. Connected devices outside appear dashed." %}</div>
|
||||
<div class="form-text mb-2">{% trans "“Location overview” shows all locations of a site and the cables between them, from the server room to the last sub-distribution. “Cross-site” combines all sites in one diagram to show how buildings and their locations are connected. “Per rack” shows each rack separately. Connected devices outside appear dashed." %}</div>
|
||||
<div class="ce-label">{{ form.topo_details.label }}</div>
|
||||
{% include 'netbox_customer_export/_pills.html' with field=form.topo_details %}
|
||||
<div class="ce-label">{% trans "More" %}</div>
|
||||
|
||||
@@ -32,6 +32,9 @@ class Edge:
|
||||
b: str
|
||||
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
|
||||
@@ -90,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 = cache
|
||||
by_pk, drawn, links, external, wireless, conns = cache
|
||||
|
||||
groups = OrderedDict()
|
||||
for pk in drawn:
|
||||
@@ -130,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))
|
||||
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)
|
||||
@@ -148,6 +151,7 @@ def build_graphs(scope, opts, per="site"):
|
||||
def _collect(scope, opts):
|
||||
"""Geräte, Symbole und Verbindungen (Kabelpfade) des Scopes einmalig einlesen."""
|
||||
from dcim.models import Interface
|
||||
from django.db.models import Q
|
||||
|
||||
resolver = SymbolResolver()
|
||||
devices = list(
|
||||
@@ -162,11 +166,13 @@ def _collect(scope, opts):
|
||||
drawn[d.pk] = (kind, icon)
|
||||
by_pk = {d.pk: d for d in devices}
|
||||
|
||||
# Verbindungen: vollständige Kabelpfade (auch über Patchpanels) zwischen Interfaces
|
||||
# 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(device_id__in=list(drawn), cable__isnull=False)
|
||||
Interface.objects.filter(Q(cable__isnull=False) | Q(wireless_link__isnull=False), device_id__in=list(drawn))
|
||||
).select_related("device")
|
||||
for iface in ifaces:
|
||||
try:
|
||||
@@ -207,57 +213,160 @@ 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")
|
||||
|
||||
return by_pk, drawn, links, external
|
||||
wireless = {k for k, v in kinds.items() if v == {"wireless"}}
|
||||
return by_pk, drawn, links, external, wireless, conns
|
||||
|
||||
|
||||
def build_location_graphs(scope, opts):
|
||||
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):
|
||||
"""Lokationsübersicht: ein Graph je Standort, Knoten = Lokationen, Linien = Kabel zwischen Lokationen.
|
||||
|
||||
Mit `combined=True` entsteht ein einziger standortübergreifender Graph über alle Lokationen im Scope, an
|
||||
jedem Knoten steht der Standort – so sieht man, wie Gebäude und ihre Lokationen untereinander verbunden sind.
|
||||
|
||||
Gezählt werden physische Kabel (Interfaces, Front- und Rear-Ports), deren Enden in verschiedenen Lokationen
|
||||
liegen – typischerweise LWL-/Kupfer-Trunks vom Serverraum zu den Unterverteilungen. Lokationen mit
|
||||
Firewall/Router/Core stehen oben, die Ebenen darunter folgen der Verkabelung.
|
||||
"""
|
||||
from dcim.models import FrontPort, Interface, RearPort
|
||||
from django.db.models import Q
|
||||
|
||||
resolver = SymbolResolver()
|
||||
devices = list(
|
||||
scope.devices().filter(location__isnull=False)
|
||||
scope.devices()
|
||||
.select_related("role", "device_type__manufacturer", "site", "location__parent", "rack")
|
||||
.order_by("site__name", "location__name")
|
||||
)
|
||||
if not devices:
|
||||
return []
|
||||
by_pk = {d.pk: d for d in devices}
|
||||
loc_of = {d.pk: d.location for d in devices}
|
||||
|
||||
def node_of(d):
|
||||
"""Lokation des Geräts – Geräte ohne Lokation (z.B. Richtfunk-APs am Dach) hängen am Standort selbst."""
|
||||
return f"l{d.location_id}" if d.location_id else f"s{d.site_id}"
|
||||
|
||||
nid_of = {d.pk: node_of(d) for d in devices}
|
||||
|
||||
# Ebene je Lokation = „höchstes“ Gerät darin (Firewall/Core oben, reine Verteiler darunter)
|
||||
tier, racks, count = {}, defaultdict(set), defaultdict(int)
|
||||
for d in devices:
|
||||
kind, _icon = resolver.resolve(d)
|
||||
t = KINDS.get(kind, ("", 3))[1] if kind else 3
|
||||
tier[d.location_id] = min(tier.get(d.location_id, 9), t)
|
||||
count[d.location_id] += 1
|
||||
nid = nid_of[d.pk]
|
||||
tier[nid] = min(tier.get(nid, 9), t)
|
||||
count[nid] += 1
|
||||
if d.rack_id:
|
||||
racks[d.location_id].add(d.rack_id)
|
||||
racks[nid].add(d.rack_id)
|
||||
|
||||
cables = {} # cable.pk -> (Knoten a, Knoten b, Kabel)
|
||||
cables = {} # ("c"|"w", pk) -> (Knoten a, Knoten b, Kabel oder WirelessLink)
|
||||
outside = {} # node_id -> Node (andere Standorte / Provider)
|
||||
for model in (Interface, FrontPort, RearPort):
|
||||
ports = scope.restrict(model.objects.filter(device_id__in=list(by_pk), cable__isnull=False)).select_related("cable")
|
||||
cond = Q(cable__isnull=False)
|
||||
if model is Interface:
|
||||
cond |= Q(wireless_link__isnull=False)
|
||||
ports = scope.restrict(model.objects.filter(cond, device_id__in=list(by_pk))).select_related("cable")
|
||||
for port in ports:
|
||||
if port.cable_id in cables:
|
||||
link = port.cable if port.cable_id else port.wireless_link
|
||||
link_key = ("c", port.cable_id) if port.cable_id else ("w", port.wireless_link_id)
|
||||
if link_key in cables:
|
||||
continue
|
||||
try:
|
||||
peers = port.link_peers or []
|
||||
except Exception: # noqa: BLE001
|
||||
continue
|
||||
a = f"l{loc_of[port.device_id].pk}"
|
||||
a = nid_of[port.device_id]
|
||||
for peer in peers:
|
||||
peer_dev = getattr(peer, "device", None)
|
||||
if peer_dev is not None:
|
||||
if peer_dev.pk in by_pk:
|
||||
b = f"l{loc_of[peer_dev.pk].pk}"
|
||||
b = nid_of[peer_dev.pk]
|
||||
elif not opts.get("topo_external"):
|
||||
continue
|
||||
else:
|
||||
@@ -274,7 +383,7 @@ def build_location_graphs(scope, opts):
|
||||
else:
|
||||
continue
|
||||
if a != b:
|
||||
cables[port.cable_id] = (a, b, port.cable)
|
||||
cables[link_key] = (a, b, link)
|
||||
break
|
||||
|
||||
links = defaultdict(list)
|
||||
@@ -282,21 +391,31 @@ def build_location_graphs(scope, opts):
|
||||
links[tuple(sorted((a, b)))].append(cable)
|
||||
|
||||
sites = OrderedDict()
|
||||
all_locs = {}
|
||||
all_locs = {} # node_id -> (Name, Standort)
|
||||
for d in devices:
|
||||
sites.setdefault(d.site, OrderedDict())[d.location_id] = d.location
|
||||
all_locs[f"l{d.location_id}"] = d.location
|
||||
nid = nid_of[d.pk]
|
||||
sites.setdefault(None if combined else d.site, OrderedDict())[nid] = d
|
||||
all_locs[nid] = (d.location.name if d.location_id else str(d.site), d.site)
|
||||
|
||||
graphs = []
|
||||
for site, locations in sites.items():
|
||||
nodes = OrderedDict()
|
||||
for loc in locations.values():
|
||||
sub = [str(loc.parent)] if loc.parent_id else []
|
||||
n_racks, n_dev = len(racks[loc.pk]), count[loc.pk]
|
||||
for nid, d in locations.items():
|
||||
loc = d.location
|
||||
if loc is not None:
|
||||
name = loc.name
|
||||
where = [str(loc.site)] if combined else []
|
||||
if loc.parent_id:
|
||||
where.append(str(loc.parent))
|
||||
else:
|
||||
name = str(d.site)
|
||||
where = [_("without location")]
|
||||
sub = [" / ".join(where)] if where else []
|
||||
n_racks, n_dev = len(racks[nid]), count[nid]
|
||||
parts = [ngettext("%(n)d rack", "%(n)d racks", n_racks) % {"n": n_racks}] if n_racks else []
|
||||
parts.append(ngettext("%(n)d device", "%(n)d devices", n_dev) % {"n": n_dev})
|
||||
sub.append(" · ".join(parts))
|
||||
nodes[f"l{loc.pk}"] = Node(f"l{loc.pk}", loc.name, "location", builtin_icon("location"), sub, tier=tier[loc.pk])
|
||||
nodes[nid] = Node(nid, name, "location", builtin_icon("location"), sub, tier=tier[nid])
|
||||
members = set(nodes)
|
||||
edges = []
|
||||
for (a, b), lst in links.items():
|
||||
@@ -307,24 +426,31 @@ def build_location_graphs(scope, opts):
|
||||
continue
|
||||
tpl = outside.get(nid)
|
||||
if tpl is None: # Lokation im Scope, aber an einem anderen Standort
|
||||
loc = all_locs[nid]
|
||||
tpl = Node(nid, loc.name, "location", builtin_icon("location"), [str(loc.site)], external=True)
|
||||
name, loc_site = all_locs[nid]
|
||||
tpl = Node(nid, name, "location", builtin_icon("location"), [str(loc_site)], external=True)
|
||||
nodes[nid] = Node(**{**tpl.__dict__})
|
||||
edges.append(Edge(a, b, [str(c) for c in lst], summary=_cable_summary(lst)))
|
||||
edges.append(Edge(
|
||||
a, b, [str(c) for c in lst], summary=_cable_summary(lst),
|
||||
wireless=all(c._meta.model_name == "wirelesslink" for c in lst),
|
||||
))
|
||||
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(_("Site %(name)s") % {"name": site}, nodes, edges))
|
||||
title = _("All sites") if combined else _("Site %(name)s") % {"name": site}
|
||||
graphs.append(Graph(title, nodes, edges))
|
||||
return graphs
|
||||
|
||||
|
||||
def _cable_summary(cables):
|
||||
"""„2× SMF, 4× CAT6a“ – Kabel ohne Typ zählen als „Kabel“."""
|
||||
"""„2× SMF, 4× CAT6a, 1× Funk“ – Kabel ohne Typ zählen als „Kabel“, Funkstrecken als „Funk“."""
|
||||
types = defaultdict(int)
|
||||
for c in cables:
|
||||
types[c.get_type_display() if c.type else _("Cable")] += 1
|
||||
if c._meta.model_name == "wirelesslink":
|
||||
types[_("Wireless")] += 1
|
||||
else:
|
||||
types[c.get_type_display() if c.type else _("Cable")] += 1
|
||||
return ", ".join(f"{n}× {t}" for t, n in sorted(types.items(), key=lambda x: -x[1]))
|
||||
|
||||
|
||||
@@ -423,12 +549,18 @@ 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:
|
||||
labels = _oriented(graph, e)
|
||||
return labels[0] + (f" (+{len(labels) - 1})" if len(labels) > 1 else "")
|
||||
return f"{len(e.labels)}×" if len(e.labels) > 1 else None
|
||||
text = labels[0] + (f" (+{len(labels) - 1})" if len(labels) > 1 else "")
|
||||
return f"{_('Wireless')}: {text}" if e.wireless else text
|
||||
count = f"{len(e.labels)}×" if len(e.labels) > 1 else ""
|
||||
if e.wireless:
|
||||
return f"{count} {_('Wireless')}".strip()
|
||||
return count or None
|
||||
|
||||
|
||||
# --- PNG ----------------------------------------------------------------------
|
||||
@@ -438,6 +570,7 @@ PALETTE = [
|
||||
(23, 150, 170), (140, 86, 75), (188, 150, 20), (200, 80, 160), (90, 90, 90),
|
||||
]
|
||||
EXTERNAL = (160, 160, 160)
|
||||
WIRELESS = (30, 136, 229) # Funkstrecken: blau, gepunktet
|
||||
|
||||
|
||||
def _font(size, bold=False):
|
||||
@@ -580,7 +713,8 @@ def render_png(graph, show_ports=False, scale=2):
|
||||
line([(min(xs), ly), (max(xs), ly)], col, dashed=u.external)
|
||||
for c, e, ex, stack_pos in entries:
|
||||
dashed = u.external or c.external
|
||||
line([(ex, ly), (ex, c.y - 2)], EXTERNAL if dashed else col, w=3 if len(e.labels) > 1 else 2, dashed=dashed)
|
||||
drop_col = WIRELESS if e.wireless else EXTERNAL if dashed else col
|
||||
line([(ex, ly), (ex, c.y - 2)], drop_col, w=3 if len(e.labels) > 1 else 2, dashed=dashed or e.wireless)
|
||||
if min(xs) < ex < max(xs): # Abzweig auf der Schiene markieren
|
||||
d.ellipse([(ex - 2.5) * S, (ly - 2.5) * S, (ex + 2.5) * S, (ly + 2.5) * S], fill=col)
|
||||
text = _edge_text(graph, e, show_ports)
|
||||
@@ -593,7 +727,8 @@ def render_png(graph, show_ports=False, scale=2):
|
||||
a, b = nodes[e.a], nodes[e.b]
|
||||
ly = gap["top"] + gap["lane_of"][("s", i)] * LANE
|
||||
dashed = a.external or b.external
|
||||
line([(a.x, a.y - 2), (a.x, ly), (b.x, ly), (b.x, b.y - 2)], EXTERNAL if dashed else (70, 70, 70), dashed=dashed)
|
||||
col = WIRELESS if e.wireless else EXTERNAL if dashed else (70, 70, 70)
|
||||
line([(a.x, a.y - 2), (a.x, ly), (b.x, ly), (b.x, b.y - 2)], col, dashed=dashed or e.wireless)
|
||||
text = _edge_text(graph, e, show_ports)
|
||||
if text:
|
||||
labels.append((text, (a.x + b.x) / 2, ly, "mm"))
|
||||
@@ -605,7 +740,8 @@ def render_png(graph, show_ports=False, scale=2):
|
||||
left, right = (a, b) if a.x < b.x else (b, a)
|
||||
line(
|
||||
[(left.x + ICON / 2 + 4, cy), (right.x - ICON / 2 - 4, cy)],
|
||||
EXTERNAL if dashed else (70, 70, 70), w=3 if len(e.labels) > 1 else 2, dashed=dashed,
|
||||
WIRELESS if e.wireless else EXTERNAL if dashed else (70, 70, 70),
|
||||
w=3 if len(e.labels) > 1 else 2, dashed=dashed or e.wireless,
|
||||
)
|
||||
text = _edge_text(graph, e, show_ports)
|
||||
if text:
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "netbox-customer-export"
|
||||
version = "0.17.0"
|
||||
version = "0.20.0"
|
||||
description = "NetBox plugin: customer documentation (PDF/Word) for sites, locations, tenants and tenant groups"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
Reference in new issue
Block a user