tools.proxmox_tools module
Proxmox VE hypervisor control via the Proxmox REST API.
Uses the proxmoxer library (see requirements.txt). Authenticate with
either a password (user like root@pam) or an API token (user like
root@pam!tokenid and password as the token secret).
Security: requires UNSANDBOXED_EXEC — controls foundational infrastructure.
TLS verification is disabled by default (typical self-signed Proxmox certs); use only on trusted networks or terminate TLS elsewhere.
- async tools.proxmox_tools.run(host='', user='', password='', node='', action='', vmid=None, snapshot_name=None, credential_profile='', ctx=None)[source]
Authorize, validate, and execute one Proxmox VE control action, returning JSON.
Handler for the
proxmox_controltool — the public entry point for VM lifecycle and snapshot operations on a Proxmox hypervisor. It enforces the privilege gate, optionally hydrates connection details from a saved credential profile, validates every field, then runs the blocking Proxmox call off the event loop and serialises the result (truncating oversized payloads).It gates on
_check_priv()(theUNSANDBOXED_EXECprivilege, resolved against Redis). Whencredential_profileis given it loads and decrypts that profile viatools._credential_profile_store.load_profile()(reading the Redis hashstargazer:proxmox_credentials:{user_id}) and overlays explicit kwargs withtools._credential_profile_store.merge_profile(). It checksactionagainst_VALID_ACTIONSand validates host/user/node/snapshot with_host_ok(),_user_ok(),_node_ok(), and_snapshot_name_ok(), requiringvmidfor every action exceptlist_vms. The realproxmoxerwork — which makes live HTTP calls to the hypervisor and can mutate VM state — is run viaasyncio.to_thread(_proxmox_dispatch, ...)so the loop is not blocked. Results larger than_MAX_JSON_CHARSare replaced with a “narrow the request” error. This function mutates no module state of its own.Registered in the module
TOOLSlist as theproxmox_controlhandler and dispatched bytool_loader.py; no direct in-repo Python callers.- Parameters:
host (
str) – Proxmox API host; required unless supplied viacredential_profile.user (
str) – Auth user/realm, e.g.root@pamorroot@pam!tokenid.password (
str) – Account password or API-token secret (required).node (
str) – Cluster node name to target.action (
str) – One of_VALID_ACTIONS(list_vms,start_vm,stop_vm,reset_vm,create_snapshot,rollback_snapshot,destroy_vm).vmid (
int|None) – Target QEMU VM id; required for every action exceptlist_vms.snapshot_name (
str|None) – Snapshot name; required for the snapshot and rollback actions.credential_profile (
str) – Name of a saved profile to load host/user/ password/node from; explicit kwargs override the loaded values.ctx (
Any) – The toolToolContextsupplyingredis,config, anduser_id;Noneyields a “No context.” error.
- Returns:
A JSON result string — the dispatch payload (with
successand action-specific keys) on success, or a JSON error for missing context, denied privilege, a bad profile load, an invalid action/host/user/node/ snapshot, a missing requiredvmid, or an over-limit response.- Return type: