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). Useinvalidate_service_instanceto force a fresh connection (e.g. after a session timeout).When
saltext.vcf.vcenteris unset butsaltext.vcf.esxiis, delegate tosaltext.vcf.utils.esxi.get_service_instance()so everyvim_*client works transparently against a standalone ESXi host.saltext.vcf.vcenterwins 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 throughsaltext.vcf.utils.esxifor standalone hosts.
- saltext.vcf.utils.vim.resolve_host_system(opts, name_or_id, profile=None)[source]¶
Locate a
vim.HostSystemfor both standalone and vCenter modes.Shared helper used by every
vim_host_*client — one place to update resolution rules.Match order:
host._moIdorhost.nameAny VMkernel VNIC’s
ipAddress— useful when the caller only knows the mgmt IP the SmartConnect was made against but the host’snameis a stale DHCP-inherited hostname.Standalone-mode fallback: if only one HostSystem exists in the entire tree, return it.
h.nameon a fresh-install ESXi is often an inherited DHCP hostname (sysrescue, etc.) andh._moIdis a fixedha-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
*_Taskfinishes, then returntask.info.result.pyVmomi’s
*_Taskmethods 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.stateeverypoll_intervalseconds (default 0.5) up totimeoutseconds (default 300). RaisesRuntimeErroron task error andTimeoutErrorif the task hasn’t finished in time.
- saltext.vcf.utils.vim.session_cookie(opts, profile=None)[source]¶
Return the
vmware_soap_sessioncookie 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 asvmware_soap_session=<token>ready for aCookieheader.