From e9c00f2b11c981a4cc4784c39a4977942c1790ca Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 30 Oct 2026 10:12:13 +0100 Subject: [PATCH] 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 --- README.md | 5 +- netbox_utilities/__init__.py | 2 +- .../netbox_utilities/netbox_utilities.css | 58 ++++++++++++++----- netbox_utilities/switch_ports.py | 27 ++++++++- .../netbox_utilities/device_switch_panel.html | 2 +- netbox_utilities/tests/test_switch_ports.py | 12 ++++ pyproject.toml | 2 +- 7 files changed, 86 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c8ad1a3..d7a31db 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/netbox_utilities/__init__.py b/netbox_utilities/__init__.py index d587bca..f265da9 100644 --- a/netbox_utilities/__init__.py +++ b/netbox_utilities/__init__.py @@ -1,6 +1,6 @@ from netbox.plugins import PluginConfig, get_plugin_config -__version__ = "0.19.0" +__version__ = "0.19.1" class NetBoxUtilitiesConfig(PluginConfig): diff --git a/netbox_utilities/static/netbox_utilities/netbox_utilities.css b/netbox_utilities/static/netbox_utilities/netbox_utilities.css index 64b20da..a2fee94 100644 --- a/netbox_utilities/static/netbox_utilities/netbox_utilities.css +++ b/netbox_utilities/static/netbox_utilities/netbox_utilities.css @@ -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; } diff --git a/netbox_utilities/switch_ports.py b/netbox_utilities/switch_ports.py index d8af067..9e2cee9 100644 --- a/netbox_utilities/switch_ports.py +++ b/netbox_utilities/switch_ports.py @@ -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.*?)(?P\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): diff --git a/netbox_utilities/templates/netbox_utilities/device_switch_panel.html b/netbox_utilities/templates/netbox_utilities/device_switch_panel.html index 94a8004..589f5f7 100644 --- a/netbox_utilities/templates/netbox_utilities/device_switch_panel.html +++ b/netbox_utilities/templates/netbox_utilities/device_switch_panel.html @@ -29,7 +29,7 @@
{% for port in column %} diff --git a/netbox_utilities/tests/test_switch_ports.py b/netbox_utilities/tests/test_switch_ports.py index bbfa87f..abe1a35 100644 --- a/netbox_utilities/tests/test_switch_ports.py +++ b/netbox_utilities/tests/test_switch_ports.py @@ -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") diff --git a/pyproject.toml b/pyproject.toml index b17b38f..82a1831 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"