tools.xenserver_tools module
XenServer / XCP-ng pool management via the XenAPI XML-RPC (HTTPS).
Uses the XenAPI PyPI package (see requirements.txt). Connects to the
pool master on port 443 by default. Works with XenServer and XCP-ng (same XAPI).
Security: requires UNSANDBOXED_EXEC — controls foundational infrastructure.
TLS verification is off by default (verify_ssl=false); typical self-signed
pool certs. Use only on trusted networks or terminate TLS elsewhere.
- async tools.xenserver_tools.run(host='', user='', password='', action='', verify_ssl=False, pool_uuid=None, host_uuid=None, vm_uuid=None, sr_uuid=None, snapshot_name=None, snapshot_vm_uuid=None, credential_profile='', ctx=None)[source]
Validate and execute one XenServer/XCP-ng pool action, returning JSON.
Entry point for the
xenserver_controltool. It enforces theUNSANDBOXED_EXECgate, optionally hydrates host/user/password from a saved credential profile, validates the action and every supplied identifier, then runs the blocking XenAPI work off the event loop and serialises the result. A response that would exceed_MAX_JSON_CHARSis replaced with a “narrow the request” error so a huge pool dump cannot blow up the message pipeline.Interactions and side effects: gates via
_check_priv(); when acredential_profileis given it loads and merges saved credentials throughtools._credential_profile_store.load_profile()/tools._credential_profile_store.merge_profile()(kwargs override the profile). It validates the action against_VALID_ACTIONSand the inputs with_host_ok(),_user_ok(),_uuid_ok(), and_snapshot_name_ok(), normalises the URL with_normalize_master_url(), and dispatches the actual XML-RPC call by running_xapi_dispatch()in a worker thread viaasyncio.to_thread(). Mutating actions (VM start/shutdown/reboot/migrate/ destroy, snapshot create/revert/delete) change live infrastructure; read actions only fetch data. Readsredis/config/user_idoffctx. Dispatched by the tool loader via thexenserver_controlhandlerentry in this module’sTOOLSlist.- Parameters:
host (
str) – Pool master hostname, IP, or URL; optional whencredential_profilesupplies it.user (
str) – XenAPI username; optional when supplied by a profile.password (
str) – Account password; optional when supplied by a profile.action (
str) – The operation to perform; must be one of_VALID_ACTIONS.verify_ssl (
bool) – WhenTrue, verify TLS; defaults toFalsefor self-signed pool certs (mapped toignore_sslfor XenAPI).host_uuid (
str|None) – Host UUID forhost_infoor thevm_pool_migratedestination.vm_uuid (
str|None) – VM UUID for VM lifecycle, snapshot-create, migrate, and destroy actions.sr_uuid (
str|None) – Reserved for future SR-scoped actions; currently ignored.snapshot_vm_uuid (
str|None) – Snapshot VM UUID forsnapshot_revertandsnapshot_delete.credential_profile (
str) – Name of a saved profile to load credentials from; explicit kwargs override the loaded values.ctx (
Any) – The ToolContext supplyingredis,config, anduser_id; required.
- Returns:
A JSON string with the action result (always carrying
success), or asuccess: falseerror for a missing context, denied privilege, invalid action/identifier, or an oversized (truncated) response.- Return type: