Files
MrBlakeandClaude Opus 5.5 c4c35ed8d4 feat: optionally maintain agent client software as netbox-slm installations
New option "Installierte Software in netbox-slm pflegen" in the client transfer
dialog (off by default, remembered per profile). For clients scanned with the
NetBox Windows Agent, missing manufacturers, software products, versions and
installations are created in the netbox-slm plugin; automatic installations
the agent no longer reports are removed, installations entered by hand stay.
Products that netbox-utilities created without a manufacturer get one.

Names, versions and the marker comment match the software transfer of
netbox-utilities, so both run side by side without duplicates and its client
software overview shows the result. Without netbox-slm the option is skipped
with a log message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 14:37:47 +01:00

96 lines
3.8 KiB
Python

"""Tiny in-memory stand-in for the parts of pynetbox the sync code uses."""
import itertools
from types import SimpleNamespace
_ids = itertools.count(1000)
class Record(SimpleNamespace):
def __init__(self, endpoint=None, **values):
super().__init__(**values)
self._endpoint = endpoint
def update(self, values):
changed = any(getattr(self, key, None) != value for key, value in values.items())
for key, value in values.items():
setattr(self, key, value)
if changed and self._endpoint is not None:
self._endpoint.updates.append((self.id, dict(values)))
return changed
def _matches(record, key, value):
if isinstance(value, list): # pynetbox sends lists as repeated query parameters (OR)
return any(_matches(record, key, item) for item in value)
if key == "brief":
return True
if key.endswith("__ie"):
return str(getattr(record, key[:-4], "")).casefold() == str(value).casefold()
if key == "vrf_id":
vrf = getattr(record, "vrf", None)
vrf_id = vrf if isinstance(vrf, int) else getattr(vrf, "id", None)
return (vrf_id is None) if value == "null" else vrf_id == value
if key == "contains":
import ipaddress
prefix = getattr(record, "prefix", None)
return prefix is not None and ipaddress.ip_address(value) in ipaddress.ip_network(str(prefix), strict=False)
if key == "address":
return str(getattr(record, "address", "")).split("/")[0] == str(value).split("/")[0]
if key.endswith("_id") and not hasattr(record, key):
related = getattr(record, key[:-3], None)
return getattr(related, "id", related) == value
return getattr(record, key, None) == value
class Endpoint:
def __init__(self, records=()):
self.records = []
self.created = []
self.updates = []
for values in records:
self.records.append(Record(self, **values))
def all(self):
return list(self.records)
def filter(self, **kwargs):
return [record for record in self.records if all(_matches(record, k, v) for k, v in kwargs.items())]
def get(self, *args, **kwargs):
if args:
kwargs = {"id": args[0]}
found = self.filter(**kwargs)
if len(found) > 1:
raise ValueError("get() returned more than one result")
return found[0] if found else None
def create(self, payload):
if isinstance(payload, list): # bulk create
return [self.create(item) for item in payload]
record = Record(self, id=next(_ids), cable=None, **payload)
self.records.append(record)
self.created.append(payload)
return record
def delete(self, objects):
ids = {getattr(item, "id", item) for item in objects}
self.deleted = getattr(self, "deleted", []) + sorted(ids)
self.records = [record for record in self.records if record.id not in ids]
return True
class FakeNetBox:
netbox_version = "4.3.0"
def __init__(self):
self.dcim = SimpleNamespace(devices=Endpoint(), interfaces=Endpoint(), cables=Endpoint(),
mac_addresses=Endpoint(), platforms=Endpoint(),
manufacturers=Endpoint(), device_types=Endpoint(), device_roles=Endpoint(),
sites=Endpoint())
self.ipam = SimpleNamespace(ip_addresses=Endpoint(), prefixes=Endpoint(), vrfs=Endpoint(), vlans=Endpoint())
self.virtualization = SimpleNamespace(clusters=Endpoint(), cluster_types=Endpoint(), virtual_machines=Endpoint(),
interfaces=Endpoint())
self.tenancy = SimpleNamespace(tenants=Endpoint())
self.extras = SimpleNamespace(custom_fields=Endpoint())