HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/esxvm.cpython-310.pyc
o

�N�g<P�@s
dZddlZddlZddlmZddlZddlmZzddl	Z	dZ
Wney-dZ
Ynwz
ddlm
Z
dZWneyCdZYnwe�e�Zdd	�Zd
d�Ze							ddd
��Zedd��Ze				ddd��Ze					ddd��Zeddd��ZdS)aw
Salt state to create, update VMware ESXi Virtual Machines.

.. Warning::
    This module will be deprecated in a future release of Salt. VMware strongly
    recommends using the
    `VMware Salt extensions <https://docs.saltproject.io/salt/extensions/salt-ext-modules-vmware/en/latest/all.html>`_
    instead of the ESX VSM module. Because the Salt extensions are newer and
    actively supported by VMware, they are more compatible with current versions
    of ESXi and they work well with the latest features in the VMware product
    line.


Dependencies
============

- pyVmomi
- jsonschema

States
======

vm_configured
-------------

Enforces correct virtual machine configuration. Creates, updates and registers
a virtual machine.

This state identifies the action which should be taken for the virtual machine
and applies that action via the create, update, register state functions.

Supported proxies: esxvm


Example:

1. Get the virtual machine ``my_vm`` status with an ``esxvm`` proxy:

Proxy minion configuration for ``esxvm`` proxy:

.. code-block:: yaml

    proxy:
      proxytype: esxvm
      datacenter: my_dc
      vcenter: vcenter.fake.com
      mechanism: sspi
      domain: fake.com
      principal: host

State configuration:

.. code-block:: yaml

      myvm_state:
        esxvm.vm_configured:
        - vm_name: my_vm
        - cpu: {{ {'count': 4, 'cores_per_socket': 2} }}
        - memory: {{ {'size': 16384, 'unit': 'MB'} }}
        - image: rhel7_64Guest
        - version: vmx-12
        - interfaces: {{ [{
                           'adapter': 'Network adapter 1',
                           'name': 'my_pg1',
                           'switch_type': 'distributed',
                           'adapter_type': 'vmxnet3',
                           'mac': '00:50:56:00:01:02,
                           'connectable': { 'start_connected': true,
                                            'allow_guest_control': true,
                                            'connected': true}},
                           {
                           'adapter': 'Network adapter 2',
                           'name': 'my_pg2',
                           'switch_type': 'distributed',
                           'adapter_type': 'vmxnet3',
                           'mac': '00:50:56:00:01:03',
                           'connectable': { 'start_connected': true,
                                            'allow_guest_control': true,
                                            'connected': true}}
                      ] }}
        - disks: {{ [{
                      'adapter': 'Hard disk 1',
                      'unit': 'MB',
                      'size': 51200,
                      'filename': 'my_vm/sda.vmdk',
                      'datastore': 'my_datastore',
                      'address': '0:0',
                      'thin_provision': true,
                      'eagerly_scrub': false,
                      'controller': 'SCSI controller 0'},
                      {
                      'adapter': 'Hard disk 2',
                      'unit': 'MB',
                      'size': 10240,
                      'filename': 'my_vm/sdb.vmdk',
                      'datastore': 'my_datastore',
                      'address': '0:1',
                      'thin_provision': true,
                      'eagerly_scrub': false,
                      'controller': 'SCSI controller 0'}
                ] }}
        - scsi_devices: {{ [{
                             'adapter': 'SCSI controller 0',
                             'type': 'paravirtual',
                             'bus_sharing': 'no_sharing',
                             'bus_number': 0}
                            ] }}
        - serial_ports: {{ [{
                             'adapter': 'Serial port 1',
                             'type': 'network',
                             'yield': false,
                             'backing': {
                                         'uri': 'my_uri',
                                         'direction': 'server',
                                         'filename': 'my_file'},
                              'connectable': {
                                              'start_connected': true,
                                              'allow_guest_control': true,
                                              'connected': true}}
                             ] }}
        - datacenter: {{ 'my_dc' }}
        - datastore: 'my_datastore'
        - placement: {{ {'cluster': 'my_cluster'} }}
        - cd_dvd_drives: {{ [] }}
        - advanced_configs: {{ {'my_param': '1'} }}
        - template: false
        - tools: false
        - power_on: false
        - deploy: false


vm_updated
----------

Updates a virtual machine to a given configuration.

vm_created
----------

Creates a virtual machine with a given configuration.

vm_registered
-------------

Registers a virtual machine with its configuration file path.

Dependencies
============

pyVmomi
-------

PyVmomi can be installed via pip:

.. code-block:: bash

    pip install pyVmomi

.. note::

    Version 6.0 of pyVmomi has some problems with SSL error handling on
    certain versions of Python. If using version 6.0 of pyVmomi, Python 2.6,
    Python 2.7.9, or newer must be present. This is due to an upstream
    dependency in pyVmomi 6.0 that is not supported in Python versions
    2.7 to 2.7.8. If the version of Python is not in the supported range,
    you will need to install an earlier version of pyVmomi.
    See `Issue #29537`_ for more information.

.. _Issue #29537: https://github.com/saltstack/salt/issues/29537

Based on the note above, to install an earlier version of pyVmomi than the
version currently listed in PyPi, run the following:

.. code-block:: bash

    pip install pyVmomi==6.0.0.2016.4

The 5.5.0.2014.1.1 is a known stable version that this original ESXi State
Module was developed against. To be able to connect through SSPI you must
use pyvmomi 6.0.0.2016.4 or above. The ESXVM State Module was tested with
this version.

About
-----

This state module was written to be used in conjunction with Salt's
:mod:`ESXi Proxy Minion <salt.proxy.esxi>` For a tutorial on how to use Salt's
ESXi Proxy Minion, please refer to the
:ref:`ESXi Proxy Minion Tutorial <tutorial-esxi-proxy>` for
configuration examples, dependency installation instructions, how to run remote
execution functions against ESXi hosts via a Salt Proxy Minion, and a larger state
example.
�N��wraps)�ESXVirtualMachineConfigSchemaTF)�VmomiSupportcCs6tsdStsdSdtjvrtjdkrtjdkrdSdS)N)Fz/State module did not load: jsonschema not found)Fz,State module did not load: pyVmomi not foundz	vim25/6.0)��)rr�	)FzaState module did not load: Incompatible versions of Python and pyVmomi present. See Issue #29537.T)�HAS_JSONSCHEMA�HAS_PYVMOMIrZ
versionMap�sys�version_info�r
r
�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/esxvm.py�__virtual__�s


rcst���fdd��}|S)z>
    Decorator wrapper to warn about azurearm deprecation
    cs6tjjjddtd��|itjjjdi|����}|S)NZArgonz�The 'esxvm' functionality in Salt has been deprecated and its functionality will be removed in version 3008 in favor of the saltext.vmware Salt Extension. (https://github.com/saltstack/salt-ext-modules-vmware))�categoryr
)�salt�utilsZversionsZ
warn_until�
FutureWarning�argsZclean_kwargs)r�kwargs�ret��functionr
r�wrapped�s�z%_deprecation_message.<locals>.wrappedr)rrr
rr�_deprecation_message�srcCs$|didd�}t�d�t��}t�d|�z?t�id|�d|�d|�d	|�d
|�d|�d|�d
|�d|	�d|
�d|�d|
�d|�d|�d|�d|�d|�d|i�|�Wntjjyi}ztj�	|��d}~wwt
d�}zt
d|dg|d�Wnutjjy�t
d||
|||d�}|r�tdr�|�
dd �|�i�t
d!|�|YSt||
|||d"�}|YStdr�|�
dd#�|�i�t
d!|�|YS|r�t|�}|YSt||||||||||	|
|||
||d$�}|YSwt||||||||||	|
||
|||d%�}t
d!|�t�|�|S)&z�
    Selects the correct operation to be executed on a virtual machine, non
    existing machines will be created, existing ones will be updated if the
    config differs.
    N���name�result�changes�commentz(Validating virtual machine configurationzschema = %s�vm_name�cpu�memory�image�version�
interfaces�disks�scsi_devices�serial_ports�
cd_dvd_drives�sata_controllers�
datacenter�	datastore�	placement�template�tools�power_on�deploy�&vsphere.get_service_instance_via_proxyzvsphere.get_vmr)Z
vm_properties�service_instancezvsphere.get_vm_config_file�r4�testr z*The virtual machine {} will be registered.�vsphere.disconnect)r1z'The virtual machine {} will be created.)r*�advanced_configsr1)r*r+r8r1)�log�tracerZ	serialize�
jsonschema�validate�
exceptionsZValidationErrorrZInvalidConfigError�__salt__ZVMwareObjectRetrievalError�__opts__�update�format�
vm_registered�	vm_cloned�
vm_created�
vm_updated)rr!r"r#r$r%r&r'r(r)r,r-r.r*r+r8r/r0r1r2rZschema�excr4�vm_filer
r
r�
vm_configureds�
��������	�
���
���������

�
����
�������5�
rHcCs|didd�}|S)zu
    Clones a virtual machine from a template virtual machine if it doesn't
    exist and a template is defined.
    Trrr
)rrr
r
rrC�srCcCs�|didd�}td�}td||
d|d�}td|||||||||	|
|||
|d	�|�}|s=|�d
id|�d�d
��|Stdrbd�||
d�dd�|��D���}|�d|d��td|�|Sztd|||||||||	|
|||
||d�}Wn.tjjy�}z t	�
d|�|r�td|�|�dt|�d��|WYd}~Sd}~ww|r�z	td||
�Wn.tjjy�}z t	�
d|�|r�td|�|�dt|�d��|WYd}~Sd}~ww|�dd
i�td|�|d
|d|�d�d�}|S)z|
    Updates a virtual machine configuration if there is a difference between
    the given and deployed configuration.
    Nrrr3zvsphere.get_vm_configF)r,Zobjectsr4zvsphere.compare_vm_configs)rr"r#r$r%r&r'r(r)r,r-�	cd_drivesr+r8T�Virtual machine z is already up to date�rrr r6zHState vm_updated will update virtual machine '{}' in datacenter '{}':
{}�
cSs g|]\}}d�||jg��qS)z:
)�joinZchanges_str)�.0�key�
differencer
r
r�
<listcomp>�s��zvm_updated.<locals>.<listcomp>�rr r7zvsphere.update_vm)r*r+r8r4�	Error: %s�vsphere.power_on_vmr1z was updated successfully)
r>r@r?rArM�itemsrr=�CommandExecutionErrorr9�error�str�VMwarePowerOnError)rr!r"r#r$r%r&r'r(r)r,r-r*r+r8r1rr4Zcurrent_configZdiffsr rrFr
r
rrE�s�
���
������

�����
�rEcCst|didd�}tdrd|�d�|d<|Std�}ztd	||||||
||||||	|
||||d
�}Wn.tjjya}z t�d|�|rKtd|�|�d
t|�d��|WYd}~Sd}~ww|r�ztd||
|d�Wn.tjj	y�}z t�d|�|r�td|�|�d
t|�d��|WYd}~Sd}~ww||d<||d�}td|�|d|d|�d�d�}|S)zR
    Creates a virtual machine with the given properties if it doesn't exist.
    Nrrr6rJz will be createdr r3zvsphere.create_vm)r)�ide_controllersr+rIr8r4rSr7FrRrTr5r1)r�infoTz created successfully)
r?r>rr=rVr9rWr@rXrY)rr!r"r#r$r%r&r'r(r)r,r-r.rZr+r*r8r1rr4r[rFrr
r
rrDsn

���
���

�rDc	
Cs�|didd�}|j�|jdj��}t�d|�td�}z
td|||||d�Wn[tjjyX}z t�	d	|�|rBtd
|�|�
dt|�d��|WYd}~Sd}~wtjjy�}z t�	d	|�|rotd
|�|�
dt|�d��|WYd}~Sd}~ww|r�ztd
|||d�Wn.tjj
y�}z t�	d	|�|r�td
|�|�
dt|�d��|WYd}~Sd}~wwtd
|�|�
d||d�d|�d�d��|S)zc
    Registers a virtual machine if the machine files are available on
    the main datastore.
    Nrrrz-Registering virtual machine with vmx file: %sr3zvsphere.register_vmr5rSr7FrRrTT)rr1rJz registered successfullyrK)Z
folderPath�file�pathr9r:r>rr=ZVMwareMultipleObjectsErrorrWr@rXZVMwareVmRegisterErrorrY)	r!r,r.rGr1rZvmx_pathr4rFr
r
rrBosX


����
���
��rB)NNNNTFF)NNNF)NNNNF)F)�__doc__�loggingr�	functoolsrZsalt.exceptionsrZsalt.config.schemas.esxvmrr;r	�ImportErrorZpyVmomirr
�	getLogger�__name__r9rrrHrCrErDrBr
r
r
r�<module>sbC��
�

�|�R