%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/states/dvs.pyc

�
���^c@@sdZddlmZmZmZddlZddlZddlZddlZ	ddl
mZddlm
Z
yddlmZeZWnek
r�eZnXeje�Zd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Z dS(ui
Manage VMware distributed virtual switches (DVSs) and their distributed virtual
portgroups (DVportgroups).

:codeauthor: :email:`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.
i(tabsolute_importtprint_functiontunicode_literalsN(tsix(trange(tVmomiSupportcC@sKtstdfSdtjkrGtjdkrGtjd	krGtdfSdS(
Nu,State module did not load: pyVmomi not foundu	vim25/6.0iii	uaState module did not load: Incompatible versions of Python and pyVmomi present. See Issue #29537.udvs(ii(iii	(tHAS_PYVMOMItFalseRt
versionMaptsystversion_info(((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pyt__virtual__�s

cC@stS(u
    Init function
    (tTrue(tlow((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pytmod_init�scC@swtd�}d}|dkr/td�}n|dkrKtd�}n|sotjjdj|���n|dS(	uo
    Returns the datacenter name configured on the proxy

    Supported proxies: esxcluster, esxdatacenter
    uvsphere.get_proxy_typeu
esxclusteruesxcluster.get_detailsu
esxdatacenteruesxdatacenter.get_detailsu'details for proxy type '{0}' not loadedu
datacenterN(t__salt__tNonetsaltt
exceptionstCommandExecutionErrortformat(t
proxy_typetdetails((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pyt_get_datacenter_name�s
	cC@s�t�}|jd�r"|dn|}tjdj|||��t}i|d6id6d/d6d/d6}g}i}t}y
td�}tdd|gd	|�}	|	s_t}t	d
r�|j
dj|||��tj|d�q|||d<td
d|d|d	|�|j
dj||��tj|d�|jii|d6d6�nddddddddg}
tjdj|||
��i}i}|	d}
xW|
D]O}||kr�|||
j|�kr�|
j|�||<||||<q�q�Wd}g}g}||kr|
j|�sC||}qx�t
t||��D]�}d|||kr�|
||dd kr�d|
||kr�|
||d=n||||
||krZ|j
|
||�|j
t|||��qZqZWn|r%||d<||d<n|r|t	d
rd!}x�|D]�}|dkr�|d"7}x{t
t||��D]?}|||}|||}|d#j|d$||�7}quWqB|d%j|||||�7}qBW|j
d&j|||��tj|d�nGtd'd|d(|d	|�|j
d)j||��tj|d�|jii|d6|d*6d6�ntd+|�Wn�tjjk
r(}tjd,j|tj���|r�td+|�nt	d
s�t|d<n|jitj|�d6t	d
stnd/d6�|SX|sY|jid-j||�d6td6�n;|jid.j|�d6|d6t	d
r�d/ntd6�|S(0u�
    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)
    unameu3Running state {0} for DVS '{1}' in datacenter '{2}'uchangesuresultucommentu&vsphere.get_service_instance_via_proxyuvsphere.list_dvsst	dvs_namestservice_instanceutestu9State {0} will create a new DVS '{1}' in datacenter '{2}'i����uvsphere.create_dvstdvs_dicttdvs_nameu+Created a new DVS '{0}' in datacenter '{1}'unewudvsudescriptionu
contact_emailucontact_nameulacp_api_versionulink_discovery_protocolumax_mtuu network_resource_control_versionu#network_resource_management_enableduDDVS '{0}' found in datacenter '{1}'. Checking for any updates in {2}iu%infrastructure_traffic_resource_poolsu
num_sharesushare_levelucustomuu(	infrastructure_traffic_resource_pools:
u		{0} from '{1}' to '{2}'
ukeyu	{0} from '{1}' to '{2}'
uCState dvs_configured will update DVS '{0}' in datacenter '{1}':
{2}uvsphere.update_dvstdvsu%Updated DVS '{0}' in datacenter '{1}'uolduvsphere.disconnectuError: {0}
{1}uJDVS '{0}' in datacenter '{1}' is correctly configured. Nothing to be done.u
N(RtgettlogtinfoRRRRRt__opts__tappendtupdatettraceRtlentdictRRRterrort	tracebackt
format_excRt	text_typetjoin(tnameRtdatacenter_nameRtchanges_requiredtrettcommentstchangestsitdvsstpropstprops_to_original_valuestprops_to_updated_valuestcurrent_dvstpropt
infra_proptoriginal_infra_res_poolstupdated_infra_res_poolstidxtchanges_stringtptdtstexc((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pytdvs_configured	s�
	"
	


		

%
	









	cC@s�i}x�|j�D]�}||krN|jiidd6||d6|6�q||||krt||t�r�t||t�r�t||||�}|r�|ji||6�q�q�|jii||d6||d6|6�qqW|S(u~
    Returns a dictionary with the diffs between two dictionaries

    It will ignore any key that doesn't exist in dict2
    uval1uval2N(tkeysR"Rt
isinstanceR%t_get_diff_dict(tdict1tdict2tret_dictR=t
sub_diff_dict((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pyRD�s)&1cC@s�i}x�|j�D]�}t||t�sDtdj|���nd||j�kry|ji||d|6�q|jit||�|6�qW|S(uO
    Returns a dictionaries with the values stored in val2 of a diff dict.
    uUnexpected diff difct '{0}'uval2(RBRCR%t
ValueErrorRR"t_get_val2_dict_from_diff_dict(t	diff_dictRGR=((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pyRJ�scC@s�i}x�|j�D]�}t||t�sDtdj|���nd||j�kry|ji||d|6�q|jit||�|6�qW|S(uO
    Returns a dictionaries with the values stored in val1 of a diff dict.
    uUnexpected diff difct '{0}'uval1(RBRCR%RIRR"t_get_val1_dict_from_diff_dict(RKRGR=((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pyRL�scC@s�g}x�|j�D]�}t||t�sDtdj|���nt||j��ddgkr}||d}t||dtj�r�dj||d�}n:t||dt�r�djdj	||d��}n||d}t||dtj�r$dj||d�}n:t||dt�r^djdj	||d��}n|j
dj|||��qt||�}|r|j
dj|��|jg|D]}dj|�^q��qqW|S(	u�
    Returns a list of string message of the differences in a diff dict.

    Each inner message is tabulated one tab deeper
    uUnexpected diff difct '{0}'uval1uval2u'{0}'u, u{0} from {1} to {2}u{0}:u	{0}(
RBRCR%RIRtsortedRtstring_typestlistR*R!t_get_changes_from_diff_dicttextend(RKtchanges_stringsR=tfrom_strtto_strtsub_changestc((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pyRP�s."##	'cC@s�t�}tjdj|||��t}i|d6id6d$d6d$d6}g}i}t}y�td�}tdd|d	|�}	g}
xN|D]F}|d}|
j|�|d=tjd
j|��g|	D]!}
|
jd�|kr�|
^q�}|s�t	}t
dr5|jdj||||��n?td
d|d|d|d	|�|jdj|||��tj|d�|jii|d6|6�q�tjdj|||��|d}t
||�}|r�t	}t
drZt|�}tjdj|��|jdj||||djg|D]}dj|�^q5���n?tdd|d|d|d	|�|jdj|||��tj|d�|jiit|�d6t|�d6|6�q�q�Wtdd|d	|�}|
j|d�x�|	D]�}|d|
krt	}t
dr\|jdj||d||��nAtdd|dd|d	|�|jd j|d||��tj|d�|jii|d6|d6�qqWtd!|�Wn�tjjk
rz}tjd"j|tj���|r1td!|�nt
dsHt|d<n|ji|jd6t
dsktnd$d6�|SX|s�|jid#j||�d6t	d6�n;|jidj|�d6|d6t
dr�d$nt	d6�|S(%u�
    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)
    u0Running state {0} on DVS '{1}', datacenter '{2}'unameuchangesuresultucommentu&vsphere.get_service_instance_via_proxyuvsphere.list_dvportgroupsRRuChecking pg '{0}'utestuJState {0} will create a new portgroup '{1}' in DVS '{2}', datacenter '{3}'uvsphere.create_dvportgrouptportgroup_dicttportgroup_nameu<Created a new portgroup '{0}' in DVS '{1}', datacenter '{2}'i����unewuOPortgroup '{0}' found in DVS '{1}', datacenter '{2}'. Checking for any updates.iuchanges_strings = {0}uIState {0} will update portgroup '{1}' in DVS '{2}', datacenter '{3}':
{4}u
u	{0}uvsphere.update_dvportgroupt	portgroupu6Updated portgroup '{0}' in DVS '{1}', datacenter '{2}'uolduvsphere.list_uplink_dvportgroupuJState {0} will remove the portgroup '{1}' from DVS '{2}', datacenter '{3}'uvsphere.remove_dvportgroupu<Removed the portgroup '{0}' from DVS '{1}', datacenter '{2}'uvsphere.disconnectuError: {0}
{1}ueAll portgroups in DVS '{0}', datacenter '{1}' exist and are correctly configured. Nothing to be done.N(RRRRRRRR!RRR R"R#RDRPR*RJRLRRRR&R'R(tstrerror(R+Rt
portgroupst
datacenterR-R.R/R0R1tcurrent_pgstexpected_pg_namestpgtpg_nameR=tfiltered_current_pgst
current_pgRKRRRVt	uplink_pgR@((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pytportgroups_configured�s�	






.
	




	)









	


	c
C@s�t�}tjdj|||��t}i|d6id6dd6dd6}g}i}t}y^td�}tdd|d	|�}	tjd
j|	��t|	|�}
|
r�t	}t
dr,t|
�}tjdj|��|jd
j|||dj
g|D]}dj|�^q���n@tdd|d|	dd|d	|�|jdj||��tj|d�|jiit|
�d6t|
�d6d6�ntd|�Wn�tjjk
rT}
tjdj|
tj���|rtd|�nt
ds"t|d<n|ji|
jd6t
dsEtndd6�|SX|s�|jidj||�d6t	d6�n;|jidj
|�d6|d6t
dr�dnt	d6�|S(u�
    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)

    u*Running {0} on DVS '{1}', datacenter '{2}'unameuchangesuresultucommentu&vsphere.get_service_instance_via_proxyuvsphere.list_uplink_dvportgroupRRucurrent_uplink_portgroup = {0}utestuchanges_strings = {0}uNState {0} will update the uplink portgroup in DVS '{1}', datacenter '{2}':
{3}u
u	{0}uvsphere.update_dvportgroupRWRYu;Updated the uplink portgroup in DVS '{0}', datacenter '{1}'i����unewuolduuplink_portgroupuvsphere.disconnectuError: {0}
{1}u\Uplink portgroup in DVS '{0}', datacenter '{1}' is correctly configured. Nothing to be done.N(RRRRRRRR#RDRR RPR!R*R"RJRLRRRR&R'R(RZ(R+Rtuplink_portgroupR\R-R.R/R0R1tcurrent_uplink_portgroupRKRRRVR@((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pytuplink_portgroup_configuredzsx	






		)





	(!t__doc__t
__future__RRRtloggingR'R	tsalt.exceptionsRtsalt.extRtsalt.ext.six.movesRtpyVmomiRRRtImportErrorRt	getLoggert__name__RRRRRARDRJRLRPRdRg(((s3/usr/lib/python2.7/site-packages/salt/states/dvs.pyt<module>�s.


	
			�				!	�

Zerion Mini Shell 1.0