fix: stack members show the whole switch stack in the port panel and PDF
The current device is marked in the panel. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
ce174c6541
commit
356034fe98
6 files changed
+27
-12
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
from netbox.plugins import PluginConfig, get_plugin_config
|
from netbox.plugins import PluginConfig, get_plugin_config
|
||||||
|
|
||||||
__version__ = "0.22.0"
|
__version__ = "0.23.0"
|
||||||
|
|
||||||
|
|
||||||
class NetBoxUtilitiesConfig(PluginConfig):
|
class NetBoxUtilitiesConfig(PluginConfig):
|
||||||
|
|||||||
@@ -81,12 +81,12 @@ def switch_panel_context(request, device):
|
|||||||
|
|
||||||
A switch stack shows one front panel per member, one below the other, with shared VLAN colours.
|
A switch stack shows one front panel per member, one below the other, with shared VLAN colours.
|
||||||
"""
|
"""
|
||||||
from .switch_stack import stack_members
|
from .switch_stack import stack_units
|
||||||
|
|
||||||
members = stack_members(device)
|
units = [
|
||||||
units = []
|
{"device": unit, "current": unit.pk == device.pk, "ports": collect_ports(interface_queryset(request, unit))}
|
||||||
for unit in [device, *members]:
|
for unit in stack_units(device)
|
||||||
units.append({"device": unit, "ports": collect_ports(interface_queryset(request, unit))})
|
]
|
||||||
ports = [port for unit in units for port in unit["ports"]]
|
ports = [port for unit in units for port in unit["ports"]]
|
||||||
switch_ports.assign_vlan_colors(ports)
|
switch_ports.assign_vlan_colors(ports)
|
||||||
texts = switch_ports.PANEL_TEXTS[switch_port_pdf.language(translation.get_language())]
|
texts = switch_ports.PANEL_TEXTS[switch_port_pdf.language(translation.get_language())]
|
||||||
@@ -97,7 +97,7 @@ def switch_panel_context(request, device):
|
|||||||
for unit in units:
|
for unit in units:
|
||||||
unit["groups"] = switch_ports.build_groups(unit["ports"])
|
unit["groups"] = switch_ports.build_groups(unit["ports"])
|
||||||
return {
|
return {
|
||||||
"stack": bool(members),
|
"stack": len(units) > 1,
|
||||||
"units": units,
|
"units": units,
|
||||||
"has_ports": any(unit["groups"] for unit in units),
|
"has_ports": any(unit["groups"] for unit in units),
|
||||||
"groups": units[0]["groups"],
|
"groups": units[0]["groups"],
|
||||||
@@ -131,14 +131,14 @@ class SwitchPortsPDFView(ContentTypePermissionRequiredMixin, View):
|
|||||||
device = get_object_or_404(
|
device = get_object_or_404(
|
||||||
Device.objects.restrict(request.user, "view").select_related("site", "rack", "device_type"), pk=pk
|
Device.objects.restrict(request.user, "view").select_related("site", "rack", "device_type"), pk=pk
|
||||||
)
|
)
|
||||||
from .switch_stack import stack_members
|
from .switch_stack import stack_units
|
||||||
|
|
||||||
lang = switch_port_pdf.language(translation.get_language())
|
lang = switch_port_pdf.language(translation.get_language())
|
||||||
stack = [device, *stack_members(device)]
|
stack = stack_units(device)
|
||||||
units = [(device_info(unit), collect_ports(interface_queryset(request, unit))) for unit in stack]
|
units = [(device_info(unit), collect_ports(interface_queryset(request, unit))) for unit in stack]
|
||||||
ports = [port for _, unit_ports in units for port in unit_ports]
|
ports = [port for _, unit_ports in units for port in unit_ports]
|
||||||
pdf = switch_port_pdf.build_pdf(
|
pdf = switch_port_pdf.build_pdf(
|
||||||
device_info(device),
|
device_info(stack[0]),
|
||||||
ports,
|
ports,
|
||||||
lang=lang,
|
lang=lang,
|
||||||
generated=timezone.localtime(),
|
generated=timezone.localtime(),
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ VLAN_PALETTE = (
|
|||||||
PANEL_TEXTS = {
|
PANEL_TEXTS = {
|
||||||
"de": {
|
"de": {
|
||||||
"title": "Ports",
|
"title": "Ports",
|
||||||
|
"this_device": "dieses Gerät",
|
||||||
"status": "Status",
|
"status": "Status",
|
||||||
"vlan": "VLAN",
|
"vlan": "VLAN",
|
||||||
"connected": "Belegt",
|
"connected": "Belegt",
|
||||||
@@ -63,6 +64,7 @@ PANEL_TEXTS = {
|
|||||||
},
|
},
|
||||||
"en": {
|
"en": {
|
||||||
"title": "Ports",
|
"title": "Ports",
|
||||||
|
"this_device": "this device",
|
||||||
"status": "Status",
|
"status": "Status",
|
||||||
"vlan": "VLAN",
|
"vlan": "VLAN",
|
||||||
"connected": "Connected",
|
"connected": "Connected",
|
||||||
|
|||||||
@@ -19,6 +19,19 @@ def stack_members(device):
|
|||||||
return sorted(members, key=lambda member: natural_key(member.name or str(member)))
|
return sorted(members, key=lambda member: natural_key(member.name or str(member)))
|
||||||
|
|
||||||
|
|
||||||
|
def stack_units(device):
|
||||||
|
"""[stack switch, *members] for a stack switch or one of its members; [device] outside a stack."""
|
||||||
|
if device is None or not device.pk:
|
||||||
|
return [device]
|
||||||
|
stack = (
|
||||||
|
SwitchStack.objects.filter(device=device).select_related("device").first()
|
||||||
|
or SwitchStack.objects.filter(members=device).select_related("device").first()
|
||||||
|
)
|
||||||
|
if stack is None:
|
||||||
|
return [device]
|
||||||
|
return [stack.device, *stack_members(stack.device)]
|
||||||
|
|
||||||
|
|
||||||
def build_stack_form_mixin():
|
def build_stack_form_mixin():
|
||||||
from dcim.models import Device
|
from dcim.models import Device
|
||||||
from utilities.forms.fields import DynamicModelMultipleChoiceField
|
from utilities.forms.fields import DynamicModelMultipleChoiceField
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
{% for unit in units %}
|
{% for unit in units %}
|
||||||
{% if stack %}
|
{% if stack %}
|
||||||
<div class="nbu-stack-member small fw-semibold{% if not forloop.first %} mt-3{% endif %}">
|
<div class="nbu-stack-member small fw-semibold{% if not forloop.first %} mt-3{% endif %}">
|
||||||
<a href="{{ unit.device.get_absolute_url }}">{{ unit.device }}</a>
|
<a href="{{ unit.device.get_absolute_url }}">{{ unit.device }}</a>{% if unit.current %} <span class="badge text-bg-secondary">{{ texts.this_device }}</span>{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="nbu-faceplate">
|
<div class="nbu-faceplate">
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "netbox-utilities"
|
name = "netbox-utilities"
|
||||||
version = "0.22.0"
|
version = "0.23.0"
|
||||||
description = "Navigation, tenant utilities, connection VLANs, partial-width racks, disks, CPU & RAM, switch port export and bulk operations for NetBox 4.6/4.7"
|
description = "Navigation, tenant utilities, connection VLANs, partial-width racks, disks, CPU & RAM, switch port export and bulk operations for NetBox 4.6/4.7"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
|||||||
Reference in new issue
Block a user