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

�N�g\D�@sdZddlZddlZddlZddlZddlmZmZm	Z	zddl
mZmZdZ
Wney3dZ
Ynwz
ddlmZdZWneyIdZYnwe�e�Zdd	�Zd
d�Zdd
�Zdd�Zd dd�Zdd�Zdd�Z			d!dd�Z				d"dd�Zdd�Zdd�Zdd�Z dS)#a^
Connection library for VMware vSAN endpoint

This library used the vSAN extension of the VMware SDK
used to manage vSAN related objects

: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

The 5.5.0.2014.1.1 is a known stable version that this original VMware utils file
was developed against.
�N)�VMwareApiError�VMwareObjectRetrievalError�VMwareRuntimeError)�vim�vmodlTF)�vsanapiutilscCstrtrdSdS)z,
    Only load if PyVmomi is installed.
    T)Fz`Missing dependency: The salt.utils.vsan module requires pyvmomi and the pyvsan extension library)�
HAS_PYVSAN�HAS_PYVMOMI�r
r
�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/vsan.py�__virtual__Jsrc
Cs�z|jjj}WnHtjjy"}z
t�|�td|j	����d}~wtjj
y9}z
t�|�t|j��d}~wtj
yO}z
t�|�t|j��d}~wwt|�d�d�dkr]dSdS)z�
    Returns whether vsan is supported on the vCenter:
        api version needs to be 6 or higher

    service_instance
        Service instance to the host or vCenter
    �,Not enough permissions. Required privilege: N�.r�FT)�contentZaboutZ
apiVersionr�fault�NoPermission�log�	exceptionr�privilegeId�VimFault�msgr�RuntimeFaultr�int�split)�service_instance�api_version�excr
r
r�vsan_supportedXs(

��

�

��rcC�Hd}tjdd�dkrt��}d|_tj|_|j}tj	||d�}|dS)z�
    Returns a vim.cluster.VsanVcClusterConfigSystem object

    service_instance
        Service instance to the host or vCenter
    N�����F��contextzvsan-cluster-config-system�
�sys�version_info�ssl�create_default_context�check_hostname�	CERT_NONE�verify_modeZ_stubrZGetVsanVcMos�rr&ZstubZvc_mosr
r
r�get_vsan_cluster_config_systemr�
r0cCr)z�
    Returns a vim.VimClusterVsanVcDiskManagementSystem object

    service_instance
        Service instance to the host or vCenter
    Nr r!Fr%zvsan-disk-management-systemr'r/r
r
r�get_vsan_disk_management_system�r1r2cCsp|s	tjj�|�}tjjjdtj	dd�}tjjj
|tjdg||d�}|s,td|�d���t
�d|�|d	d
S)z�
    Returns a host's vsan system

    service_instance
        Service instance to the host or vCenter

    host_ref
        Refernce to ESXi host

    hostname
        Name of ESXi host. Default value is None.
    zconfigManager.vsanSystemF)�path�type�skipzconfig.enabled)Z
property_listZ
container_ref�traversal_speczHost's 'z' VSAN system was not retrievedz[%s] Retrieved VSAN systemr�object)�salt�utils�vmware�get_managed_object_namer�queryZPropertyCollectorZ
TraversalSpecrZ
HostSystemZget_mors_with_propertiesZHostVsanSystemrr�trace)r�host_ref�hostnamer6Zobjsr
r
r�get_host_vsan_system�s$
��
�r@c

CsRtjj�|�}|j}t�d||�t�ddd�|D��t�	�}|g|_
||_t|dd�r0dnd|_
||_z|�|�}WnctjjyX}	z
t�|	�td	|	j����d
}	~	wtjjyo}	z
t�|	�t|	j��d
}	~	wtjjy�}	zt�|	�td|	j�d���d
}	~	wtjy�}	z
t�|	�t|	j��d
}	~	wwt|g|�d
S)a�
    Creates a disk group

    service_instance
        Service instance to the host or vCenter

    vsan_disk_mgmt_system
        vim.VimClusterVsanVcDiskManagemenetSystem representing the vSan disk
        management system retrieved from the vsan endpoint.

    host_ref
        vim.HostSystem object representing the target host the disk group will
        be created on

    cache_disk
        The vim.HostScsidisk to be used as a cache disk. It must be an ssd disk.

    capacity_disks
        List of vim.HostScsiDisk objects representing of disks to be used as
        capacity disks. Can be either ssd or non-ssd. There must be a minimum
        of 1 capacity disk in the list.
    z;Creating a new disk group with cache disk '%s' on host '%s'�capacity_disk_ids = %scS�g|]}|j�qSr
��
canonicalName��.0�cr
r
r�
<listcomp>��z$create_diskgroup.<locals>.<listcomp>r�ssd�allFlash�hybridr
N�Method '�' not foundT)r8r9r:r;rDr�debugr=r�"VimVsanHostDiskMappingCreationSpec�
cacheDisks�
capacityDisks�getattr�creationType�host�InitializeDiskMappingsrrrrrrrr�MethodNotFoundr�methodr�_wait_for_tasks)
r�vsan_disk_mgmt_systemr>�
cache_disk�capacity_disksr?�
cache_disk_id�spec�taskrr
r
r�create_diskgroup�sH�

��

�
�

��r`c
CsNtjj�|�}|j}|j}t�d||�t�ddd�|D��t	�
�}|g|_||_t
|dd�r3dnd|_||_z|�|�}	Wn^t	jjy[}
z
t�|
�td	|
j����d
}
~
wt	jjyr}
z
t�|
�t|
j��d
}
~
wtjjy�}
zt�|
�td|
j�d���d
}
~
wtjy�}
zt|
j��d
}
~
wwt|	g|�d
S)a�
    Adds capacity disk(s) to a disk group.

    service_instance
        Service instance to the host or vCenter

    vsan_disk_mgmt_system
        vim.VimClusterVsanVcDiskManagemenetSystem representing the vSan disk
        management system retrieved from the vsan endpoint.

    host_ref
        vim.HostSystem object representing the target host the disk group will
        be created on

    diskgroup
        The vsan.HostDiskMapping object representing the host's diskgroup where
        the additional capacity needs to be added

    new_capacity_disks
        List of vim.HostScsiDisk objects representing the disks to be added as
        capacity disks. Can be either ssd or non-ssd. There must be a minimum
        of 1 new capacity disk in the list.
    z?Adding capacity to disk group with cache disk '%s' on host '%s'znew_capacity_disk_ids = %scSrBr
rCrEr
r
rrH"rIz-add_capacity_to_diskgroup.<locals>.<listcomp>rrJrKrLr
NrMrNT)r8r9r:r;rJrDrrOr=rrPrQrRrSrTrUrVrrrrrrrrrWrrXrrY)rrZr>�	diskgroupZnew_capacity_disksr?r[r]r^r_rr
r
r�add_capacity_to_diskgroup�sN���

��

�
�
��rbc
Cs<|s	tjj�|�}|j}|j}t�d||�t�ddd�|D��|s)t	|||�}t
��}	t
��|	_
|r;t
jj|	j
_nt
jj|	j
_z	|j||	d�}
WnHt
jjye}z
t�|�td|j����d}~wt
jjy|}z
t�|�t|j��d}~wtjy�}z
t�|�t|j��d}~wwtjj�|
|d�d	S)
a}
    Removes capacity disk(s) from a disk group.

    service_instance
        Service instance to the host or vCenter

    host_vsan_system
        ESXi host's VSAN system

    host_ref
        Reference to the ESXi host

    diskgroup
        The vsan.HostDiskMapping object representing the host's diskgroup from
        where the capacity needs to be removed

    capacity_disks
        List of vim.HostScsiDisk objects representing the capacity disks to be
        removed. Can be either ssd or non-ssd. There must be a minimum
        of 1 capacity disk in the list.

    data_evacuation
        Specifies whether to gracefully evacuate the data on the capacity disks
        before removing them from the disk group. Default value is True.

    hostname
        Name of ESXi host. Default value is None.

    host_vsan_system
        ESXi host's VSAN system. Default value is None.
    zCRemoving capacity from disk group with cache disk '%s' on host '%s'rAcSrBr
rCrEr
r
rrHrrIz2remove_capacity_from_diskgroup.<locals>.<listcomp>)Zdisk�maintenanceSpecr
NZremove_capacityT)r8r9r:r;rJrDrrOr=r@r�HostMaintenanceSpec�VsanHostDecommissionMode�vsanMode�$VsanHostDecommissionModeObjectActionZevacuateAllData�objectAction�noActionZRemoveDisk_Taskrrrrrrrrrr�
wait_for_task)rr>rar\Zdata_evacuationr?�host_vsan_systemr[r]�
maint_specr_rr
r
r�remove_capacity_from_diskgroupAsP(�
��
�

��

�

��rmc
Cs4|s	tjj�|�}|jj}t�d||�|st|||�}t	�
�}t	��|_t	j
}	|r0|	j|j_n|	j|j_z
|j|g|d�}
WnHt	jjyZ}z
t�|�td|j����d}~wt	jjyq}z
t�|�t|j��d}~wtjy�}z
t�|�t|j��d}~wwtjj�|
|d�t�d||�dS)a
    Removes a disk group.

    service_instance
        Service instance to the host or vCenter

    host_ref
        Reference to the ESXi host

    diskgroup
        The vsan.HostDiskMapping object representing the host's diskgroup from
        where the capacity needs to be removed

    hostname
        Name of ESXi host. Default value is None.

    host_vsan_system
        ESXi host's VSAN system. Default value is None.

    data_accessibility
        Specifies whether to ensure data accessibility. Default value is True.
    z5Removing disk group with cache disk '%s' on host '%s')�mappingrcr
N�remove_diskgroupz4Removed disk group with cache disk '%s' on host '%s'T)r8r9r:r;rJrDrrOr@rrdrerfrgZensureObjectAccessibilityrhriZRemoveDiskMapping_Taskrrrrrrrrrrrj)rr>rar?rkZerase_disk_partitionsZdata_accessibilityr]rlZ
object_actionr_rr
r
rro�sP�


�

��

�

���roc
Cs�tjj�|�}t�d|�tjj�|�}t|�}z|�|�WSt	j
jy9}z
t�|�t
d|j����d}~wt	j
jyP}z
t�|�t
|j��d}~wtjyf}z
t�|�t|j��d}~ww)z�
    Returns the extended cluster vsan configuration object
    (vim.VsanConfigInfoEx).

    cluster_ref
        Reference to the cluster
    z,Retrieving cluster vsan info of cluster '%s'r
N)r8r9r:r;rr=�(get_service_instance_from_managed_objectr0ZVsanClusterGetConfigrrrrrrrrrrr)�cluster_ref�cluster_name�si�vsan_cl_conf_sysrr
r
r�get_cluster_vsan_info�s*	

��

�

��ruc
Cs�tjj�|�}t�d||�tjj�|�}tjj�|�}z|�	||�}WnHt
jjy?}z
t�
|�td|j����d}~wt
jjyV}z
t�
|�t|j��d}~wtjyl}z
t�
|�t|j��d}~wwt|g|�dS)z�
    Reconfigures the VSAN system of a cluster.

    cluster_ref
        Reference to the cluster

    cluster_vsan_spec
        Cluster VSAN reconfigure spec (vim.vsan.ReconfigSpec).
    z&Reconfiguring vsan on cluster '%s': %sr
N)r8r9r:r;rr=rpZvsanr0ZVsanClusterReconfigrrrrrrrrrrrrY)rqZcluster_vsan_specrrrsrtr_rr
r
r�reconfigure_cluster_vsan�s,


��

�

��rvc
Cs�t�dd�dd�|D���zt�||�WnHtjjy1}z
t�|�t	d|j
����d}~wtjjyH}z
t�|�t	|j��d}~wt
jy^}z
t�|�t|j��d}~wwt�dd�dd�|D���dS)	z1
    Wait for tasks created via the VSAN API
    zWaiting for vsan tasks: {0}z, cS�g|]}t|��qSr
��str�rF�tr
r
rrH�z#_wait_for_tasks.<locals>.<listcomp>r
NzTasks %s finished successfullycSrwr
rxrzr
r
rrH&r|)rr=�joinrZWaitForTasksrrrrrrrrrrr)Ztasksrrr
r
rrYs&

��

�

�� rY)N)TNN)NNFT)!�__doc__�loggingr*r(Zsalt.utils.vmwarer8Zsalt.exceptionsrrrZpyVmomirrr	�ImportErrorZ
salt.ext.vsanrr�	getLogger�__name__rrrr0r2r@r`rbrmrorurvrYr
r
r
r�<module>sL+��

!<G
�V
�G