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

�N�g�h�@s�dZddlZddlZddlZz
ddlmZdZWney#dZYnwe�	e
�Zdd�Zdd	�Z
d
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)ab
Manage VMware distributed virtual switches (DVSs) and their distributed virtual
portgroups (DVportgroups).

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

Examples
========

Several settings can be changed for DVSs and DVporgroups. Here are two examples
covering all of the settings. Fewer settings can be used

DVS
---

.. code-block:: python

    'name': 'dvs1',
    'max_mtu': 1000,
    'uplink_names': [
        'dvUplink1',
        'dvUplink2',
        'dvUplink3'
    ],
    'capability': {
        'portgroup_operation_supported': false,
        'operation_supported': true,
        'port_operation_supported': false
    },
    'lacp_api_version': 'multipleLag',
    'contact_email': 'foo@email.com',
    'product_info': {
        'version':
        '6.0.0',
        'vendor':
        'VMware,
        Inc.',
        'name':
        'DVS'
    },
    'network_resource_management_enabled': true,
    'contact_name': 'me@email.com',
    'infrastructure_traffic_resource_pools': [
        {
            'reservation': 0,
            'limit': 1000,
            'share_level': 'high',
            'key': 'management',
            'num_shares': 100
        },
        {
            'reservation': 0,
            'limit': -1,
            'share_level': 'normal',
            'key': 'faultTolerance',
            'num_shares': 50
        },
        {
            'reservation': 0,
            'limit': 32000,
            'share_level': 'normal',
            'key': 'vmotion',
            'num_shares': 50
        },
        {
            'reservation': 10000,
            'limit': -1,
            'share_level': 'normal',
            'key': 'virtualMachine',
            'num_shares': 50
        },
        {
            'reservation': 0,
            'limit': -1,
            'share_level': 'custom',
            'key': 'iSCSI',
            'num_shares': 75
        },
        {
            'reservation': 0,
            'limit': -1,
            'share_level': 'normal',
            'key': 'nfs',
            'num_shares': 50
        },
        {
            'reservation': 0,
            'limit': -1,
            'share_level': 'normal',
            'key': 'hbr',
            'num_shares': 50
        },
        {
            'reservation': 8750,
            'limit': 15000,
            'share_level': 'high',
            'key': 'vsan',
            'num_shares': 100
        },
        {
            'reservation': 0,
            'limit': -1,
            'share_level': 'normal',
            'key': 'vdp',
            'num_shares': 50
        }
    ],
    'link_discovery_protocol': {
        'operation':
        'listen',
        'protocol':
        'cdp'
    },
    'network_resource_control_version': 'version3',
    'description': 'Managed by Salt. Random settings.'

Note: The mandatory attribute is: ``name``.

Portgroup
---------

.. code-block:: python

    'security_policy': {
        'allow_promiscuous': true,
        'mac_changes': false,
        'forged_transmits': true
    },
    'name': 'vmotion-v702',
    'out_shaping': {
        'enabled': true,
        'average_bandwidth': 1500,
        'burst_size': 4096,
        'peak_bandwidth': 1500
    },
    'num_ports': 128,
    'teaming': {
        'port_order': {
            'active': [
                'dvUplink2'
            ],
            'standby': [
                'dvUplink1'
            ]
        },
        'notify_switches': false,
        'reverse_policy': true,
        'rolling_order': false,
        'policy': 'failover_explicit',
        'failure_criteria': {
            'check_error_percent': true,
            'full_duplex': false,
            'check_duplex': false,
            'percentage': 50,
            'check_speed': 'minimum',
            'speed': 20,
            'check_beacon': true
        }
    },
    'type': 'earlyBinding',
    'vlan_id': 100,
    'description': 'Managed by Salt. Random settings.'

Note: The mandatory attributes are: ``name``, ``type``.

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.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 ESXi State
Module was developed against.
�N)�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.�dvs)�HAS_PYVMOMIrZ
versionMap�sys�version_info�r
r
�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/dvs.py�__virtual__�s


rcCsdS)z
    Init function
    Tr
)�lowr
r
r�mod_init�srcCsTtd�}d}|dkrtd�}n	|dkrtd�}|s&tj�d|�d���|d	S)
zo
    Returns the datacenter name configured on the proxy

    Supported proxies: esxcluster, esxdatacenter
    zvsphere.get_proxy_typeNZ
esxclusterzesxcluster.get_detailsZ
esxdatacenterzesxdatacenter.get_detailszdetails for proxy type 'z' not loaded�
datacenter)�__salt__�salt�
exceptions�CommandExecutionError)Z
proxy_type�detailsr
r
r�_get_datacenter_name�s


�rc
Cst�}|�d�r|dn|}t�d|||�d}|iddd�}g}i}d}�zytd�}td|g|d�}	|	sxd	}td
rP|�d�|||��t�|d��nH||d<td
|||d�|�d�||��t�|d�|�dd|ii��n gd�}
t�	d|||
�i}i}|	d}
|
D]}||vr�|||
�|�kr�|
�|�||<||||<q�d}g}g}||v�r
|
�|�s�||}nMt
t||��D]D}d|||vr�|
||ddkr�d|
||vr�|
||d=||||
||k�r|�|
||�|�t|||��q�|�r||d<||d<|�r�td
�rud}|D]>}|dk�rT|d7}t
t||��D]}|||}|||}|d�|d||�7}�q7�q$|d�|||||�7}�q$|�d�|||��t�|d�ntd|||d �|�d!�||��t�|d�|�d||d"�i�td#|�WnBt
jj�y�}z3tjd$|d	d%�|�r�td#|�td
�s�d|d&<|�t|�td
�s�dndd'��|WYd}~Sd}~ww|�s�|�d(�||�d	d'��|S|�d)�|�|td
�rdnd	d*��|S)+z�
    Configures a DVS.

    Creates a new DVS, if it doesn't exist in the provided datacenter or
    reconfigures it if configured differently.

    dvs
        DVS dict representations (see module sysdocs)
    �namez0Running state %s for DVS '%s' in datacenter '%s'FN�r�changes�result�comment�&vsphere.get_service_instance_via_proxyzvsphere.list_dvss)Z	dvs_names�service_instanceT�testz6State {} will create a new DVS '{}' in datacenter '{}'���zvsphere.create_dvs)�dvs_dict�dvs_namerz)Created a new DVS '{}' in datacenter '{}'r�new)�descriptionZ
contact_emailZcontact_nameZlacp_api_versionZlink_discovery_protocolZmax_mtuZ network_resource_control_versionZ#network_resource_management_enabledzADVS '%s' found in datacenter '%s'. Checking for any updates in %srZ%infrastructure_traffic_resource_poolsZ
num_sharesZshare_levelZcustom�z(	infrastructure_traffic_resource_pools:
z		{} from '{}' to '{}'
�keyz	{} from '{}' to '{}'
z@State dvs_configured will update DVS '{}' in datacenter '{}':
{}zvsphere.update_dvs)rrrz#Updated DVS '{}' in datacenter '{}'�r!�old�vsphere.disconnect�	Error: %s��exc_infor�rrzHDVS '{}' in datacenter '{}' is correctly configured. Nothing to be done.�
�rrr)r�get�log�infor�__opts__�append�format�update�trace�range�len�dictrrr�error�str�join)rrZdatacenter_namer �changes_required�ret�commentsr�siZdvssZpropsZprops_to_original_valuesZprops_to_updated_valuesZcurrent_dvsZpropZ
infra_propZoriginal_infra_res_poolsZupdated_infra_res_pools�idxZchanges_string�p�d�s�excr
r
r�dvs_configured	s 
�
�����
��



����

�

��
�
�������
���
�����rEcCs�i}|��D]J}||vr|�|d||d�i�q||||krPt||t�rBt||t�rBt||||�}|rA|�||i�q|�|||||d�i�q|S)z~
    Returns a dictionary with the diffs between two dictionaries

    It will ignore any key that doesn't exist in dict2
    N)�val1�val2)�keysr4�
isinstancer8�_get_diff_dict)Zdict1Zdict2�ret_dictrAZ
sub_diff_dictr
r
rrJ�s��rJcC�ri}|��D]0}t||t�std|�d���d||��vr+|�|||di�q|�|t||�i�q|S)zO
    Returns a dictionaries with the values stored in val2 of a diff dict.
    �Unexpected diff difct '�'rG)rHrIr8�
ValueErrorr4�_get_val2_dict_from_diff_dict��	diff_dictrKrAr
r
rrP��rPcCrL)zO
    Returns a dictionaries with the values stored in val1 of a diff dict.
    rMrNrF)rHrIr8rOr4�_get_val1_dict_from_diff_dictrQr
r
rrT�rSrTcCsTg}|��D]�}t||t�std|�d���t||���ddgkr�||d}t||dt�r<d�||d�}nt||dt�rQd�d�||d��}||d}t||dt�rjd�||d�}nt||dt�rd�d�||d��}|�	|�d|�d|���qt
||�}|r�|�	|�d	��|�d
d�|D��q|S)z�
    Returns a list of string message of the differences in a diff dict.

    Each inner message is tabulated one tab deeper
    rMrNrFrGz'{}'z, z from z to �:cS�g|]}d|���qS��	r
��.0�cr
r
r�
<listcomp>�z/_get_changes_from_diff_dict.<locals>.<listcomp>)rHrIr8rO�sortedr:r3�listr;r2�_get_changes_from_diff_dict�extend)rR�changes_stringsrAZfrom_strZto_strZsub_changesr
r
rr`�s,�r`c
sZt�}t�d|||�d}|iddd�}g}i}d}�z*td�}td||d�}	g}
|D]�}|d�|
���|d=t�d	���fd
d�|	D�}|s�d}td
r^|�d�|�||��ntd|�||d�|�d��||��t�|d�|��d|ii�q-t�d�||�|d}
t	|
|�}|r�d}td
r�t
|�}t�d|�|�d�|�||d�dd�|D����ntd|�||d�|�d��||��t�|d�|��t|�t
|�d�i�q-td||d�}|
�|d�|	D]G}
|
d|
v�r=d}td
�r|�d�||
d||��ntd |
d||d!�|�d"�|
d||��t�|d�|�|
dd#|
ii�q�td$|�WnAtjj�y�}z2tjd%|dd&�|�ratd$|�td
�sjd|d'<|�|jtd
�sudndd(��|WYd}~Sd}~ww|�s�|�d)�||�dd(��|S|�d�|�|td
�r�dndd*��|S)+z�
    Configures portgroups on a DVS.

    Creates/updates/removes portgroups in a provided DVS

    dvs
        Name of the DVS

    portgroups
        Portgroup dict representations (see module sysdocs)
    z-Running state %s on DVS '%s', datacenter '%s'FNrrzvsphere.list_dvportgroups�rrrzChecking pg '%s'csg|]}|�d��kr|�qS)r)r.)rZrA�Zpg_namer
rr\4sz)portgroups_configured.<locals>.<listcomp>TrzFState {} will create a new portgroup '{}' in DVS '{}', datacenter '{}'zvsphere.create_dvportgroup)�portgroup_dictZportgroup_namerrz9Created a new portgroup '{}' in DVS '{}', datacenter '{}'rr!zLPortgroup '%s' found in DVS '%s', datacenter '%s'. Checking for any updates.r�changes_strings = %szDState {} will update portgroup '{}' in DVS '{}', datacenter '{}':
{}r,cSrVrWr
rYr
r
rr\cr]�vsphere.update_dvportgroup�re�	portgrouprrz3Updated portgroup '{}' in DVS '{}', datacenter '{}'r%�vsphere.list_uplink_dvportgroupzFState {} will remove the portgroup '{}' from DVS '{}', datacenter '{}'zvsphere.remove_dvportgroup)rirrz9Removed the portgroup '{}' from DVS '{}', datacenter '{}'r&r'r(r)rr+zcAll portgroups in DVS '{}', datacenter '{}' exist and are correctly configured. Nothing to be done.r-)rr/r0rr2r1r3r4r5rJr`r;rPrTrrrr9�strerror)rrZ
portgroupsrr<r=r>rr?Zcurrent_pgsZexpected_pg_namesZpgZfiltered_current_pgsZ
current_pgrRrbZ	uplink_pgrDr
rdr�portgroups_configureds
�
��
��
���
�����	�
�
���
���
�����rlc
Cs�t�}t�d|||�d}|iddd�}g}i}d}zptd�}td||d�}	t�d|	�t|	|�}
|
r�d	}td
rYt|
�}t�d|�|�d�	|||d
�
dd�|D����ntd||	d||d�|�d�	||��t�|d�|�dt|
�t
|
�d�i�td|�Wn=tjjy�}z/tjd|d	d�|r�td|�td
s�d|d<|�|jtd
s�dndd��|WYd}~Sd}~ww|s�|�d�	||�d	d��|S|�d
�
|�|td
r�dnd	d��|S)z�
    Configures the uplink portgroup on a DVS. The state assumes there is only
    one uplink portgroup.

    dvs
        Name of the DVS

    upling_portgroup
        Uplink portgroup dict representations (see module sysdocs)

    z'Running %s on DVS '%s', datacenter '%s'FNrrrjrczcurrent_uplink_portgroup = %sTrrfzJState {} will update the uplink portgroup in DVS '{}', datacenter '{}':
{}r,cSrVrWr
rYr
r
rr\�r]z/uplink_portgroup_configured.<locals>.<listcomp>rgrrhz9Updated the uplink portgroup in DVS '{}', datacenter '{}'r�uplink_portgroupr%r'r(r)rr+zZUplink portgroup in DVS '{}', datacenter '{}' is correctly configured. Nothing to be done.r-)rr/r0rr5rJr1r`r2r3r;r4rPrTrrrr9rk)
rrrmrr<r=r>rr?Zcurrent_uplink_portgrouprRrbrDr
r
r�uplink_portgroup_configured�s�
�
�����������
�����rn)�__doc__�loggingrZsalt.exceptionsrZpyVmomirr�ImportError�	getLogger�__name__r/rrrrErJrPrTr`rlrnr
r
r
r�<module>s0K�
;%