%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/vmware.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddl
ZddlZddlZddlZddlmZddlmZyNddlmZmZmZmZmZddlmZmZmZeZ Wne!k
r-e"Z nXy"ddl#Z#ddl$Z$eZ%Wne!k
rie"Z%nXej&e'�Z(d�Z)ddddd	�Z+d
�Z,d�Z-d�Z.ddddd
ddd�Z/ddd�Z0dd�Z1d�Z2d�Z3d�Z4d�Z5d�Z6d�Z7d�Z8d�Z9d�Z:d�Z;d�Z<d�Z=d�Z>ddde"d�Z?d dd!�Z@ddde"d"�ZAd#�ZBd$�ZCd%�ZDd&�ZEde"d'�ZFd(�ZGdd)�ZHd*�ZId+�ZJde"d,�ZKd-�ZLd.�ZMd/�ZNd0�ZOde"d1�ZPdd2�ZQd3�ZRd4�ZSdd5�ZTdd6�ZUdddd7�ZVdddd8�ZWd9�ZXde"d:�ZYd;�ZZd<�Z[d=�Z\d>�Z]d?�Z^d@�Z_dA�Z`dB�ZadC�Zbdde"dD�ZcdE�ZdddF�ZedG�ZfdH�ZgddI�ZhddJ�ZidK�Zjddde"dL�ZkdddM�ZldddN�ZmdddO�Zndde"dP�ZoddQ�ZpdddR�Zqde"dS�ZrdT�ZsddU�ZtddV�ZudW�Zvde"dX�ZwdY�ZxdZ�Zyd[�Zzd\�Z{d]�Z|d^�Z}d_�Z~d`dadb�Zdddddc�Z�ddd�Z�dde�Z�df�Z�dgdh�Z�ddi�Z�ddj�Z�dk�Z�dl�Z�dm�Z�dS(nul	
Connection library for VMware

.. versionadded:: 2015.8.2

This is a base library used by a number of VMware services such as VMware
ESX, ESXi, and vCenter servers.

:codeauthor: Nitin Madhok <nmadhok@clemson.edu>
:codeauthor: Alexandru Bleotu <alexandru.bleotu@morganstanley.com>

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

- pyVmomi Python Module
- ESXCLI: This dependency is only needed to use the ``esxcli`` function. No other
  functions in this module rely on ESXCLI.

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`_ 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.

ESXCLI
------

This dependency is only needed to use the ``esxcli`` function. At the time of this
writing, no other functions in this module rely on ESXCLI.

The ESXCLI package is also referred to as the VMware vSphere CLI, or vCLI. VMware
provides vCLI package installation instructions for `vSphere 5.5`_ and
`vSphere 6.0`_.

.. _vSphere 5.5: http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.vcli.getstart.doc/cli_install.4.2.html
.. _vSphere 6.0: http://pubs.vmware.com/vsphere-60/index.jsp#com.vmware.vcli.getstart.doc/cli_install.4.2.html

Once all of the required dependencies are in place and the vCLI package is
installed, you can check to see if you can connect to your ESXi host or vCenter
server by running the following command:

.. code-block:: bash

    esxcli -s <host-location> -u <username> -p <password> system syslog config get

If the connection was successful, ESXCLI was successfully installed on your system.
You should see output related to the ESXi host's syslog configuration.

i(tabsolute_importtprint_functiontunicode_literalsN(tsix(t
BadStatusLine(tGetSitSmartConnectt
DisconnecttGetStubtSoapStubAdapter(tvimtvmodltVmomiSupportcC@str
tStdfS(u,
    Only load if PyVmomi is installed.
    uBMissing dependency: The salt.utils.vmware module requires pyVmomi.(tHAS_PYVMOMItTruetFalse(((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt__virtual__ssc
	C@s�tjjjd�}|s,tjd�tS|d
krAd}n|d
krVd}n|rr|dj|�7}n|s�|dj||||||�7}n%|dj|||||||�7}tj	j
j|dd	�}	|	S(u)
    Shell out and call the specified esxcli commmand, parse the result
    and return something sane.

    :param host: ESXi or vCenter host to connect to
    :param user: User to connect as, usually root
    :param pwd: Password to connect with
    :param port: TCP port
    :param cmd: esxcli command and arguments
    :param esxi_host: If `host` is a vCenter host, then esxi_host is the
                      ESXi machine on which to execute this command
    :param credstore: Optional path to the credential store file

    :return: Dictionary
    uesxcliuJMissing dependency: The salt.utils.vmware.esxcli function requires ESXCLI.i�uhttpsu --credstore '{0}'u; -s {0} -u {1} -p '{2}' --protocol={3} --portnumber={4} {5}uB -s {0} -h {1} -u {2} -p '{3}' --protocol={4} --portnumber={5} {6}toutput_logleveluquietN(tsalttutilstpathtwhichtlogterrorRtNonetformattmodulestcmdmodtrun_all(
thosttusertpwdtcmdtprotocoltportt	esxi_hostt	credstoretesx_cmdtret((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytesxcli}s8
			
	
cC@s�tjd�d}|dkrd|dkr@tjjd��n|dkrtjjd��qn�|dkr�|dk	r�|dk	r�yt|||�}Wq�tk
r�}	tjjt	j
|	���q�Xqdj|�}
tjj|
��ntjjdj|���yJtjd||�td	|d
|d|d|d
|d|d|�}Wnrt
k
r�}	d|	jkr�tjd|	j�tjd�tjd��q�ntk
r�}	dj|�}y�t|	tjj�r�d|	jksdt	j
|	�kr`td	|d
|d|d|d
|dttdttd���d|d|�}n=tj|	�t|	d�r�|	jn|}
tjj|
��Wq�tk
r�}	dt	j
|	�kr�tjtj�}
tj|
_y=td	|d
|d|d|d
|d|
d|d|�}Wq�tk
r�}	tj|	�t|	d�rW|	jnt	j
|	�}
tjjdj||
���q�Xq�t|	d�r�|	jn|}
tj|	�tjj|
��q�XnXtjt|�|S(u|
    Internal method to authenticate with a vCenter server or ESX/ESXi host
    and return the service instance object.
    uRetrieving new service instanceuuserpassuXLogin mechanism userpass was specified but the mandatory parameter 'username' is missinguXLogin mechanism userpass was specified but the mandatory parameter 'password' is missingusspiuLLogin mechanism '{0}' was specified but the mandatory parameters are missinguUnsupported mechanism: '{0}'u7Connecting using the '%s' mechanism, with username '%s'RRRR!R"tb64tokent	mechanismuunexpected keyword argumentu5Initial connect to the VMware endpoint failed with %suOThis may mean that a version of PyVmomi EARLIER than 6.0.0.2016.6 is installed.u/We recommend updating to that version or later.uQCould not connect to host '{0}'. Please check the debug log for more information.u [SSL: CERTIFICATE_VERIFY_FAILED]t
sslContextu_create_unverified_contextu_create_stdlib_contextumsgucertificate verify failedu$Could not connect to host '{0}': {1}N( RttraceRRt
exceptionstCommandExecutionErrortget_gssapi_tokent	ExceptiontVMwareConnectionErrorRt	text_typeRRt	TypeErrortmessageRt
isinstanceR
tfaulttHostConnectFaulttmsgtgetattrtsslt	exceptionthasattrt
SSLContexttPROTOCOL_TLSv1t	CERT_NONEtverify_modetatexittregisterR(RtusernametpasswordR!R"R)t	principaltdomainttokentexcterr_msgtservice_instancetdefault_msgtcontext((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt_get_service_instance�s�
		"			



		


'	
cC@s|jjjd|�}|S(u�
    Get a reference to a VMware customization spec for the purposes of customizing a clone

    si
        ServiceInstance for the vSphere or ESXi server (see get_service_instance)

    customization_spec_name
        Name of the customization spec

    tname(tcontenttcustomizationSpecManagertGetCustomizationSpec(tsitcustomization_spec_name((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_customizationspec_refscC@sUt|�}|jj|j|gt�}x$|jD]}|j|kr4|Sq4WdS(u
    Get reference to an object of specified object type and name

    si
        ServiceInstance for the vSphere or ESXi server (see get_service_instance)

    obj_type
        Type of the object (vim.StoragePod, vim.Datastore, etc)

    obj_name
        Name of the object

    N(t
get_inventorytviewManagertCreateContainerViewt
rootFolderRtviewRMR(RQtobj_typetobj_namet	inventoryt	containertitem((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_mor_using_container_view(suuserpasscC@s�|dkrd}n|dkr*d}nt�}|r�t�}	tjjj�s�t|	d�r�|	jdj	|t
j|�g�kr�t|�d}q�|Sn|s�t
||||||||�}ntjd�y|j�Wntjjk
r:tjd�t|�t
||||||||�}n�tjjk
r}}
tj|
�tjjdj|
j���nrtjjk
r�}
tj|
�tjj|
j��n8tjk
r�}
tj|
�tjj|
j��nX|S(	u)
    Authenticate with a vCenter server or ESX/ESXi host and return the service instance object.

    host
        The location of the vCenter server or ESX/ESXi host.

    username
        The username used to login to the vCenter server or ESX/ESXi host.
        Required if mechanism is ``userpass``

    password
        The password used to login to the vCenter server or ESX/ESXi host.
        Required if mechanism is ``userpass``

    protocol
        Optionally set to alternate protocol if the vCenter server or ESX/ESXi host is not
        using the default protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the vCenter server or ESX/ESXi host is not
        using the default port. Default port is ``443``.

    mechanism
        pyVmomi connection mechanism. Can either be ``userpass`` or ``sspi``.
        Default mechanism is ``userpass``.

    principal
        Kerberos service principal. Required if mechanism is ``sspi``

    domain
        Kerberos user domain. Required if mechanism is ``sspi``
    uhttpsi�uhostu:u*Checking connection is still authenticatedu.Session no longer authenticating. Reconnectingu.Not enough permissions. Required privilege: {}N(RRRRRtplatformtis_proxyR;RtjoinRR1RRLRR+tCurrentTimeR
R5tNotAuthenticatedtNoPermissionR:R,tVMwareApiErrorRtprivilegeIdtVimFaultR7RtRuntimeFaulttVMwareRuntimeError(RRBRCR!R"R)RDRERItstubRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_service_instance>s`$				'
	



	

c	
C@s�d}tjd dkr=tj�}t|_tj|_n|j	}|j
jd�d}|jjd�d}|t
j�d	<td
|d|d|d
|ddd|�}|j|_|S(uT
    Returns a stub that points to a different path,
    created from an existing connection.

    service_instance
        The Service Instance.

    path
        Path of the new stub.

    ns
        Namespace of the new stub.
        Default value is None

    version
        Version of the new stub.
        Default value is None.
    iiiiu:iu"iuvcSessionCookieRtnsRtversiontpoolSizeR*N(iii(Rtsystversion_infoR9tcreate_default_contextRtcheck_hostnameR>R?t_stubRtsplittcookieRtGetRequestContextR	(	RIRRlRmRKRjthostnametsession_cookietnew_stub((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_new_service_instance_stub�s"			u	<unnamed>cC@sA|s|j}ntjd|�tjd�}|j|_|S(u�
    Retrieves the service instance from a managed object.

    me_ref
        Reference to a managed object (of type vim.ManagedEntity).

    name
        Name of managed object. This field is optional.
    u4[%s] Retrieving service instance from managed objectuServiceInstance(RMRR+R
tServiceInstanceRs(tmo_refRMRQ((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt(get_service_instance_from_managed_object�s
cC@s�tjd�yt|�Wn�tjjk
ra}tj|�tjj	dj
|j���nrtjjk
r�}tj|�tjj	|j
��n8tjk
r�}tj|�tjj|j
��nXdS(u�
    Function that disconnects from the vCenter server or ESXi host

    service_instance
        The Service Instance from which to obtain managed object references.
    u
Disconnectingu.Not enough permissions. Required privilege: {}N(RR+RR
R5RdR:RR,ReRRfRgR7RRhRi(RIRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
disconnect�s

	

cC@sy|jjj}Wn�tjjk
rY}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nXtjd|�|dkr�tS|dkr�tStj	j
dj|���dS(u�
    Function that returns True if the connection is made to a vCenter Server and
    False if the connection is made to an ESXi host

    service_instance
        The Service Instance from which to obtain managed object references.
    u.Not enough permissions. Required privilege: {}u
api_type = %su
VirtualCenteru	HostAgentuFUnexpected api type '{0}' . Supported types: 'VirtualCenter/HostAgent'N(RNtabouttapiTypeR
R5RdRR:RR,ReRRfRgR7RRhRiR+RR(RItapi_typeRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytis_connection_to_a_vcenter�s*
	

	cC@s�y|jjSWn�tjjk
rT}tj|�tjj	dj
|j���nrtjjk
r�}tj|�tjj	|j
��n8tjk
r�}tj|�tjj|j
��nXdS(u�
    Returns information of the vCenter or ESXi host

    service_instance
        The Service Instance from which to obtain managed object references.
    u/Not enough permissions. Required privilege: {0}N(RNRR
R5RdRR:RR,ReRRfRgR7RRhRi(RIRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_service_infos
	

cC@sst|�}||krot|�}|jj|jtjgt�}x'|jD]}|j	|krO|SqOWndS(u�
    Return a reference to a Distributed Virtual Switch object.

    :param service_instance: PyVmomi service instance
    :param dvs_name: Name of DVS to return
    :return: A PyVmomi DVS object
    N(tlist_dvsRTRURVRWR
tDistributedVirtualSwitchRRXRMR(RItdvs_nametswitchesR[R\R]((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt_get_dvs(s!cC@s
|jjjS(uT
    Helper function that returns a list of PhysicalNics and their information.
    (tconfigtnetworktpnic(thost_reference((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
_get_pnics;scC@s
|jjjS(uS
    Helper function that returns a list of VirtualNics and their information.
    (R�R�tvnic(R�((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
_get_vnicsBscC@s
|jjS(u_
    Helper function that returns a list of Virtual NicManagers
    and their information.
    (t
configManagertvirtualNicManager(R�((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt_get_vnic_managerIscC@s+x$|jD]}|j|kr
|Sq
WdS(u�
    Return a portgroup object corresponding to the portgroup name on the dvs

    :param dvs: DVS object
    :param portgroup_name: Name of portgroup to return
    :return: Portgroup object
    N(t	portgroupRMR(tdvstportgroup_nameR�((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt_get_dvs_portgroupQscC@s+x$|jD]}|j|kr
|Sq
WdS(u�
    Return a portgroup object corresponding to the portgroup name on the dvs

    :param dvs: DVS object
    :param portgroup_name: Name of portgroup to return
    :return: Portgroup object
    N(R�RMR(R�R�R�((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt_get_dvs_uplink_portgroup`scC@s�tstd��ndj|||�}tjd|�tj|tj�}tj|�}d}x||j
s�|j|�}|r�tj
r�tj|�Stjtjjj|��S|j
r�Pn|sgtjjd��qgqgWtjjd��dS(u�
    Get the gssapi token for Kerberos connection

    principal
       The service principal
    host
       Host url where we would like to authenticate
    domain
       Kerberos user domain
    u#The gssapi library is not imported.u{0}/{1}@{2}u%Retrieving gsspi token for service %su,Can't receive token, no response from serveru-Context established, but didn't receive tokenN(t
HAS_GSSAPItImportErrorRRtdebugtgssapitNametC_NT_USER_NAMEtInitContextRtestablishedtstepRtPY2tbase64t	b64encodeRRtstringutilstto_bytesR,R-(RDRREtservicetservice_nametctxtin_tokent	out_token((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyR.os(	
			cC@sqi}t|�jjdkrm|jjj|j�jtj	gt
�}|rd|jrd|jdjj
j|d<|jdjj
j|d<x@|jdjj
jD](}|jjdkr�|j|d<q�q�W|jdjjjj|d<|jdjjjj|d<|jdjjjj|d	<|jdjjjj|d
<|jdjjjj|d<|jdjjjj|d<|jdjjd
d
|d<|jdjjj|d<|jdjjjj�j d�|d<|jdjj!dj"|d<|jdjjjj#|d<|jdjj$j%|d<|jdjj$j&|d<|d|d|d<i|d<i|d<i|d<i|d<x�|jdj'j(j)j*D]�}g|d|j+<g|d|j+<g|d|j+<|d|j+j,|j-j.j/�|d|j+j,|j-j.j/�|j-j.j0rV|d|j+j,|j-j.j0j1�n|j-j2|d|j+<q�W|jdj'j(j3j4|d<|jdj'j(j3j5|d<dj6|jdj'j(j3j4|jdj'j(j3j5r�dnd|jdj'j(j3j5�|d <x5|jdj'j(j7j8D]}|j2|d|j+<q#W|jdj'j9j:j;j|d!<nd"}n|S(#u�
    Return hardware info for standard minion grains if the service_instance is a HostAgent type

    service_instance
        The service instance object to get hardware info for

    .. versionadded:: 2016.11.0
    u	HostAgentiumanufactureruproductnameu
ServiceTaguserialnumberu
osfullnameuosmanufactureru	osreleaseuosbuildu	os_familyuosiu	mem_totalubiosversionu%m/%d/%Yubiosreleasedateu	cpu_modelukernelunum_cpu_socketsu
num_cpu_coresunum_cpusu
ip_interfacesuip4_interfacesuip6_interfacesuhwaddr_interfacesuhostudomainu	{0}{1}{2}u.uufqdnutimezoneN(=RTRR�RNRURVtRetrieveContentRWR
t
HostSystemRRXthardwaret
systemInfotvendortmodeltotherIdentifyingInfotidentifierTypetkeytidentifierValuetsummaryR�tproducttfullNameRmtbuildRMt
memorySizetbiosInfotbiosVersiontreleaseDatetdatetstrftimetcpuPkgtdescriptiont
productLineIdtcpuInfotnumCpuPackagestnumCpuCoresR�t
networkSystemt
networkConfigR�tdevicetappendtspectipt	ipAddresst
ipV6ConfigtipV6Addresstmact	dnsConfigthostNamet
domainNameRtnetworkInfoR�tdateTimeSystemtdateTimeInfottimeZoneR(RIt
hw_grain_dataRXt_datat_vnict_pnic((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_hardware_grains�s`	)



 !!'"  #	cC@s
|j�S(u�
    Return the inventory of a Service Instance Object.

    service_instance
        The Service Instance Object for which to obtain inventory.
    (R�(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyRT�scC@s�ytjd�|j�jSWn�tjjk
rd}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nXdS(u�
    Returns the root folder of a vCenter.

    service_instance
        The Service Instance Object for which to obtain the root folder.
    uRetrieving root folderu.Not enough permissions. Required privilege: {}N(RR+R�RWR
R5RdR:RR,ReRRfRgR7RRhRi(RIRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_root_folder�s

	

c

C@s�|st|�}n|}t}|rB|rBt}y"|jjj||gt�}Wn�tjjk
r�}t	j
|�tjj
dj|j���nrtjjk
r�}t	j
|�tjj
|j��n8tjk
r}t	j
|�tjj|j��nXtjjjdddddtdtjj�}ntjjjd|d|sctntd	|�}	tjjjd
|d|s�tntd|s�|gnd�}
tjjjd|
gd
|	gdt�}y|jjj|g�}Wn�tjjk
r=}t	j
|�tjj
dj|j���nrtjjk
rw}t	j
|�tjj
|j��n8tjk
r�}t	j
|�tjj|j��nX|r~y|j �Wq~tjjk
r	}t	j
|�tjj
dj|j���q~tjjk
rC}t	j
|�tjj
|j��q~tjk
rz}t	j
|�tjj|j��q~Xn|S(u7
    Returns the content of the specified type of object for a Service Instance.

    For more information, please see:
    http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.wssdk.pg.doc_50%2FPG_Ch5_PropertyCollector.7.6.html

    service_instance
        The Service Instance from which to obtain content.

    obj_type
        The type of content to obtain.

    property_list
        An optional list of object properties to used to return even more filtered content results.

    container_ref
        An optional reference to the managed object to search under. Can either be an object of type Folder, Datacenter,
        ComputeResource, Resource Pool or HostSystem. If not specified, default behaviour is to search under the inventory
        rootFolder.

    traversal_spec
        An optional TraversalSpec to be used instead of the standard
        ``Traverse All`` spec.

    local_properties
        Flag specifying whether the properties to be retrieved are local to the
        container. If that is the case, the traversal spec needs to be None.
    u.Not enough permissions. Required privilege: {}RMutraverseEntitiesRuviewtskipttypetalltpathSettobjt	selectSett	objectSettpropSettreportMissingObjectsInResultsN(!R�RRRNRURVR
R5RdRR:RR,ReRRfRgR7RRhRitquerytPropertyCollectort
TraversalSpecRXt
ContainerViewtPropertySpect
ObjectSpecRt
FilterSpectpropertyCollectortRetrieveContentstDestroy(
RIRYt
property_listt
container_refttraversal_spectlocal_propertiestobj_reftlocal_traversal_specRGt
property_spectobj_spectfilter_specRN((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_content�s� 
	

				
	


	

unamecC@s{t||d|gd|�}xV|D]N}tj|jdd��jd�}|||ksk||kr%|dSq%WdS(u
    Returns the first managed object reference having the specified property value.

    service_instance
        The Service Instance from which to obtain managed object references.

    object_type
        The type of content for which to obtain managed object references.

    property_value
        The name of the property for which to obtain the managed object reference.

    property_name
        An object property used to return the specified object reference results. Defaults to ``name``.

    container_ref
        An optional reference to the managed object to search under. Can either be an object of type Folder, Datacenter,
        ComputeResource, Resource Pool or HostSystem. If not specified, default behaviour is to search under the inventory
        rootFolder.
    R�R�uobjectuu'"N(tget_mors_with_propertiesRR1tgettstripR(RItobject_typetproperty_valuet
property_nameR�tobject_listR�tobj_id((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_mor_by_propertyms
$cC@s||g}i|d6|d6|d6|d6}yt||�}Wn\tk
rct||�}n=tk
r�}	|	jtjkr�|	�nt||�}nXg}
xR|D]J}i}x!|jD]}
|
j||
j<q�W|j|d<|
j	|�q�Wt
jdt|
��|
S(u�
    Returns a list containing properties and managed object references for the managed object.

    service_instance
        The Service Instance from which to obtain managed object references.

    object_type
        The type of content for which to obtain managed object references.

    property_list
        An optional list of object properties used to return even more filtered managed object reference results.

    container_ref
        An optional reference to the managed object to search under. Can either be an object of type Folder, Datacenter,
        ComputeResource, Resource Pool or HostSystem. If not specified, default behaviour is to search under the inventory
        rootFolder.

    traversal_spec
        An optional TraversalSpec to be used instead of the standard
        ``Traverse All`` spec

    local_properties
        Flag specigying whether the properties to be retrieved are local to the
        container. If that is the case, the traversal spec needs to be None.
    u
property_listu
container_refutraversal_speculocal_propertiesuobjectuRetrieved %s objects(
R�RtIOErrorterrnotEPIPER�tvalRMR�R�RR+tlen(RIR�R�R�R�R�tcontent_argstcontent_kwargsRNRGR�R�t
propertiestprop((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyR��s,


	

c	C@s�t|�}tjdt|�j�y<t|t|�d|ddgdt�}|dd}Wntjj	k
r�d}nXtjd|t|�j|�t|t|�d|d|dt�}|s�t
jjd	j
|���n|dS(
u�
    Returns specific properties of a managed object, retrieved in an
    optimally.

    mo_ref
        The managed object reference.

    properties
        List of properties of the managed object to retrieve.
    uRetrieving name of %sR�R�unameR�iu	<unnamed>u%Retrieving properties '%s' of %s '%s'u4Properties of managed object '{0}' weren't retrieved(R}RR+R�t__name__R�RRR�tInvalidPropertyRR,ReR(R|R	RItitemstmo_name((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt get_properties_of_managed_object�s.		
			cC@st|dg�}|jd�S(u�
    Returns the name of a managed object.
    If the name wasn't found, it returns None.

    mo_ref
        The managed object reference.
    uname(RR�(R|tprops((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_managed_object_name�scC@s�|dkrtjjj�S|dkr8tjjj�S|dkrTtjjj�S|dkrptjjj�S|dkr�tjjj�Std��dS(u�
    Return the network adapter type.

    adpater_type
        The adapter type from which to obtain the network adapter type.
    uvmxnetuvmxnet2uvmxnet3ue1000ue1000eu,An unknown network adapter object type name.N(	R
tvmR�t
VirtualVmxnettVirtualVmxnet2tVirtualVmxnet3tVirtualE1000t
VirtualE1000et
ValueError(tadapter_type((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_network_adapter_type�scC@s�t|tjjj�rdSt|tjjj�r8dSt|tjjj�rTdSt|tjjj�rpdSt|tjjj�r�dSt	d��dS(u�
    Returns the network adapter type.

    adapter_object
        The adapter object from which to obtain the network adapter type.
    uvmxnet2uvmxnet3uvmxnetue1000eue1000u'An unknown network adapter object type.N(
R4R
RR�RRRRRR(tadapter_object((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_network_adapter_object_typesc	C@s�t|�}tjd||r-dj|�nd|�dg}tjjjdddt	dt
jdtjjjdd	dtdt
j
�g�}t|�}gt|t
jd
|d|d|�D],}|s�|r�|d|kr�|d
^q�}|S(u
    Returns distributed virtual switches (DVSs) in a datacenter.

    dc_ref
        The parent datacenter reference.

    dvs_names
        The names of the DVSs to return. Default is None.

    get_all_dvss
        Return all DVSs in the datacenter. Default is False.
    uCRetrieving DVSs in datacenter '%s', dvs_names='%s', get_all_dvss=%su,unameRu
networkFolderR�R�R�uchildEntityR�R�R�uobjectN(RRR+RaRRR�R�R�RR
t
DatacenterRtFolderR}R�R�(	tdc_reft	dvs_namestget_all_dvsstdc_nameR	R�RItiR
((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_dvsss0
			
,c	C@s�t|�}tjd|�t|�}tjjjdddtdt	j
�}t|t	jd|ddgd	|�}|s�t
jjd
j|���n|ddS(
u6
    Retrieves the network folder of a datacenter
    u,Retrieving network folder in datacenter '%s'Ru
networkFolderR�R�R�R�unameR�u3Network folder in datacenter '{0}' wasn't retrievediuobject(RRR+R}RR�R�R�RR
RR�RRR,tVMwareObjectRetrievalErrorR(RR"RIR�tentries((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_network_folderEs"				cC@sRt|�}tjd||�|s4tj�}n|js[tj�|_||j_nt|�}y|j	|�}Wn�tj
jk
r�}tj|�t
jjdj|j���nrtj
jk
r�}tj|�t
jj|j��n8tjk
r1}tj|�t
jj|j��nXt||tj|j��dS(uq
    Creates a distributed virtual switches (DVS) in a datacenter.
    Returns the reference to the newly created distributed virtual switch.

    dc_ref
        The parent datacenter reference.

    dvs_name
        The name of the DVS to create.

    dvs_create_spec
        The DVS spec (vim.DVSCreateSpec) to use when creating the DVS.
        Default is None.
    u$Creating DVS '%s' in datacenter '%s'u/Not enough permissions. Required privilege: {0}N(RRR+R
t
DVSCreateSpect
configSpectVMwareDVSConfigSpecRMR'tCreateDVS_TaskR5RdR:RR,ReRRfRgR7RRhRit
wait_for_taskRR1t	__class__(RR�tdvs_create_specR"tnetw_folder_refttaskRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
create_dvs\s,	
	

cC@st|�}tjd|�y|j|�}Wn�tjjk
ru}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nXt||tj|j��dS(u�
    Updates a distributed virtual switch with the config_spec.

    dvs_ref
        The DVS reference.

    dvs_config_spec
        The updated config spec (vim.VMwareDVSConfigSpec) to be applied to
        the DVS.
    uUpdating dvs '%s'u/Not enough permissions. Required privilege: {0}N(RRR+tReconfigureDvs_TaskR
R5RdR:RR,ReRRfRgR7RRhRiR,RR1R-(tdvs_reftdvs_config_specR�R0RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
update_dvs�s 
	

cC@s�t|�}tjd||�y|jd|�Wn�tjjk
ry}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nXdS(u�
    Sets whether NIOC is enabled on a DVS.

    dvs_ref
        The DVS reference.

    enabled
        Flag specifying whether NIOC is enabled.
    u<Setting network resource management enable to %s on dvs '%s'tenableu/Not enough permissions. Required privilege: {0}N(RRR+tEnableNetworkResourceManagementR
R5RdR:RR,ReRRfRgR7RRhRi(R3tenabledR�RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt+set_dvs_network_resource_management_enabled�s 
	

	

c	C@spt|tjtjf�s0tjjd��nt|�}tj	dt
|�j||ridj|�nd|�dg}t|tj�r�tjjjdddtdtjd	tjjjdd
dtdtj�g�}n'tjjjdddtdtj�}t|�}gt|tjd|d
|d|�D],}|s\|r:|d|kr:|d^q:}|S(uz
    Returns distributed virtual porgroups (dvportgroups).
    The parent object can be either a datacenter or a dvs.

    parent_ref
        The parent object reference. Can be either a datacenter or a dvs.

    portgroup_names
        The names of the dvss to return. Default is None.

    get_all_portgroups
        Return all portgroups in the parent. Default is False.
    uEParent has to be either a datacenter, or a distributed virtual switchuMRetrieving portgroup in %s '%s', portgroups_names='%s', get_all_portgroups=%su,unameRu
networkFolderR�R�R�uchildEntityu	portgroupR�R�R�uobjectN(R4R
RR�RR,tArgumentValueErrorRRR+R�RRaRRR�R�R�RRRR}R�tDistributedVirtualPortgroup(	t
parent_reftportgroup_namestget_all_portgroupstparent_nameR	R�RIR#R
((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_dvportgroups�sD					
&c
C@s�t|�}tjd|�tjjjdddtdtj	�}t
|�}gt|tjd|ddgd	|�D]F}|drwg|dD]}|j
d
kr�|^q�rw|d^qw}|s�tjjdj|���n|d
S(u�
    Returns the uplink distributed virtual portgroup of a distributed virtual
    switch (dvs)

    dvs_ref
        The dvs reference
    u'Retrieving uplink portgroup of dvs '%s'Ru	portgroupR�R�R�R�utagR�uSYSTEM/DVS.UPLINKPGuobjectu*Uplink portgroup of DVS '{0}' wasn't foundi(RRR+RR�R�R�RR
R�R}R�R;R�RR,R%R(R3R�R�RItentryttR
((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_uplink_dvportgroup�s&		

<	cC@st|�}tjd|j|�tjd|�y|j|�}Wn�tjjk
r�}tj|�t	j
jdj|j
���nrtjjk
r�}tj|�t	j
j|j��n8tjk
r�}tj|�t	j
j|j��nXt||tj|j��dS(u�
    Creates a distributed virtual portgroup on a distributed virtual switch
    (dvs)

    dvs_ref
        The dvs reference

    spec
        Portgroup spec (vim.DVPortgroupConfigSpec)
    uAdding portgroup %s to dvs '%s'u	spec = %su/Not enough permissions. Required privilege: {0}N(RRR+RMtCreateDVPortgroup_TaskR
R5RdR:RR,ReRRfRgR7RRhRiR,RR1R-(R3R�R�R0RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytcreate_dvportgroups"
	

cC@st|�}tjd|�y|j|�}Wn�tjjk
ru}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nXt||tj|j��dS(u�
    Updates a distributed virtual portgroup

    portgroup_ref
        The portgroup reference

    spec
        Portgroup spec (vim.DVPortgroupConfigSpec)
    uUpdating portgrouo %su/Not enough permissions. Required privilege: {0}N(RRR+tReconfigureDVPortgroup_TaskR
R5RdR:RR,ReRRfRgR7RRhRiR,RR1R-(t
portgroup_refR�tpg_nameR0RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytupdate_dvportgroup.s 

	

cC@st|�}tjd|�y|j�}Wn�tjjk
rr}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nXt||tj|j��dS(ud
    Removes a distributed virtual portgroup

    portgroup_ref
        The portgroup reference
    uRemoving portgroup %su/Not enough permissions. Required privilege: {0}N(RRR+tDestroy_TaskR
R5RdR:RR,ReRRfRgR7RRhRiR,RR1R-(RGRHR0RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytremove_dvportgroupJs 
	

c	C@s+t|tj�s'tjjd��nt|�}tjdt	|�j
||r`dj|�nd|�dg}t
|�}tjjjdddtdtjd	tjjjdd
dtdtj�g�}gt|tjd|d|d
|�D],}|s|r�|d|kr�|d^q�}|S(us
    Returns networks of standard switches.
    The parent object can be a datacenter.

    parent_ref
        The parent object reference. A datacenter object.

    network_names
        The name of the standard switch networks. Default is None.

    get_all_networks
        Boolean indicates whether to return all networks in the parent.
        Default is False.
    uParent has to be a datacenter.uHRetrieving network from %s '%s', network_names='%s', get_all_networks=%su,unameRu
networkFolderR�R�R�uchildEntityR�R�R�uobjectN(R4R
RRR,R:RRR+R�RRaRR}RR�R�R�RRRR�tNetwork(	R<t
network_namestget_all_networksR?R	RIR�R#R
((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_networkscs8					
&cC@sV|dkrdg}ng}t|||�}x|D]}|j|d�q7W|S(u�
    Returns a simple list of objects from a given service instance.

    service_instance
        The Service Instance for which to obtain a list of objects.

    object_type
        The type of content for which to obtain information.

    properties
        An optional list of object properties used to return reference results.
        If not provided, defaults to ``name``.
    unameN(RR�R�(RIt
vim_objectR	R
t	item_listR]((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytlist_objects�s
cC@s�tjd�y|jj}Wn�tjjk
rc}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nX|S(u�
    Returns the license manager.

    service_instance
        The Service Instance Object from which to obrain the license manager.
    uRetrieving license manageru/Not enough permissions. Required privilege: {0}(RR�RNtlicenseManagerR
R5RdR:RR,ReRRfRgR7RRhRi(RItlic_managerRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_license_manager�s

	

cC@s�tjd�y|jjj}Wn�tjjk
rf}tj|�t	j
jdj|j
���nrtjjk
r�}tj|�t	j
j|j��n8tjk
r�}tj|�t	j
j|j��nX|s�t	j
jd��n|S(u�
    Returns the license assignment manager.

    service_instance
        The Service Instance Object from which to obrain the license manager.
    u%Retrieving license assignment manageru/Not enough permissions. Required privilege: {0}u,License assignment manager was not retrieved(RR�RNRStlicenseAssignmentManagerR
R5RdR:RR,ReRRfRgR7RRhRiR%(RItlic_assignment_managerRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_license_assignment_manager�s$

	

	cC@s�|st|�}ntjd�y|jSWn�tjjk
rs}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nXdS(u
    Returns the licenses on a specific instance.

    service_instance
        The Service Instance Object from which to obrain the licenses.

    license_manager
        The License Manager object of the service instance. If not provided it
        will be retrieved.
    uRetrieving licensesu/Not enough permissions. Required privilege: {0}N(RURR�tlicensesR
R5RdR:RR,ReRRfRgR7RRhRi(RItlicense_managerRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_licenses�s 

	

cC@s|st|�}ntj�}d|_||_tjd|�y|j||g�}Wn�tjj	k
r�}tj
|�tjj
dj|j���nrtjjk
r�}tj
|�tjj
|j��n8tjk
r}tj
|�tjj|j��nX|S(uC
    Adds a license.

    service_instance
        The Service Instance Object.

    key
        The key of the license to add.

    description
        The description of the license to add.

    license_manager
        The License Manager object of the service instance. If not provided it
        will be retrieved.
    uVpxClientLicenseLabeluAdding license '%s'u/Not enough permissions. Required privilege: {0}(RUR
tKeyValueR�tvalueRR�t
AddLicenseR5RdR:RR,ReRRfRgR7RRhRi(RIR�R�RZtlabeltvmware_licenseRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytadd_license�s(		
	

c
C@s�|st|�}n|s0tjjd��nd}d}t}|s+|rWt}nd}y|jjj	}Wq4t
jjk
r�}t
j|�tjjdj|j���q4t
jjk
r�}t
j|�tjj|j��q4tjk
r'}t
j|�tjj|j��q4Xn	|j}t
jd|�y|j|�}Wn�t
jjk
r�}t
j|�tjjdj|j���nrt
jjk
r�}t
j|�tjj|j��n8tjk
r}t
j|�tjj|j��nX|dkrOt|�dkrOt
jd�tjjd��n|r�||d	jkr�t
jd
||d	j�tjjd��q�ng|D]}	|	j^q�S(
u�
    Returns the licenses assigned to an entity. If entity ref is not provided,
    then entity_name is assumed to be the vcenter. This is later checked if
    the entity name is provided.

    service_instance
        The Service Instance Object from which to obtain the licenses.

    entity_ref
        VMware entity to get the assigned licenses for.
        If None, the entity is the vCenter itself.
        Default is None.

    entity_name
        Entity name used in logging.
        Default is None.

    license_assignment_manager
        The LicenseAssignmentManager object of the service instance.
        If not provided it will be retrieved.
        Default is None.
    uNo entity_name passedumoiduuuidu/Not enough permissions. Required privilege: {0}u$Retrieving licenses assigned to '%s'iuCUnexpectectedly retrieved more than one VCenter license assignment.u2Unexpected return. Expect only a single assignmentiu0Getting license info for wrong vcenter: %s != %su3Got license assignment info for a different vcenterN(RXRR,R:RRRRNRtinstanceUuidR
R5RdRR:ReRRfRgR7RRhRit_moIdR+tQueryAssignedLicensesRR%tentityDisplayNametassignedLicense(
RIt
entity_reftentity_nametlicense_assignment_managert	entity_idtentity_typet
check_nameRGtassignmentsta((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_assigned_licenses%sd	
	

	
	


			c	C@s�|st|�}nd}|s�y|jjj}Wn�tjjk
rz}tj	|�t
jjdj
|j���nXtjjk
r�}t
jj|j��n+tjk
r�}t
jj|j��nX|s�d}q�n	|j}tjd|�y|j|||�}Wn�tjjk
r\}tj	|�t
jjdj
|j���nrtjjk
r�}tj	|�t
jj|j��n8tjk
r�}tj	|�t
jj|j��nX|S(u�
    Assigns a license to an entity.

    service_instance
        The Service Instance Object from which to obrain the licenses.

    license_key
        The key of the license to add.

    license_name
        The description of the license to add.

    entity_ref
        VMware entity to assign the license to.
        If None, the entity is the vCenter itself.
        Default is None.

    entity_name
        Entity name used in logging.
        Default is None.

    license_assignment_manager
        The LicenseAssignmentManager object of the service instance.
        If not provided it will be retrieved
        Default is None.
    u/Not enough permissions. Required privilege: {0}uvCenteruAssigning license to '%s'N(RXRRNRRbR
R5RdRR:RR,ReRRfRgR7RRhRiRcR+tUpdateAssignedLicense(	RItlicense_keytlicense_nameRgRhRiRjRGR`((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytassign_licensezsH
		

	

cC@st|tj�S(u�
    Returns a list of datacenters associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain datacenters.
    (RRR
R(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytlist_datacenters�scC@sRgt|tjddg�D],}|s>|r|d|kr|d^q}|S(uX
    Returns all datacenters in a vCenter.

    service_instance
        The Service Instance Object from which to obtain cluster.

    datacenter_names
        List of datacenter names to filter by. Default value is None.

    get_all_datacenters
        Flag specifying whether to retrieve all datacenters.
        Default value is None.
    R�unameuobject(R�R
R(RItdatacenter_namestget_all_datacentersR#R
((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_datacenters�s	&cC@sAt|d|g�}|s9tjjdj|���n|dS(u�
    Returns a vim.Datacenter managed object.

    service_instance
        The Service Instance Object from which to obtain datacenter.

    datacenter_name
        The datacenter name
    RuuDatacenter '{0}' was not foundi(RwRR,R%R(RItdatacenter_nameR
((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_datacenter�s
		cC@s�t|�}tjd|�y|j|�}Wn�tjjk
ru}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nX|S(u�
    Creates a datacenter.

    .. versionadded:: 2017.7.0

    service_instance
        The Service Instance Object

    datacenter_name
        The datacenter name
    uCreating datacenter '%s'u.Not enough permissions. Required privilege: {}(R�RR+tCreateDatacenterR
R5RdR:RR,ReRRfRgR7RRhRi(RIRxtroot_foldertdc_objRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytcreate_datacenter�s 
	

cC@s�t|�}tjd||�t|d|�}tjjjdddtdt	j
dtjjjdddtdt	j�g�}gt
|t	jd	|d
dgd|�D] }|d|kr�|d
^q�}|s�tjjdj||���n|dS(u�
    Returns a cluster in a datacenter.

    dc_ref
        The datacenter reference

    cluster
        The cluster to be retrieved
    u,Retrieving cluster '%s' from datacenter '%s'RMRu
hostFolderR�R�R�uchildEntityR�R�unameR�uobjectu/Cluster '{0}' was not found in datacenter '{1}'i(RRR+R}RR�R�R�RR
RRRR�tClusterComputeResourceRR,R%R(RtclusterR"RQR�R#R
((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_clusters0
	
			
 	cC@s�t|�}tjd||�y|jj||�Wn�tjjk
r|}tj|�t	j
jdj|j
���nrtjjk
r�}tj|�t	j
j|j��n8tjk
r�}tj|�t	j
j|j��nXdS(u�
    Creates a cluster in a datacenter.

    dc_ref
        The parent datacenter reference.

    cluster_name
        The cluster name.

    cluster_spec
        The cluster spec (vim.ClusterConfigSpecEx).
        Defaults to None.
    u(Creating cluster '%s' in datacenter '%s'u.Not enough permissions. Required privilege: {}N(RRR+t
hostFoldertCreateClusterExR
R5RdR:RR,ReRRfRgR7RRhRi(Rtcluster_nametcluster_specR"RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytcreate_cluster9s 	

	

cC@st|�}tjd|�y|j|dt�}Wn�tjjk
r{}tj|�t	j
jdj|j
���nrtjjk
r�}tj|�t	j
j|j��n8tjk
r�}tj|�t	j
j|j��nXt||d�dS(u�
    Updates a cluster in a datacenter.

    cluster_ref
        The cluster reference.

    cluster_spec
        The cluster spec (vim.ClusterConfigSpecEx).
        Defaults to None.
    uUpdating cluster '%s'tmodifyu.Not enough permissions. Required privilege: {}uClusterUpdateTaskN(RRR+tReconfigureComputeResource_TaskRR
R5RdR:RR,ReRRfRgR7RRhRiR,(tcluster_refR�R�R0RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytupdate_clusterYs"

	

cC@st|tj�S(u�
    Returns a list of clusters associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain clusters.
    (RRR
R~(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
list_clusterswscC@st|tj�S(u�
    Returns a list of datastore clusters associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain datastore clusters.
    (RRR
t
StoragePod(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytlist_datastore_clusters�scC@st|tj�S(u�
    Returns a list of datastores associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain datastores.
    (RRR
t	Datastore(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytlist_datastores�sc
C@sVg}t||d|�}x4|D],}y.|jjddj|j|�d|�}Wn�tjjk
r�}	tj	|	�t
jjdj|	j
���nrtjjk
r�}	tj	|	�t
jj|	j��n8tjk
r
}	tj	|	�t
jj|	j��nXy&|jt
jjj||d��Wq"t
jjk
rMq"Xq"W|S(u�
    Get the files with a given browser specification from the datastore.

    service_instance
        The Service Instance Object from which to obtain datastores.

    directory
        The name of the directory where we would like to search

    datastores
        Name of the datastores

    container_object
        The base object for searches

    browser_spec
        BrowserSpec object which defines the search criteria

    return
        list of vim.host.DatastoreBrowser.SearchResults objects
    tdatastore_namest
datastorePathu[{}] {}t
searchSpecu.Not enough permissions. Required privilege: {}uquery virtual machine files(tget_datastorestbrowsertSearchDatastore_TaskRRMR
R5RdRR:RR,ReRfRgR7RRhRiR�RtvmwareR,tVMwareFileNotFoundError(
RIt	directoryt
datastorestcontainer_objecttbrowser_spectfilestdatastore_objectstdatobjR0RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_datastore_files�s,
!

	

&cC@s9t|�}|r%tjd|�nStjd|||�|rxt|tj�rxtjjdj	|j
j���n|r�|r�tjd|�t|||�}tj
jj|dg�}|jdg�}g}	x�g|D]$}
t|
jtj�r�|
j^q�D]v}g|jD]}|j|kr|^qsCqntjd|jg|jD]}|j^q\�|	j|j�qWtjd|	�|r�|j|	�q�|	}n|r�|r�tjd|�gStjd	|�t|tj�r)tjjjd
ddd
dtdtj�}
n_t|tj�rktjjjd
ddd
dtdtj�}
nt|tj�r�tjjjd
ddd
dtdtj�}
n�t|tj�r�tjjjd
ddddtdtj�}
n�t|tj �rgt|�dkrgtjjjdddtjjjdd
dtdtj�gdtdtj �}
n!tjjdj	|j
j���t!|dtj"ddgd|d|
�}tjdt#|��g|D]"}
|s�|
d|kr�|
^q�}tjdg|D]}
|
d^q�g|D]}
|
d^q%S(u	
    Returns a list of vim.Datastore objects representing the datastores visible
    from a VMware object, filtered by their names, or the backing disk
    cannonical name or scsi_addresses

    service_instance
        The Service Instance Object from which to obtain datastores.

    reference
        The VMware object from which the datastores are visible.

    datastore_names
        The list of datastore names to be retrieved. Default value is None.

    backing_disk_ids
        The list of canonical names of the disks backing the datastores
        to be retrieved. Only supported if reference is a vim.HostSystem.
        Default value is None

    get_all_datastores
        Specifies whether to retrieve all disks in the host.
        Default value is False.
    u)Retrieving all datastores visible to '%s'uLRetrieving datastores visible to '%s': names = (%s); backing disk ids = (%s)u@Unsupported reference type '{0}' when backing disk filter is setu.Filtering datastores with backing disk ids: %sufileSystemVolumeInfo.mountInfou(Found datastore '%s' for disk id(s) '%s'u#Datastore found for disk filter: %suYNo datastore to be filtered after retrieving the datastores backed by the disk id(s) '%s'udatastore_names = %sRMuhost_datastore_traversalRu	datastoreR�R�ucluster_datastore_traversaludatacenter_datastore_traversaludatastore_cluster_traversaluchildEntityuDatacentersR�u Unsupported reference type '{0}'R�R�unameR�R�uRetrieved %s datastoresuFiltered datastores: %suobject($RRR+R4R
R�RR,R:RR-Rtget_storage_systemRR�RR�tvolumetHostVmfsVolumetextenttdiskNameRMR�textendRR�R�R�RR~RR�RR�R�R(RIt	referenceR�tbacking_disk_idstget_all_datastoresRZtstorage_systemRtmount_infostdisk_datastoresR#tvolteR�R
((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyR��s�	
	
			(+	&							'cC@s�t|�}tjd||�y|j|�Wn�tjjk
rv}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nXdS(u�
    Renames a datastore

    datastore_ref
        vim.Datastore reference to the datastore object to be changed

    new_datastore_name
        New datastore name
    uRenaming datastore '%s' to '%s'u.Not enough permissions. Required privilege: {}N(RRR+tRenameDatastoreR
R5RdR:RR,ReRRfRgR7RRhRi(t
datastore_reftnew_datastore_nametds_nameRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytrename_datastoreFs

	

c	C@s�|st|�}ntjjjdddtjdt�}t|tj	ddgd|d|�}|s�t
jjd	j
|���ntjd
|�|ddS(
u)
    Returns a host's storage system
    RuconfigManager.storageSystemR�R�R�u
systemFileR�R�u-Host's '{0}' storage system was not retrievedu[%s] Retrieved storage systemiuobject(RRR�R�R�R
R�RR�tHostStorageSystemRR,R%RRR+(RIthost_refRwR�tobjs((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyR�as"						cC@s�y|jd|g�}Wn�tjjk
r_}tj|�tjjdj	|j
���nrtjjk
r�}tj|�tjj|j��n8t
jk
r�}tj|�tjj|j��nXtjd|d�|dS(ua
    Returns partition informations for a device path, of type
    vim.HostDiskPartitionInfo
    t
devicePathu/Not enough permissions. Required privilege: {0}upartition_info = %si(tRetrieveDiskPartitionInfoR
R5RdRR:RR,ReRRfRgR7RRhRiR+(R�tdevice_pathtpartition_infosRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt_get_partition_infozs 	
	

c
C@sgtjd�g|jjD]}|jdkr|^q}|sbtjjdj|j	���n|d}t
jd|jjd|jj�}d|_y(|j
d|d	t
jjd
|�}Wn�t
jjk
r}tj|�tjjdj|j���nrt
jjk
rA}tj|�tjj|j��n8tjk
rx}tj|�tjj|j��nXtjd|�tjd
�g|jjD]r}|jj|jjks�|jjdkr�|jjdkr�|jj|jjkr�|jdkr�|j^q�}	|	sBtjjdj|j	���ntjd|	d�|	d|jfS(u�
    Computes the new disk partition info when adding a new vmfs partition that
    uses up the remainder of the disk; returns a tuple
    (new_partition_number, vim.HostDiskPartitionSpec
    uUAdding a partition at the end of the disk and getting the new computed partition specunoneu,Free partition was not found on device '{0}'ittotalt	partitionuvmfsR�tpartitionFormattlayoutu/Not enough permissions. Required privilege: {0}ucomputed partition info = {0}uRetrieving new partition numberiuBNew partition was not found in computed partitions of device '{0}'unew partition number = %s(RR+R�R�R�RR,tVMwareObjectNotFoundErrorRt
deviceNameR
tHostDiskPartitionLayoutR�tComputeDiskPartitionInfot$HostDiskPartitionInfoPartitionFormattgptR5RdR:ReRfRgR7RRhRitstarttblocktendtVMwareNotFoundErrorR�(
R�R�tpartition_infotptfree_partitionstfree_partitionR�tcomputed_partition_infoRGtpartition_numbers((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt _get_new_computed_partition_spec�sV
	
			

	


	c
C@s�t|�}|j}tjd||||�|s[t|d|�}t|||�}n|}t||j�}	tjd|	�t	||j|	�\}
}t
jdt
jd|d|dt
j
d|d	|
��d
|jd	|�}y|jjj|�}
Wn�t
jjk
rH}tj|�tjjdj|j���nrt
jjk
r�}tj|�tjj|j��n8tjk
r�}tj|�tjj|j��nXtjd||�|
S(
uA
    Creates a VMFS datastore from a disk_id

    host_ref
        vim.HostSystem object referencing a host to create the datastore on

    datastore_name
        Name of the datastore

    disk_ref
        vim.HostScsiDislk on which the datastore is created

    vmfs_major_version
        VMFS major version to use
    u>Creating datastore '%s' on host '%s', scsi disk '%s', vmfs v%sRMupartition_info = %stvmfstmajorVersiont
volumeNameR�R�R�tdiskUuidu/Not enough permissions. Required privilege: {0}u#Created datastore '%s' on host '%s'(Rt
canonicalNameRR�R}R�R�R�R+R�R
tVmfsDatastoreCreateSpectHostVmfsSpectHostScsiDiskPartitiontuuidR�tdatastoreSystemtCreateVmfsDatastoreR5RdR:RR,ReRRfRgR7RRhRi(R�tdatastore_nametdisk_reftvmfs_major_versionR�Rwtdisk_idRQttarget_diskR�tnew_partition_numbertpartition_specR�tds_refRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytcreate_vmfs_datastore�sN							
	

c	C@s�|st|�}nt|�}tjjjdddtjdt�}t	|tj
ddgd|d|�}|s�tjj
d	j|���ntjd
|�|ddS(
u�
    Returns a host's datastore system

    host_ref
        Reference to the ESXi host

    hostname
        Name of the host. This argument is optional.
    RuconfigManager.datastoreSystemR�R�R�u	datastoreR�R�u/Host's '{0}' datastore system was not retrievedu[%s] Retrieved datastore systemiuobject(RR}RR�R�R�R
R�RR�tHostDatastoreSystemRR,R%RRR+(R�RwRIR�R�((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_host_datastore_system	s$						cC@sqt|dddg�}|d}tjd|�|jd�}|setjjdj|���nt|dj	�}t
|dj	d|�}y|j|�Wn�tj
jk
r�}tj|�tjjdj|j���nrtj
jk
r"}tj|�tjj|j��n8tjk
rY}tj|�tjj|j��nXtjd	||�d
S(u�
    Creates a VMFS datastore from a disk_id

    service_instance
        The Service Instance Object containing the datastore

    datastore_ref
        The reference to the datastore to remove
    uhostuinfounameuRemoving datastore '%s'u9Datastore '{0}' can't be removed. No attached hosts foundiRwu/Not enough permissions. Required privilege: {0}u[%s] Removed datastore '%s'N(RRR�R�RR,ReRRR�R�tRemoveDatastoreR
R5RdR:RfRgR7RRhRiR+(RIR�tds_propsR�tds_hostsRwthost_ds_systemRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytremove_datastore.	s4

		
	

cC@s\dg}|r+|r+tjjd��n|s:g}n|sOt|�}n%t||�}|rt|jd�nt|tjd|d|�}t	j
dg|D]}|d^q��g}	x�|D]�}|rt|dtj�s�q�nt
|d�}
|
|krq�qn|r0|	j|d�q�n|d|kr�|	j|d�q�q�W|	S(u�
    Returns a list of vim.HostSystem objects representing ESXi hosts
    in a vcenter filtered by their names and/or datacenter, cluster membership.

    service_instance
        The Service Instance Object from which to obtain the hosts.

    datacenter_name
        The datacenter name. Default is None.

    host_names
        The host_names to be retrieved. Default is None.

    cluster_name
        The cluster name - used to restrict the hosts retrieved. Only used if
        the datacenter is set.  This argument is optional.

    get_all_hosts
        Specifies whether to retrieve all hosts in the container.
        Default value is False.
    unameu7Must specify the datacenter when specifying the clusteruparentR�R�uRetrieved hosts: %suobject(RR,R:R�RyR�R�R
R�RR+R4R~R(RIRxt
host_namesR�t
get_all_hostsR	tstart_pointthoststhtfiltered_hostsR?((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt	get_hostsT	s<	
				'
	c@s�|st|�}n|s0t|||�}ny
|j}Wn�tjjk
r�}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nX|stj	jdj|���n|j}|sFtj	jdj|���n|jdkrstj	jdj|���ni}x1|jD]&�|j�fd��jD��q�Wtjd||�|S(u�
    Returns a map between the scsi addresses and the keys of all luns on an ESXi
    host.
        map[<scsi_address>] = <lun key>

    service_instance
        The Service Instance Object from which to obtain the hosts

    host_ref
        The vim.HostSystem object representing the host that contains the
        requested disks.

    storage_system
        The host's storage system. Default is None.

    hostname
        Name of the host. Default is None.
    u/Not enough permissions. Required privilege: {0}u2Host's '{0}' storage device info was not retrievedu-Host's '{0}' multipath info was not retrievedu&No luns were retrieved from host '{0}'c@s,i|]"}�j|jjd�d�qS(u,i(tlunRMRt(t.0R�(tl(s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pys
<dictcomp>�	s	u+Scsi address to lun id map on host '%s': %sN(RR�tstorageDeviceInfoR
R5RdRR:RR,ReRRfRgR7RRhRiR%t
multipathInfoR�RtupdateRR+(RIR�R�Rwtdevice_infoRGtmultipath_infotlun_key_by_scsi_addr((R�s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt _get_scsi_address_to_lun_key_map�	sJ	

	

					
cC@s�|st|�}n|sft|d|�}t|||�}|sftjjdj|���qfny
|j}Wn�tj	j
k
r�}tj|�tjj
dj|j���nrtj	jk
r�}tj|�tjj
|j��n8tjk
r*}tj|�tjj|j��nX|sOtjjdj|���n|j}|r�tjd|g|D]}|j^qq�|Stjd|�gS(u>
    Returns a list of all vim.HostScsiDisk objects in a disk

    host_ref
        The vim.HostSystem object representing the host that contains the
        requested disks.

    storage_system
        The host's storage system. Default is None.

    hostname
        Name of the host. This argument is optional.
    RMu-Host's '{0}' storage system was not retrievedu/Not enough permissions. Required privilege: {0}u2Host's '{0}' storage device info was not retrievedu$Retrieved scsi luns in host '%s': %su#Retrieved no scsi_luns in host '%s'(RR}R�RR,R%RR�R
R5RdRR:ReRfRgR7RRhRitscsiLunR+R�(R�R�RwRQR�RGt	scsi_lunsR�((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_all_luns�	sB	

	

			 c@s�|st|�}nt|d|�}|sBt|||�}nt||||�}d�t|||�D���fd�tj|�D�S(u]
    Returns a map of all vim.ScsiLun objects on a ESXi host keyed by their
    scsi address

    host_ref
        The vim.HostSystem object representing the host that contains the
        requested disks.

    storage_system
        The host's storage system. Default is None.

    hostname
        Name of the host. This argument is optional.
    RMcS@si|]}||j�qS((R�(R�td((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pys
<dictcomp>
s	c@s#i|]\}}�||�qS(((R�t	scsi_addrtlun_key(tluns_to_key_map(s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pys
<dictcomp> 
s	(RR}R�R�R�Rt	iteritems(R�R�RwRQtlun_ids_to_scsi_addr_map((Rs5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_scsi_address_to_lun_map
s	c	C@sht|�}|r%tjd|�n&tjd|||�|pD|sKgSt|d|�}t|||�}g}|r�t||||�}gtj|�D]\}	}
|	|kr�|
^q�}tjd|�nt||�}g|D]H}t	|t
j�r�|s/|r |j|ks/|j
|kr�|^q�}
tjd|g|
D]}|j^qN�|
S(uS
    Returns a list of vim.HostScsiDisk objects representing disks
    in a ESXi host, filtered by their cannonical names and scsi_addresses

    host_ref
        The vim.HostSystem object representing the host that contains the
        requested disks.

    disk_ids
        The list of canonical names of the disks to be retrieved. Default value
        is None

    scsi_addresses
        The list of scsi addresses of the disks to be retrieved. Default value
        is None

    get_all_disks
        Specifies whether to retrieve all disks in the host.
        Default value is False.
    u!Retrieving all disks in host '%s'u@Retrieving disks in host '%s': ids = (%s); scsi addresses = (%s)RMu&disk_keys based on scsi_addresses = %su Retrieved disks in host '%s': %s(RRR+R}R�R�RRR�R4R
tHostScsiDiskR�R�(R�tdisk_idstscsi_addressest
get_all_disksRwRQR�t	disk_keysR�R�R�R�tdiskt
scsi_disksR�((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt	get_disks$
s6	
		
	 c	C@spt|�}t|�}|s3t|||�}nt|dg�}|jd�srtjjdj|���nt	j
d|t|d�djg|dD]}|j
^q���g|dD]-}t|tj�r�|j
|kr�|^q�}|stjjdj||���nt	j
d||dj�t||dj�}t	j
d|t|jj�|�|S(	u
    Returns all partitions on a disk

    host_ref
        The reference of the ESXi host containing the disk

    disk_id
        The canonical name of the disk whose partitions are to be removed

    storage_system
        The ESXi host's storage system. Default is None.
    ustorageDeviceInfo.scsiLunu'No devices were retrieved in host '{0}'u[%s] Retrieved %s devices: %su, u&Disk '{0}' was not found in host '{1}'u[%s] device_path = %siu+[%s] Retrieved %s partition(s) on disk '%s'(RR}R�RR�RR,R%RRR+RRaR�R4R
RR�R�R�R�(	R�R�R�RwRIRR�tdisksR�((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_disk_partition_info\
s8
		
	!		c
	C@su|st|�}n|s0t|||�}ntjjjdddtjdt�}t	|tj
dgd|d|�}|s�tjj
dj|���ntjd	|t|d
jdg��djg|d
jdg�D]}|j^q���g|d
jdg�D]-}t|tj�r|j|kr|^q}|sktjj
dj||���ntjd
||d
j�y!|j|d
jtj��Wn�tjjk
r�}	tj|	�tjjdj|	j���nrtjjk
r&}	tj|	�tjj|	j ��n8tj!k
r]}	tj|	�tjj"|	j ��nXtjd||�dS(u�
    Erases all partitions on a disk

    in a vcenter filtered by their names and/or datacenter, cluster membership

    service_instance
        The Service Instance Object from which to obtain all information

    host_ref
        The reference of the ESXi host containing the disk

    disk_id
        The canonical name of the disk whose partitions are to be removed

    hostname
        The ESXi hostname. Default is None.

    storage_system
        The ESXi host's storage system. Default is None.
    RuconfigManager.storageSystemR�R�ustorageDeviceInfo.scsiLunR�R�u'Host's '{0}' devices were not retrievedu[%s] Retrieved %s devices: %siu, u&Disk '{0}' was not found in host '{1}'u[%s] device_path = %su/Not enough permissions. Required privilege: {0}u#[%s] Erased partitions on disk '%s'N(#RR�RR�R�R�R
R�RR�R�RR,R%RRR+RR�RaR�R4RR�tUpdateDiskPartitionstHostDiskPartitionSpecR5RdR:ReRfRgR7RhRi(
RIR�R�RwR�R�tresultsR�R
RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyterase_disk_partitions�
s\							-	
	

cC@s�t|�}|r%tjd|�ntjd||�|sBgSy|jj}Wn�tjjk
r�}tj|�t	j
jdj|j
���nrtjjk
r�}tj|�t	j
j|j��n8tjk
r	}tj|�t	j
j|j��nX|s.t	j
jdj|���n|j}|s[t	j
jdj|���n|j}|sngSg|D]$}|s�|jj|kru|^qu}	tjd|g|	D]}
|
jj^q��|	S(u�
    Returns a list of vim.VsanHostDiskMapping objects representing disks
    in a ESXi host, filtered by their cannonical names.

    host_ref
        The vim.HostSystem object representing the host that contains the
        requested disks.

    cache_disk_ids
        The list of cannonical names of the cache disks to be retrieved. The
        canonical name of the cache disk is enough to identify the disk group
        because it is guaranteed to have one and only one cache disk.
        Default is None.

    get_all_disk_groups
        Specifies whether to retrieve all disks groups in the host.
        Default value is False.
    u'Retrieving all disk groups on host '%s'uARetrieving disk groups from host '%s', with cache disk ids : (%s)u/Not enough permissions. Required privilege: {0}u"No host config found on host '{0}'u(No vsan storage info found on host '{0}'u<Retrieved disk groups on host '%s', with cache disk ids : %s(RRR+R�tvsanHostConfigR
R5RdR:RR,ReRRfRgR7RRhRiR%tstorageInfotdiskMappingtssdR�(R�tcache_disk_idstget_all_disk_groupsRwtvsan_host_configRGtvsan_storage_infotvsan_disk_mappingstdmtdisk_groupsR�((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_diskgroups�
sJ	

	

				
#cC@s�|jj|ks9tjjdj|jj|���ng|jD]}|j^qC}t|�t|�kr�tjjdjt|�t|����ntj	d|�t
S(uw
    Checks that the disks in a disk group are as expected and raises
    CheckError exceptions if the check fails
    uAIncorrect diskgroup cache disk; got id: '{0}'; expected id: '{1}'u=Incorrect capacity disks; got ids: '{0}'; expected ids: '{1}'u2Checked disks in diskgroup with cache disk id '%s'(RR�RR,R:RtnonSsdtsortedRR+R(t
disk_groupt
cache_disk_idtcapacity_disk_idsR�t
non_ssd_disks((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt_check_disks_in_diskgroups				cC@s�t|�}t|�}tjd|�|s�tjjjdddtj	dt
�}t|tjdgd|d|�}|s�|d	j
d�r�tjd
|�dS|d	dd	St|dg�}|s�tjd
|�dS|dd	SdS(u�
    Returns a vim.HostScsiDisk if the host cache is configured on the specified
    host, other wise returns None

    host_ref
        The vim.HostSystem object representing the host that contains the
        requested disks.

    host_cache_manager
        The vim.HostCacheConfigurationManager object representing the cache
        configuration manager on the specified host. Default is None. If None,
        it will be retrieved in the method
    u&Retrieving the host cache on host '%s'Ru'configManager.cacheConfigurationManagerR�R�ucacheConfigurationInfoR�R�iuHost '%s' has no host cacheN(RR}RR+RR�R�R�R
R�RR�tHostCacheConfigurationManagerR�RR(R�thost_cache_managerRwRIR�R((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_host_cache$s.				c	C@s�t|�}|s^t|dg�}|jd�sQtjjdj|���n|d}ntjd||j	|�t
jd|d|�}tjd|�y|j|�}Wn�t
j
jk
r�}tj|�tjjdj|j���nrt
j
jk
r2}tj|�tjj|j��n8tjk
ri}tj|�tjj|j��nXt||d�tjd	|�tS(
uB
    Configures the host cahe of the specified host

    host_ref
        The vim.HostSystem object representing the host that contains the
        requested disks.

    datastore_ref
        The vim.Datastore opject representing the datastore the host cache will
        be configured on.

    swap_size_MiB
        The size in Mibibytes of the swap.

    host_cache_manager
        The vim.HostCacheConfigurationManager object representing the cache
        configuration manager on the specified host. Default is None. If None,
        it will be retrieved in the method
    u'configManager.cacheConfigurationManageruHost '{0}' has no host cacheuIConfiguring the host cache on host '%s', datastore '%s', swap size=%s MiBt	datastoretswapSizeuhost_cache_spec=%su/Not enough permissions. Required privilege: {0}uHostCacheConfigurationTasku"Configured host cache on host '%s'(RRR�RR,R%RRR+RMR
tHostCacheConfigurationSpectConfigureHostCache_TaskR5RdR:ReRfRgR7RRhRiR,R(	R�R�t
swap_size_MiBR'RwRR�R0RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytconfigure_host_cacheMs<	
			
	

cC@st|tj�S(u�
    Returns a list of hosts associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain hosts.
    (RRR
R�(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
list_hosts�sc	C@s�dg}|sg}n|r0t||�}nt|�}t|tjd|d|�}g}x8|D]0}|s�|d|krg|j|d�qgqgW|s�tjjdj	||���n|S(ul
    Retrieves resource pool objects

    service_instance
        The service instance object to query the vCenter

    resource_pool_names
        Resource pool names

    datacenter_name
        Name of the datacenter where the resource pool is available

    get_all_resource_pools
        Boolean

    return
        Resourcepool managed object reference
    unameR�R�uobjectuIThe resource pools with properties names={} get_all={} could not be found(
RyR�R�R
tResourcePoolR�RR,R%R(	RItresource_pool_namesRxtget_all_resource_poolsR	R�tresource_poolstselected_poolstpool((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_resource_pools�s(				
	cC@st|tj�S(u�
    Returns a list of resource pools associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain resource pools.
    (RRR
R0(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytlist_resourcepools�scC@st|tj�S(u�
    Returns a list of networks associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain networks.
    (RRR
RL(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
list_networks�scC@st|tj�S(u�
    Returns a list of VMs associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain VMs.
    (RRR
tVirtualMachine(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytlist_vms�scC@st|tj�S(u�
    Returns a list of folders associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain folders.
    (RRR
R(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytlist_folders�scC@st|tj�S(u�
    Returns a list of distributed virtual switches associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain distributed virtual switches.
    (RRR
R�(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyR��scC@st|tj�S(u�
    Returns a list of vApps associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain vApps.
    (RRR
t
VirtualApp(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
list_vapps�scC@st|tjj�S(u�
    Returns a list of distributed virtual portgroups associated with a given service instance.

    service_instance
        The Service Instance Object from which to obtain distributed virtual switches.
    (RRR
R�R;(RI((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytlist_portgroups�siudebugcC@s�d}tj�}tjd||jj�y
|j}Wn�tjjk
r~}tj	|�t
jjdj
|j���n�tjjk
r�}tj	|�t
jj|j��nrtjjk
r�}tj	|�t
jj|j��n8tjk
r)}tj	|�t
jj|j��nXx�|jdksK|jdkr�||dkr�dj
|||�}	|dkr�tj|	�q�tj|	�ntjdtj�|d�|d	7}y
|j}Wq-tjjk
r}tj	|�t
jjdj
|j���q-tjjk
rR}tj	|�t
jj|j��q-tjjk
r�}tj	|�t
jj|j��q-tjk
r�}tj	|�t
jj|j��q-Xq-W|jd
krdj
|||�}	|dkrtj|	�n
tj|	�|jSy
|j�WnZtjjk
ro}tj	|�t
jjdj
|j���ntjjk
r�}tj	|�t
jj|j��n�tjjk
r�}tj	|�t
jj|j��n�tjjk
r}tj	|�t
jj|j��nitjjk
r�}tj	|�|j}
|jrpdj
|
|jdj�}
nt
jj|
��nXd
S(u3
    Waits for a task to be completed.

    task
        The task to wait for.

    instance_name
        The name of the ESXi host, vCenter Server, or Virtual Machine that
        the task is being run on.

    task_type
        The type of task being performed. Useful information for debugging purposes.

    sleep_seconds
        The number of seconds to wait before querying the task again.
        Defaults to ``1`` second.

    log_level
        The level at which to log task information. Default is ``debug``,
        but ``info`` is also supported.
    iutask = %s, task_type = %su.Not enough permissions. Required privilege: {}urunninguqueuedu.[ {0} ] Waiting for {1} task to finish [{2} s]uinfog�?iusuccessu6[ {0} ] Successfully completed {1} task in {2} secondsu	{0} ({1})N( ttimeRR+R-RtinfoR
R5RdR:RR,ReRRftFileNotFoundR�R7RgRRhRitstateR�tsleeptresultRtSystemErrortVMwareSystemErrortInvalidArgumenttfaultMessageR3(R0t
instance_namet	task_typet
sleep_secondst	log_levelttime_countert
start_timet	task_infoRGR7texc_message((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyR,s�

	


!


	





	



			c	C@s
|r(|r(tjjj||�}n|saddddddddd	d
ddd
dg}ntjjj|tj|d|d|�}g|D]}|d|kr�|^q�}|s�tjjd��n3t	|�dkrtjj
djdg���n|dS(u�
    Get virtual machine properties based on the traversal specs and properties list,
    returns Virtual Machine object with properties.

    service_instance
        Service instance object to access vCenter

    name
        Name of the virtual machine.

    datacenter
        Datacenter name

    vm_properties
        List of vm properties.

    traversal_spec
        Traversal Spec object(s) for searching.

    parent_ref
        Container Reference object for searching under a given object.
    unameuconfig.hardware.deviceusummary.storage.committedusummary.storage.uncommittedusummary.storage.unsharedu
layoutEx.fileuconfig.guestFullNameuconfig.guestIdu	guest.netuconfig.hardware.memoryMBuconfig.hardware.numCPUuconfig.files.vmPathNameusummary.runtime.powerStateuguest.toolsStatusR�R�u"The virtual machine was not found.iu uSMultiple virtual machines were found with thesame name, please specify a container.i(RRR�RyR�R
R9R,R%RtVMwareMultipleObjectsErrorRa(	RIRMt
datacentert
vm_propertiesR�R<tvm_listRtvm_formatted((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytget_vm_by_propertyis:
	)c
C@srtjd�|r�t||ddg�}tjjj|ddg�}d|krb|d}qntjjdj	ddg���n�d	|krtjjj
||d	g|�}t|�d
kr�tjjdj	ddj
|d	�g���n|d
}nj|rntjjj||�}tjjj|ddg�}	d|	krY|	d}qntjjd��n|S(u�
    Returns a Folder Object

    service_instance
        Service instance object

    datacenter
        Name of the datacenter

    placement
        Placement dictionary

    base_vm_name
        Existing virtual machine name (for cloning)
    uRetrieving folder informationRSunameR	uparentu uThe virtual machine parentuobject is not definedufolderiu'Multiple instances are available of theuspecified folder {0}iuvmFolderu.The datacenter vm folder object is not defined(RR+RVRRR�RR,R%Ratget_foldersRRQRRy(
RIRRt	placementtbase_vm_namet	vm_objecttvm_propst
folder_objecttfolder_objectstdatacenter_objecttdc_props((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
get_folder�s.

"

cC@s�tjd�d \}}d|kr{t|d|d|dg�}|s{tjjdjddj|d�g���ny't	|dd	d
g�}|d
}Wn�t
jjk
rmt
jj
jddd
tdtjdt
jj
jdd
d
tdtj�g�}t|tjd|dddgd|�}|rK|dd}qntjjdj|d���nX|d}nkd|krBt||dgd|�}	t|	�dkr�tjjdjddj|d�g���n|	d}t	|d	dg�}
d|
kr|
d}q�tjjdjddg���n�d|kr�t||�}t||d�}t	|d	d
g�}
d
|
kr�|
d
}n!tjjdjddg���|}ntjjdjdg���||fS(!uP
    To create a virtual machine a resource pool needs to be supplied, we would like to use the strictest as possible.

    datacenter
        Name of the datacenter

    placement
        Dictionary with the placement info, cluster, host resource pool name

    return
        Resource pool, cluster and host object if any applies
    u Retrieving placement informationuhostRxR�u uThe specified hostu{0} cannot be found.iR	uresourcePoolRuparentR�R�R�R�R�unameR�uobjectu.The resource pool of host {0} cannot be found.uresourcepooliu'Multiple instances are available of theuspecified host {}.uThe resource pool's parentuobject is not defineduclusteruThe cluster's resource pooluPlacement is not defined.N(NN(RR+RR�RR,R%RaRRRR�RR�R�RR
R�RR~R�R0R6RRQRyR�(RIRRRXtresourcepool_objecttplacement_objectthost_objectst
host_propsR�t
resourcepoolstresourcepool_objectst	res_propsR^tcluster_objectt
clus_props((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
get_placement�sz


		
			

	
	
	
	cC@s�|j�dkr)t|dd�}nX|j�dkrNt|d�}n3|j�dkrot|�}ntjjd��i|d6dd6S(	u�
    Converts the given size to KB based on the unit, returns a long integer.

    unit
        Unit of the size eg. GB; Note: to VMware a GB is the same as GiB = 1024MiB
    size
        Number which represents the size
    ugbiumbukbuThe unit is not specifiedusizeuKBuunit(tlowertintRR,R:(tunittsizettarget_size((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
convert_to_kb
s	uoncC@s0|dkr�y|j�}d}Wq�tjjk
rh}tj|�tjjdj	|j
���q�tjjk
r�}tj|�tjj|j��q�t
jk
r�}tj|�tjj|j��q�Xn�|dkr�y|j�}d}Wq�tjjk
rE}tj|�tjjdj	|j
���q�tjjk
r}tj|�tjj|j��q�t
jk
r�}tj|�tjj|j��q�Xntjjd��yt|t|�|�WnCtjjk
r+}tjjdjdd	j	|�g���nX|S(
u�
    Powers on/off a virtual machine specified by it's name.

    virtual_machine
        vim.VirtualMachine object to power on/off virtual machine

    action
        Operation option to power on/off the machine
    uonupower onu.Not enough permissions. Required privilege: {}uoffu	power offu!The given action is not supportedu uAn error occurred during poweru$operation, a file was not found: {0}(tPowerOnR
R5RdRR:RR,ReRRfRgR7RRhRitPowerOffR:R,RR�tVMwarePowerOnErrorRa(tvirtual_machinetactionR0t	task_nameRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytpower_cycle_vm3
sL


	



	

cC@s#yO|r9t|tj�r9|j|d|d|�}n|j|d|�}Wn�tjjk
r�}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r}tj|�tj	j|j��nXt||ddd�}|S(u�
    Creates virtual machine from config spec

    vm_name
        Virtual machine name to be created

    vm_config_spec
        Virtual Machine Config Spec object

    folder_object
        vm Folder managed object reference

    resourcepool_object
        Resource pool object where the machine will be created

    host_object
        Host object where the machine will ne placed (optional)

    return
        Virtual Machine managed object reference
    R5Ru.Not enough permissions. Required privilege: {}u
CreateVM Taski
uinfo(R4R
R�t
CreateVM_TaskR5RdRR:RR,ReRRfRgR7RRhRiR,(tvm_nametvm_config_specR\Rathost_objectR0RGRZ((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt	create_vmf
s(

	

cC@sjya|r9|jjd|d|dtd|d|�}n'|jjd|d|dtd|�}Wn�tjjk
r�}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r}tj|�tj	j|j��nXyt||d�}Wn4tj	jk
re}tj	jdj|���nX|S(	u$
    Registers a virtual machine to the inventory with the given vmx file, on success
    it returns the vim.VirtualMachine managed object reference

    datacenter
        Datacenter object of the virtual machine, vim.Datacenter object

    name
        Name of the virtual machine

    vmx_path:
        Full path to the vmx file, datastore name should be included

    resourcepool
        Placement resource pool of the virtual machine, vim.ResourcePool object

    host
        Placement host of the virtual machine, vim.HostSystem object
    RRMt
asTemplateRR5u.Not enough permissions. Required privilege: {}uRegisterVM TaskuZAn error occurred during registration operation, the configuration file was not found: {0}(tvmFoldertRegisterVM_TaskRR
R5RdRR:RR,ReRRfRgR7RRhRiR,R�tVMwareVmRegisterError(RRRMtvmx_pathRaR{R0RGtvm_ref((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pytregister_vm�
s6

	

	cC@s�t|�}tjd|�y|j|�}Wn�tjjk
ru}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nXt||d�}|S(u�
    Updates the virtual machine configuration with the given object

    vm_ref
        Virtual machine managed object reference

    vm_config_spec
        Virtual machine config spec object to update
    uUpdating vm '%s'u.Not enough permissions. Required privilege: {}uReconfigureVM Task(RRR+tReconfigVM_TaskR
R5RdR:RR,ReRRfRgR7RRhRiR,(R�RzRyR0RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt	update_vm�
s"

	

cC@s�t|�}tjd|�y|j�}Wn�tjjk
rr}tj|�tj	j
dj|j���nrtjj
k
r�}tj|�tj	j
|j��n8tjk
r�}tj|�tj	j|j��nXt||d�dS(uo
    Destroys the virtual machine

    vm_ref
        Managed object reference of a virtual machine object
    uDestroying vm '%s'u.Not enough permissions. Required privilege: {}uDestroy TaskN(RRR+RJR
R5RdR:RR,ReRRfRgR7RRhRiR,(R�RyR0RG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt	delete_vm�
s 
	

cC@s�t|�}tjd|�y|j�Wn�tjjk
rp}tj|�tj	j
dj|j���nXtjj
k
r�}tj	j
|j��n+tjk
r�}tj	j|j��nXdS(uo
    Destroys the virtual machine

    vm_ref
        Managed object reference of a virtual machine object
    uDestroying vm '%s'u.Not enough permissions. Required privilege: {}N(RRR+tUnregisterVMR
R5RdR:RR,ReRRfRgR7RRhRi(R�RyRG((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt
unregister_vm�
s
	(�t__doc__t
__future__RRRR@RtloggingR?RoR9tsalt.exceptionsRtsalt.modules.cmdmodtsalt.utils.pathtsalt.utils.platformtsalt.utils.stringutilstsalt.extRtsalt.ext.six.moves.http_clientRt
pyVim.connectRRRRR	tpyVmomiR
RRRR
R�RR�R�R�t	getLoggerRRRRR'RLRSR^RkRzR}R~R�R�R�R�R�R�R�R�R.R�RTR�R�RR�RRRRR$R'R1R5R9R@RCRERIRKRORRRURXR[RaRoRsRtRwRyR}R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RRRRRR%R(R.R/R6R7R8R:R;R�R=R>R,RVR`RjRpRwR|R�R�R�R�(((s5/usr/lib/python2.7/site-packages/salt/utils/vmware.pyt<module>Js(





	
9	c				^*		 								#	@	
	x 4	$			(	'		6				/		'UG	
			$	 		
	
	
	/�			@=	&C<27.I<	*5	
.	
	
	
	
	
	
	
g7+R	3-2		

Zerion Mini Shell 1.0