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__/pbm.cpython-310.pyc
o

�N�g�Q�@s�dZddlZddlZddlZddlmZmZddlmZddl	m
Z
z
ddlmZdZ
Wney7dZ
Ynwe�e�Zd	d
�Zdd�Zd
d�Zdd�Zdd�ZdS)aY

Manages VMware storage policies
(called pbm because the vCenter endpoint is /pbm)

Examples
========

Storage policy
--------------

.. code-block:: python

    {
        "name": "salt_storage_policy"
        "description": "Managed by Salt. Random capability values.",
        "resource_type": "STORAGE",
        "subprofiles": [
            {
                "capabilities": [
                    {
                        "setting": {
                            "type": "scalar",
                            "value": 2
                        },
                        "namespace": "VSAN",
                        "id": "hostFailuresToTolerate"
                    },
                    {
                        "setting": {
                            "type": "scalar",
                            "value": 2
                        },
                        "namespace": "VSAN",
                        "id": "stripeWidth"
                    },
                    {
                        "setting": {
                            "type": "scalar",
                            "value": true
                        },
                        "namespace": "VSAN",
                        "id": "forceProvisioning"
                    },
                    {
                        "setting": {
                            "type": "scalar",
                            "value": 50
                        },
                        "namespace": "VSAN",
                        "id": "proportionalCapacity"
                    },
                    {
                        "setting": {
                            "type": "scalar",
                            "value": 0
                        },
                        "namespace": "VSAN",
                        "id": "cacheReservation"
                    }
                ],
                "name": "Rule-Set 1: VSAN",
                "force_provision": null
            }
        ],
    }

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

- pyVmomi Python Module

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 <https://github.com/saltstack/salt/issues/29537>` for more
    information.
�N)�ArgumentValueError�CommandExecutionError)�recursive_diff)�	list_diff)�VmomiSupportTFcCs.tsdSdtjvrtjdkrtjdkrdSdS)N)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_PYVMOMIrZ
versionMap�sys�version_info�r
r
�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/pbm.py�__virtual__qs


rcCsdS)z
    Init function
    Tr
)�lowr
r
r�mod_init�src
Cs�t�|�}td�}t�d|�t|�d��d}t�d||�t�d|�d}|iddd	�}g}i}d}d}	�zTtd
�}	td|	�}
t�d|
�|�d
�r�t|d
�dkr\td��|d
d}|
d
d}t	|d|�dg�dd�}
|d
=|�d�r�|d=|d=t
|t|��}|
d
=t
|
|�}|js�|
js�|j�r�d|j
vs�d|j
vr�td��d}td�rg}|jr�|�dd�|j�d�D��|js�|
jr�|�d�|jr�|�dd�|j�d�D��|
jr�|�d�|�dd�|
j�d�D��|�d �||d�|���ntd!|
d||	d"�|�d#|�d$��t�|d%�|j
}|j
g|d
<|
j
|d
dd<|d
dd�sA|d
dd=|d
d�sK|d
=|j}|jg|d
<|
j|d
dd<|d
dd�sm|d
dd=|d
d�sw|d
=|�d&||d'�i�t�|�td(|	�Wn=t�y�}z0t�d)|�|	�r�td(|	�td�s�d|d*<|�|jtd�s�dndd+��|WYd}~Sd}~ww|�s�|�d,�|�dd+��|S|�d�|�|td�r�dndd-��|S).z�
    Configures the default VSAN policy on a vCenter.
    The state assumes there is only one default VSAN policy on a vCenter.

    policy
        Dict representation of a policy
    �vsphere.get_proxy_type�proxy_type = %s�.get_details�vcenterzRunning %s on vCenter '%s'zpolicy = %sFN��name�changes�result�comment�&vsphere.get_service_instance_via_proxyz vsphere.list_default_vsan_policyzcurrent_policy = %s�subprofiles��AMultiple sub_profiles ({0}) are not supported in the input policyr�capabilities�id��keyr�descriptionzE'name' and 'description' of the default VSAN policy cannot be updatedT�testcS�g|]}|�qSr
r
��.0Zchanger
r
r�
<listcomp>��z2default_vsan_policy_configured.<locals>.<listcomp>�
�subprofiles:cS�g|]}d|���qS�z  r
r&r
r
rr(�����  capabilities:cSr,r-r
r&r
r
rr(�r.z@State {} will update the default VSAN policy on vCenter '{}':
{}�vsphere.update_storage_policy��policyZpolicy_dict�service_instancez,Updated the default VSAN policy in vCenter '�'���Zdefault_vsan_policy��new�old�vsphere.disconnect�	Error: %sr�rrzPDefault VSAN policy in vCenter '{}' is correctly configured. Nothing to be done.�rrr)�copy�deepcopy�__salt__�log�trace�info�get�lenrrr�dict�diffs�
new_values�__opts__�extend�changes_str�split�append�changes_str2�format�join�
old_values�updater�error�strerror)rr2�policy_copy�
proxy_typer�changes_required�ret�commentsr�si�current_policy�
subprofile�current_subprofile�capabilities_differ�subprofile_differ�
policy_differ�str_changesrGrP�excr
r
r�default_vsan_policy_configured�s




�
�



�
�

��
�����
�
��
���

���
�����rbcs�g}g}d}|iddd�}t�d|�d}�z�td�}t�d|�t|�d��d}t�d	||�td
�}tddd
�|D�|d�}	t�d|	�|D�]��t���}
�fdd
�|	D�}|rd|dnd}|s�d}tdr{|�d�|�d|��ntd�d�|d�|�d��d|��|��dd��t�|d�qM��	d�r�t
�d�dkr�td���dd}
|dd}t|d|
�	dg�dd �}�d=|
�	d�r�|
d=|d=t
|t|
��}|d=t
|��}|js�|js�|j�r�d}td�rTg}|j�r
|�d!d
�|j�d"�D��|j�s|j�rC|�d#�|j�r,|�d$d
�|j�d"�D��|j�rC|�d%�|�d&d
�|j�d"�D��|�d'�|�d|d"�|���ntd(|d|
|d)�|�d*��d|��t�|d�|j}|jg|d<|j|ddd<|ddd�s�|ddd=|dd�s�|d=|j}|jg|d<|j|ddd<|ddd�s�|ddd=|dd�s�|d=|�||d��qM|�d+��d��qMtd,|�Wn=t�y!}z0t�d-|�|�r�td,|�td�sd|d.<|�|jtd�sdndd/��|WYd}~Sd}~ww|�s2|�d0�|�dd/��|S|�d"�|�d1|itd�rBdndd2��|S)3z�
    Configures storage policies on a vCenter.

    policies
        List of dict representation of the required storage policies
    FNrz
policies = %srrrrz"Running state '%s' on vCenter '%s'rzvsphere.list_storage_policiescSsg|]}|d�qS�rr
)r'r2r
r
rr(Fsz/storage_policies_configured.<locals>.<listcomp>)Zpolicy_namesr3zcurrent_policies = %scs g|]}|d�dkr|�qSrcr
)r'�p�r2r
rr(MsrTr$z<State {} will create the storage policy '{}' on vCenter '{}'rzvsphere.create_storage_policy)r3z+Created storage policy '{}' on vCenter '{}'r6r5rrrrr r!cSr%r
r
r&r
r
rr(�r)r*r+cSr,r-r
r&r
r
rr(�r.r/cSr,r-r
r&r
r
rr(�r.z@State {} will update the storage policy '{}' on vCenter '{}':
{}r0r1z/Updated the storage policy '{}' in vCenter '{}'z6Storage policy '{}' is up to date. Nothing to be done.r9r:rr;zOAll storage policy in vCenter '{}' is correctly configured. Nothing to be done.Zstorage_policiesr<)r@rAr?rBr=r>rHrLrNrCrDrrrrErFrIrJrKrMrOrGrPrrRrQrS)rZpoliciesrXrrVrWrYrUrZcurrent_policiesrTZfiltered_policiesrZr[r\r]r^r_r`rGrPrar
rer�storage_policies_configured/s@

�


��
���
�
�

���
�
���
�������
��
����
���
�����rfc

CsTt�d|||�i}d}|iddd�}d}zGtd�}td||d�}|d|kr0d	�||�}n&d
}d|d|d�i}td
rGd�|||�}ntd|||d�d�||�}t�|�Wn1ty�}	z%t�d|	�|rrtd|�|�|	jtd
s|dndd��|WYd}	~	Sd}	~	ww||d<|r�|�|td
r�dnd
d��|Sd
|d<|S)z�
    Assigns a default storage policy to a datastore

    policy
        Name of storage policy

    datastore
        Name of datastore
    z1Running state %s for policy '%s', datastore '%s'.FNrrz0vsphere.list_default_storage_policy_of_datastore)�	datastorer3rzNStorage policy '{}' is already assigned to datastore '{}'. Nothing to be done.TZdefault_storage_policy)r8r7r$z;State {} will assign storage policy '{}' to datastore '{}'.z2vsphere.assign_default_storage_policy_to_datastore)r2rgr3z2Storage policy '{} was assigned to datastore '{}'.r:r9r;r)rrr)	r@rBr?rNrHrrRrQrS)
rr2rgrrVrWrYZexisting_policyrrar
r
r�default_storage_policy_assigned�sb
�
����������	�rh)�__doc__r=�loggingrZsalt.exceptionsrrZsalt.utils.dictdifferrZsalt.utils.listdifferrZpyVmomirr
�ImportError�	getLogger�__name__r@rrrbrfrhr
r
r
r�<module>s*\�
%E