check_redfish: model components as NetBox modules - #560
Conversation
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.
|
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 The only thing I changed is the conflict against #551: two option inserts landed in the same spot in |
|
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. The type catalog was being filled with per-instance names. A module type is a shared catalog entry, but 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. |
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.pyandsettings-example.ini- both options are kept. Commits are his.Suite is 141 with the modules tests.