feat(vmware): add vm_platform_from_annotation_relation config option#509
Open
dirtycache wants to merge 6 commits into
Open
feat(vmware): add vm_platform_from_annotation_relation config option#509dirtycache wants to merge 6 commits into
dirtycache wants to merge 6 commits into
Conversation
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>
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.
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
commentsfield. 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_relationto the VMware source handler, following the same key = value regex pattern as the existingvm_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.searchwithre.DOTALL. This means:vm_platform_relationwhen both would matchThe annotation is now always read from vCenter regardless of the
skip_vm_commentssetting, so platform detection works correctly even when comment syncing is disabled. Ifskip_vm_commentsis true, the annotation is used only for platform detection and is not written tocomments.Changes
module/sources/vmware/config.py: registers the newConfigOptionin the relations group with its own validator that compiles patterns withre.DOTALLmodule/sources/vmware/connection.py: reads annotation unconditionally, applies annotation-based platform override aftervm_platform_relation, guardscommentsassignment behindskip_vm_commentssettings-example.ini: documents the new option with a concrete exampleConfig example
Backwards compatibility
Fully backwards compatible. If
vm_platform_from_annotation_relationis not set, the new code path is a no-op (empty list iteration). No existing behaviour changes.