saltext.vcf.utils.vim

vSphere SOAP/VMODL connection helpers (pyVmomi).

Used for capabilities that vSphere REST doesn’t yet expose — vSAN imperative ops, Auto Deploy, Fault Tolerance, PerfManager historical counters, PropertyCollector real-time subscriptions, AlarmManager authoring, ExtensionManager, LicenseAssignmentManager, PBM policy authoring.

The pyvmomi package is a hard dependency of saltext-vcf. Connect to vCenter (or directly to an ESXi host) once per (host, username) pair and cache the ServiceInstance. Modules call get_service_instance() and operate on si.content to reach the various managers.

Config is read from Salt opts/pillar under the same saltext.vcf.vcenter key as utils/vcenter (REST), so REST and SOAP modules share one credential block:

saltext.vcf:
  vcenter:
    host: mgmt-vc.vcf.nimbus.internal
    username: administrator@vsphere.local
    password: VMware123!VMware123!
    verify_ssl: false
saltext.vcf.utils.vim.get_config(opts, profile=None)[source]

SOAP shares the REST vCenter config — no separate pillar key.

saltext.vcf.utils.vim.get_service_instance(opts, profile=None)[source]

Return a connected pyVmomi ServiceInstance.

Cached per (host, username). Use invalidate_service_instance to force a fresh connection (e.g. after a session timeout).

saltext.vcf.utils.vim.invalidate_service_instance(opts, profile=None)[source]

Disconnect and drop the cached ServiceInstance for this target.

saltext.vcf.utils.vim.content(opts, profile=None)[source]

Shortcut: get_service_instance(opts).RetrieveContent().

saltext.vcf.utils.vim.wait_for_task(task, *, timeout=300, poll_interval=0.5)[source]

Block until a pyVmomi *_Task finishes, then return task.info.result.

pyVmomi’s *_Task methods are async: they return as soon as vCenter accepts the request, before the operation has actually taken effect. Callers that immediately query the resulting state race the task; wrap every mutating SOAP call with this helper.

Polls task.info.state every poll_interval seconds (default 0.5) up to timeout seconds (default 300). Raises RuntimeError on task error and TimeoutError if the task hasn’t finished in time.

Return the vmware_soap_session cookie from the cached ServiceInstance.

Used to authenticate HTTP requests to vCenter /folder/?dsName=… style file-transfer endpoints (datastore upload/download, OVF push/pull). The cookie value is wrapped as vmware_soap_session=<token> ready for a Cookie header.