Compare commits

...
4 Commits
Author SHA1 Message Date
MrBlakeandClaude Opus 5.5 899b4c58fc chore: release 4.11.0
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 09:27:10 +01:00
MrBlakeandClaude Opus 5.5 89fe37ea04 feat: fill in detected stacks in the optional NetBox Utilities plugin
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 09:27:09 +01:00
MrBlakeandClaude Opus 5.5 34b1391ff0 chore: release 4.10.5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 08:41:38 +01:00
MrBlakeandClaude Opus 5.5 340f404f94 fix: allow equal interface names on different stack member devices
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 08:41:24 +01:00
6 changed files with 76 additions and 6 deletions

No files matched your search

+4
View File
@@ -87,6 +87,10 @@ vSphere and Proxmox VE, HPE/Aruba switches and Windows clients in NetBox.
IRF): every member is assigned to its own NetBox device (suggested from the
NetBox virtual chassis positions, stored per switch) and gets its own ports;
LAGs and VLAN interfaces stay on the switch's device
- Optional: with the [NetBox Utilities](https://git.mrblake.cc/MrBlake/Netbox-Utilities)
plugin (0.24.0 or later) a detected stack is also entered as its switch stack
(the switch's device as stack switch, the other member devices as members);
members entered by hand are kept. Without the plugin this step is skipped
- Cables from LLDP/CDP, also with FQDN system names or via the management IP
- The switch configuration is only changed when "Enable LLDP if needed" is
explicitly switched on
+1 -1
View File
@@ -3,7 +3,7 @@
#define AppName "NetBox Synchronizer"
#ifndef AppVersion
#define AppVersion "4.10.4"
#define AppVersion "4.11.0"
#endif
#define AppPublisher "Louis-Alexander Kerst"
#define AppExeName "NetBoxSynchronizer.exe"
+1 -1
View File
@@ -1,7 +1,7 @@
"""NetBox Synchronizer – VMs, switches and clients from the field into NetBox."""
APP_NAME = "NetBox Synchronizer"
APP_VERSION = "4.10.4"
APP_VERSION = "4.11.0"
APP_PUBLISHER = "Louis-Alexander Kerst"
APP_USER_MODEL_ID = "Louis-AlexanderKerst.NetBoxSynchronizer"
+38
View File
@@ -1583,6 +1583,43 @@ def _new_report():
}
def _sync_switch_stack(nb, device, members, dry_run, report):
"""Fill in the switch stack of the optional NetBox Utilities plugin.
The switch's device is the stack switch, the other member devices are
added to it; members entered by hand stay. Without the plugin nothing happens.
"""
others = {member.id: member for member in members.values() if member is not None and member.id != device.id}
if not others:
return
try:
endpoint = nb.plugins.utilities.switch_stacks
stacks = list(endpoint.filter(device_id=device.id))
except AttributeError:
return
except Exception as error: # noqa: BLE001
if getattr(getattr(error, "req", None), "status_code", None) != 404:
report["errors"].append(f"Switch-Stack (NetBox Utilities): {error}")
return
stack = stacks[0] if stacks else None
current = [getattr(item, "id", item) for item in (getattr(stack, "members", None) or [])]
missing = [member_id for member_id in others if member_id not in current]
if not missing:
return
names = ", ".join(others[member_id].name for member_id in missing)
report["changes"].append(f"Switch-Stack {device.name}: Mitglieder {names} eintragen (NetBox Utilities)"
if stack else f"Switch-Stack {device.name} neu mit Mitgliedern {names} (NetBox Utilities)")
if dry_run:
return
try:
if stack:
stack.update({"members": current + missing})
else:
endpoint.create({"device": device.id, "members": missing})
except Exception as error: # noqa: BLE001
report["errors"].append(f"Switch-Stack (NetBox Utilities): {error}")
def sync_snapshot_to_netbox(nb, config, snapshot, create_cables=True, dry_run=False, log=_noop):
"""Write a discovery snapshot to NetBox.
@@ -1611,6 +1648,7 @@ def sync_snapshot_to_netbox(nb, config, snapshot, create_cables=True, dry_run=Fa
skipped = sum(1 for name, owner in owners.items() if owner is None
and stack_member(name, snapshot.get("platform")) == member)
report["notes"].append(f"Stack-Mitglied {member}: kein NetBox-Gerät gewählt – {skipped} Ports übersprungen")
_sync_switch_stack(nb, device, members, dry_run, report)
records = {}
for interface in snapshot["interfaces"]:
+5 -3
View File
@@ -976,12 +976,14 @@ class SwitchMappingDialog(_Dialog):
chosen = combo.currentData()
target = "" if chosen == self.NEW else chosen
mapping = result[switch["id"]]["interface_map"]
if target and (switch["id"], target) in used:
# Stack members have their own devices, so equal names are only a clash on the same device.
key = (switch["id"], item.get("owner_id"), target)
if target and key in used:
self.show_error(f"{switch['name']}: „{target}“ ist mehreren Schnittstellen zugeordnet "
f"({used[(switch['id'], target)]}, {item['name']}).")
f"({used[key]}, {item['name']}).")
return
if target:
used[(switch["id"], target)] = item["name"]
used[key] = item["name"]
# Plain name matches stay automatic; everything else is remembered.
if item["method"] == "name" and target == item["netbox_name"]:
mapping.pop(item["name"], None)
+27 -1
View File
@@ -1,6 +1,6 @@
from types import SimpleNamespace
from fake_netbox import FakeNetBox, Record
from fake_netbox import Endpoint, FakeNetBox, Record
from netbox_sync.core.switches import (
build_snapshot,
@@ -366,6 +366,32 @@ def test_stack_members_go_to_their_own_netbox_devices():
assert [(payload["device"], payload["name"]) for payload in nb.dcim.interfaces.created] == [(1, "lag1")]
def test_stack_is_filled_in_netbox_utilities_when_the_plugin_exists():
nb, switch, _snapshot = _numbered_setup()
snapshot = _stack_snapshot()
nb.dcim.devices.records.append(Record(nb.dcim.devices, id=4, name="access-01-2", tenant=SimpleNamespace(id=7)))
switch["stack_devices"] = {"1": 1, "2": 4}
# Without the plugin the stack is simply not written.
report = sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=False)
assert not report["errors"] and not any("Switch-Stack" in change for change in report["changes"])
nb.plugins = SimpleNamespace(utilities=SimpleNamespace(switch_stacks=Endpoint()))
stacks = nb.plugins.utilities.switch_stacks
report = sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=False, dry_run=True)
assert "Switch-Stack access-01 neu mit Mitgliedern access-01-2 (NetBox Utilities)" in report["changes"]
assert stacks.created == []
sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=False)
assert stacks.created == [{"device": 1, "members": [4]}]
stacks.records[0].device = SimpleNamespace(id=1)
report = sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=False, dry_run=True)
assert not any("Switch-Stack" in change for change in report["changes"]), "already complete"
# Members entered by hand stay, missing ones are added.
stacks.records[0].members = [9]
sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=False)
assert stacks.updates[-1] == (stacks.records[0].id, {"members": [9, 4]})
def test_virtual_chassis_positions_are_suggested():
nb, switch, _snapshot = _numbered_setup()
snapshot = _stack_snapshot()