Compare commits
4
Commits
38b3ec2a27
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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.
|
technician only exports what they are allowed to see.
|
||||||
|
|
||||||
Open it via the **Customer Docs** button on site, location, tenant and tenant
|
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).
|
**PDF**, **Word** and **HTML preview** (opens in a new tab).
|
||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
@@ -182,7 +182,7 @@ sudo systemctl restart netbox netbox-rq
|
|||||||
|
|
||||||
### Branding in NetBox (recommended)
|
### 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)
|
- name, company name, footer and **logo upload** (PNG/JPG)
|
||||||
- colours via colour picker: primary, accent, table header text, labels, zebra stripes
|
- colours via colour picker: primary, accent, table header text, labels, zebra stripes
|
||||||
@@ -258,13 +258,15 @@ 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.
|
- 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×".
|
- 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.
|
- **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.
|
||||||
- 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.
|
||||||
- Selectable labels: management IP, model, ports on links.
|
- Selectable labels: management IP, model, ports on links.
|
||||||
- Device names longer than 15 characters are wrapped, preferably at `-`, `_`, `.` or spaces.
|
- 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):
|
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)
|
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"
|
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.17.0"
|
version = "0.19.1"
|
||||||
author = "Claude"
|
author = "Claude"
|
||||||
base_url = "customer-export"
|
base_url = "customer-export"
|
||||||
min_version = "4.6.8"
|
min_version = "4.6.8"
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ class ExportForm(forms.Form):
|
|||||||
choices=(
|
choices=(
|
||||||
("site", _("Whole network (per site)")),
|
("site", _("Whole network (per site)")),
|
||||||
("locations", _("Location overview (connections between locations)")),
|
("locations", _("Location overview (connections between locations)")),
|
||||||
|
("locations_all", _("Cross-site location overview (all locations in one diagram)")),
|
||||||
("rack", _("Per rack")),
|
("rack", _("Per rack")),
|
||||||
),
|
),
|
||||||
initial=["site"],
|
initial=["site"],
|
||||||
|
|||||||
Binary file not shown.
@@ -1507,13 +1507,16 @@ msgstr "vCPU je Kern"
|
|||||||
|
|
||||||
msgid ""
|
msgid ""
|
||||||
"“Location overview” shows all locations of a site and the cables between "
|
"“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 "
|
"them, from the server room to the last sub-distribution. “Cross-site” "
|
||||||
"each rack separately. Connected devices outside appear dashed."
|
"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 ""
|
msgstr ""
|
||||||
"„Lokationsübersicht“ zeigt alle Lokationen eines Standorts und die Kabel "
|
"„Lokationsübersicht“ zeigt alle Lokationen eines Standorts und die Kabel "
|
||||||
"zwischen ihnen, vom Serverraum bis zur letzten Unterverteilung. „Je Rack“ "
|
"zwischen ihnen, vom Serverraum bis zur letzten Unterverteilung. "
|
||||||
"zeigt jedes Rack einzeln. Verbundene Geräte außerhalb erscheinen "
|
"„Standortübergreifend“ fasst alle Standorte in einem Diagramm zusammen, um "
|
||||||
"gestrichelt."
|
"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 "%(n)d device"
|
||||||
msgid_plural "%(n)d devices"
|
msgid_plural "%(n)d devices"
|
||||||
@@ -1529,3 +1532,25 @@ msgid "%(n)d rack"
|
|||||||
msgid_plural "%(n)d racks"
|
msgid_plural "%(n)d racks"
|
||||||
msgstr[0] "%(n)d Rack"
|
msgstr[0] "%(n)d Rack"
|
||||||
msgstr[1] "%(n)d Racks"
|
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"
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from django.utils.translation import gettext_lazy as _
|
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(
|
PluginMenuItem(
|
||||||
link="plugins:netbox_customer_export:select",
|
link="plugins:netbox_customer_export:select",
|
||||||
link_text=_("Customer Documentation"),
|
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,6 +618,8 @@ def topology(scope, opts):
|
|||||||
if "locations" in scopes:
|
if "locations" in scopes:
|
||||||
locs = build_location_graphs(scope, opts)
|
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)]
|
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:
|
if "rack" in scopes:
|
||||||
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)
|
||||||
|
|||||||
@@ -176,7 +176,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="ce-label mt-0">{{ form.topo_scope.label }}</div>
|
<div class="ce-label mt-0">{{ form.topo_scope.label }}</div>
|
||||||
{% include 'netbox_customer_export/_pills.html' with field=form.topo_scope %}
|
{% 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>
|
<div class="ce-label">{{ form.topo_details.label }}</div>
|
||||||
{% include 'netbox_customer_export/_pills.html' with field=form.topo_details %}
|
{% include 'netbox_customer_export/_pills.html' with field=form.topo_details %}
|
||||||
<div class="ce-label">{% trans "More" %}</div>
|
<div class="ce-label">{% trans "More" %}</div>
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class Edge:
|
|||||||
b: str
|
b: str
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -90,7 +91,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 = cache
|
by_pk, drawn, links, external, wireless = cache
|
||||||
|
|
||||||
groups = OrderedDict()
|
groups = OrderedDict()
|
||||||
for pk in drawn:
|
for pk in drawn:
|
||||||
@@ -130,7 +131,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))
|
edges.append(Edge(a, b, labels, wireless=(a, b) in wireless))
|
||||||
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)
|
||||||
@@ -148,6 +149,7 @@ def build_graphs(scope, opts, per="site"):
|
|||||||
def _collect(scope, opts):
|
def _collect(scope, opts):
|
||||||
"""Geräte, Symbole und Verbindungen (Kabelpfade) des Scopes einmalig einlesen."""
|
"""Geräte, Symbole und Verbindungen (Kabelpfade) des Scopes einmalig einlesen."""
|
||||||
from dcim.models import Interface
|
from dcim.models import Interface
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
resolver = SymbolResolver()
|
resolver = SymbolResolver()
|
||||||
devices = list(
|
devices = list(
|
||||||
@@ -162,11 +164,12 @@ def _collect(scope, opts):
|
|||||||
drawn[d.pk] = (kind, icon)
|
drawn[d.pk] = (kind, icon)
|
||||||
by_pk = {d.pk: d for d in devices}
|
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", …]
|
links = defaultdict(list) # (a, b) -> ["Gi1/0/1 – eth0", …]
|
||||||
|
kinds = defaultdict(set) # (a, b) -> {"cable", "wireless"}
|
||||||
external = {} # node_id -> Node-Vorlage
|
external = {} # node_id -> Node-Vorlage
|
||||||
ifaces = scope.restrict(
|
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")
|
).select_related("device")
|
||||||
for iface in ifaces:
|
for iface in ifaces:
|
||||||
try:
|
try:
|
||||||
@@ -207,57 +210,74 @@ 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)
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def build_location_graphs(scope, opts):
|
def build_location_graphs(scope, opts, combined=False):
|
||||||
"""Lokationsübersicht: ein Graph je Standort, Knoten = Lokationen, Linien = Kabel zwischen Lokationen.
|
"""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
|
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
|
liegen – typischerweise LWL-/Kupfer-Trunks vom Serverraum zu den Unterverteilungen. Lokationen mit
|
||||||
Firewall/Router/Core stehen oben, die Ebenen darunter folgen der Verkabelung.
|
Firewall/Router/Core stehen oben, die Ebenen darunter folgen der Verkabelung.
|
||||||
"""
|
"""
|
||||||
from dcim.models import FrontPort, Interface, RearPort
|
from dcim.models import FrontPort, Interface, RearPort
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
resolver = SymbolResolver()
|
resolver = SymbolResolver()
|
||||||
devices = list(
|
devices = list(
|
||||||
scope.devices().filter(location__isnull=False)
|
scope.devices()
|
||||||
.select_related("role", "device_type__manufacturer", "site", "location__parent", "rack")
|
.select_related("role", "device_type__manufacturer", "site", "location__parent", "rack")
|
||||||
.order_by("site__name", "location__name")
|
.order_by("site__name", "location__name")
|
||||||
)
|
)
|
||||||
if not devices:
|
if not devices:
|
||||||
return []
|
return []
|
||||||
by_pk = {d.pk: d for d in devices}
|
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)
|
# Ebene je Lokation = „höchstes“ Gerät darin (Firewall/Core oben, reine Verteiler darunter)
|
||||||
tier, racks, count = {}, defaultdict(set), defaultdict(int)
|
tier, racks, count = {}, defaultdict(set), defaultdict(int)
|
||||||
for d in devices:
|
for d in devices:
|
||||||
kind, _icon = resolver.resolve(d)
|
kind, _icon = resolver.resolve(d)
|
||||||
t = KINDS.get(kind, ("", 3))[1] if kind else 3
|
t = KINDS.get(kind, ("", 3))[1] if kind else 3
|
||||||
tier[d.location_id] = min(tier.get(d.location_id, 9), t)
|
nid = nid_of[d.pk]
|
||||||
count[d.location_id] += 1
|
tier[nid] = min(tier.get(nid, 9), t)
|
||||||
|
count[nid] += 1
|
||||||
if d.rack_id:
|
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)
|
outside = {} # node_id -> Node (andere Standorte / Provider)
|
||||||
for model in (Interface, FrontPort, RearPort):
|
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:
|
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
|
continue
|
||||||
try:
|
try:
|
||||||
peers = port.link_peers or []
|
peers = port.link_peers or []
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
continue
|
continue
|
||||||
a = f"l{loc_of[port.device_id].pk}"
|
a = nid_of[port.device_id]
|
||||||
for peer in peers:
|
for peer in peers:
|
||||||
peer_dev = getattr(peer, "device", None)
|
peer_dev = getattr(peer, "device", None)
|
||||||
if peer_dev is not None:
|
if peer_dev is not None:
|
||||||
if peer_dev.pk in by_pk:
|
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"):
|
elif not opts.get("topo_external"):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@@ -274,7 +294,7 @@ def build_location_graphs(scope, opts):
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
if a != b:
|
if a != b:
|
||||||
cables[port.cable_id] = (a, b, port.cable)
|
cables[link_key] = (a, b, link)
|
||||||
break
|
break
|
||||||
|
|
||||||
links = defaultdict(list)
|
links = defaultdict(list)
|
||||||
@@ -282,21 +302,31 @@ def build_location_graphs(scope, opts):
|
|||||||
links[tuple(sorted((a, b)))].append(cable)
|
links[tuple(sorted((a, b)))].append(cable)
|
||||||
|
|
||||||
sites = OrderedDict()
|
sites = OrderedDict()
|
||||||
all_locs = {}
|
all_locs = {} # node_id -> (Name, Standort)
|
||||||
for d in devices:
|
for d in devices:
|
||||||
sites.setdefault(d.site, OrderedDict())[d.location_id] = d.location
|
nid = nid_of[d.pk]
|
||||||
all_locs[f"l{d.location_id}"] = d.location
|
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 = []
|
graphs = []
|
||||||
for site, locations in sites.items():
|
for site, locations in sites.items():
|
||||||
nodes = OrderedDict()
|
nodes = OrderedDict()
|
||||||
for loc in locations.values():
|
for nid, d in locations.items():
|
||||||
sub = [str(loc.parent)] if loc.parent_id else []
|
loc = d.location
|
||||||
n_racks, n_dev = len(racks[loc.pk]), count[loc.pk]
|
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 = [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})
|
parts.append(ngettext("%(n)d device", "%(n)d devices", n_dev) % {"n": n_dev})
|
||||||
sub.append(" · ".join(parts))
|
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)
|
members = set(nodes)
|
||||||
edges = []
|
edges = []
|
||||||
for (a, b), lst in links.items():
|
for (a, b), lst in links.items():
|
||||||
@@ -307,24 +337,31 @@ def build_location_graphs(scope, opts):
|
|||||||
continue
|
continue
|
||||||
tpl = outside.get(nid)
|
tpl = outside.get(nid)
|
||||||
if tpl is None: # Lokation im Scope, aber an einem anderen Standort
|
if tpl is None: # Lokation im Scope, aber an einem anderen Standort
|
||||||
loc = all_locs[nid]
|
name, loc_site = all_locs[nid]
|
||||||
tpl = Node(nid, loc.name, "location", builtin_icon("location"), [str(loc.site)], external=True)
|
tpl = Node(nid, name, "location", builtin_icon("location"), [str(loc_site)], external=True)
|
||||||
nodes[nid] = Node(**{**tpl.__dict__})
|
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"):
|
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)
|
||||||
if nodes:
|
if nodes:
|
||||||
_layout(nodes, edges)
|
_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
|
return graphs
|
||||||
|
|
||||||
|
|
||||||
def _cable_summary(cables):
|
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)
|
types = defaultdict(int)
|
||||||
for c in cables:
|
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]))
|
return ", ".join(f"{n}× {t}" for t, n in sorted(types.items(), key=lambda x: -x[1]))
|
||||||
|
|
||||||
|
|
||||||
@@ -427,8 +464,12 @@ def _edge_text(graph, e, show_ports):
|
|||||||
return e.summary
|
return e.summary
|
||||||
if show_ports:
|
if show_ports:
|
||||||
labels = _oriented(graph, e)
|
labels = _oriented(graph, e)
|
||||||
return labels[0] + (f" (+{len(labels) - 1})" if len(labels) > 1 else "")
|
text = labels[0] + (f" (+{len(labels) - 1})" if len(labels) > 1 else "")
|
||||||
return f"{len(e.labels)}×" if len(e.labels) > 1 else None
|
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 ----------------------------------------------------------------------
|
# --- PNG ----------------------------------------------------------------------
|
||||||
@@ -438,6 +479,7 @@ PALETTE = [
|
|||||||
(23, 150, 170), (140, 86, 75), (188, 150, 20), (200, 80, 160), (90, 90, 90),
|
(23, 150, 170), (140, 86, 75), (188, 150, 20), (200, 80, 160), (90, 90, 90),
|
||||||
]
|
]
|
||||||
EXTERNAL = (160, 160, 160)
|
EXTERNAL = (160, 160, 160)
|
||||||
|
WIRELESS = (30, 136, 229) # Funkstrecken: blau, gepunktet
|
||||||
|
|
||||||
|
|
||||||
def _font(size, bold=False):
|
def _font(size, bold=False):
|
||||||
@@ -580,7 +622,8 @@ def render_png(graph, show_ports=False, scale=2):
|
|||||||
line([(min(xs), ly), (max(xs), ly)], col, dashed=u.external)
|
line([(min(xs), ly), (max(xs), ly)], col, dashed=u.external)
|
||||||
for c, e, ex, stack_pos in entries:
|
for c, e, ex, stack_pos in entries:
|
||||||
dashed = u.external or c.external
|
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
|
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)
|
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)
|
text = _edge_text(graph, e, show_ports)
|
||||||
@@ -593,7 +636,8 @@ def render_png(graph, show_ports=False, scale=2):
|
|||||||
a, b = nodes[e.a], nodes[e.b]
|
a, b = nodes[e.a], nodes[e.b]
|
||||||
ly = gap["top"] + gap["lane_of"][("s", i)] * LANE
|
ly = gap["top"] + gap["lane_of"][("s", i)] * LANE
|
||||||
dashed = a.external or b.external
|
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)
|
text = _edge_text(graph, e, show_ports)
|
||||||
if text:
|
if text:
|
||||||
labels.append((text, (a.x + b.x) / 2, ly, "mm"))
|
labels.append((text, (a.x + b.x) / 2, ly, "mm"))
|
||||||
@@ -605,7 +649,8 @@ def render_png(graph, show_ports=False, scale=2):
|
|||||||
left, right = (a, b) if a.x < b.x else (b, a)
|
left, right = (a, b) if a.x < b.x else (b, a)
|
||||||
line(
|
line(
|
||||||
[(left.x + ICON / 2 + 4, cy), (right.x - ICON / 2 - 4, cy)],
|
[(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)
|
text = _edge_text(graph, e, show_ports)
|
||||||
if text:
|
if text:
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "netbox-customer-export"
|
name = "netbox-customer-export"
|
||||||
version = "0.17.0"
|
version = "0.19.1"
|
||||||
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