vmware: add match_vm_by_serial/mac_address/ip_address options - #532
Open
remote24 wants to merge 1 commit into
Open
vmware: add match_vm_by_serial/mac_address/ip_address options#532remote24 wants to merge 1 commit into
remote24 wants to merge 1 commit into
Conversation
VM matching currently falls through name+cluster -> MAC address -> serial (BIOS UUID) -> primary IP, with the last three not scoped by cluster and (aside from serial, only partially) not configurable. When a VM is cloned or migrated between vCenters/clusters in a way that preserves its MAC/UUID/IP, a stale copy left behind in one cluster can silently overwrite the cluster/site/status of the real, active VM tracked under a different cluster instead of becoming its own NetBox object, even though NetBox's own VirtualMachine model only requires name uniqueness per cluster, not globally. Adds three options mirroring the existing match_host_by_serial pattern, each defaulting to True to preserve current behavior: match_vm_by_serial, match_vm_by_mac_address, match_vm_by_ip_address. Tested against a NetBox 4.6.7 instance with ~600 VMs across 4 vCenter sources, including several VMs with genuinely duplicated MAC/serial across clusters. With all three disabled, previously-misattributed VMs now correctly resolve to independent, per-cluster NetBox objects and no other object's cluster/site/status was affected. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
VM matching falls through name+cluster → MAC → serial/BIOS UUID → primary IP. Only the serial step has an opt-out (
match_host_by_serial, host-only) — MAC and IP have none, and none of the three fallbacks are scoped by cluster.This breaks any setup where a VM is cloned or migrated between vCenters in a way that preserves its MAC, UUID, or IP (common for cross-vCenter migration or cold-copy backups). NetBox itself allows duplicate VM names across different clusters, but netbox-sync doesn't respect that: a stale copy in cluster A fails the name+cluster check, falls through to MAC/serial/IP, matches the real VM's object in cluster B, and overwrites its
cluster/site/status.Net effect: a VM present in two sources ends up in NetBox once, not twice — silently, with nothing in the log indicating a problem.
Reproduction
myvmis active inClusterB(cluster=ClusterB,status=active).ClusterA, processed first insettings.ini.netbox-sync.py -nreassigns the same object:NBDevicetoo (steps 2–3 apply there), though only tested for VMs.Related issues
match_host_by_serial, the pattern this PR follows.match_vm_by_ip_addressis a no-op until it merges. Included so it's ready when it does.Fix
Three new options mirroring
match_host_by_serial, all defaulting toTrue(no behavior change unless opted in):match_vm_by_serial,match_vm_by_mac_address,match_vm_by_ip_address.Tested against NetBox 4.6.7 with ~600 VMs across 4 vCenter sources, including several with genuinely duplicated MAC/serial across clusters. With all three disabled, previously-misattributed VMs now resolve to independent, per-cluster objects; no other object's cluster/site/status changed.
See commit for the full patch (
module/sources/vmware/config.py,module/sources/vmware/connection.py,settings-example.ini).