fix: MGMT label for management ports and light/dark theme for the switch panel

Management ports (management only, or named mgmt/management/oobm/me0 ...)
show "MGMT" instead of the overflowing full name and form their own group
at the end; other ports without a number are shortened. The faceplate,
jacks, notches and frames use theme variables for NetBox's light and dark
mode instead of a fixed dark design.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-10-30 10:12:13 +01:00
1 parent b1ecbbbb75
commit e9c00f2b11
7 files changed
+86 -22

No files matched your search

+4 -1
View File
@@ -513,7 +513,10 @@ view in the web interface of Aruba switches:
- A dark faceplate with every physical port as an RJ45 or SFP jack, odd ports
on top and even ports below, grouped per stack member or line card.
- **Status** view: green = link/connected, dark = free, red dot = disabled.
- **Status** view: green = link/connected, empty jack = free, red dot = disabled.
- Management ports (marked *management only* or named `mgmt`, `management`,
`oobm`, `me0` …) are shown as **MGMT** in a group of their own at the end.
- The faceplate follows NetBox's light and dark theme.
- **VLAN** view: every VLAN from the interface label gets its own colour (the
same colours as in the PDF), the VLAN is printed in the jack and the text
colour is chosen for contrast; free ports are dimmed, connected ports framed.
+1 -1
View File
@@ -1,6 +1,6 @@
from netbox.plugins import PluginConfig, get_plugin_config
__version__ = "0.19.0"
__version__ = "0.19.1"
class NetBoxUtilitiesConfig(PluginConfig):
@@ -403,18 +403,42 @@ a.nbu-disk-slot[draggable="true"] {
/* ---------- Switch front panel on the device page (Aruba-like) ---------- */
/* Light theme by default; NetBox sets data-bs-theme="dark" on the html element for the dark theme. */
.nbu-switch-card {
--nbu-plate-from: #eef0f2;
--nbu-plate-to: #d9dde1;
--nbu-plate-edge: #c4c9ce;
--nbu-plate-label: #495057;
--nbu-jack-border: rgba(0, 0, 0, .35);
--nbu-jack-free: #ffffff;
--nbu-jack-free-ink: #6c757d;
--nbu-link: #2fb344;
--nbu-frame: #212529;
}
[data-bs-theme="dark"] .nbu-switch-card {
--nbu-plate-from: #3a3f45;
--nbu-plate-to: #2a2e33;
--nbu-plate-edge: #1d2024;
--nbu-plate-label: #ced4da;
--nbu-jack-border: rgba(0, 0, 0, .6);
--nbu-jack-free: #15181b;
--nbu-jack-free-ink: #8a9199;
--nbu-frame: #ffffff;
}
.nbu-faceplate {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: .75rem 1.25rem;
padding: .75rem 1rem;
border-radius: .6rem;
background: linear-gradient(180deg, #3a3f45 0%, #2a2e33 100%);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 1px 3px rgba(0, 0, 0, .25);
border: 1px solid var(--nbu-plate-edge);
background: linear-gradient(180deg, var(--nbu-plate-from) 0%, var(--nbu-plate-to) 100%);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15), 0 1px 3px rgba(0, 0, 0, .15);
overflow-x: auto;
}
.nbu-faceplate-label {
color: #ced4da;
color: var(--nbu-plate-label);
font-size: .7rem;
margin-bottom: .3rem;
letter-spacing: .02em;
@@ -439,12 +463,12 @@ a.nbu-disk-slot[draggable="true"] {
width: 2.15rem;
height: 1.9rem;
border-radius: .2rem .2rem .35rem .35rem;
border: 1px solid rgba(0, 0, 0, .55);
border: 1px solid var(--nbu-jack-border);
text-decoration: none !important;
line-height: 1;
transition: transform .1s, filter .1s;
}
/* RJ45 latch notch */
/* RJ45 latch notch in the colour of the faceplate */
.nbu-jack:not(.nbu-jack-sfp)::before {
content: "";
position: absolute;
@@ -453,7 +477,7 @@ a.nbu-disk-slot[draggable="true"] {
width: 40%;
height: .22rem;
transform: translateX(-50%);
background: #2a2e33;
background: var(--nbu-plate-to);
border-radius: .15rem .15rem 0 0;
}
.nbu-jack-sfp {
@@ -462,12 +486,16 @@ a.nbu-disk-slot[draggable="true"] {
}
.nbu-jack:hover {
transform: translateY(-1px);
filter: brightness(1.15);
filter: brightness(1.1);
}
.nbu-jack-number {
font-size: .68rem;
font-weight: 700;
}
.nbu-jack-mgmt .nbu-jack-number {
font-size: .55rem;
letter-spacing: .02em;
}
.nbu-jack-vlan {
font-size: .5rem;
max-width: 100%;
@@ -478,10 +506,10 @@ a.nbu-disk-slot[draggable="true"] {
display: none;
}
/* Status view: green link, dark free port, disabled with a red mark */
.nbu-jack-connected { background: #2fb344; color: #fff; }
.nbu-jack-free { background: #15181b; color: #8a9199; }
.nbu-jack-disabled { background: #15181b; color: #6c737a; }
/* Status view: green link, free port in the jack colour of the theme, disabled with a red dot */
.nbu-jack-connected { background: var(--nbu-link); color: #fff; }
.nbu-jack-free,
.nbu-jack-disabled { background: var(--nbu-jack-free); color: var(--nbu-jack-free-ink); }
.nbu-jack-disabled::after {
content: "";
position: absolute;
@@ -493,11 +521,11 @@ a.nbu-disk-slot[draggable="true"] {
background: #d63939;
}
/* VLAN view: fill by VLAN label; free ports dimmed, connected ports with a bright frame */
/* VLAN view: fill by VLAN label; free ports dimmed, connected ports framed */
.nbu-switch-vlan .nbu-jack-vlan { display: block; }
.nbu-switch-vlan .nbu-jack-labelled { background: var(--nbu-vlan); color: var(--nbu-ink); }
.nbu-switch-vlan .nbu-jack:not(.nbu-jack-labelled) { background: #15181b; color: #8a9199; }
.nbu-switch-vlan .nbu-jack-connected { box-shadow: 0 0 0 2px #fff; }
.nbu-switch-vlan .nbu-jack:not(.nbu-jack-labelled) { background: var(--nbu-jack-free); color: var(--nbu-jack-free-ink); }
.nbu-switch-vlan .nbu-jack-connected { box-shadow: 0 0 0 2px var(--nbu-frame); }
.nbu-switch-vlan .nbu-jack-free.nbu-jack-labelled,
.nbu-switch-vlan .nbu-jack-disabled.nbu-jack-labelled { opacity: .45; }
@@ -514,6 +542,6 @@ a.nbu-disk-slot[draggable="true"] {
border-radius: .15rem;
margin-right: .3rem;
vertical-align: -.1rem;
border: 1px solid rgba(0, 0, 0, .35);
border: 1px solid var(--nbu-jack-border);
}
.nbu-jack-swatch.nbu-jack-disabled::after { top: .1rem; right: .1rem; width: .3rem; height: .3rem; }
+24 -3
View File
@@ -74,6 +74,8 @@ PANEL_TEXTS = {
},
}
# Out-of-band management ports by name, e.g. "mgmt", "Management", "mgmt0", "oobm", "me0", "MgmtEth0/RP0/CPU0/0".
_MGMT_NAME = re.compile(r"(?i)^(mgmt|management|oobm|me0|fxp0|em0|ma1|mgmteth)")
_NAME_PATTERN = re.compile(r"^(?P<prefix>.*?)(?P<number>\d+)$")
_NATURAL = re.compile(r"(\d+)")
@@ -175,11 +177,19 @@ class Port:
def number(self):
return split_name(self.name)[1]
@property
def is_management(self):
return self.mgmt_only or bool(_MGMT_NAME.match(self.name or ""))
@property
def short(self):
"""Text inside the tile: the port number, or the name if it has none."""
"""Text inside the tile: the port number, "MGMT" for management ports, else a shortened name."""
if self.is_management:
return "MGMT"
number = self.number
return str(number) if number is not None else self.name
if number is not None:
return str(number)
return (self.name or "")[:5]
@property
def vlan(self):
@@ -223,12 +233,19 @@ def _zip_longest(top, bottom):
yield (top[index] if index < len(top) else None, bottom[index] if index < len(bottom) else None)
MGMT_GROUP = ("__mgmt__", False)
def build_groups(ports):
"""Physical ports grouped by name prefix and medium, in natural order."""
groups = {}
for port in ports:
if port.virtual:
continue
if port.is_management:
# All management ports in one small group at the end.
groups.setdefault(MGMT_GROUP, PortGroup(title="Management", optical=False)).ports.append(port)
continue
prefix, _ = split_name(port.name)
optical = is_optical(port.type)
key = (prefix, optical)
@@ -236,7 +253,11 @@ def build_groups(ports):
title = prefix.rstrip("/:-. ") or "Ports"
groups[key] = PortGroup(title=f"{title} (SFP)" if optical else title, optical=optical)
groups[key].ports.append(port)
return sorted(groups.values(), key=lambda group: (natural_key(group.title), group.optical))
management = groups.get(MGMT_GROUP)
return sorted(
groups.values(),
key=lambda group: (group is management, natural_key(group.title), group.optical),
)
def summary(ports):
@@ -29,7 +29,7 @@
<div class="nbu-faceplate-column">
{% for port in column %}
<a href="{{ port.url }}"
class="nbu-jack nbu-jack-{{ port.state }}{% if group.optical %} nbu-jack-sfp{% endif %}{% if port.color %} nbu-jack-labelled{% endif %}"
class="nbu-jack nbu-jack-{{ port.state }}{% if group.optical %} nbu-jack-sfp{% endif %}{% if port.color %} nbu-jack-labelled{% endif %}{% if port.is_management %} nbu-jack-mgmt{% endif %}"
{% if port.color %}style="--nbu-vlan: {{ port.color }}; --nbu-ink: {{ port.ink }}"{% endif %}
data-bs-toggle="tooltip" data-bs-html="true"
title="<strong>{{ port.name|force_escape }}</strong><br>{{ port.state_text }}{% if port.label %}<br>{{ texts.vlan }}: {{ port.label|force_escape }}{% endif %}{% if port.peer %}<br>{{ texts.peer }}: {{ port.peer|force_escape }}{% endif %}{% if port.description %}<br><em>{{ port.description|force_escape }}</em>{% endif %}">
@@ -145,3 +145,15 @@ class InkTest(SimpleTestCase):
self.assertEqual(switch_ports.ink_for("#1f77b4"), "#ffffff")
self.assertEqual(port("1", label="10", assigned_color="#2ca02c").ink, "#000000")
self.assertEqual(port("2").ink, "")
class ManagementTest(SimpleTestCase):
def test_management_ports_are_abbreviated_and_grouped_last(self):
ports = [port("Management"), port("Gi1/0/1"), port("mgmt0"), port("oobm"), port("eth0", mgmt_only=True)]
self.assertEqual([p.short for p in ports], ["MGMT", "1", "MGMT", "MGMT", "MGMT"])
groups = switch_ports.build_groups(ports)
self.assertEqual([group.title for group in groups], ["Gi1/0", "Management"])
self.assertEqual(len(groups[-1].ports), 4)
def test_other_ports_without_number_are_shortened(self):
self.assertEqual(port("console").short, "conso")
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "netbox-utilities"
version = "0.19.0"
version = "0.19.1"
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"
requires-python = ">=3.12"