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

�N�g�&�@s�dZddlZddlZddlmZmZmZzddlm	Z	m
Z
mZdZWne
y-dZYnwe�e�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zddd�Zdd�Zdd�Zdd�Zdd�ZdS)a�
Library for VMware Storage Policy management (via the pbm endpoint)

This library is used to manage the various policies available in VMware

:codeauthor: Alexandru Bleotu <alexandru.bleotu@morganstaley.com>

Dependencies
~~~~~~~~~~~~

- pyVmomi Python Module

pyVmomi
-------

PyVmomi can be installed via pip:

.. code-block:: bash

    pip install pyVmomi

.. note::

    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==5.5.0.2014.1.1
�N)�VMwareApiError�VMwareObjectRetrievalError�VMwareRuntimeError)�pbm�vim�vmodlTFcCstrdSdS)z,
    Only load if PyVmomi is installed.
    T)FzJMissing dependency: The salt.utils.pbm module requires the pyvmomi library)�HAS_PYVMOMI�r	r	�B/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/pbm.py�__virtual__=src
C��tjjj|ddd�}t�d|�}z|��j}W|Stj	j
y3}z
t�|�t
d|j����d}~wtj	jyJ}z
t�|�t
|j��d}~wtjy`}z
t�|�t|j��d}~ww)zi
    Returns a profile manager

    service_instance
        Service instance to the host or vCenter
    �pbm/2.0�/pbm/sdk��ns�path�ServiceInstance�,Not enough permissions. Required privilege: N)�salt�utils�vmware�get_new_service_instance_stubrr�RetrieveContentZprofileManagerr�fault�NoPermission�log�	exceptionr�privilegeId�VimFault�msgr�RuntimeFaultr�Zservice_instanceZstubZpbm_si�profile_manager�excr	r	r
�get_profile_managerK�,��

��

�

��r$c
Cr)zj
    Returns a placement solver

    service_instance
        Service instance to the host or vCenter
    r
rrrrN)rrrrrrrZplacementSolverrrrrrrrrrrr rr!r	r	r
�get_placement_solverfr%r&c
Cs�tjjtjjjd�}z|�|�}WnHtjjy,}z
t	�
|�td|j����d}~wtjj
yC}z
t	�
|�t|j��d}~wtjyY}z
t	�
|�t|j��d}~wwg}|D]}|�|j�q^|S)zv
    Returns a list of all capability definitions.

    profile_manager
        Reference to the profile manager.
    ��resourceTyperN)r�profile�ResourceType�ResourceTypeEnum�STORAGEZFetchCapabilityMetadatarrrrrrrrrrr r�extendZcapabilityMetadata)r"�res_typeZcap_categoriesr#Zcap_definitions�catr	r	r
�get_capability_definitions�s0�

��

�

��r0c
Cs�z|�|�WStjjy!}z
t�|�td|j����d}~wtjjy8}z
t�|�t|j	��d}~wt
jyN}z
t�|�t|j	��d}~ww)z�
    Returns a list of policies with the specified ids.

    profile_manager
        Reference to the profile manager.

    policy_ids
        List of policy ids to retrieve.
    rN)
rrrrrrrrrrrr r)r"�
policy_idsr#r	r	r
�get_policies_by_id�s"


��

�

��r2c
s�tjjtjjjd�}z|�|�}WnHtjjy,}z
t	�
|�td|j����d}~wtjj
yC}z
t	�
|�t|j��d}~wtjyY}z
t	�
|�t|j��d}~wwt	�d|�dd�t||�D�}|rn|S�srg��fdd�|D�S)aJ
    Returns a list of the storage policies, filtered by name.

    profile_manager
        Reference to the profile manager.

    policy_names
        List of policy names to filter by.
        Default is None.

    get_all_policies
        Flag specifying to return all policies, regardless of the specified
        filter.
    r'rNzpolicy_ids = %scSs"g|]
}|jjtjjjkr|�qSr	)r(rr)r+r,��.0�pr	r	r
�
<listcomp>�s
�z(get_storage_policies.<locals>.<listcomp>csg|]	}|j�vr|�qSr	)�namer3��policy_namesr	r
r6�s)rr)r*r+r,ZQueryProfilerrrrrrrrrrr r�tracer2)r"r9Zget_all_policiesr.r1r#Zpoliciesr	r8r
�get_storage_policies�s:�

��

�

���r;c
Cs�z|�|�WdStjjy#}z
t�|�td|j����d}~wtjjy:}z
t�|�t|j	��d}~wt
jyP}z
t�|�t|j	��d}~ww)z�
    Creates a storage policy.

    profile_manager
        Reference to the profile manager.

    policy_spec
        Policy update spec.
    rN)
ZCreaterrrrrrrrrrr r)r"�policy_specr#r	r	r
�create_storage_policy�s"


��

�

��r=c
Cs�z
|�|j|�WdStjjy%}z
t�|�td|j����d}~wtjj	y<}z
t�|�t|j
��d}~wtjyR}z
t�|�t
|j
��d}~ww)z�
    Updates a storage policy.

    profile_manager
        Reference to the profile manager.

    policy
        Reference to the policy to be updated.

    policy_spec
        Policy update spec.
    rN)ZUpdate�	profileIdrrrrrrrrrrr r)r"�policyr<r#r	r	r
�update_storage_policy�s"


��

�

��r@c
Cs�tjj|jdd�}t�d|�z|�|�}WnHtjj	y1}z
t�
|�td|j����d}~wtjj
yH}z
t�
|�t|j��d}~wtjy^}z
t�
|�t|j��d}~wwt||g�}|sotd|�d���|dS)	z�
    Returns the default storage policy reference assigned to a datastore.

    profile_manager
        Reference to the profile manager.

    datastore
        Reference to the datastore.
    �	Datastore�ZhubIdZhubType�placement_hub = %srNzStorage policy with id 'z' was not foundr)r�	placement�PlacementHub�_moIdrr:ZQueryDefaultRequirementProfilerrrrrrrrrr rr2r)r"�	datastoreZhubZ	policy_idr#Zpolicy_refsr	r	r
�'get_default_storage_policy_of_datastores2

��

�

��
�rHc
Cs�tjj|jdd�}t�d|�z|�|j|g�WdStj	j
y5}z
t�|�td|j
����d}~wtj	jyL}z
t�|�t|j��d}~wtjyb}z
t�|�t|j��d}~ww)z�
    Assigns a storage policy as the default policy to a datastore.

    profile_manager
        Reference to the profile manager.

    policy
        Reference to the policy to assigned.

    datastore
        Reference to the datastore.
    rArBrCrN)rrDrErFrr:ZAssignDefaultRequirementProfiler>rrrrrrrrrr r)r"r?rGZ
placement_hubr#r	r	r
�*assign_default_storage_policy_to_datastore;s.
�
�

��

�

��rI)NF)�__doc__�loggingZsalt.utils.vmwarerZsalt.exceptionsrrrZpyVmomirrrr�ImportError�	getLogger�__name__rrr$r&r0r2r;r=r@rHrIr	r	r	r
�<module>s*'�

-"