Skip to content

vmware: add match_vm_by_serial/mac_address/ip_address options - #532

Open
remote24 wants to merge 1 commit into
bb-Ricardo:developmentfrom
remote24:fix/vm-cross-cluster-matching-fallbacks
Open

vmware: add match_vm_by_serial/mac_address/ip_address options#532
remote24 wants to merge 1 commit into
bb-Ricardo:developmentfrom
remote24:fix/vm-cross-cluster-matching-fallbacks

Conversation

@remote24

@remote24 remote24 commented Aug 6, 2026

Copy link
Copy Markdown

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

  • VM myvm is active in ClusterB (cluster=ClusterB, status=active).
  • A powered-off duplicate (same MAC/UUID) exists in ClusterA, processed first in settings.ini.
  • netbox-sync.py -n reassigns the same object:
    Virtual machine 'myvm' attribute 'cluster' changed from 'ClusterB' to 'ClusterA'
    Virtual machine 'myvm' attribute 'status' changed from 'active' to 'offline'
    Virtual machine 'myvm' attribute 'site' changed from '<ClusterB's site>' to '<ClusterA's site>'
    
    Confirmed via the API — one object, not two. Likely affects NBDevice too (steps 2–3 apply there), though only tested for VMs.

Related issues

Fix

Three new options mirroring match_host_by_serial, all defaulting to True (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).

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>
@remote24
remote24 requested a review from bb-Ricardo as a code owner August 6, 2026 07:58
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.

1 participant