Repository navigation
fix: match interfaces by the primary MAC address object on NetBox >= 4.2 - #585
Merged
semx merged 1 commit intoOct 8, 2026
Merged
Conversation
From NetBox 4.2 on, sources only maintain the interface's primary MAC address object. The legacy 'mac_address' field keeps the value NetBox returned when the data was read and is never updated during a run. map_object_interfaces_to_current_interfaces() still matched on that field. If one source changed an interface's primary MAC address, the next source still saw the old MAC address. With a VMware and a check_redfish source syncing the same ESXi hosts, a BMC port (i.e. Lenovo XCC) whose MAC address had ended up on vmk0 was merged into vmk0 on every run. The BMC IP moved to vmk0, the host's management IP was removed and the primary IP of the device got unset. Use the MAC address of the primary MAC address object on NetBox >= 4.2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
semx
approved these changes
Oct 8, 2026
semx
left a comment
Collaborator
There was a problem hiding this comment.
Reproduced on a NetBox 4.7.2 with vcsim and a check_redfish inventory for the same host, the BMC MAC planted on vmk0 as its primary MAC the way an earlier run leaves it. Without this change the BMC port is merged into vmk0 on every run: vmk0 becomes mgmt_only, gets the BMC IP, loses the host IP and the device loses primary_ip4; the next run flips it back. With it, vmk0 gets its own MAC back, the BMC port gets its own interface with its IP, primary_ip4 stays, and the second run changes nothing. Both new tests fail on development without the fix; the suite is green with it.
Two things, neither blocks:
- The
< 4.2branch has no test: dropping the version check and always reading the primary MAC object passes the whole suite. One case withinventory.netbox_api_version = "4.1.0"and an interface that only hasmac_addresswould pin it. Fine to add in a follow-up if you prefer. get_object_based_on_macs()in the VMware source still identifies hosts and VMs by the legacymac_address. Same staleness, different place; I'll track it separately, it is not part of this fix.
Branch is off main again; I'll switch the base to development and merge once CI has run.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On NetBox >= 4.2,
map_object_interfaces_to_current_interfaces()now matches interfaces by the MAC address of theirprimary_mac_addressobject. Before, it used the legacymac_addressfield. That field keeps the value NetBox returned at read time and isn't updated during a run, so a source could match against a MAC address that an earlier source had already replaced. NetBox < 4.2 keeps usingmac_address.With a VMware and a check_redfish source syncing the same ESXi hosts, this merged the Lenovo XCC port into
vmk0on every run, which moved the XCC IP tovmk0and unset the device's primary IP. Details in #584.Changes:
module/sources/common/source_base.py: read the MAC address from the primary MAC address object on NetBox >= 4.2tests/test_interface_matching_primary_mac.py: a stale legacy MAC no longer matches, and the primary MAC still does. Both tests fail without the fix.Tested against NetBox 4.7.2 with a vCenter 8.0.3 source and the check_redfish inventory files of HPE and Lenovo hosts: the XCC ports get their own interfaces again,
vmk0keeps its MAC and management IP, and a second run makes no changes.pytest: 259 passed (vcsim installed).Fixes #584
🤖 Generated with Claude Code