Skip to content

feat(vmware): add vm_platform_from_annotation_relation config option#509

Open
dirtycache wants to merge 6 commits into
bb-Ricardo:mainfrom
dirtycache:main
Open

feat(vmware): add vm_platform_from_annotation_relation config option#509
dirtycache wants to merge 6 commits into
bb-Ricardo:mainfrom
dirtycache:main

Conversation

@dirtycache

Copy link
Copy Markdown

Problem

Appliance-style VMs — network and security virtual appliances, load balancers, firewalls, etc. — typically run on a modified Linux base. vSphere correctly identifies the underlying kernel as CentOS, Ubuntu, or similar, and that is what gets synced to NetBox as the VM's platform. The actual product identity is lost.

These VMs often carry product-identifying text in their vCenter annotation (Notes field), which is already synced to NetBox as the comments field. There is currently no way to use that annotation content to influence platform assignment.

This is a gap that affects any operator running virtual appliances alongside general-purpose Linux VMs: both classes end up with the same platform name in NetBox, making it impossible to filter or report on them by platform.

Related issues: #429, #495.

Solution

Adds a new optional config option vm_platform_from_annotation_relation to the VMware source handler, following the same key = value regex pattern as the existing vm_platform_relation.

The key difference is what is matched: instead of matching the vSphere-reported guest OS name, patterns are matched against the full vCenter annotation text using re.search with re.DOTALL. This means:

  • patterns match anywhere in a multi-line annotation without anchoring
  • newlines are transparently handled — no special flags needed in the config
  • the option takes priority over vm_platform_relation when both would match

The annotation is now always read from vCenter regardless of the skip_vm_comments setting, so platform detection works correctly even when comment syncing is disabled. If skip_vm_comments is true, the annotation is used only for platform detection and is not written to comments.

Changes

  • module/sources/vmware/config.py: registers the new ConfigOption in the relations group with its own validator that compiles patterns with re.DOTALL
  • module/sources/vmware/connection.py: reads annotation unconditionally, applies annotation-based platform override after vm_platform_relation, guards comments assignment behind skip_vm_comments
  • settings-example.ini: documents the new option with a concrete example

Config example

; Map F5 BIG-IP LTM Virtual Edition VMs to the TMOS platform regardless of
; what vSphere reports as the guest OS
vm_platform_from_annotation_relation = BIG-IP Local Traffic Manager Virtual Edition.*F5 = TMOS

; Multiple mappings are comma-separated, same as other relation options
; vm_platform_from_annotation_relation = ProductA.*Vendor = PlatformA, ProductB.*Vendor = PlatformB

Backwards compatibility

Fully backwards compatible. If vm_platform_from_annotation_relation is not set, the new code path is a no-op (empty list iteration). No existing behaviour changes.

Lab Admin and others added 6 commits June 17, 2026 16:57
Allows overriding a VM's platform in NetBox based on a regex match
against the vCenter annotation (notes) field. Useful when vSphere
misreports the guest OS — F5 BIG-IP/BIG-IQ VE VMs identify as CentOS
but carry identifying text in their annotation.

Patterns are compiled with re.DOTALL and matched via re.search so they
span newlines and match anywhere in the annotation without anchoring.
Takes priority over vm_platform_relation when both would match.

The annotation is now always read from vCenter regardless of the
skip_vm_comments setting, so platform detection works even when
comment syncing is disabled.
Introduces a new config option that allows the same IP address to
appear on multiple VM interfaces simultaneously without triggering
duplicate-assignment warnings or being skipped.

A common real-world scenario is isolated HA peer-to-peer VLANs where
the same /30 addressing scheme is reused across many VM pairs. The
IPs are unique within each link VLAN but overlap globally, causing
netbox-sync's in-memory duplicate check to warn and skip the second
(and subsequent) interface assignments.

When an IP falls within a configured overlapping subnet, netbox-sync
creates a separate NetBox IP address object per interface rather than
sharing a single object. The existing duplicate-check logic for all
other IPs is unchanged.
vmware-vapi-runtime 2.52.0 imports pkg_resources at runtime in
vmware/vapi/l10n/bundle.py. setuptools >= 81 added a DeprecationWarning
to pkg_resources, causing a UserWarning to be emitted on every run when
the vSphere source is configured.

Suppress the specific warning at startup until the vapi stack is upgraded
to 9.x, where the import is replaced with importlib.resources.
…rsing (#1)

configparser joins multi-line values with \n, so relation entries on
continuation lines start with a leading newline. The previous strip(' "')
left that newline in the regex pattern, causing matches to fail unless
the annotation itself started with a newline.

Using strip() fixes multi-line *_relation config values in settings.ini.

Co-authored-by: Lab Admin <labadmin@netbox.wwtcai.com>
…-IQ mapping (#2)

Co-authored-by: Lab Admin <labadmin@netbox.wwtcai.com>
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