saltext.vcf.utils.vcenter

vCenter REST API connection helpers.

Authentication uses the vCenter session API (POST /api/session), which returns a vmware-api-session-id token. The token is cached per (host, username) pair in a module-level dict so that multiple calls within the same Salt loader session do not re-authenticate on every invocation.

Config is read from Salt opts/pillar under saltext.vcf.vcenter:

saltext.vcf:
  vcenter:
    host: mgmt-vc.vcf.nimbus.internal
    username: administrator@vsphere.local
    password: VMware123!VMware123!
    verify_ssl: false
    # Optional. Default 30s; bump for long-running calls like OVF deploy.
    timeout: 1800
saltext.vcf.utils.vcenter.get_config(opts, profile=None)[source]

Extract vCenter connection config from Salt opts/pillar.

Returns a dict with keys: host, username, password, verify_ssl, timeout.

saltext.vcf.utils.vcenter.get_session(opts, profile=None)[source]

Return an authenticated (requests.Session, host) tuple for vCenter.

The session has the vmware-api-session-id header pre-set. The token is cached for the lifetime of the Python process; call invalidate_session() to force re-authentication.

saltext.vcf.utils.vcenter.invalidate_session(opts, profile=None)[source]

Remove the cached session token, forcing re-authentication on next call.

saltext.vcf.utils.vcenter.api_get(opts, path, params=None, profile=None, timeout=None)[source]

GET /api/<path> from vCenter and return parsed JSON.

timeout overrides the per-request timeout in seconds. Defaults to the pillar saltext.vcf.vcenter.timeout value, or DEFAULT_TIMEOUT.

saltext.vcf.utils.vcenter.api_post(opts, path, body=None, params=None, profile=None, timeout=None)[source]

POST JSON body to vCenter and return parsed JSON.

timeout overrides the per-request timeout (seconds). Long-running calls like OVF deploy should pass an explicit higher value.

saltext.vcf.utils.vcenter.api_patch(opts, path, body=None, profile=None, timeout=None)[source]

PATCH JSON body to vCenter and return parsed JSON.

saltext.vcf.utils.vcenter.api_put(opts, path, body=None, profile=None, timeout=None)[source]

PUT JSON body to vCenter and return parsed JSON.

saltext.vcf.utils.vcenter.api_delete(opts, path, profile=None, timeout=None)[source]

DELETE a resource from vCenter.