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.example.test
    username: administrator@vsphere.local
    password: secret
    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).

When saltext.vcf.vcenter is unset but saltext.vcf.esxi is, delegate to saltext.vcf.utils.esxi.get_service_instance() so every vim_* client works transparently against a standalone ESXi host. saltext.vcf.vcenter wins when both are set.

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.is_standalone_esxi(opts, profile=None)[source]

Return True when only saltext.vcf.esxi (no vCenter) is configured.

The two SOAP entry points diverge in credential source and host-lookup semantics; vim_* clients use this to route through saltext.vcf.utils.esxi for standalone hosts.

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

Locate a vim.HostSystem for both standalone and vCenter modes.

Shared helper used by every vim_host_* client — one place to update resolution rules.

Match order:

  1. host._moId or host.name

  2. Any VMkernel VNIC’s ipAddress — useful when the caller only knows the mgmt IP the SmartConnect was made against but the host’s name is a stale DHCP-inherited hostname.

  3. Standalone-mode fallback: if only one HostSystem exists in the entire tree, return it. h.name on a fresh-install ESXi is often an inherited DHCP hostname (sysrescue, etc.) and h._moId is a fixed ha-host — both are impractical to target by.

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.