Skip to content

suppress pkg_resources DeprecationWarning from vmware-vapi-runtime on setuptools >= 81#510

Open
dirtycache wants to merge 4 commits into
bb-Ricardo:mainfrom
dirtycache:fix/suppress-pkg-resources-deprecation-warning
Open

suppress pkg_resources DeprecationWarning from vmware-vapi-runtime on setuptools >= 81#510
dirtycache wants to merge 4 commits into
bb-Ricardo:mainfrom
dirtycache:fix/suppress-pkg-resources-deprecation-warning

Conversation

@dirtycache

Copy link
Copy Markdown

Problem

Users running netbox-sync with a vSphere source on systems where setuptools >= 81 is installed receive a UserWarning on every run:

/path/to/vmware/vapi/l10n/bundle.py:59: UserWarning: pkg_resources is deprecated as an API.
See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is
slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  from pkg_resources import resource_string

This warning originates in vmware-vapi-runtime 2.52.0 (vmware/vapi/l10n/bundle.py), which imports pkg_resources at runtime. setuptools 81.0.0 (released February 2026) added a DeprecationWarning to pkg_resources/__init__.py, causing this to surface for anyone on a current setuptools.

Because the warning is emitted to stderr, it bypasses the >/dev/null in the documented cron entry and produces unwanted email noise for cron-based deployments.

Root cause

vmware-vapi-runtime 2.52.0 uses pkg_resources.resource_string() to load .properties resource files from the package. The modern stdlib replacement is importlib.resources, which is available in all Python versions netbox-sync supports (3.6+).

Broadcom has already made this fix in vmware-vapi-runtime 9.1.0.0, where the import is replaced with importlib.resources. However, upgrading the full vapi stack (vmware-vapi-runtime, vmware-vapi-common-client, vmware-vcenter) from 2.52.0/8.0.3.0 to 9.1.0.0 is a non-trivial change:

  • The 9.x packages come from a new repo (vcf-sdk-python, the rebranded VMware Cloud Foundation SDK)
  • VCF SDK 9.x officially targets vCenter 8.x/9.x and drops vCenter 7.x support, which conflicts with netbox-sync's stated compatibility

That upgrade is worth pursuing separately once the compatibility implications are fully assessed.

Fix

Suppress the specific warning at startup in netbox-sync.py, before any vmware modules are imported:

import warnings
warnings.filterwarnings("ignore", message="pkg_resources is deprecated", category=UserWarning)

The filter is scoped to the exact warning message rather than suppressing all UserWarnings. It will become a harmless no-op once the vapi stack is eventually upgraded to 9.x.

Alternatives considered

  • Pin setuptools < 81: Treats the symptom, keeps the codebase on aging build tooling, and still leaves a time bomb when pkg_resources is eventually removed from setuptools entirely.
  • -W flag on the Python invocation: Only helps users following the exact documented cron entry; does not help systemd, Docker, Kubernetes, or direct invocations.
  • Suppress stderr entirely (2>&1): The documented cron entry already does this; the problem affects users who route stderr to logs or rely on cron email for error alerting.

Lab Admin added 4 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.
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