Skip to content

check_redfish: model components as NetBox modules - #560

Open
semx wants to merge 4 commits into
developmentfrom
feature/check-redfish-modules
Open

check_redfish: model components as NetBox modules#560
semx wants to merge 4 commits into
developmentfrom
feature/check-redfish-modules

Conversation

@semx

@semx semx commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Closes #473, integrates #552 by @marcinpsk.

NetBox deprecated inventory items in 4.3 and points at modules instead. This adds model_components_as_modules, off by default: with it on, and NetBox 4.3 or newer, every component check_redfish reports becomes a module in a module bay typed from a catalog. With it off, or on older NetBox, nothing changes and inventory items are written as before.

His branch predated #551, so the only thing I had to do was resolve the two adjacent option inserts in config.py and settings-example.ini - both options are kept. Commits are his.

Suite is 141 with the modules tests.

marcinpsk and others added 2 commits September 9, 2026 19:06
NetBox deprecated inventory items in 4.3 and points at modules as the replacement
(bb-Ricardo/netbox-sync issue 473). Modules carry a type from a catalog, live in a
named bay, and own their interfaces and power ports, so the hardware a server
reports can be modelled as what it is rather than as free text.

New option model_components_as_modules, default False, so nothing changes unless it
is set. When it is set and NetBox is 4.3 or newer, every component check_redfish
reports (CPU, DIMM, drive, controller, enclosure, NIC, PSU, fan, BMC) becomes a
module in a module bay, typed by a module type. On an older NetBox the option is
ignored and inventory items are used, so one configuration works across versions.

update_all_items() dispatches to update_all_modules() and the inventory item path is
untouched, which keeps the two backends side by side rather than replacing one.

Object model: NBModuleType, NBModuleBay and NBModule, all gated on NetBox 4.3.
NBModule has no name of its own, so it is keyed on its bay and derives its display
name from it. NBInterface and NBPowerPort gain a module foreign key, and NBModule
becomes a valid custom field target.

The bay is the physical slot and is keyed on a stable identifier, never on a name
carrying the installed part: the CPU socket, the DIMM slot label, the drive slot,
the NIC adapter id, the PSU slot. A part swap then reuses the bay and re-points the
module type instead of creating a second bay. A slot longer than the 64 characters
NetBox stores is shortened to a prefix plus a digest of the full name, so two long
slots sharing a prefix do not collapse onto one bay.

Bay matching is strict. update_module() never moves a module between bays, so an
unmatched current module is a removed component, marked absent and kept registered
with this source, not a target to remap another component onto.

NetBox requires a manufacturer on a module type. It is taken from redfish, then from
an existing module type for the same model so a curated value is not clobbered, then
from the device vendor.

NIC ports and the BMC interface are attached to their parent module, and PSU power
ports to their supply module. NetBox cascade-deletes module components, so those
links are cleared again when the option is turned off or no parent module resolves,
which stops a module prune removing a port this source still manages. With modules
on, a NIC port is named by its stable redfish id and the long descriptive label
moves to the description.

settings-example.ini is regenerated with netbox-sync.py -g rather than hand edited.

The tests drive the real CheckRedfish methods against the real inventory: the
version and option matrix, the full module graph, idempotency, module type reuse and
re-pointing, bay stability across part swaps, prefix-colliding long names, strict bay
matching, absent components, interface and power port links in both directions, and
the inventory item path still being used when the option is off.
@semx
semx requested a review from bb-Ricardo as a code owner September 9, 2026 23:01
@semx

semx commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

Not merging this one, it is your call. You wrote "probably not" on #473 when asked whether netbox-sync would move to modules, and this decides how hardware ends up modelled in NetBox, so it should be your decision rather than mine.

What I checked: it is off by default and additionally gated on NetBox 4.3, so nothing changes for anyone who does not set model_components_as_modules; with it off the inventory-item path is unchanged; suite is 141 green including the module tests that come with it. What I did not check is the module modelling itself - bay naming, type catalog, how components map onto module types - that is @marcinpsk's design and worth your eyes.

The only thing I changed is the conflict against #551: two option inserts landed in the same spot in config.py and settings-example.ini, both are kept. His commits are untouched.

@semx

semx commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

I said I had not checked the module modelling itself, so I did - stood up NetBox 4.7 in docker, pointed a check_redfish inventory at a device the VMware source had just created, and ran it. Two things came out of it, both fixed on this branch, his commits untouched.

The feature was not idempotent. NBModuleBay, NBModuleType and NBModule were never read back from NetBox - NBInventoryItem is in dependent_netbox_objects, those three are not - so every run after the first tried to create them again: 230 errors, Module type with this Manufacturer and Model already exists, then the module POST failing with module_type: This field is required, and the tags being rewritten on every pass. They are now requested, but only when the option is on, so nobody else pays for three extra queries.

The type catalog was being filled with per-instance names. A module type is a shared catalog entry, but storage_enclosure, physical_drive, manager and storage_controller never put their model into the item data - it only went into the display name - so the type came out as Disk.Bay.0 Disk.Bay.0 (HDD ST2000NX0273) or BP_PSV 0:1 instead of ST2000NX0273 and BP14G+EXP. On a fleet that is a new module type per component per server. They pass the model now, and where a component has neither model nor part number the fallback is the component class (Fan) rather than the instance name.

Measured on NetBox 4.7 with one Dell inventory: before, second run 230 errors and 109 changes; after, first run 0 errors and the next run 0 errors and 0 changes. Catalog is 9 types, one per real part: BCM57416, 16G Monolithic, BP14G+EXP, Fan, PERC H755 Front, PWR SPLY,1400W, Xeon Gold 6338, MTA36ASF8G72PZ, ST2000NX0273. Switching the option on also tags the old inventory items orphaned, so the migration cleans up after itself.

Suite is 183. Still your call whether modules are the direction you want, but the implementation holds up now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants