tools.vmware_tools module
VMware ESXi / vCenter management via pyVmomi (vSphere API).
Stateless: connect per call in a worker thread, disconnect in finally.
Requires UNSANDBOXED_EXEC. TLS verification off by default for self-signed
infrastructure certs (trusted networks only).
Connection profiles: encrypted per-user JSON (host, user, password, port, verify_ssl).
- async tools.vmware_tools.run(action='', host='', user='', password='', port=443, verify_ssl=False, vm_uuid=None, vm_name=None, snapshot_name=None, credential_profile='', ctx=None)[source]
Validate and execute one VMware vCenter/ESXi management action.
Handler for the
vmware_controltool and the module’s primary entry point. It enforces the privilege gate, validates the action against_VALID_ACTIONS, resolves connection settings (optionally from a saved credential profile, with explicit kwargs overriding), checks that the requiredvm_uuid/vm_nameis present for per-VM actions, then runs the blocking vSphere work off the event loop. Results are size-capped to_MAX_JSON_CHARSso an oversized inventory cannot overrun the response.It calls
_check_priv()(UNSANDBOXED_EXEC) for authorization; whencredential_profileis set it loads the encrypted profile via_cred_loadand combines it with the passed kwargs via_cred_merge(tools._credential_profile_store); and it executes_vmware_dispatch()throughasyncio.to_threadso the synchronous pyVmomi session does not block the loop. Invoked by the tool dispatcher intools/__init__.py, which calls this handler with the tool arguments and the ToolContext; there are no other internal callers.- Parameters:
action (
str) – The action to perform; must be in_VALID_ACTIONS.host (
str) – vCenter/ESXi host; required unless supplied by the profile.user (
str) – vSphere login; required unless supplied by the profile.password (
str) – Password; required unless supplied by the profile.port (
int) – vSphere API TCP port (defaults to 443).verify_ssl (
bool) – Whether to verify TLS (defaults to False).vm_uuid (
str|None) – VM instance UUID for per-VM actions (preferred).vm_name (
str|None) – VM display name for per-VM actions when no UUID is given.snapshot_name (
str|None) – Snapshot name, required for thesnapshot_*actions.credential_profile (
str) – Optional saved profile name; its values are used as defaults and overridden by any non-empty kwargs above.ctx (
Any) – The ToolContext; required for privilege check and profile loading.
- Return type:
- Returns:
A JSON string with the dispatch result, or a JSON error (no context, missing privilege, invalid action, profile load failure, missing host/user/password, missing VM identifier, or a size-limit truncation notice when the serialized result exceeds
_MAX_JSON_CHARS).