%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlmZddlZddlZddl	Z	ddl
Z
ddlZddl
Z
ddlZddlZddlZddlZddlZddlmZddljZddlmZyddlmZeZWnek
reZnXyddl m!Z!e!�Wnek
rGnXd	Z"d
Z#dZ$dZ%d
Z&dZ'dZ(e	j)e*�Z+dZ,d�Z-d�Z.d�Z/d�Z0d�Z1d�Z2e3e3e3d�Z4deee3e3d�Z5e3d�Z6e3d�Z7d�Z8d�Z9d�Z:d�Z;d �Z<d!�Z=d"�Z>d#�Z?e3e3d$�Z@d%�ZAe3e3e3d&�ZBd'�ZCd(�ZDd)�ZEd*d+d,�ZFd-�ZGd.�ZHe3d/d0�ZId1�ZJd2�ZKed3�ZLd4�ZMe3e3d5�ZNe3e3d6�ZOe3e3d7�ZPe3e3d8�ZQe3e3d9�ZRe3e3d:�ZSe3e3d;�ZTe3e3d<�ZUe3e3d=�ZVe3e3d>�ZWe3e3d?�ZXe3e3d@�ZYe3e3dA�ZZe3dB�Z[e3dC�Z\e3dD�Z]e3dE�Z^e3dF�Z_e3e3dG�Z`e3e3dH�Zae3e3dI�Zbe3dJ�Zcee3dK�Zde3dL�Zeee3dM�Zfe3dN�Zge3dO�ZhdP�ZidQ�ZjdR�ZkdS�Zle3e3dT�Zme3e3dU�Zne3e3dV�Zoe3dW�Zpee3dX�Zqe3e3dY�Zre3e3dZ�Zse3e3d[�Zte3e3d\�Zue3e3d]�Zve3e3d^�Zwe3e3d_�Zxe3e3d`�Zye3e3da�Zze3e3db�Z{e3e3dc�Z|e3e3dd�Z}e3e3de�Z~e3e3df�Ze3e3dg�Z�e3e3dh�Z�e3e3di�Z�e3e3dj�Z�e3e3dk�Z�e3e3dl�Z�dS(muF
VMware Cloud Module
===================

.. versionadded:: 2015.5.4

The VMware cloud module allows you to manage VMware ESX, ESXi, and vCenter.

See :ref:`Getting started with VMware <cloud-getting-started-vmware>` to get started.

:codeauthor: Nitin Madhok <nmadhok@clemson.edu>


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.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 cloud
driver was developed against.

.. note::
    Ensure python pyVmomi module is installed by running following one-liner
    check. The output should be 0.

    .. code-block:: bash

       python -c "import pyVmomi" ; echo $?


Configuration
=============

To use this module, set up the vCenter or ESX/ESXi URL, username and password in the
cloud configuration at
``/etc/salt/cloud.providers`` or ``/etc/salt/cloud.providers.d/vmware.conf``:

.. code-block:: yaml

    my-vmware-config:
      driver: vmware
      user: 'DOMAIN\user'
      password: 'verybadpass'
      url: '10.20.30.40'

    vcenter01:
      driver: vmware
      user: 'DOMAIN\user'
      password: 'verybadpass'
      url: 'vcenter01.domain.com'
      protocol: 'https'
      port: 443

    vcenter02:
      driver: vmware
      user: 'DOMAIN\user'
      password: 'verybadpass'
      url: 'vcenter02.domain.com'
      protocol: 'http'
      port: 80

    esx01:
      driver: vmware
      user: 'admin'
      password: 'verybadpass'
      url: 'esx01.domain.com'

.. note::

    Optionally, ``protocol`` and ``port`` can be specified if the vCenter
    server is not using the defaults. Default is ``protocol: https`` and
    ``port: 443``.

.. note::
    .. versionchanged:: 2015.8.0

    The ``provider`` parameter in cloud provider configuration was renamed to ``driver``.
    This change was made to avoid confusion with the ``provider`` parameter that is
    used in cloud profile configuration. Cloud provider configuration now uses ``driver``
    to refer to the salt-cloud driver that provides the underlying functionality to
    connect to a cloud provider, while cloud profile configuration continues to use
    ``provider`` to refer to the cloud provider configuration that you define.

To test the connection for ``my-vmware-config`` specified in the cloud
configuration, run :py:func:`test_vcenter_connection`
i(tabsolute_importtprint_functiontunicode_literals(trandintN(tSaltCloudSystemExit(tsix(tvim(tdisable_warningsuVMware ESXi 5.5i�u%moveAllDiskBackingsAndDisallowSharingu"moveAllDiskBackingsAndAllowSharingumoveChildMostDiskBackingucreateNewChildDiskBackingu[^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$uvmwarecC@s*t�tkrtSt�tkr&tStS(uL
    Check for VMware configuration and if required libs are available.
    (tget_configured_providertFalsetget_dependenciest__virtualname__(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt__virtual__�s
cC@stjttptd�S(u/
    Return the first configured instance.
    uurluuserupassword(uurluuserupassword(tconfigtis_provider_configuredt__opts__t__active_provider_name__R(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyR�s	cC@sitd6}tjt|�S(u*
    Warn if dependencies aren't met.
    upyVmomi(tHAS_PYVMOMIR
tcheck_driver_dependenciesR(tdeps((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyR
�s

cC@satjd|t�}|s$d}ntjjj||ttjjjtjjjt|���S(u-
    Return the script deployment object
    uscriptubootstrap-salt(	R
tget_cloud_config_valueRtsalttutilstcloudt	os_scripttsalt_config_to_yamlt
minion_config(tvm_tscript_name((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytscript�s	cC@sCt|t�r|St|tj�r?|j�dkr;tStSdS(Nutrue(t
isinstancetboolRtstring_typestlowertTrueR	tNone(tvar((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_str_to_bool�s
cC@s�tjdt�tdt�}tjdt�tdt�}tjdt�tdt�}tjdt�tdtdd�}tjdt�tdtdd	�}tjjj|||d
|d|�S(uN
    Authenticate with vCenter server and return service instance object.
    uurlt
search_globaluuserupassworduprotocoltdefaultuhttpsuporti�tprotocoltport(	R
RRRR	RRtvmwaretget_service_instance(turltusernametpasswordR(R)((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_get_si�scC@s~|s|r2|r|nt|dd�|_n|rG||j_ntjjj�}tjjjjj	|_
||_|S(Ng�@(tinttcapacityInKBtbackingtdiskModeRtvmtdevicetVirtualDeviceSpect	Operationteditt	operation(tdisktsize_kbtsize_gbtmodet	disk_spec((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_edit_existing_hard_disk_helpers&	i�cC@s�tdd�}t|dd�}	tjjj�}
d|
_tjjjjj|
_	tjjj
�|
_||
j_tj�|
j_
||
jj
_dj|�|
jj
_tjjj
j�|
j_||
jj_||
jj_d|
jj_|rytjjjt�tj|�}|stjjjt�tj|�}|sgtdj||���ntjjjt�|dt�}
d	}x`|
D]X}t j!d
|j"|jj#|�|jj$r�|jj#|kr�|jj#}|}q�q�W|stdj||���qndt%j&|j"�d
|}|d|d|
jj_'||
jj_(t j!d|j"||�n||
j_)||
j_*|	|
j_+|
S(Ni���i0���g�@ucreateu{0} GBu
persistentuISpecified datastore/datastore cluster ({0}) for disk ({1}) does not existtget_all_datastoresiuCFound datastore (%s) with free space (%s) in datastore cluster (%s)ubSpecified datastore cluster ({0}) for disk ({1}) does not have any accessible datastores availableu[u] u/u.vmdku0Using datastore (%s) for disk (%s), vm_name (%s)(,RR0RR4R5R6t
fileOperationR7taddR9tVirtualDisktkeytDescriptiont
deviceInfotlabeltformattsummarytFlatVer2BackingInfoR2tthinProvisionedteagerlyScrubR3RRR*tget_mor_using_container_viewR/t	Datastoret
StoragePodRtget_datastoresR"tlogttracetnamet	freeSpacet
accessibleRt	text_typetfileNamet	datastoret
controllerKeyt
unitNumberR1(t
disk_labelR<tunit_numbertcontroller_keytthin_provisiont
eagerly_scrubRXtvm_namet
random_keyR;R>t
datastore_reftdatastore_cluster_reftdatastore_listtdatastore_free_spacetds_reftdatastore_path((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_add_new_hard_disk_helpersP	!!!

	c
C@s�|j�j�|j�j�|dkr�tjjj|�}t|t|��r_|}q�tj	d|j
jt|�jj
dd�dd	j�|�n(|r�tjd
|j
j|�n|}|dkr/tjjjt�tj|d|�}tjjjj�|_||j_||j_n�|d
kr�tjjjt�tjj|d|�}tjjd|jd|jjj �}tjjjj!�|_||j_"nB|s�dj#|j
j�}ndj#|j
j|�}t$|��|j|_|j
|_
||j
_%|j&|_&|j'|_'|j(|_(|j)|_)|j*|_*|j+|_+|j,|_,tjjj-�}	tjjj-j.j/|	_0||	_|	S(Nuvmxnetuvmxnet2uvmxnet3ue1000ue1000eu'Changing type of '%s' from '%s' to '%s'u.iiu5Cannot change type of '%s' to '%s'. Not changing typeustandardt
container_refudistributedtportgroupKeyt
switchUuidu:The switch type to be used by '{0}' has not been specifiedu:Cannot create '{0}'. Invalid/unsupported switch type '{1}'(uvmxnetuvmxnet2uvmxnet3ue1000ue1000e(1tstripR!RRR*tget_network_adapter_typeRttypeRQtdebugRFRGt__name__trsplitterrortget_mor_by_propertyR/RtNetworkR4R5tVirtualEthernetCardtNetworkBackingInfoR2t
deviceNametnetworktdvstDistributedVirtualPortgrouptPortConnectionRDR
tdistributedVirtualSwitchtuuidt!DistributedVirtualPortBackingInfoR)RHRRItconnectabletslotInfoRYRZtaddressTypet
macAddresstwakeOnLanEnabledR6R7R8R9(
tnetwork_adaptertnew_network_nametadapter_typetswitch_typeRitedited_network_adaptertnetwork_reftdvs_port_connectionterr_msgtnetwork_spec((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_edit_existing_network_adapterYsl		&
					cC@s�tdd�}|j�j�|j�j�tjjj�}|dkrhtjj	j
|�|_nA|s�tjd|�ntj
d	||�tjjj�|_tjjjjj|_|d
kr*tjjjj�|j_||jj_tjj	jt�tj|d|�|jj_n�|dkr�tjj	jt�tjj|d|�}tjjd
|jd|jjj �}	tjjjj!�|j_|	|jj_"n6|s�dj#|�}
ndj#||�}
t$|
��|dkrd|j_%||j_&n||j_tj'�|j_(||jj(_)||jj(_*t+|j_,tjjj-j.�|j_/t+|jj/_0t+|jj/_1|S(Ni��i`�uvmxnetuvmxnet2uvmxnet3ue1000ue1000euHThe type of '%s' has not been specified. Creating default type 'vmxnet3'uSCannot create network adapter of type '%s'. Creating '%s' of default type 'vmxnet3'ustandardRiudistributedRjRku:The switch type to be used by '{0}' has not been specifiedu:Cannot create '{0}'. Invalid/unsupported switch type '{1}'uuassigned(uvmxnetuvmxnet2uvmxnet3ue1000ue1000e(2RRlR!RR4R5R6RRR*RmRQRoRrtVirtualVmxnet3R7RBR9RuRvR2RwRsR/RtRxRyRzR{RDR
R|R}R~R)RHRR�R�RERFRGRIR"R�t
VirtualDevicetConnectInfoRtstartConnectedtallowGuestControl(tnetwork_adapter_labeltnetwork_nameR�R�tmacRiRaR�R�R�R�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_add_new_network_adapter_helper�sb

					cC@s@||_tjjj�}tjjjjj|_||_|S(N(t	sharedBusRR4R5R6R7R8R9(tscsi_controllertbus_sharingt	scsi_spec((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_edit_existing_scsi_controller�s
		c	C@s�tdd�}d|kr1|dj�j�nd}d|krY|dj�j�nd}tjjj�}|dkr�d}tjjj�|_n�|dkr�d}tjjj	�|_n`|d	kr�d
}tjjj
�|_n6|sdj|�}ndj||�}t|��tjjjj
j|_||j_||j_tj�|j_||jj_||jj_|d
kr�tjjjjj|j_nE|dkr�tjjjjj|j_ntjjjjj|j_|S(Ni��i���utypeubus_sharingulsilogicu	LSI Logiculsilogic_sasu
LSI Logic SasuparavirtualuVMware paravirtual SCSIu(The type of '{0}' has not been specifiedu3Cannot create '{0}'. Invalid/unsupported type '{1}'uvirtualuphysical(RRlR!R#RR4R5R6tVirtualLsiLogicControllertVirtualLsiLogicSASControllertParaVirtualSCSIControllerRHRR7RBR9RDt	busNumberRERFRGRItVirtualSCSIControllertSharingtvirtualSharingR�tphysicalSharingt	noSharing(	tscsi_controller_labelt
propertiest
bus_numberRaR�R�R�RIR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_add_new_scsi_controller_helper�s:((cC@s�|dkrtdd�}ntjjj�}tjjj�|_tjjjjj|_	||j_
||j_tj�|j_
||jj
_||jj
_|S(uR
    Helper function for adding new IDE controllers

    .. versionadded:: 2016.3.0

    Args:
      ide_controller_label: label of the IDE controller
      controller_key: if not None, the controller key to use; otherwise it is randomly generated
      bus_number: bus number

    Returns: created device spec for an IDE controller

    i8���i�N(R#RRR4R5R6tVirtualIDEControllerR7RBR9RDR�RERFRGRI(tide_controller_labelR]R�tide_spec((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_add_new_ide_controller_helper(scC@s|dkr�tjjjj�|_||j_|jd�djd�d}t	j
jjt
�tj|�}|r�||j_ndj|�|j_nu|dkr|dkr�tjjjj�|_d	|j_q|d
krtjjjj�|_d|j_qn|S(Nudatastore_iso_fileu[i����u]iuISO {0}u
client_deviceupassthroughu
Remote DeviceuatapiuRemote ATAPI(RR4R5tVirtualCdromtIsoBackingInfoR2RWt	partitiont
rpartitionRRR*RsR/RNRXRHRFRItRemotePassthroughBackingInfotRemoteAtapiBackingInfo(tdrivetdevice_typeR=tiso_pathRXRb((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_set_cd_or_dvd_backing_typeIs  !cC@sf|j�j�|j�j�tjjj�}tjjjjj|_t	||||�|_|S(N(
RlR!RR4R5R6R7R8R9R�(R�R�R=R�t
drive_spec((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_edit_existing_cd_or_dvd_drive`scC@sdtdd�}|j�j�|j�j�tjjj�}tjjjjj|_	tjjj
�|_tj�|j_|dkr�t
|j|||�|_nV|s�tjd|�ntjd||�tjjj
j�|j_d|jj_||j_||jj_||j_tjjjj�|j_t|jj_t|jj_|S(	Ni/�iH�udatastore_iso_fileu
client_deviceuWThe 'device_type' of '%s' has not been specified. Creating default type 'client_device'uVCannot create CD/DVD drive of type '%s'. Creating '%s' of default type 'client_device'u
Remote Device(udatastore_iso_fileu
client_device(RRlR!RR4R5R6R7RBR9R�RERFR�RQRoRrR�R2RIRDRGRYR�R�RR"R�R�(tdrive_labelR]R�R=R�RaR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_add_new_cd_or_dvd_drive_helperks2

cC@stjjj�}tjjj�|_dt|j��krX|d}||j_ndt|j��kr�|d}||j_	ndt|j��kr�t
j|d�}t
j|d�}tjjjd|�|j_
||j_ntjjj�|j_
|S(Nudomainugatewayuipusubnet_maskt	ipAddress(RR4t
customizationtAdapterMappingt
IPSettingstadaptertlisttkeyst	dnsDomaintgatewayRRVtFixedIptipt
subnetMasktDhcpIpGenerator(t
adapter_specstadapter_mappingtdomainR�R�tsubnet_mask((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_set_network_adapter_mapping�s

cC@sF|jj|krB|s0td|d|�}qB||jj_n|S(NR:R=(R2R3R?R5(R5R=R>((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_get_mode_spec�scC@s]|dkr/|dk	r/t|dd�}n|j|krStd|d|�nd}|S(Ng�@R:R;(R#R0R1R?(R5R<R;R>((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_get_size_spec�s*cC@s'|d7}|dkr#|d7}n|S(u�
    Apparently vmware reserves ID 7 for SCSI controllers, so we cannot specify
    hard drives for 7.

    Skip 7 to make sure.
    ii((R\((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_iter_disk_unit_number�s

c5
C@s�d}d}g}g}g}g}	g}
g}i}g}
|dk	}|r#x�|jjjD]�}t|tjjj�r\dt|j	��krt
|�}|j|jj
�|jj
t|dj	��krYd}d|d|jj
kr*t|d|jj
d�}t|dd�}n,|j}|d3}tjd|jj
|�|j|kr�tdjt|d|jj
d�|jj
t|jd4����ntd|d|�}d	|d|jj
kr7|d|jj
d	d5kr(|d|jj
d	}t|||�}q7td
��n|dk	rV|j|�qVqYqq^t|jtjjjjtjjjjf�r�dt|j	��kr|
j|jj
�|jj
t|dj	��kr�|d|jj
d}d|d|jj
kr#|d|jj
dnd}d|d|jj
kr[|d|jj
dnd}t|||||�}t|d|jj
�}|j|�|
j|�q�qq^t|d�r�dt|j	��kr|d7}|j|jj
�|jj
t|dj	��kr�|d|jj
}d|krR|dj�j�nd}|r�|d6kr�dj|�}||j kr�t!||�}|j|�q�q�q�qq^t|tjjj"�r�dt|j	��kr|j|jj
�|jj
t|dj	��kr�d|d|jj
krJ|d|jj
dnd}d	|d|jj
kr�|d|jj
d	nd}d|d|jj
kr�|d|jj
dnd}t#||||�}|j|�q�qq^t|tjjj$�r^t%|j�||j&<q^q^Wndt|j	��krwtt'|dj	��t'|
��}|j(�|r�tjd|�nx�|D]�} |d| d}d|d| kr�|d| dnd}d|d| kr�|d| dnd}d|d| kr!|d| dnd}!t)| ||||!|�}t|d| �}|j|�|
j|�q�Wndt|j	��kr#tt'|dj	��t'|��}"|"j(�|"r�tjd |"�nxH|"D]=}#|d|#}t*|#||�}|j|�|d7}q�Wnd!t|j	��kr	tt'|d!j	��t'|	��}$|$j(�|$r�tjd"|$�nt+d#d$�}%t,|%kr�t-nd}&xS|$D]H}'t.|'|&|�}(|j|(�|d7}|&dk	r�|&d7}&q�q�Wndt|j	��kr�
tt'|dj	��t'|��})|)j(�|)rb	tjd%|)�nxI|)D]>}*t|d|*d�}d&|d|*kr�	t/|d|*d&�nt0}+d'|d|*kr�	t/|d|*d'�nt0},|d|*j1d(d�}-t2|*||d)|+d*|,d+|-d,|�}d-|d|*kr�
xH|D]=}.|.jjj
|d|*d-krJ
|.jj&|j_3PqJ
qJ
Wn|j|�t
|�}qi	Wndt|j	��kr�tt'|dj	��t'|��}/|/j(�|/rtjd.|/�nx�|/D]w}0d|d|0krB|d|0dnd}d	|d|0krn|d|0d	nd}d|d|0kr�|d|0dnd}d}1d-|d|0kr	x�|D]A}.|.jjj
|d|0d-kr�|.jj&}1d||1<Pq�q�Wn6x3t4j5|�D]"\}2}3|3d/kr|2}1PqqW|1sXtj6d0|0�qt7|0|1|||�}|j|�||1cd7<qWni|d16|
d26}4|4S(7Niudiskusizeg�@uyVirtual disk size for '%s' was not specified in the cloud profile or map file. Using existing virtual disk size of '%sGB'u�The specified disk size '{0}GB' for '{1}' is smaller than the disk image size '{2}GB'. It must be equal to or greater than the disk imageR5R;umodeuindependent_persistentuindependent_nonpersistentu	dependentu$Invalid disk backing mode specified!unetworkunameuadapter_typeuuswitch_typeuscsiCtlrUnitNumberuscsiiubus_sharinguvirtualuphysicalunou
{0}Sharingucdudevice_typeuiso_pathuNetworks adapters to create: %sumacuSCSI controllers to create: %suideuIDE controllers to create: %stcallufunctionuHard disks to create: %suthin_provisionu
eagerly_scrubu	datastoreR^R_RXR`u
controlleruCD/DVD drives to create: %siuPNo more available controllers for '%s'. All IDE controllers are currently in useudevice_specsunics_mapg0Ag0A(uindependent_persistentuindependent_nonpersistentu	dependent(uvirtualuphysicaluno(8R#R
thardwareR5RRR4RCR�R�R�tappendRFRGtfloatR0R1RQRoRRHR�R�R2RuRvR~R�R�thasattrRlR!R�R�R�R�R�tlenRDtsettsortR�R�tget_vcenter_versiontESX_5_5_NAME_PORTIONt!SAFE_ESX_5_5_CONTROLLER_KEY_INDEXR�RR	tgetRhRYRt	iteritemsRrR�(5tdevicesR4Ritnew_vm_nameR\R�tdevice_specstexisting_disks_labeltexisting_scsi_controllers_labeltexisting_ide_controllers_labeltexisting_network_adapters_labeltexisting_cd_drives_labeltide_controllerstnics_maptcloning_from_vmR5R>R<R;R=R�R�R�R�R�tscsi_controller_propertiesR�R�R�R�t
cd_drive_spectnetwork_adapters_to_createR�R�tscsi_controllers_to_createR�tide_controllers_to_createtvcenter_nametcontroller_indexR�R�tdisks_to_createR[R^R_RXtspectcd_drives_to_createtcd_drive_labelR]tide_controller_keytnum_devicestret((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_manage_devices�sd"	
			"88

"("888 &

,,,
&


&



&

22	
!
&

,,,
!

	

cC@s�d}tj�}x�||kr�|ddkrJtjd|j|�ntj|jjj�dkr�tjd|j|�t	Stj
dtj�|d�|d7}qWtjd|j|�tS(	Niiu4[ %s ] Waiting for VMware tools to be running [%s s]uguestToolsRunninguG[ %s ] Successfully got VMware tools running on the guest in %s secondsg�?iuS[ %s ] Timeout Reached. VMware tools still not running after waiting for %s seconds(
ttimeRQtinfoRSRRVRItguestttoolsRunningStatusR"tsleeptwarningR	(tvm_reftmax_waitttime_countert	starttime((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_wait_for_vmware_tools�s$

cC@s�|jd�}t|�dkr%tSxCt|�D]5\}}yt|�||<Wq2tk
rftSXq2W|\}}}}|dks�|dks�|dkr�tS|dkr�|dkr�tSx3|||fD]"}|dks�|d	kr�tSq�WtS(
uJ
    Check if the IP address is valid
    Return either True or False
    u.iii�ii�i�ii�(tsplitR�R	t	enumerateR0t
ValueErrorR"(t
ip_addresstoctetstitoctettfirst_octettsecond_octettthird_octettfourth_octet((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt	_valid_ip�s"
	$cC@s�|}|}t||�}|sy|jjj}tjjj|�}tj	d||�t
|t�ru|ru|dStSd}t
j
�}x||kr�|ddkr�tjd|j|�n|jjjr
t|jjj�r
tjd|j|�|jjjSxf|jjD]X}	|	jjrxC|	jjD]2}
t|
j�r6tjd|j|�|
jSq6WqqWt
jdt
j
�|d�|d7}q�Wtjd|j|�tS(	Nu<Timeout waiting for VMware tools. The name %s resolved to %siiu2[ %s ] Waiting to retrieve IPv4 information [%s s]u<[ %s ] Successfully retrieved IPv4 information in %s secondsg�?iuX[ %s ] Timeout Reached. Unable to retrieve IPv4 information after waiting for %s seconds(RRIR
RSRRRxthost_to_ipsRQRoRR�R	R�R�R�R�R
tnettipConfigR�R�(R�R�tmax_wait_vmware_toolstmax_wait_iptvmware_tools_statusR`tresolved_ipsR�RRt
current_ip((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_wait_for_ipsJ	
$



iudebugcC@s~d}tj�}x�|jjdkr�||dkrntj|dkrRtjntjd|j||�ntjdtj�|d�|d7}qWx�|jjdkr#||dkr�tj|dkr�tjntjd|j||�ntjdtj�|d�|d7}q�W|jjdkrmtj|dkrQtjntjd|j||�n
tj	d	�dS(
Niu
notRespondinguinfou+[ %s ] Waiting for host %s to finish [%s s]g�?iu	connectedu3[ %s ] Successfully completed host %s in %s secondsu)Could not connect back to the host system(
R�truntimetconnectionStateRQtloggingtINFOtDEBUGRSR�Rr(thost_reft	task_typet
sleep_secondst	log_levelR�R((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_wait_for_host5s0cC@sydd�}i}d|kr/|d|d<nd|krZdj||d��|d<nd|kr�||d	�}d
j||d��}dj||�|d<i|d
6|d6|d<nd|kr�tj||d��|d<nd|kr||d�|d<nd|kr.|djj|d<nd|krP||d�|d<nd|kr{tj||d��|d<nd|ks�d|kr3i}g}d|kr�xP|dD]A}i|jd6|jd6|jd6||j<|j	|j�q�Wnd|kr||d<nd|kr3||d<q3nt
d �|D��rui}	g}
d!|kr4x�|d!D]�}i|	|jj<d"|kr�|j
f|	|jjd#<|jjf|	|jjd$<|jjf|	|jjd%<t|�jjd&d'�d'|	|jjd(<|jr2|j|	|jjd)<nt|d*�r�|jr�|jj|	|jjd+<|jj|	|jjd,<|jj|	|jjd<|jj|	|jjd-<nt|d.�r�|jr�|j|	|jjd.<nt|d/�r|j|	|jjd/<nt|d0�r9|j|	|jjd0<nt|d1�rb|j|	|jjd2<nt|d3�r�|j|	|jjd3<nt|tjjj �r�|j!|	|jjd4<|j"j#|	|jjd5<|j"j$|	|jjd6<q�nt|d7�rl|j|	|jjd7<|
j%|j�qlqlWnd"|krM|	|d"<nd|ksed8|kru|
|d8<qund9|kr�id:|kr�t&|d:�ndd;6d<|kr�t&|d<�ndd=6d>|kr�t&|d>�ndd?6}||d9<nd@|krui}
dA|krhxJ|dAD];}i|j
d#6|j'd6|j(d6|jd(6|
|j
<q&Wn|
|d@<n|S(BNuN/AcS@s||kr|S||S(ul
        Return either a named value from a VirtualMachineConfig or a
        default string "N/A".
        ((tmachinetsectionR'((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt	defaulttoUsuidunameuimageu{0} (Detected)uconfig.guestFullNameusizeuconfig.hardware.numCPUu{0} MBuconfig.hardware.memoryMBucpu: {0}
ram: {1}ucpuumemoryu	size_dictustateusummary.runtime.powerStateuguest_iduconfig.guestIduhostnameuobjectupathuconfig.files.vmPathNameutools_statusuguest.toolsStatusuprivate_ipsunetworksu	guest.netu	connecteduip_addressesumac_addresscs@s|]}|dkVqdS(udevicesumac_addressu
mac_addressesN(udevicesumac_addressu
mac_addresses((t.0tx((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pys	<genexpr>�suconfig.hardware.deviceudevicesukeyulabelusummaryu.iutypeu
unitNumberuconnectableustartConnecteduallowGuestControlustatusu
controllerKeyuaddressTypeu	busNumberudeviceu
deviceKeysuvideoRamSizeInKBucapacityInKBudiskModeufileNameu
macAddressu
mac_addressesustorageusummary.storage.committedu	committedusummary.storage.uncommitteduuncommittedusummary.storage.unshareduunsharedufilesu
layoutEx.file()RHRRVR�thostNamet	connectedR�R�RxtextendtanyRFRGRDRIRnRpRqRZR�RR�R�tstatusRYR�R�R5tvideoRamSizeInKBRRR4RCR1R2R3RWR�R0RStsize(R4t	selectionR#tvm_select_infotcputramtnetwork_full_infotip_addressesRtdevice_full_infotdevice_mac_addressesR5tstorage_full_infotfile_full_infotfilename((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_format_instance_info_selectTs�


	
-	 
##&




c
C@shi}g}d|kr�x�|dD]u}i|jd6|jjd6|jjd6t|�jjdd�dd6||jj<|jr�|j||jjd<nt|d	�r#|j	r#|j	j
||jjd
<|j	j||jjd<|j	j||jjd<|j	j
||jjd
<nt|d�rU|jrU|j||jjd<nt|d�r~|j||jjd<nt|d�r�|j||jjd<|j|j�nt|d�r�|j||jjd<nt|d�r	|j||jjd<nt|d�r2|j||jjd<nt|tjjj�r#|j||jjd<|jj||jjd<|jj||jjd<q#q#Wnid|kr�t|d�ndd6d|kr�t|d�ndd6d|krt|d�ndd6}i}d|krmxJ|dD];}i|jd6|jd 6|jd!6|jd6||j<q+Wni}g}d"|kr�xP|d"D]A}	i|	jd6|	j d#6|	jd$6||	j!<|j"|	j �q�Wnd%|kr�|d%nd}
d&|krd'j#|d&�nd}it$j%|d �d(6d)|krOd*j#|d)�ndd+6d,j#|
|�d!6i|
d-6|d.6d/6d0|kr�t$j%|d0�ndd16|d26gd36|d46|d56|d66d7|kr�t$j%|d7�ndd86t$j%|d9j&j'�d:6|d;6|d<6d=|kr4t$j%|d=�ndd>6d?|krZt$j%|d?�ndd@6}|S(ANuconfig.hardware.deviceukeyulabelusummaryu.iutypeu
unitNumberuconnectableustartConnecteduallowGuestControlu	connectedustatusu
controllerKeyuaddressTypeu
macAddressu	busNumberudeviceu
deviceKeysuvideoRamSizeInKBucapacityInKBudiskModeufileNameusummary.storage.committeduN/Au	committedusummary.storage.uncommitteduuncommittedusummary.storage.unshareduunsharedu
layoutEx.fileunameusizeu	guest.netuip_addressesumac_addressuconfig.hardware.numCPUuconfig.hardware.memoryMBu{0} MBuiduconfig.guestFullNameu{0} (Detected)uimageucpu: {0}
ram: {1}ucpuumemoryu	size_dictusummary.runtime.powerStateustateuprivate_ipsu
public_ipsudevicesustorageufilesuconfig.guestIduguest_iduobjectuhostnameu
mac_addressesunetworksuconfig.files.vmPathNameupathuguest.toolsStatusutools_status((RDRFRGRIRnRpRqRZR�RR�R�R'R*RYR�R�R�R�R5R+RRR4RCR1R2R3RWR0RSR,R�RxR(RHRRVR�R&(
R4R3R4R5R5R6R7R1R2RR/R0tvm_full_info((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_format_instance_info�s�


-	$##&




%&&&&)ucC@s�i}x�|D]�}dj||j�}i|jd6|jd6tj|j�jd�dd6|jd6|d6||<|r�||jkr�||S|j	r
t
|j	||�}|r�|S|j|�q
q
W|S(	Nu{0}/{1}unameudescriptionu.iucreatedustateupath(RHRStdescriptionRRVt
createTimeRtstatetsnapshottchildSnapshotListt_get_snapshotstupdate(t
snapshot_listtcurrent_snapshottparent_snapshot_patht	snapshotsR>t
snapshot_pathR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyR@Ds"


 
	cC@sJ|j|kr|Sx0|jD]%}t||�}|dk	r|SqWdS(N(RSR?t_get_snapshot_ref_helperR#(t
base_snapshott
snapshot_nameR>tsnapshot_ref((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRG]scC@sdd}y:x3|jjD]%}t||�}|dk	rPqqWWnttfk
r_d}nX|S(N(R#R>trootSnapshotListRGt
IndexErrortAttributeError(R�RIRJt
root_snapshot((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_get_snapshot_ref_by_nameis
c	C@sf|jjrd}nM|jjdkr0d}n2|jjjdkrNd}n|jjdkrid}n�|jjd	kr\tjd
|j	�y�|jj
dkr�|r�tjd|j	�|jd
�}n%|jj
dkr�|j�}ndStj
jj||j	ddddd�Wn3tk
rR}tjd|j	|dtj�dSXd}nd}|S(Nu,VMware tools cannot be updated on a templateutoolsOku"VMware tools is already up to dateu	poweredOnu&VM must be powered on to upgrade toolsutoolsNotRunningutoolsNotInstalledu3VMware tools is either not running or not installedutoolsOlduUpgrading VMware tools on %suwindowsGuestuReboot suppressed on %su/S /v"/qn REBOOT=R"u
linuxGuestu5Only Linux and Windows guests are currently supportedu
tools upgradeRiRuinfou/Error while upgrading VMware tools on VM %s: %stexc_info_on_logleveluVMware tools upgrade faileduVMware tools upgrade succeededu"VMWare tools could not be upgraded(utoolsNotRunningutoolsNotInstalled(u
linuxGuestuwindowsGuest(R
ttemplateR�ttoolsStatusRIRt
powerStateRQR�RStguestFamilytUpgradeToolsRRR*t
wait_for_taskt	ExceptionRrRR(R4trebootR*ttasktexc((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt_upg_tools_helpervs>				
	cC@sh|dkrtjjS|dkr,tjjS|dkrBtjjS|dkrXtjjStd��dS(u_
    Convert a string representation of a HostHostBusAdapter into an
    object reference.
    uparallelublockuiscsiufibreuUnknown Host Bus Adapter TypeN(RthosttParallelScsiHbatBlockHbatInternetScsiHbatFibreChannelHbaR(thba_type((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt
_get_hba_type�s



cC@sJ|dkrtd��nyt�Wntk
rE}dj|�SXdS(u*
    Test if the connection can be made to the vCenter server using
    the specified credentials inside ``/etc/salt/cloud.providers``
    or ``/etc/salt/cloud.providers.d/vmware.conf``

    CLI Example:

    .. code-block:: bash

        salt-cloud -f test_vcenter_connection my-vmware-config
    ufunctionuJThe test_vcenter_connection function must be called with -f or --function.ufailed to connect: {0}uconnection successful(RR/RWRH(tkwargsR�RZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyttest_vcenter_connection�scC@s=|dkrtd��ntjjjt��}|jjS(u�
    Show the vCenter Server version with build number.

    CLI Example:

    .. code-block:: bash

        salt-cloud -f get_vcenter_version my-vmware-config
    ufunctionuFThe get_vcenter_version function must be called with -f or --function.(RRRR*t
get_inventoryR/tabouttfullName(RcR�tinv((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyR��s

cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the data centers for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_datacenters my-vmware-config
    ufunctionuCThe list_datacenters function must be called with -f or --function.uDatacenters(RRRR*tlist_datacentersR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRi�s
cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the distributed virtual portgroups for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_portgroups my-vmware-config
    ufunctionuBThe list_portgroups function must be called with -f or --function.u
Portgroups(RRRR*tlist_portgroupsR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRj�s
cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the clusters for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_clusters my-vmware-config
    ufunctionu@The list_clusters function must be called with -f or --function.uClusters(RRRR*t
list_clustersR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRks
cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the datastore clusters for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_datastore_clusters my-vmware-config
    ufunctionuJThe list_datastore_clusters function must be called with -f or --function.uDatastore Clusters(RRRR*tlist_datastore_clustersR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRl"s
cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the datastores for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_datastores my-vmware-config
    ufunctionuBThe list_datastores function must be called with -f or --function.u
Datastores(RRRR*tlist_datastoresR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRm5s
cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the hosts for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_hosts my-vmware-config
    ufunctionu=The list_hosts function must be called with -f or --function.uHosts(RRRR*t
list_hostsR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRnHs
cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the resource pools for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_resourcepools my-vmware-config
    ufunctionuEThe list_resourcepools function must be called with -f or --function.uResource Pools(RRRR*tlist_resourcepoolsR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRo[s
cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the standard networks for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_networks my-vmware-config
    ufunctionu@The list_networks function must be called with -f or --function.uNetworks(RRRR*t
list_networksR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRpns
cC@s�|dkrtd��ni}dg}tjjjt�tj|�}x.|D]&}idd6|dd6||d<qRW|S(u�
    Return a list of all VMs and templates that are on the specified provider, with no details

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_nodes_min my-vmware-config
    uactionuAThe list_nodes_min function must be called with -f or --function.unameuRunningustateuid(RRRR*tget_mors_with_propertiesR/RtVirtualMachine(RcR�R�t
vm_propertiestvm_listR4((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytlist_nodes_min�s
	!
$c	C@sj|dkrtd��ni}ddddddg}tjjjt�tj|�}x	|D]}d|kr}|dnd	}d|kr�d
j|d�nd	}i|dd6d|kr�dj|d�nd	d
6dj||�d6i|d6|d6d6d|kr#t	j
|d�nd	d6d|krC|dgngd6gd6}|||d<qaW|S(us
    Return a list of all VMs and templates that are on the specified provider, with basic fields

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_nodes my-vmware-config

    To return a list of all VMs and templates present on ALL configured providers, with basic
    fields:

    CLI Example:

    .. code-block:: bash

        salt-cloud -Q
    uactionu=The list_nodes function must be called with -f or --function.unameuguest.ipAddressuconfig.guestFullNameuconfig.hardware.numCPUuconfig.hardware.memoryMBusummary.runtime.powerStateuN/Au{0} MBuidu{0} (Detected)uimageucpu: {0}
ram: {1}usizeucpuumemoryu	size_dictustateuprivate_ipsu
public_ips(RRRR*RqR/RRrRHRRV(	RcR�R�RsRtR4R/R0tvm_info((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt
list_nodes�s4	!
%&& 
cC@s�|dkrtd��ni}ddddddd	d
ddd
dddg}tjjjt�tj|�}x"|D]}t|�||d<qyW|S(ux
    Return a list of all VMs and templates that are on the specified provider, with full details

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_nodes_full my-vmware-config

    To return a list of all VMs and templates present on ALL configured providers, with full
    details:

    CLI Example:

    .. code-block:: bash

        salt-cloud -F
    uactionuBThe list_nodes_full function must be called with -f or --function.uconfig.hardware.deviceusummary.storage.committedusummary.storage.uncommittedusummary.storage.unsharedu
layoutEx.fileuconfig.guestFullNameuconfig.guestIdu	guest.netuconfig.hardware.memoryMBunameuconfig.hardware.numCPUuconfig.files.vmPathNameusummary.runtime.powerStateuguest.toolsStatus(	RRRR*RqR/RRrR:(RcR�R�RsRtR4((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytlist_nodes_full�s,	!
cC@sD|dkrtd��ni}g}tjd�}|sKtd��nd|krg|jd�nd|kr�|jd�nd	|kr�|jd
dg�nd|kr�|jd
�nd|ks�d|kr�|jd�nd|ks
d|ks
d|kr|jd�nd|krE|jddddg�nd|kra|jd�nd|kr}|jd�nd|kr�|jd�nd|kr�|jd �nd!|kr�|jd"�n|s�iSd|kr�|jd�ntjjjt	�t
j|�}x%|D]}t||�||d<qW|S(#u�
    Return a list of all VMs and templates that are on the specified provider, with fields
    specified under ``query.selection`` in ``/etc/salt/cloud``

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_nodes_select my-vmware-config

    To return a list of all VMs and templates present on ALL configured providers, with
    fields specified under ``query.selection`` in ``/etc/salt/cloud``:

    CLI Example:

    .. code-block:: bash

        salt-cloud -S
    uactionuDThe list_nodes_select function must be called with -f or --function.uquery.selectionu,query.selection not found in /etc/salt/clouduidunameuimageuconfig.guestFullNameusizeuconfig.hardware.numCPUuconfig.hardware.memoryMBustateusummary.runtime.powerStateuprivate_ipsunetworksu	guest.netudevicesumac_addressu
mac_addressesuconfig.hardware.deviceustorageusummary.storage.committedusummary.storage.uncommittedusummary.storage.unsharedufilesu
layoutEx.fileuguest_iduconfig.guestIduhostnameuguest.hostNameupathuconfig.files.vmPathNameutools_statusuguest.toolsStatus(
RRR�R�R(RRR*RqR/RRrR8(R�R�RsR-RtR4((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytlist_nodes_selectsZ$
!
cC@s�|dkrtd��nddddddd	d
ddd
dddg}tjjjt�tj|�}x(|D] }|d|krst|�SqsWiS(u�
    List all available details of the specified VM

    CLI Example:

    .. code-block:: bash

        salt-cloud -a show_instance vmname
    uactionu<The show_instance action must be called with -a or --action.uconfig.hardware.deviceusummary.storage.committedusummary.storage.uncommittedusummary.storage.unsharedu
layoutEx.fileuconfig.guestFullNameuconfig.guestIdu	guest.netuconfig.hardware.memoryMBunameuconfig.hardware.numCPUuconfig.files.vmPathNameusummary.runtime.powerStateuguest.toolsStatus(	RRRR*RqR/RRrR:(RSR�RsRtR4((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt
show_instance`s,
	!
cC@s�|dkrtd��ni}dddddg}tjjjt�tj|�}x�|D]�}d|kr^|dr^i|dd6d|kr�|dndd	6d|kr�|dndd
6d|kr�|dndd6||d<q^q^W|S(u�
    Return a list of all the templates present in this VMware environment with basic
    details

    CLI Example:

    .. code-block:: bash

        salt-cloud --list-images my-vmware-config
    uactionuaThe avail_images function must be called with -f or --function, or with the --list-images option.unameuconfig.templateuconfig.guestFullNameuconfig.hardware.numCPUuconfig.hardware.memoryMBuN/Auguest_fullnameucpusuram(RRRR*RqR/RRr(R�t	templatesRsRtR4((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytavail_images�s$	!
/cC@s(|dkrtd��ntdd�S(u�
    Return a list of all the available locations/datacenters in this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud --list-locations my-vmware-config
    uactionugThe avail_locations function must be called with -f or --function, or with the --list-locations option.R�ufunction(RRi(R�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytavail_locations�s
cC@s,|dkrtd��ntjd�iS(u"
    Return a list of all the available sizes in this VMware environment.

    CLI Example:

    .. code-block:: bash

        salt-cloud --list-sizes my-vmware-config

    .. note::

        Since sizes are built into templates, this function will return
        an empty dictionary.

    uactionu_The avail_sizes function must be called with -f or --function, or with the --list-sizes option.uQBecause sizes are built into templates with VMware, there are no sizes to return.(RRQR�(R�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytavail_sizes�scC@s/|dkrtd��nitdd�d6S(u�
    List all the templates present in this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_templates my-vmware-config
    ufunctionuAThe list_templates function must be called with -f or --function.R�u	Templates(RR|(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytlist_templates�s
cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the folders for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_folders my-vmware-config
    ufunctionu?The list_folders function must be called with -f or --function.uFolders(RRRR*tlist_foldersR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyR��s
cC@s�|dkrtd��ni}dddg}tjjjt�tj|�}x�|D]�}|dr�|r�|jd�|dkr�it	|dj
�|d6St	|dj
�||d<qX|rX|jd�|dkrXiSqXW|S(u�
    List snapshots either for all VMs and templates or for a specific VM/template
    in this VMware environment

    To list snapshots for all VMs and templates:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_snapshots my-vmware-config

    To list snapshots for a specific VM/template:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_snapshots my-vmware-config name="vmname"
    ufunctionuAThe list_snapshots function must be called with -f or --function.unameurootSnapshotusnapshot(RRRR*RqR/RRrR�R@RK(RcR�R�RsRtR4((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytlist_snapshots	s 	!

cC@s
|dkrtd��nddg}tjjjt�tj|�}x�|D]�}|d|krO|ddkr�d}tj	d||�|Sy=tj	d|�|d	j
�}tjjj||d
�Wqtk
r}tj
d||dtj�d
SXqOqOWdS(u
    To start/power on a VM using its name

    CLI Example:

    .. code-block:: bash

        salt-cloud -a start vmname
    uactionu4The start action must be called with -a or --action.unameusummary.runtime.powerStateu	poweredOnualready powered onuVM %s %suStarting VM %suobjectupower onu!Error while powering on VM %s: %sRPufailed to power onu
powered on(RRRR*RqR/RRrRQR�tPowerOnRVRWRrRR(RSR�RsRtR4R�RYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytstart:s.
	!
	
c	C@s$|dkrtd��nddg}tjjjt�tj|�}x�|D]�}|d|krO|ddkr�d}tj	d||�|SyTtj	d|�|r�|d	j
�n)|d	j�}tjjj||d
�Wqt
k
r}tjd||dtj�d
SXqOqOWdS(u�
    To stop/power off a VM using its name

    .. note::

        If ``soft=True`` then issues a command to the guest operating system
        asking it to perform a clean shutdown of all services.
        Default is soft=False

        For ``soft=True`` vmtools should be installed on guest system.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a stop vmname
        salt-cloud -a stop vmname soft=True
    uactionu3The stop action must be called with -a or --action.unameusummary.runtime.powerStateu
poweredOffualready powered offuVM %s %suStopping VM %suobjectu	power offu"Error while powering off VM %s: %sRPufailed to power offupowered off(RRRR*RqR/RRrRQR�t
ShutdownGuesttPowerOffRVRWRrRR(	RStsoftR�RsRtR4R�RYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytstopgs2	!
	
cC@s:|dkrtd��nddg}tjjjt�tj|�}x�|D]�}|d|krO|ddkr�d}tj	d||�|S|ddkr�d	}tj	d||�|Sy=tj	d
|�|dj
�}tjjj||d�Wq2tk
r.}tj
d
||dtj�dSXqOqOWdS(uz
    To suspend a VM using its name

    CLI Example:

    .. code-block:: bash

        salt-cloud -a suspend vmname
    uactionu6The suspend action must be called with -a or --action.unameusummary.runtime.powerStateu
poweredOffu#cannot suspend in powered off stateuVM %s %su	suspendedualready suspendeduSuspending VM %suobjectususpendu Error while suspending VM %s: %sRPufailed to suspend(RRRR*RqR/RRrRQR�tSuspendRVRWRrRR(RSR�RsRtR4R�RYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytsuspend�s6
	!
	
c	C@s4|dkrtd��nddg}tjjjt�tj|�}x�|D]�}|d|krO|ddks�|ddkr�d}tj	d||�|SyTtj	d	|�|r�|d
j
�n)|d
j�}tjjj||d�Wq,t
k
r(}tjd||d
tj�dSXqOqOWdS(u�
    To reset a VM using its name

    .. note::

        If ``soft=True`` then issues a command to the guest operating system
        asking it to perform a reboot. Otherwise hypervisor will terminate VM and start it again.
        Default is soft=False

        For ``soft=True`` vmtools should be installed on guest system.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a reset vmname
        salt-cloud -a reset vmname soft=True
    uactionu4The reset action must be called with -a or --action.unameusummary.runtime.powerStateu	suspendedu
poweredOffu+cannot reset in suspended/powered off stateuVM %s %suResetting VM %suobjecturesetuError while resetting VM %s: %sRPufailed to reset(RRRR*RqR/RRrRQR�tRebootGuesttResetVM_TaskRVRWRrRR(	RSR�R�RsRtR4R�RYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytreset�s2	!
 	
cC@s�|dkrtd��nddg}tjjjt�tj|�}x�|D]�}|d|krO|ddkr�d}tj	d||�|Sy"tj	d|�|d	j
�Wq�tk
r�}tjd
||dt
j�dSXqOqOWd
S(u�
    To do an immediate power off of a VM using its name. A ``SIGKILL``
    is issued to the vmx process of the VM

    CLI Example:

    .. code-block:: bash

        salt-cloud -a terminate vmname
    uactionu8The terminate action must be called with -a or --action.unameusummary.runtime.powerStateu
poweredOffualready powered offuVM %s %suTerminating VM %suobjectu!Error while terminating VM %s: %sRPufailed to terminateu
terminated(RRRR*RqR/RRrRQR�t	TerminateRWRrRR(RSR�RsRtR4R�RZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt	terminate
	s,	!
	
cC@s|dkrtd��ntddddj|�di|d6d	td
dtd�dd
g}tjjjt�t	j
|�}x|D]}|d|kr�|d
dkr&y=tjd|�|dj
�}tjjj||d�Wq&tk
r"}tjd||dtj�dSXny=tjd|�|dj�}tjjj||d�Wq�tk
r�}tjd||dtj�dSXq�q�Wtddddj|�di|d6d	td
dtd�tjdt�tkrtd|tjd�dt�ntS(u�
    To destroy a VM from the VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -d vmname
        salt-cloud --destroy vmname
        salt-cloud -a destroy vmname
    ufunctionuEThe destroy action must be called with -d, --destroy, -a or --action.ucloud.fire_eventueventudestroying instanceusalt/cloud/{0}/destroyingtargsunametsock_dirusock_dirt	transportu	transportusummary.runtime.powerStateu
poweredOffuPowering Off VM %suobjectu	power offu"Error while powering off VM %s: %sRPufailed to destroyuDestroying VM %sudestroyu Error while destroying VM %s: %sudestroyed instanceusalt/cloud/{0}/destroyeduupdate_cachedirucloud.delete_minion_cachediru:i(Rt	__utils__RHRRRR*RqR/RRrRQR�R�RVRWRrRRtDestroy_TaskR�R	R"RR(RSR�RsRtR4RYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytdestroy7	s\

	!
	
	


$cGC@s�y=|dr<tjttpd|dd|�tkr<tSWntk
rPnXtddddj|d�d	td
d|dddd
g�dtddtd�tjd|tdd��}tjd|tdd��}tjd|tdd��}tjd|tdd��}tjd|tdd��}tjd|tdd��}tjd|tdd��}tjd|tdt�}tjd|tdd��}	tjd|tdd��}
tjd|tdd��}tjd|tdd��}tjd|tdd��}
tjd|tdd��}tjd |tdt
�}tjd!|td"tdd��}tjd#|td"t
dt
�}tjd$|tdd��}tjd'|td"tdd(�}tjd)|td"tdd��}tjd*|td"tdd��}tjd+|td"tdt
�}tjd,|td"tdd��}tjd-|td"tdd��}tjd.|td"tdd/�}tjd0|td"tdt�}tjd1|td"tdd2�}tjd3|td"tdd��}t�}d�}|r/tj
jjt�tj|�}|r&|nd�}nd4|kr�|rttj
jj|tj|�}|rk|nd�}ntj
jj|tj|d4d5|�} | r�| jjr�dnd6}!q�td7��nd�}!d�} |r@tj
jj|tj|d5|�}"|"s�tjd8|�|!s+|!dkr=td9��q=q�n�|r�tj
jj|tj|d5|�}#|#s�tjd:|�|!s�|!dkr�td;��q�q�|#j}"nG|!dkr�td<��n,|!s�td=��ntjd>|!|d4�|r�|jd?�}$|}%xA|$D]9}&|&rtj
jj|tj|&d5|%�}'|'}%qqW|'stjd@|�tjdA|!|d4�| j}'qn�|r�|s�tjdB|�tjdC|!|d4�| j}'q|j}'n5|!s�tdD��n tjdA|!|d4�| j}'d4|kr[tjj �}(|r:|"sF|rR|#rR|"|(_!n|r�tj
jj|tj"|d5|�})|)r�|)|(_#q	tj
jj|tj$|d5|�}*|*s	tjdE|�tjdF|!|d4�q	n$tjdG�tjdF|!|d4�|r�tj
jj|tj%|d5|�}+|+rE|+|(_&qXtjdH|�q�n�|sptdI��n<tj
jj|tj"|�})|)s�tdJj|���n|r�tj
jjt�tj%|d5|�}+|+s�tjdH|�q�ntjj'�},|r�	| d�k	r�	dKj|�}|| jj(kr}	tjdL| jj(|�tjj)�}-dM|-_*||-_+|-|,_,q�	tjdN|�n|	r�	tjdO|	�t-|	�|,_.n|
r�	tjdP|
�t-|
�|,_/n|r�
y�t0j1dQ|�\}.}/|/j2�dRkr"
t-|.�}0nR|/j2�dSkrM
t-t3|.�dT�}0n'dUj|/�}1tj|1�i|1dV6SWn#t4t5fk
r�
t-|�}0nXtjdW|0�|0|,_6n|r�
t7|dX| d5|dY|�}2|2dZ|,_8n|
r?xKt9j:|
�D]7\}3}4tj;j<d[|3d\|4�}5|,j=j>|5�qWn|rZt9j?|�|,_@nd4|krPtA|,| |(||�}6|6s�tB|,| |(|�}6n|r�|r�tj
jjCd]|d^|�}|jD|6_EnM|r"|r"d_tF|jG��kr"tjjEjH�}7d`tF|jG��kr3|d`|7_Int0jJda�}8t0jK|8|�r�t0j|8|dbdc�dd}9t0j|8|dbdc�de}:n|}9|}:df| jjLkr�tjjEjM�};tjjEjNdg|9�|;_O|:|;_PntjjEjQ�};tjjEjR�|;_St
|;jS_Tdc|;jS_UtjjEjV�|;jS_W||;jSjW_X||;jSjW_Y|r�
tjjEjZ�|;_[||;j[_\ntjjEj]�|;_^||;j^__||;j^_`tjjEjN�|;j^_a|9|;j^ja_btjjEjc�|;_dtjjEjedh|7di|;dj|2dk�}<|<|6_En|s4||6_fntjdltgjh|6��nU||,_btjji�|,_jdmj||�|,jj_k||,_ltjdntgjh|,��|jm�}=|=jndo�r�|=do=ny�tdddpdqj|d�d	td
dr|=tF|=��dtddtd�d4|kr3tjods|d|!|d4�|r�|)r�|*r�tjpjqdt|*�}>tjpjrdudvdX| dw|>dx|6dy|dz|'�}?|jsjtjud{|?�}@|jsjtjv|@jwddjx�}Atj
jjy|A|d|d}d~�q�| jz|'||6�}Atj
jjy|A|dvd}d~�nctjod|d�|re|'j{|,|"|+�}An|'j{|,|"�}Atj
jjy|A|d�d�d~�WnGt|k
r�}Bd�j|d|B�}1tj|1d�t}j~�i|1dV6SXtj
jj|tj|d5|�}Cy?|!rC|rC|Cj�}Atj
jjy|A|d�d}d~�nWn-t|k
rs}Btjod��tjo|B�nXd�}D|r|rt�|C|�}E|Ertjod�||E�|r||d�<d�|kr�|E|d�<ntjod�||d��td�|t�}Dqqnt�|d�d��}F|rKt�|Dt��rK|Djnd�i�|Fd�<ntddd�d�j|d�d	td
d�|dddd
g�dtddtd�|FS(�u
    To create a single VM in the VMware environment.

    Sample profile and arguments that can be specified in it can be found
    :ref:`here. <vmware-cloud-profile>`

    CLI Example:

    .. code-block:: bash

        salt-cloud -p vmware-centos6.5 vmname
    uprofileuvmwareRucloud.fire_eventueventustarting createusalt/cloud/{0}/creatingunameR�ucloud.filter_eventucreatinguproviderudriverR�usock_dirR�u	transportR'ufolderu
datacenteruresourcepooluclusteru	datastoreuhostutemplateunum_cpusucores_per_socketumemoryudevicesuextra_configu
annotationupower_onuprivate_keyR&udeployuwait_for_ip_timeoutii<udomainulocaluhardware_versionuimageu
customizationucustomization_specuwin_passworduwin_organization_nameuOrganizationu
plain_textuwin_user_fullnameuWindows Useruwin_run_onceu	clonefromRiuvmuGThe VM/template that you have specified under clonefrom does not exist.u,Specified resource pool: '%s' does not existu-You must specify a resource pool that exists.u&Specified cluster: '%s' does not existu'You must specify a cluster that exists.uRYou must either specify a cluster or a resource pool when cloning from a template.uCYou must either specify a cluster or a resource pool when creating.u%Using resource pool used by the %s %su/u%Specified folder: '%s' does not existu&Using folder in which %s %s is presentu)Specified datacenter: '%s' does not existu1Using datacenter folder in which %s %s is presentuKYou must either specify a folder or a datacenter when creating not cloning.u:Specified datastore/datastore cluster: '%s' does not existu!Using datastore used by the %s %su(No datastore/datastore cluster specifiedu#Specified host: '%s' does not existu7You must specify a datastore when creating not cloning.u)Specified datastore: '{0}' does not existu
vmx-{0:02}u1Scheduling hardware version upgrade from %s to %sualwaysu*Virtual hardware version already set to %suSetting cpu to: %suSetting cores per socket to: %su[^\W\d_]+|\d+.\d+|\d+umbugbg�@u$Invalid memory type specified: '{0}'uErroruSetting memory to: %s MBR4R�udevice_specsRDtvaluetsitcustomization_spec_nameunetworkudns_serversu[^\w-]tmaxsplitiii����uWindowsRStglobalIPSettingstidentityt
nicSettingMapunics_mapuclone_spec set to:
%su[{0}] {1}/{1}.vmxuconfig_spec set to:
%supasswordurequesting instanceusalt/cloud/{0}/requestingu
requestinguCreating %s from %s(%s)t
storagePodRnuclonetpodSelectionSpect	cloneSpect	cloneNametfoldertstorageSpecu!apply storage DRS recommendationsiuinfouCreating %sucreateiuError creating {0}: {1}RPupoweru2Powering on the VM threw this exception. Ignoring.u[ %s ] IPv4 is: %sukey_filenameussh_hostu[ %s ] Deploying to %sucloud.bootstrapR�uactionu
deploy_kwargsucreated instanceusalt/cloud/{0}/createducreatedNi�(�R
tis_profile_configuredRRR	RMR�RHRR#R"R/RRR*RsRt
DatacenterRrRQRtResourcePoolRQRrtClusterComputeResourcetresourcePoolRoRtFoldertparenttvmFolderR4tRelocateSpectpoolRNRXROt
HostSystemR\t
ConfigSpectversiontScheduledHardwareUpgradeInfot
upgradePolicyt
versionKeytscheduledHardwareUpgradeInfoR0tnumCPUstnumCoresPerSockettretfindallR!R�t	TypeErrorRtmemoryMBR�tdeviceChangeRR�toptiontOptionValuetextraConfigR�RVt
annotationthandle_snapshottbuild_clonespectget_customizationspec_refR�R�R�R�tGlobalIPSettingst
dnsServerListtcompiletsearcht
guestFullNamet	LinuxPrept	FixedNameR&R�tSysprept
GuiUnattendedt
guiUnattendedt	autoLogontautoLogonCounttPasswordR.R�t	plainTextt
GuiRunOncet
guiRunOncetcommandListtUserDatatuserDataRgtorgNametcomputerNameRStIdentificationtidentificationt
SpecificationtpowerOntpprinttpformattFileInfotfilest
vmPathNametguestIdtcopyR�R�t
storageDrstPodSelectionSpectStoragePlacementSpectcontenttstorageResourceManagertRecommendDatastorest"ApplyStorageDrsRecommendation_TasktrecommendationsRDRVtClonet
CreateVM_TaskRWRRR�RRzRtdict(GRR`R�t
datacentertresourcepooltclusterRXR\RQtnum_cpustcores_per_sockettmemoryR�textra_configR�tpowertkey_filenametdeploytwait_for_ip_timeoutR�thardware_versiontguest_idR�tcustomization_spectwin_passwordtwin_organization_namet
plain_texttwin_user_fullnametwin_run_onceR�Ritdatacenter_reft
object_reft
clone_typetresourcepool_reftcluster_reftfolder_partstsearch_referencetfolder_partt
folder_reft
reloc_specRbRcRtconfig_spectscheduled_hardware_upgradet
memory_numtmemory_unitt	memory_mbR�tspecsRDR�R�t
clone_spect	global_iptnon_hostname_charst	host_nametdomain_nameR�tcustom_spectevent_kwargstpod_spectstorage_spectrecommended_datastoresRYRZt
new_vm_reftoutR�tdata((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytcreate�	s�

		

"
	!	
			
	
		$
						
	$	
	
		

	""#
$
&



"
cC@sed|krdSttttg}t|||||�}|satdjdj|����n|S(uU
    Returns a clone spec for cloning from shapshots
    :rtype vim.vm.CloneSpec
    usnapshotu8Invalid disk move type specified supported types are {0}u N(	R#tFLATTEN_DISK_FULL_CLONEtCOPY_ALL_DISKS_FULL_CLONEtCURRENT_STATE_LINKED_CLONEtQUICK_LINKED_CLONEt get_clonespec_for_valid_snapshotRRHtjoin(R	RRRQRt
allowed_typesR((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyR��s 			cC@s�t}t|ddkr&t|_nft|ddkrFt|_nFt|ddkrft|_n&t|ddkr�t|_nt}|r�t||||�SdS(u3
    return clonespec only if values are valid
    usnapshotudisk_move_typeN(	R"R tdiskMoveTypeRRRR	R�R#(R	RRRQRtmoving((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyR!�sc	C@sY|jtkr:tjjd|d|d|d|jj�Stjjd|d|d|�S(u 
    Returns the clone spec
    RQtlocationR
R>(R$R RR4t	CloneSpecR>tcurrentSnapshot(R	RRRQ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyR��s
cC@s;|dkrtd��n|r<d|kr<|jd�nd
}|sWtd��n|spt|�dkrtd��nt�}tjjj|t	j
|�}|r�id|6S|jj}t
|t	j�r7y|jd|�Wn0tk
r}tjd	||d
tj�tSXtjd|�id|6StS(u�
    Create a new data center in this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f create_datacenter my-vmware-config name="MyNewDatacenter"
    ufunctionuDThe create_datacenter function must be called with -f or --function.unameu:You must specify name of the new datacenter to be created.iPuJThe datacenter name must be a non empty string of less than 80 characters.udatacenter already existsRSu Error creating datacenter %s: %sRPuCreated datacenter %sucreatedN(RR�R#R�R/RRR*RsRR�R�t
rootFolderRR�tCreateDatacenterRWRQRrRRR	Ro(RcR�tdatacenter_nameR�R�R�RZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytcreate_datacenter�s6
'		
c	C@s�|dkrtd��n|r<d|kr<|jd�nd}|rcd|krc|jd�nd}|s~td��n|s�td��nt�}t|tj�s�tjj	j
|tj|�}|s�td��q�ntjj	j
|tj|�}|rid|6Stjj
�}|j}t|tj�r�y|jd	|d
|�Wn0tk
r�}tjd||dtj�tSXtjd
||j�id|6StS(u�
    Create a new cluster under the specified datacenter in this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f create_cluster my-vmware-config name="myNewCluster" datacenter="datacenterName"
    ufunctionuAThe create_cluster function must be called with -f or --function.unameu
datacenteru7You must specify name of the new cluster to be created.uLYou must specify name of the datacenter where the cluster should be created.u(The specified datacenter does not exist.ucluster already existsRSR�uError creating cluster %s: %sRPu&Created cluster %s under datacenter %sucreatedN(RR�R#R/RRR�RRR*RsR�R�tConfigSpecExt
hostFolderR�tCreateClusterExRWRQRrRRR	RoRS(	RcR�tcluster_nameR�R�Rtcluster_specR�RZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytcreate_clustersH
''			

cC@sL|dkrtd��n|r<d|kr<|jd�nd
}|rcd|krc|jd�nd
}|s~td��ntjjjt�tj	|�}yh|r�t
jd||�|jj
j|�dj|�}n&t
jd|�|jj
j�d	}Wn7tk
r@}t
jd
||dtj�id|6SXi||6S(u
    To rescan a specified HBA or all the HBAs on the Host System

    CLI Example:

    .. code-block:: bash

        salt-cloud -f rescan_hba my-vmware-config host="hostSystemName"
        salt-cloud -f rescan_hba my-vmware-config hba="hbaDeviceName" host="hostSystemName"
    ufunctionu=The rescan_hba function must be called with -f or --function.uhbauhostu)You must specify name of the host system.uRescanning HBA %s on host %surescanned HBA {0}uRescanning all HBAs on host %surescanned all HBAsu(Error while rescaning HBA on host %s: %sRPufailed to rescan HBAN(RR�R#RRR*RsR/RR�RQR�t
configManagert
storageSystemt	RescanHbaRHtRescanAllHbaRWRrRR(RcR�thbaRRR�RZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt
rescan_hbaMs0''!
	
cC@sx|dkrtd��ni}dg}tjjjt�tj|�}x&|D]}t|d�||d<qRW|S(uy
    To upgrade VMware Tools on all virtual machines present in
    the specified provider

    .. note::

        If the virtual machine is running Windows OS, this function
        will attempt to suppress the automatic reboot caused by a
        VMware Tools upgrade.

    CLI Example:

    .. code-block:: bash

        salt-cloud -f upgrade_tools_all my-vmware-config
    ufunctionuDThe upgrade_tools_all function must be called with -f or --function.unameuobject(	RRRR*RqR/RRrR[(R�R�RsRtR4((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytupgrade_tools_all}s	!
cC@sI|dkrtd��ntjjjt�tj|�}t||�S(u�
    To upgrade VMware Tools on a specified virtual machine.

    .. note::

        If the virtual machine is running Windows OS, use ``reboot=True``
        to reboot the virtual machine after VMware tools upgrade. Default
        is ``reboot=False``

    CLI Example:

    .. code-block:: bash

        salt-cloud -a upgrade_tools vmname
        salt-cloud -a upgrade_tools vmname reboot=True
    uactionu<The upgrade_tools action must be called with -a or --action.(	RRRR*RsR/RRrR[(RSRXR�R�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt
upgrade_tools�s
!cC@s
|dkrtd��ni}|rBd|krB|jd�nd}dg}tjjjt�tj	|�}x�|D]�}g||d<xB|dj
D]3}t|tj�r�||dj
|j�q�q�W|ry||dkryii|||6d6SqyWi|d6S(u�
    List hosts for each cluster; or hosts for a specified cluster in
    this VMware environment

    To list hosts for each cluster:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_hosts_by_cluster my-vmware-config

    To list hosts for a specified cluster:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_hosts_by_cluster my-vmware-config cluster="clusterName"
    ufunctionuHThe list_hosts_by_cluster function must be called with -f or --function.uclusterunameuobjectuHosts by ClusterN(RR�R#RRR*RqR/RR�R\RR�R�RS(RcR�R�R0tcluster_propertiestcluster_listR�R\((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytlist_hosts_by_cluster�s"'		
cC@s|dkrtd��ni}|rBd|krB|jd�nd}dg}tjjjt�tj	|�}x�|D]�}g||d<xE|dj
jD]3}t|tj
�r�||dj|j�q�q�W|ry||dkryii|||6d6SqyWi|d6S(u�
    List clusters for each datacenter; or clusters for a specified datacenter in
    this VMware environment

    To list clusters for each datacenter:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_clusters_by_datacenter my-vmware-config

    To list clusters for a specified datacenter:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_clusters_by_datacenter my-vmware-config datacenter="datacenterName"
    ufunctionuNThe list_clusters_by_datacenter function must be called with -f or --function.u
datacenterunameuobjectuClusters by DatacenterN(RR�R#RRR*RqR/RR�R.tchildEntityRR�R�RS(RcR�R�R+tdatacenter_propertiestdatacenter_listR�R�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytlist_clusters_by_datacenter�s'	!
c	C@s9|dkrtd��ni}|rBd|krB|jd�nd}dg}tjjjt�tj	|�}x�|D]�}g||d<xn|dj
jD]\}t|tj
�r�xA|jD]3}t|tj�r�||dj|j�q�q�Wq�q�W|ry||dkryii|||6d6SqyWi|d6S(u�
    List hosts for each datacenter; or hosts for a specified datacenter in
    this VMware environment

    To list hosts for each datacenter:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_hosts_by_datacenter my-vmware-config

    To list hosts for a specified datacenter:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_hosts_by_datacenter my-vmware-config datacenter="datacenterName"
    ufunctionuKThe list_hosts_by_datacenter function must be called with -f or --function.u
datacenterunameuobjectuHosts by DatacenterN(RR�R#RRR*RqR/RR�R.R>RR�R\R�R�RS(	RcR�R�R+R?R@R�R�R\((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytlist_hosts_by_datacenter
s"'	!
&c
	C@s6|dkrtd��ni}|rHd|krH|jd�j�nd}|rod|kro|jd�nd}ddg}|r�|dkr�tdj|���ntjjjt	�t
j|�}x\|D]T}i||d<x|dD]}i|jd6|j
d
6t|�jjdd�dd6}	|r�t|t|��r�|j||dkr�|	||d|j|j<q�i|	|j6||d|j<q�q�|j||dkr�|	||d|j|j<q�i|	|j6||d|j<q�W|d|kr�ii|||6d6Sq�Wi|d6S(u�
    List all HBAs for each host system; or all HBAs for a specified host
    system; or HBAs of specified type for each host system; or HBAs of
    specified type for a specified host system in this VMware environment

    .. note::

        You can specify type as either ``parallel``, ``iscsi``, ``block``
        or ``fibre``.

    To list all HBAs for each host system:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_hbas my-vmware-config

    To list all HBAs for a specified host system:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_hbas my-vmware-config host="hostSystemName"

    To list HBAs of specified type for each host system:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_hbas my-vmware-config type="HBAType"

    To list HBAs of specified type for a specified host system:

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_hbas my-vmware-config host="hostSystemName" type="HBAtype"
    ufunctionu<The list_hbas function must be called with -f or --function.utypeuhostunameu#config.storageDevice.hostBusAdapteruparallelublockuiscsiufibreu/Specified hba type {0} currently not supported.udriverustatusu.iuHBAs by HostN(uparallelublockuiscsiufibre(RR�R!R#RHRRR*RqR/RR�tdriverR*RnRpRqRRbtmodelR5(
RcR�R�RaRthost_propertiest	host_listR\R7thba_spec((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt	list_hbasC
s<+-'	!


#%#cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the distributed virtual switches for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_dvs my-vmware-config
    ufunctionu;The list_dvs function must be called with -f or --function.uDistributed Virtual Switches(RRRR*tlist_dvsR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRI�
s
cC@s8|dkrtd��nitjjjt��d6S(u�
    List all the vApps for this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f list_vapps my-vmware-config
    ufunctionu=The list_vapps function must be called with -f or --function.uvApps(RRRR*t
list_vappsR/(RcR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyRJ�
s
cC@s|dkrtd��n|r<d|kr<|jd�nd}tjjjt�tj	|�}|sq|r�td��n|j
jr�id|6Sy5|jdddt
�}tjjj||d	�Wn7tk
r}tjd
||dtj�id|6SXid
|6S(u�
    To put the specified host system in maintenance mode in this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f enter_maintenance_mode my-vmware-config host="myHostSystemName"
    ufunctionuIThe enter_maintenance_mode function must be called with -f or --function.uhostu1You must specify a valid name of the host system.ualready in maintenance modettimeoutitevacuatePoweredOffVmsuenter maintenance modeu9Error while moving host system %s in maintenance mode: %sRPu failed to enter maintenance modeuentered maintenance modeN(RR�R#RRR*RsR/RR�RtinMaintenanceModetEnterMaintenanceModeR"RVRWRQRrRR(RcR�RRRYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytenter_maintenance_mode�
s(
'!	
cC@s|dkrtd��n|r<d|kr<|jd�nd
}tjjjt�tj	|�}|sq|r�td��n|j
js�id|6Sy/|jdd�}tjjj
||d�Wn7tk
r�}tjd	||d
tj�id|6SXid|6S(u�
    To take the specified host system out of maintenance mode in this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f exit_maintenance_mode my-vmware-config host="myHostSystemName"
    ufunctionuHThe exit_maintenance_mode function must be called with -f or --function.uhostu1You must specify a valid name of the host system.ualready not in maintenance modeRKiuexit maintenance modeu=Error while moving host system %s out of maintenance mode: %sRPufailed to exit maintenance modeuexited maintenance modeN(RR�R#RRR*RsR/RR�RRMtExitMaintenanceModeRVRWRQRrRR(RcR�RRRYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytexit_maintenance_mode�
s(
'!	
c
C@s�|dkrtd��nt�}|rEd|krE|jd�nd
}|s`td��ng}d}t}x2ttjj|j	d��j
d��D]\}}tjj||�}|jj
jd|�}	t|	tj�rtjd|�|j|	�q�t|	tj�r:tjd|�|j|	�q�t}|sutjd|�|j|jjj|��q�tjd	|�|j||d
j|��q�W|r�id|6Sid|6S(uE
    Create the specified folder path in this VMware environment

    .. note::

        To create a Host and Cluster Folder under a Datacenter, specify
        ``path="/yourDatacenterName/host/yourFolderName"``

        To create a Network Folder under a Datacenter, specify
        ``path="/yourDatacenterName/network/yourFolderName"``

        To create a Storage Folder under a Datacenter, specify
        ``path="/yourDatacenterName/datastore/yourFolderName"``

        To create a VM and Template Folder under a Datacenter, specify
        ``path="/yourDatacenterName/vm/yourFolderName"``

    CLI Example:

    .. code-block:: bash

        salt-cloud -f create_folder my-vmware-config path="/Local/a/b/c"
        salt-cloud -f create_folder my-vmware-config path="/MyDatacenter/vm/MyVMFolder"
        salt-cloud -f create_folder my-vmware-config path="/MyDatacenter/host/MyHostFolder"
        salt-cloud -f create_folder my-vmware-config path="/MyDatacenter/network/MyNetworkFolder"
        salt-cloud -f create_folder my-vmware-config path="/MyDatacenter/storage/MyStorageFolder"
    ufunctionu@The create_folder function must be called with -f or --function.upathu)You must specify a non empty folder path.u/t
inventoryPathu Path %s/ exists in the inventoryu4Creating folder %s under rootFolder in the inventoryu"Creating path %s/ in the inventoryiuspecfied path already existsucreated the specified pathN(RR/R�R#R"RtostpathtnormpathRlRR"R�tsearchIndextFindByInventoryPathRRR�RQRoR�R�R	R)tCreateFolder(
RcR�R�tfolder_pathtfolder_refstinventory_pathtpath_existstindextfolder_nameR((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt
create_folders:	'7"c
C@s�|dkrtd��n|dkr0i}n|rQd|krQ|jd�nd}|sltd��nt|jdt��}t|jdt��}tjjj	t
�tj|�}|j
jjdkr�tjd|�t}t}n|r|rtjd	�t}nd
|kr.|jd
�nd}y;|j||||�}tjjj||dd
d�Wn0tk
r�}	tjd||	dtj�dSXit|jj|jj�d6S(un
    Create a snapshot of the specified virtual machine in this VMware
    environment

    .. note::

        If the VM is powered on, the internal state of the VM (memory
        dump) is included in the snapshot by default which will also set
        the power state of the snapshot to "powered on". You can set
        ``memdump=False`` to override this. This field is ignored if
        the virtual machine is powered off or if the VM does not support
        snapshots with memory dumps. Default is ``memdump=True``

    .. note::

        If the VM is powered on when the snapshot is taken, VMware Tools
        can be used to quiesce the file system in the virtual machine by
        setting ``quiesce=True``. This field is ignored if the virtual
        machine is powered off; if VMware Tools are not available or if
        ``memdump=True``. Default is ``quiesce=False``

    CLI Example:

    .. code-block:: bash

        salt-cloud -a create_snapshot vmname snapshot_name="mySnapshot"
        salt-cloud -a create_snapshot vmname snapshot_name="mySnapshot" [description="My snapshot"] [memdump=False] [quiesce=True]
    uactionu>The create_snapshot action must be called with -a or --action.u
snapshot_nameu>You must specify snapshot name for the snapshot to be created.umemdumpuquiesceu	poweredOnuBVM %s is not powered on. Setting both memdump and quiesce to FalseuIYou can only set either memdump or quiesce to True. Setting quiesce=Falseudescriptionuucreate snapshotiuinfou'Error while creating snapshot of %s: %sRPufailed to create snapshotuSnapshot created successfullyN(RR#R�R%R"R	RRR*RsR/RRrRIRRSRQRoR�tCreateSnapshotRVRWRrRRR@R>RKR((
RSRcR�RItmemdumptquiesceR�tdescRYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytcreate_snapshotes>	'!	
	!#	
c
C@s�|dkrtd��n|dkr0i}n|rQd|krQ|jd�nd}t|jdt��}tjjjt	�t
j|�}|js�t
jd|�dSd}y�|dkr�t
jd|�|jd	|�}n_t
jd
||�dj|�}t||�}|dkr1dj|�S|jjd	|�}tjjj||d
dd�Wn0tk
r�}	t
jd||	dtj�dSX|S(u{
    Revert virtual machine to it's current snapshot. If no snapshot
    exists, the state of the virtual machine remains unchanged

    .. note::

        The virtual machine will be powered on if the power state of
        the snapshot when it was created was set to "Powered On". Set
        ``power_off=True`` so that the virtual machine stays powered
        off regardless of the power state of the snapshot when it was
        created. Default is ``power_off=False``.

        If the power state of the snapshot when it was created was
        "Powered On" and if ``power_off=True``, the VM will be put in
        suspended state after it has been reverted to the snapshot.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a revert_to_snapshot vmame [power_off=True]
        salt-cloud -a revert_to_snapshot vmame snapshot_name="selectedSnapshot" [power_off=True]
    uactionuAThe revert_to_snapshot action must be called with -a or --action.u
snapshot_nameu	power_offu,VM %s does not contain any current snapshotsu
revert failedureverted to current snapshotu#Reverting VM %s to current snapshottsuppressPowerOnuReverting VM %s to snapshot %sureverted to snapshot {0}u'specified snapshot '{0}' does not existurevert to snapshotiuinfou+Error while reverting VM %s to snapshot: %sRPN(RR#R�R%R	RRR*RsR/RRrtrootSnapshotRQRrRotRevertToCurrentSnapshotRHROR>tRevertRVRWRR(
RSRcR�RItsuppress_power_onR�tmsgRYRJRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytrevert_to_snapshot�s<	'!	
#	
c	C@sg|dkrtd��n|dkr0i}n|rQd|krQ|jd�nd}t|jdt��}|s�td��ntjjjt	�t
j|�}t||�s�td��nyDt||�j
}|j|�}tjjj||ddd	�Wn0tk
r9}tjd
||dtj�dSX|j
rcit|j
j|j
j�d
6SdS(u-
    Remove a snapshot of the specified virtual machine in this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -a remove_snapshot vmname snapshot_name="mySnapshot"
        salt-cloud -a remove_snapshot vmname snapshot_name="mySnapshot" [remove_children="True"]
    uactionu>The create_snapshot action must be called with -a or --action.u
snapshot_nameuremove_childrenu>You must specify snapshot name for the snapshot to be deleted.u5Сould not find the snapshot with the specified name.uremove snapshotiuinfou'Error while removing snapshot of %s: %sRPufailed to remove snapshotuSnapshot removed successfullyuSnapshots removed successfullyN(RR#R�R%R	RRR*RsR/RRrROR>tRemoveSnapshot_TaskRVRWRQRrRRR@RKR((	RSRcR�RItremove_childrenR�tsnap_objRYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytremove_snapshot�s:	'!#	
	cC@s�|dkrtd��ntjjjt�tj|�}y/|j�}tjjj	||ddd�Wn0t
k
r�}tjd||dt
j�dSXd	S(
u�
    Remove all the snapshots present for the specified virtual machine.

    .. note::

        All the snapshots higher up in the hierarchy of the current snapshot tree
        are consolidated and their virtual disks are merged. To override this
        behavior and only remove all snapshots, set ``merge_snapshots=False``.
        Default is ``merge_snapshots=True``

    CLI Example:

    .. code-block:: bash

        salt-cloud -a remove_all_snapshots vmname [merge_snapshots=False]
    uactionuCThe remove_all_snapshots action must be called with -a or --action.uremove snapshotsiuinfou+Error while removing snapshots on VM %s: %sRPuFailed to remove snapshotsuRemoved all snapshots(RRRR*RsR/RRrtRemoveAllSnapshotsRVRWRQRrRR(RSRcR�R�RYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytremove_all_snapshots4s 	#	
cC@s�|dkrtd��ntjjjt�tj|�}|jj	r`tdj
|���ny|j�Wn0tk
r�}t
jd||dtj�dSXdj
|�S(u�
    Convert the specified virtual machine to template.

    CLI Example:

    .. code-block:: bash

        salt-cloud -a convert_to_template vmname
    uactionuBThe convert_to_template action must be called with -a or --action.u{0} already a templateu,Error while converting VM to template %s: %sRPufailed to convert to teamplateu{0} converted to template(RRRR*RsR/RRrR
RQRHtMarkAsTemplateRWRQRrRR(RSRcR�R�RZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytconvert_to_template^s"
!	
cC@s:|dkrtd��n|r<d|kr<|jd�nd3}|rcd|krc|jd�nd3}|r�d|kr�|jd�nd3}tjdt�tdt�}tjdt�tdt�}tjd	t�tdt�}|s�td
��n|std��n|s)td��n|r5|sB|p>|rQtd
��nt�}|r�t	j
jj|t
j|�}	|	s�td��q�n|r�t	j
jj|t
j|�}
|
s�td��q�nt
jjd|d|d|�}|r||_n2tjd�y�tjd�tjd4dtjdtj�}tjddddj|�fd|jdtjdtj�}
tjd5d|
jdtjdtj�}t	j
jj|jj��}|jd"�d#j�}tjd$|�||_Wn7t k
r6}tj!d%||d&t"j#�id'|6SXy�|rj|	j$d(|d)t%�}d*j|�}n|r�|
j&j'd(|d+t%�}d,j|�}nt	j
jj(||d-d.d/�Wnot k
r.}t)|t
j*j+�rtj!d0�tj,d1|j�ntj!d2||d&t"j#�id'|6SXi||6S(6u
    Add a host system to the specified cluster or datacenter in this VMware environment

    .. note::

        To use this function, you need to specify ``esxi_host_user`` and
        ``esxi_host_password`` under your provider configuration set up at
        ``/etc/salt/cloud.providers`` or ``/etc/salt/cloud.providers.d/vmware.conf``:

        .. code-block:: yaml

            vcenter01:
              driver: vmware
              user: 'DOMAIN\user'
              password: 'verybadpass'
              url: 'vcenter01.domain.com'

              # Required when adding a host system
              esxi_host_user: 'root'
              esxi_host_password: 'myhostpassword'
              # Optional fields that can be specified when adding a host system
              esxi_host_ssl_thumbprint: '12:A3:45:B6:CD:7E:F8:90:A1:BC:23:45:D6:78:9E:FA:01:2B:34:CD'

        The SSL thumbprint of the host system can be optionally specified by setting
        ``esxi_host_ssl_thumbprint`` under your provider configuration. To get the SSL
        thumbprint of the host system, execute the following command from a remote
        server:

        .. code-block:: bash

            echo -n | openssl s_client -connect <YOUR-HOSTSYSTEM-DNS/IP>:443 2>/dev/null | openssl x509 -noout -fingerprint -sha1

    CLI Example:

    .. code-block:: bash

        salt-cloud -f add_host my-vmware-config host="myHostSystemName" cluster="myClusterName"
        salt-cloud -f add_host my-vmware-config host="myHostSystemName" datacenter="myDatacenterName"
    ufunctionu;The add_host function must be called with -f or --function.uhostuclusteru
datacenteruesxi_host_userR&uesxi_host_passworduesxi_host_ssl_thumbprintuAYou must specify the ESXi host username in your providers config.uAYou must specify the ESXi host password in your providers config.u>You must specify either the IP or DNS name of the host system.u@You must specify either the cluster name or the datacenter name.u!Specified cluster does not exist.u$Specified datacenter does not exist.R&tuserNameR.u?SSL thumbprint has not been specified in provider configurationu>Trying to get the SSL thumbprint directly from the host systemuechou-ntstdouttstderruopensslus_clientu-connectu{0}:443tstdinux509u-nooutu-fingerprintu-sha1u=i����u0SSL thumbprint received from the host system: %su7Error while trying to get SSL thumbprint of host %s: %sRPufailed to add hostR�tasConnectedu added host system to cluster {0}taddConnectedu#added host system to datacenter {0}uadd host systemiuinfou:Authenticity of the host's SSL certificate is not verifieduTTry again after setting the esxi_host_ssl_thumbprint to %s in provider configurationuError while adding host %s: %sN(uechou-n(uopensslux509u-nooutu-fingerprintu-sha1(-RR�R#R
RRRR	R/RRR*RsRR�R�R\tConnectSpect
sslThumbprintRQR�Rot
subprocesstPopentPIPERHRutstringutilstto_strtreadRRlRWRrRRtAddHostR"R.tAddStandaloneHostRVRtfaulttSSLVerifyFaultR�(RcR�RR0R+t	host_usert
host_passwordthost_ssl_thumbprintR�RR�R�tp1tp2tp3Rtssl_thumbprintRZRYR�((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytadd_host�s�('''		

						
	
#
	
	
cC@s.|dkrtd��n|r<d|kr<|jd�nd
}|sWtd��nt�}tjjj|tj	|�}|s�td��nyVt
|jtj�r�|j
�}n|jj
�}tjjj||ddd�Wn7tk
r"}tjd	||d
tj�id|6SXid|6S(u�
    Remove the specified host system from this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f remove_host my-vmware-config host="myHostSystemName"
    ufunctionu>The remove_host function must be called with -f or --function.uhostu)You must specify name of the host system.u%Specified host system does not exist.uremove hostRuinfou Error while removing host %s: %sRPufailed to remove hosturemoved host from vcenterN(RR�R#R/RRR*RsRR�RR�R�R�RVRWRQRrRR(RcR�RR�RRYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytremove_host+s0
'	#	
cC@s$|dkrtd��n|r<d|kr<|jd�nd}|sWtd��nt�}tjjj|tj	|�}|s�td��n|j
jdkr�id|6Sy/|j�}tjjj
||dd	d
�Wn7tk
r}tjd||dtj�id
|6SXid|6S(u�
    Connect the specified host system in this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f connect_host my-vmware-config host="myHostSystemName"
    ufunctionu?The connect_host function must be called with -f or --function.uhostu)You must specify name of the host system.u%Specified host system does not exist.u	connecteduhost system already connecteduconnect hostiuinfou"Error while connecting host %s: %sRPufailed to connect hostuconnected hostN(RR�R#R/RRR*RsRR�RRtReconnectHost_TaskRVRWRQRrRR(RcR�RR�RRYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytconnect_host_s0
'	#	
cC@s$|dkrtd��n|r<d|kr<|jd�nd}|sWtd��nt�}tjjj|tj	|�}|s�td��n|j
jdkr�id|6Sy/|j�}tjjj
||dd	d
�Wn7tk
r}tjd||dtj�id
|6SXid|6S(u�
    Disconnect the specified host system in this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f disconnect_host my-vmware-config host="myHostSystemName"
    ufunctionuBThe disconnect_host function must be called with -f or --function.uhostu)You must specify name of the host system.u%Specified host system does not exist.udisconnectedu host system already disconnectedudisconnect hostRuinfou%Error while disconnecting host %s: %sRPufailed to disconnect hostudisconnected hostN(RR�R#R/RRR*RsRR�RRtDisconnectHost_TaskRVRWRQRrRR(RcR�RR�RRYRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytdisconnect_host�s0
'	#	
cC@s�|dkrtd��n|r<d|kr<|jd�nd}|rid|krit|jd��nt}|s�td��nt�}tjjj	|t
j|�}|s�td��n|jj
dkr�td��n|jjs�td	��n|jjstd
��ny$|j|�t|ddd
�Wn7tk
rt}tjd||dtj�id|6SXid|6S(u�
    Reboot the specified host system in this VMware environment

    .. note::

        If the host system is not in maintenance mode, it will not be rebooted. If you
        want to reboot the host system regardless of whether it is in maintenance mode,
        set ``force=True``. Default is ``force=False``.

    CLI Example:

    .. code-block:: bash

        salt-cloud -f reboot_host my-vmware-config host="myHostSystemName" [force=True]
    ufunctionu>The reboot_host function must be called with -f or --function.uhostuforceu)You must specify name of the host system.u%Specified host system does not exist.u
notRespondinguPSpecified host system cannot be rebooted in it's current state (not responding).u.Specified host system does not support reboot.u�Specified host system is not in maintenance mode. Specify force=True to force reboot even if there are virtual machines running or other operations in progress.urebooti
uinfou!Error while rebooting host %s: %sRPufailed to reboot hostu
rebooted hostN(RR�R#R%R	R/RRR*RsRR�RRt
capabilitytrebootSupportedRMtRebootHost_TaskR RWRQRrRR(RcR�RtforceR�RRZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytreboot_host�s@'-	
	
c	C@s{|dkrtd��n|r<d|kr<|jd�nd}|rcd|krc|jd�nd}|s~td��n|s�t|�dkr�td��n|s�td��nt�}tjjj|t	j
|�}|r�id	|6Stjjj|t	j|�}|s&td
��ny|jj
d|�Wn0tk
ro}tjd||d
tj�tSXid|6S(u
    Create a new datastore cluster for the specified datacenter in this VMware environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f create_datastore_cluster my-vmware-config name="datastoreClusterName" datacenter="datacenterName"
    ufunctionuKThe create_datastore_cluster function must be called with -f or --function.unameu
datacenteruAYou must specify name of the new datastore cluster to be created.iPuQThe datastore cluster name must be a non empty string of less than 80 characters.uVYou must specify name of the datacenter where the datastore cluster should be created.u datastore cluster already existsu(The specified datacenter does not exist.RSu'Error creating datastore cluster %s: %sRPucreatedN(RR�R#R�R/RRR*RsRROR�tdatastoreFoldertCreateStoragePodRWRQRrRRR	(RcR�tdatastore_cluster_nameR+R�RcR�RZ((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pytcreate_datastore_cluster
s>
''		
(�t__doc__t
__future__RRRtrandomRR�R�RR�tos.pathRSR|tsalt.utils.cloudRtsalt.utils.networktsalt.utils.stringutilstsalt.utils.xmlutiltsalt.utils.vmwaretsalt.exceptionsRtsalt.configR
tsalt.extRtpyVmomiRR"RtImportErrorR	trequests.packages.urllib3RR�R�RRRR tIP_REt	getLoggerRpRQRRRR
RR%R/R#R?RhR�R�R�R�R�R�R�R�R�R�R�R�R�RR
RR R8R:R@RGROR[RbRdR�RiRjRkRlRmRnRoRpRuRwRxRyRzR|R}R~RR�R�R�R�R�R�R�R�RR�R!R�R,R2R8R9R:R=RARBRHRIRJRORQR_RdRkRoRqRsR�R�R�R�R�R�(((s</usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.pyt<module>ss



	
		
		
	BMD			1	!			+			
�		'	/	�	c		
1	93X*(1-919-M	��			9E0".,.Y++MNG:*'�422G

Zerion Mini Shell 1.0