%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s=dZddlmZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddlm
Z
ddlZddljjZddlZddlZddlZddlZddlZddlmZdd	lmZdd
lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)m*Z*dd
l+m,Z,ddl-m.Z.m/Z/m0Z0ddl1m2Z2m3Z3ej4e5�Z6yddl7Z7e8Z9Wne:k
r�e;Z9nXy�ddl<m=Z=m>Z>m?Z?m@Z@de@jAkoEejBddfkoEejBdddfkrae6jCd�e:��ne8ZDWne:k
r�e;ZDnXejjEjFd�ZGeGr�e8ZHne;ZHdZIdddddgZJd�ZKd�ZLd�ZMd �ZNd!�ZOe&eD�eNddddd�ePd"���ZQe&eD�eNddddd�d#���ZRe&eH�ePePePePePePePd$��ZSe&eH�ePePePePd%��ZTe&eH�ePePePePd&��ZUe&eH�ePePd'd(ePePd)��ZVe&eH�ePePePePd*��ZWe&eH�ePePePePd+��ZXe&eH�ePePePePd,��ZYe&eH�ePePe8e8ePePd-��ZZe&eH�ePePePePd.��Z[e&eH�ePePePePePd/��Z\e'd0�ePePePePe;d1��Z]e'd0�ePePe;d2��Z^e&eD�e'd0�ePePePd3���Z_e&eD�e'd0�ePePePd4���Z`e&eD�e'd0�ePePePd5���Zae&eD�e'd0�ePePePd6���Zbe&eD�e'd0�ePePePd7���Zce&eD�e'd0�ePePePd8���Zde&eD�e'd0�ePePePd9���Zee&eD�eNddddd�eOePd:����Zfe&eD�e'd0�ePePd;���Zge&eD�e'd0�ePePd<���Zhe&eD�e'd0�ePePd=���Zie&eD�e'd0�ePePd>���Zje&eD�e'd0�ePePd?���Zke&eD�e'd0�ePePd@���Zle&eD�e'd0�ePePdA���Zme&eD�e'd0�ePePdB���Zne&eD�e'd0�ePePdC���Zoe&eD�e'd0�ePePdD���Zpe&eD�e'd0�ePePdE���Zqe&eD�e'd0�ePePdF���Zre&eD�e'd0�ePePePdG���Zse&eD�e'd0�ePePePdH���Zte&eD�e'd0�ePePePdI���Zue&eD�e'd0�ePePePdJ���Zve&eD�e'd0�ePePePdK���Zwe&eD�e'd0�ePePePdL���Zxe&eD�e'd0�ePePePdM���Zye&eD�e'd0�ePePePdN���Zze&eD�e'd0�ePePdO���Z{e&eD�e'd0�ePePePdP���Z|e&eD�e'd0�ePePePd'dQ���Z}e&eD�e'd0�ePePePdR���Z~e&eD�e'd0�ePePePdS���Ze&eD�e'd0�ePePePdT���Z�dU�Z�dV�Z�dW�Z�dX�Z�dY�Z�e&eD�eNdd�eOePePePdZ����Z�d[�Z�d\�Z�d]�Z�d^�Z�d_�Z�d`�Z�e&eD�eNdd�eOePda����Z�e&eD�eNdd�eOePdb����Z�dc�Z�dd�Z�de�Z�df�Z�e&eD�eNdd�eOePePePdg����Z�e&eD�eNdd�eOePdh����Z�di�Z�dj�Z�dk�Z�dl�Z�e&eD�eNdd�eOePdm����Z�e&eD�eNdd�eOe8dn����Z�e&eD�eNdd�eOePdo����Z�dp�Z�e&eD�eNdd�eOePePdq����Z�e&eD�eNdd�eOePdr����Z�ds�Z�e&eD�eNdd�eOePdt����Z�du�Z�e&eD�eNdd�eOePdv����Z�e&eD�eNdd�eOePdw����Z�e&eD�eNddd�eOePdx����Z�e&eD�eNddd�eOePdy����Z�e&eD�eNdddd�eOePePdz����Z�e&eD�eNdd�eOePd{����Z�d|�Z�e&eD�eNdd�eOePePePd}����Z�ePe8d~�Z�e&eD�e&e9�eNdd�eOePePePd�����Z�e&eD�e&e9�eNdd�eOePePePd������Z�e&eD�eNddd�eOePePePePd�����Z�e&eD�e&e9�eNd�eOe8ePd������Z�e&eD�eNddd�eOePd�����Z�e&eD�eNddd�eOePd�����Z�e&eD�eNdd�eOePd�����Z�e&eD�eNdd�eOe8ePd�����Z�d��Z�d��Z�e&eD�e&e9�eNdd�eOePePd������Z�e&eD�e&e9�eNdd�eOe8ePd������Z�e&eD�eNdddd�eOePePePePd�����Z�e&eD�eNd�eOePePePd�����Z�e&eD�eNd�eOePePePd�����Z�e&eD�eNd�eOePePePd�����Z�e&eD�eNd�eOePePd�����Z�e&eD�e&e9�eNd�eOe8ePd������Z�e&eD�e&e9�eNd�eOe8ePd������Z�e&eD�e&e9�eNd�eOe8e8ePd������Z�e&eD�e&e9�eNd�eOe8ePd������Z�e&eD�eNd�eOePd�����Z�e&eD�e&e9�eNd�eOePePePd������Z�d��Z�d��Z�d��Z�d��Z�d��Z�ePd��Z�d��Z�d��Z�d��Z�d��Z�d��Z�ePePePePd��Z�ePePePePePd��Z�e&eD�e'd0�ePePePd����Z�e&eD�eNdddd�d����Z�d��Z�d��Z�d��Z�e&eD�eOePePePePePd����Z�e&eD�eOePd����Z�d�d��Z�d��Z�d��Z�e&eD�eNddd�eOePd�����Z�ePd��Z�e&eD�eNddd�eOePd�����Z�d��Z�e&eD�eNddd�eOePd�����Z�d��Z�ePePd�ePePePePePd��Z�d�d��Z�d��Z�ePd�ePePePd��Z�d��Z�d��Z�dd��Z�d��Z�dd��Z�ePePePd�ePd��Z�d��Z�d�d��Z�ePePd��Z�d��Z�ePd��Z�d��Z�ePePd��Z�d��Z�d��Z�d��Z�d��Z�eOePe8ePd���Z�d��Z�d��Z�d��Z�d��Z�ePePd��Z�d��Z�e&eD�eNddd�eOePePePePePePd�����Z�e&eD�eNddd�eOePePePePePePePePePePePePePePd�����Z�e&eD�eNddd�eOePd�����Z�e&eD�eNddd�eOePePd�����Z�e&eD�eNddd�eOePePd�����Z�ePePd��Ze&eD�eNddd�eOePe;ePd�����Ze&eD�eNddd�eOePe;ePd�����ZdS(�s&
Manage VMware vCenter servers and ESXi hosts.

.. versionadded:: 2015.8.4

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

Dependencies
============

- pyVmomi Python Module
- 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.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 vSphere Execution
Module was developed against.

ESXCLI
------

Currently, about a third of the functions used in the vSphere Execution Module require
the ESXCLI package be installed on the machine running the Proxy Minion process.

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.

.. note::

    Be aware that some functionality in this execution module may depend on the
    type of license attached to a vCenter Server or ESXi host(s).

    For example, certain services are only available to manipulate service state
    or policies with a VMware vSphere Enterprise or Enterprise Plus license, while
    others are available with a Standard license. The ``ntpd`` service is restricted
    to an Enterprise Plus license, while ``ssh`` is available via the Standard
    license.

    Please see the `vSphere Comparison`_ page for more information.

.. _vSphere Comparison: https://www.vmware.com/products/vsphere/compare


About
=====

This execution module was designed to be able to handle connections both to a
vCenter Server, as well as to an ESXi host. It utilizes the pyVmomi Python
library and the ESXCLI package to run remote execution functions against either
the defined vCenter server or the ESXi host.

Whether or not the function runs against a vCenter Server or an ESXi host depends
entirely upon the arguments passed into the function. Each function requires a
``host`` location, ``username``, and ``password``. If the credentials provided
apply to a vCenter Server, then the function will be run against the vCenter
Server. For example, when listing hosts using vCenter credentials, you'll get a
list of hosts associated with that vCenter Server:

.. code-block:: bash

    # salt my-minion vsphere.list_hosts <vcenter-ip> <vcenter-user> <vcenter-password>
    my-minion:
    - esxi-1.example.com
    - esxi-2.example.com

However, some functions should be used against ESXi hosts, not vCenter Servers.
Functionality such as getting a host's coredump network configuration should be
performed against a host and not a vCenter server. If the authentication
information you're using is against a vCenter server and not an ESXi host, you
can provide the host name that is associated with the vCenter server in the
command, as a list, using the ``host_names`` or ``esxi_host`` kwarg. For
example:

.. code-block:: bash

    # salt my-minion vsphere.get_coredump_network_config <vcenter-ip> <vcenter-user>         <vcenter-password> esxi_hosts='[esxi-1.example.com, esxi-2.example.com]'
    my-minion:
    ----------
        esxi-1.example.com:
            ----------
            Coredump Config:
                ----------
                enabled:
                    False
        esxi-2.example.com:
            ----------
            Coredump Config:
                ----------
                enabled:
                    True
                host_vnic:
                    vmk0
                ip:
                    coredump-location.example.com
                port:
                    6500

You can also use these functions against an ESXi host directly by establishing a
connection to an ESXi host using the host's location, username, and password. If ESXi
connection credentials are used instead of vCenter credentials, the ``host_names`` and
``esxi_hosts`` arguments are not needed.

.. code-block:: bash

    # salt my-minion vsphere.get_coredump_network_config esxi-1.example.com root <host-password>
    local:
    ----------
        10.4.28.150:
            ----------
            Coredump Config:
                ----------
                enabled:
                    True
                host_vnic:
                    vmk0
                ip:
                    coredump-location.example.com
                port:
                    6500
i(tabsolute_importN(twraps(tsix(trange(tzip(t	list_diff(trecursive_diff(tCommandExecutionErrortVMwareSaltErrortArgumentValueErrortInvalidConfigErrortVMwareObjectRetrievalErrortVMwareApiErrortInvalidEntityErrortVMwareObjectExistsError(tdependstignores_kwargs(tESXClusterConfigSchematESXClusterEntitySchema(tVCenterEntitySchema(tDiskGroupsDiskIdSchematVmfsDatastoreSchematSimpleHostCacheSchema(tESXVirtualMachineDeleteSchemat!ESXVirtualMachineUnregisterSchema(tvimtvmodltpbmtVmomiSupports	vim25/6.0iii	sFpyVmomi not loaded: Incompatible versions of Python. See Issue #29537.tesxclitvspheretesxit
esxclustert
esxdatacentertvcentertesxvmcC@stS(N(t__virtualname__(((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt__virtual__�scC@sRtjdi�jd�r'tddStjdi�jd�rNtddSdS(s�
    Returns the proxy type retrieved either from the pillar of from the proxy
    minion's config.  Returns ``<undefined>`` otherwise.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.get_proxy_type
    tproxyt	proxytypes<undefined>(t
__pillar__tgett__opts__(((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_proxy_type�s
c	C@s)t�}|dkr%td�}n�|dkrAtd�}ni|dkr]td�}nM|dkrytd�}n1|d	kr�td
�}ntdj|���d|kr�|jd�n|jd�|jd
�|jd�|jd�|jd�|jd�|jd�|jd�fS(sG
    Returns the connection details of the following proxies: esxi
    Rsesxi.get_detailsR sesxcluster.get_detailsR!sesxdatacenter.get_detailsR"svcenter.get_detailsR#sesxvm.get_detailss'{0}' proxy is not supportedthosttusernametpasswordtprotocoltportt	mechanismt	principaltdomain(R+t__salt__RtformatR)(R'tdetails((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_proxy_connection_details�s&		c@s�fd�}|S(s�
    Decorator to specify which proxy types are supported by a function

    proxy_types:
        Arbitrary list of strings with the supported types of proxies
    c@s"t����fd��}|S(Nc@sOt�}|�kr3tdj|�j���n�|tjjj|��S(Ns,'{0}' proxy is not supported by function {1}(R+RR5t__name__tsalttutilstargstclean_kwargs(R;tkwargst
proxy_type(tfntproxy_types(s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt__supports_proxies s	(R(R?RA(R@(R?s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_supports_proxiess((R@RB((R@s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytsupports_proxiess
c@s��j�y(tj��\�}��}}}Wn,tk
r_tj��\�}��nX�dk	rr�ng�t�������fd��}|S(s�
    Decorator that connects to a target system (vCenter or ESXi host) using the
    proxy details and passes the connection (vim.ServiceInstance) to
    the decorated function.

    Supported proxies: esxi, esxcluster, esxdatacenter.

    Notes:
        1. The decorated function must have a ``service_instance`` parameter
        or a ``**kwarg`` type argument (name of argument is not important);
        2. If the ``service_instance`` parameter is already defined, the value
        is passed through to the decorated function;
        3. If the ``service_instance`` parameter in not defined, the
        connection is created using the proxy details and the service instance
        is returned.

    CLI Example:
        None, this is a decorator
    c@s�d�kr+�r+tdj����nt�}d}d�kr��jd�}|t��t��kr&t|�|kr�||s�tjjj	|�}t
|�}|||<q�q�|jd�s�tjjj	|�}||d<q�q&n1|jd�s&tjjj	|�}||d<nyB�|tjjj
|��}|rctjjj|�n|SWnBtk
r�}|r�tjjj|�ntjtj��nXdS(Ntservice_instancesRFunction {0} must have either a 'service_instance', or a '**kwargs' type parameter(RR5R7tNonetindextlenR9R:tvmwaretget_service_instancetlistR)R;R<t
disconnectt	ExceptionRtreraisetsystexc_info(R;R=tconnection_detailstlocal_service_instancetidxtrette(t	arg_namestdefault_valuesR?tfn_nametkwargs_name(s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt _gets_service_instance_via_proxyJs@	
			
N(R8tinspecttgetfullargspectAttributeErrort
getargspecRER(R?t	args_namet_RY((RURVR?RWRXs8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytgets_service_instance_via_proxy,s	(
'>cC@st�}tjjj|�S(s3
    Returns a service instance to the proxied endpoint (vCenter/ESXi host).

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    Note:
        Should be used by state functions not invoked directly.

    CLI Example:
        See note above
    (R7R9R:RHRI(RDRP((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_service_instance_via_proxy�s	cC@stjjj|�tS(s�
    Disconnects from a vCenter or ESXi host

    Note:
        Should be used by state functions, not invoked directly.

    service_instance
        Service instance (vim.ServiceInstance)

    CLI Example:

        See note above.
    (R9R:RHRKtTrue(RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRK�scC@s>i}|r�t|t�s*td��nx
|D]�}	tjjj||||d|d|d|	d|�}
|
ddkr�|jii|
jd�d	6|	6�q1|ji|
|	6�q1Wn{tjjj||||d|d|d|�}
|
ddkr&|jii|
jd�d	6|6�n|ji|
|6�|S(
s�
    Run an ESXCLI command directly on the host or list of hosts.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    cmd_str
        The ESXCLI command to run. Note: This should not include the ``-s``, ``-u``,
        ``-p``, ``-h``, ``--protocol``, or ``--portnumber`` arguments that are
        frequently passed when using a bare ESXCLI command from the command line.
        Those arguments are handled by this function via the other args and kwargs.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    esxi_hosts
        If ``host`` is a vCenter host, then use esxi_hosts to execute this function
        on a list of one or more ESXi machines.

    credstore
        Optionally set to path to the credential store file.

    CLI Example:

    .. code-block:: bash

        # Used for ESXi host connection information
        salt '*' vsphere.esxcli_cmd my.esxi.host root bad-password             'system coredump network get'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.esxcli_cmd my.vcenter.location root bad-password             'system coredump network get' esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'
    s'esxi_hosts' must be a list.R/R0t	esxi_hostt	credstoretretcodeitstdouttError(	t
isinstanceRJRR9R:RHRtupdateR)(tcmd_strR,R-R.R/R0t
esxi_hostsRdRSRctresponse((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt
esxcli_cmd�s$/
'	'cC@sdd}i}|r�t|t�s0td��nx-|D]�}	tjjj||||d|d|d|	d|�}
|
ddkr�|jii|
jd	�d
6|	6�q7|jiit	|
�d6|	6�q7Wn�tjjj||||d|d|d|�}
|
ddkr9|jii|
jd	�d
6|6�n't	|
�}|jii|d6|6�|S(sh
    Retrieve information on ESXi or vCenter network dump collection and
    format it into a dictionary.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    esxi_hosts
        If ``host`` is a vCenter host, then use esxi_hosts to execute this function
        on a list of one or more ESXi machines.

    credstore
        Optionally set to path to the credential store file.

    :return: A dictionary with the network configuration, or, if getting
             the network config failed, a an error message retrieved from the
             standard cmd.run_all dictionary, per host.

    CLI Example:

    .. code-block:: bash

        # Used for ESXi host connection information
        salt '*' vsphere.get_coredump_network_config my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.get_coredump_network_config my.vcenter.location root bad-password             esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'

    ssystem coredump network gets'esxi_hosts' must be a list.R/R0RcRdReiRfRgsCoredump Config(
RhRJRR9R:RHRRiR)t_format_coredump_stdout(R,R-R.R/R0RkRdtcmdRSRcRlRf((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_coredump_network_config�s(.
'(	'c
C@sp|rd}nd}dj|�}	i}
|r�t|t�sNtd��nx|D]�}tjjj||||	d|d|d|d|�}|d	dkr�|
jii|j	d
�d6|6�qU|
jii|d6|6�qUWn�tjjj||||	d|d|d|�}|d	dkrQ|
jii|j	d
�d6|6�n|
jii|d6|6�|
S(
s}
    Enable or disable ESXi core dump collection. Returns ``True`` if coredump is enabled
    and returns ``False`` if core dump is not enabled. If there was an error, the error
    will be the value printed in the ``Error`` key dictionary for the given host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    enabled
        Python True or False to enable or disable coredumps.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    esxi_hosts
        If ``host`` is a vCenter host, then use esxi_hosts to execute this function
        on a list of one or more ESXi machines.

    credstore
        Optionally set to path to the credential store file.

    CLI Example:

    .. code-block:: bash

        # Used for ESXi host connection information
        salt '*' vsphere.coredump_network_enable my.esxi.host root bad-password True

        # Used for connecting to a vCenter Server
        salt '*' vsphere.coredump_network_enable my.vcenter.location root bad-password True             esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'
    iis"system coredump network set -e {0}s'esxi_hosts' must be a list.R/R0RcRdReRfRgsCoredump Enabled(
R5RhRJRR9R:RHRRiR)(
R,R-R.tenabledR/R0RkRdt	enable_itRoRSRcRl((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytcoredump_network_enableHs,-	
'"	'tvmk0idc
C@s3dj|||�}
i}|r�t|t�s?td��nx�|D]w}tjjj||||
d|d|d|d|	�}
|
ddkr�t|
d	<n
t	|
d	<|j
i|
|6�qFWnktjjj||||
d|d|d|	�}
|
ddkrt|
d	<n
t	|
d	<|j
i|
|6�|S(
s�

    Set the network parameters for a network coredump collection.
    Note that ESXi requires that the dumps first be enabled (see
    `coredump_network_enable`) before these parameters may be set.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    dump_ip
        IP address of host that will accept the dump.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    esxi_hosts
        If ``host`` is a vCenter host, then use esxi_hosts to execute this function
        on a list of one or more ESXi machines.

    host_vnic
        Host VNic port through which to communicate. Defaults to ``vmk0``.

    dump_port
        TCP port to use for the dump, defaults to ``6500``.

    credstore
        Optionally set to path to the credential store file.

    :return: A standard cmd.run_all dictionary with a `success` key added, per host.
             `success` will be True if the set succeeded, False otherwise.

    CLI Example:

    .. code-block:: bash

        # Used for ESXi host connection information
        salt '*' vsphere.set_coredump_network_config my.esxi.host root bad-password 'dump_ip.host.com'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.set_coredump_network_config my.vcenter.location root bad-password 'dump_ip.host.com'             esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'
    s0system coredump network set -v {0} -i {1} -o {2}s'esxi_hosts' must be a list.R/R0RcRdReitsuccess(R5RhRJRR9R:RHRtFalseRbRi(R,R-R.tdump_ipR/R0t	host_vnict	dump_portRkRdRoRSRcRl((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytset_coredump_network_config�s.@		


	

cC@sbd}i}|r�t|t�s0td��nx+|D]�}	tjjj||||d|d|d|	d|�}
|
ddkr�|jii|
d	d
6td6d
d6|	6�q7|jit
|
�|	6�q7Wn�tjjj||||d|d|d|�}
|
ddkrD|jii|
d	d
6td6d
d6|6�n|jit
|
�|6�|S(s[
    Show status of all firewall rule sets.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    esxi_hosts
        If ``host`` is a vCenter host, then use esxi_hosts to execute this function
        on a list of one or more ESXi machines.

    credstore
        Optionally set to path to the credential store file.

    :return: Nested dictionary with two toplevel keys ``rulesets`` and ``success``
             ``success`` will be True or False depending on query success
             ``rulesets`` will list the rulesets and their statuses if ``success``
             was true, per host.

    CLI Example:

    .. code-block:: bash

        # Used for ESXi host connection information
        salt '*' vsphere.get_firewall_status my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.get_firewall_status my.vcenter.location root bad-password             esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'
    snetwork firewall ruleset lists'esxi_hosts' must be a list.R/R0RcRdReiRfRgRutrulesetsN(RhRJRR9R:RHRRiRvREt_format_firewall_stdout(R,R-R.R/R0RkRdRoRSRcRl((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_firewall_status�s.-
!	c	
C@s�dj||�}	i}
|r�t|t�s<td��nx�|D]P}tjjj||||	d|d|d|d|�}|
ji||6�qCWnDtjjj||||	d|d|d|�}|
ji||6�|
S(s-
    Enable or disable an ESXi firewall rule set.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    ruleset_enable
        True to enable the ruleset, false to disable.

    ruleset_name
        Name of ruleset to target.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    esxi_hosts
        If ``host`` is a vCenter host, then use esxi_hosts to execute this function
        on a list of one or more ESXi machines.

    credstore
        Optionally set to path to the credential store file.

    :return: A standard cmd.run_all dictionary, per host.

    CLI Example:

    .. code-block:: bash

        # Used for ESXi host connection information
        salt '*' vsphere.enable_firewall_ruleset my.esxi.host root bad-password True 'syslog'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.enable_firewall_ruleset my.vcenter.location root bad-password True 'syslog'             esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'
    s;network firewall ruleset set --enabled {0} --ruleset-id={1}s'esxi_hosts' must be a list.R/R0RcRd(	R5RhRJRR9R:RHRRi(
R,R-R.truleset_enabletruleset_nameR/R0RkRdRoRSRcRl((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytenable_firewall_rulesetFs 8
	cC@s�d}i}|r�t|t�s0td��nx�|D]P}	tjjj||||d|d|d|	d|�}
|ji|
|	6�q7WnDtjjj||||d|d|d|�}
|ji|
|6�|S(s
    Reload the syslog service so it will pick up any changes.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    esxi_hosts
        If ``host`` is a vCenter host, then use esxi_hosts to execute this function
        on a list of one or more ESXi machines.

    credstore
        Optionally set to path to the credential store file.

    :return: A standard cmd.run_all dictionary.  This dictionary will at least
             have a `retcode` key.  If `retcode` is 0 the command was successful.

    CLI Example:

    .. code-block:: bash

        # Used for ESXi host connection information
        salt '*' vsphere.syslog_service_reload my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.syslog_service_reload my.vcenter.location root bad-password             esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'
    ssystem syslog reloads'esxi_hosts' must be a list.R/R0RcRd(RhRJRR9R:RHRRi(R,R-R.R/R0RkRdRoRSRcRl((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytsyslog_service_reload�s+
	cC@s�i}|r�|dkr�|	r�t|	t�s<td��nxP|	D]�}t|||dtddd|d|d|gd	|
�j|�}
|
d
dkr�|jiii|
dd
6td6d6|6�qC|jiiitd6d6|6�qCWq�t|||dtddd|d|d	|
�j|�}
|
d
dkrm|jiii|
dd
6td6d6|6�q�|jiiitd6d6|6�n|	r=t|	t�s�td��nx�|	D]y}t|||||d|d|d|d|d	|
�}
|j|�dkr%|jii|6�n||j|
�q�Wnmt|||||d|d|d|d	|
�}
|j|�dkr�|jii|6�n||j|
�|S(s6	
    Set the specified syslog configuration parameter. By default, this function will
    reset the syslog service after the configuration is set.

    host
        ESXi or vCenter host to connect to.

    username
        User to connect as, usually root.

    password
        Password to connect with.

    syslog_config
        Name of parameter to set (corresponds to the command line switch for
        esxcli without the double dashes (--))

        Valid syslog_config values are ``logdir``, ``loghost``, ``default-rotate`,
        ``default-size``, ``default-timeout``, and ``logdir-unique``.

    config_value
        Value for the above parameter. For ``loghost``, URLs or IP addresses to
        use for logging. Multiple log servers can be specified by listing them,
        comma-separated, but without spaces before or after commas.

        (reference: https://blogs.vmware.com/vsphere/2012/04/configuring-multiple-syslog-servers-for-esxi-5.html)

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    firewall
        Enable the firewall rule set for syslog. Defaults to ``True``.

    reset_service
        After a successful parameter set, reset the service. Defaults to ``True``.

    esxi_hosts
        If ``host`` is a vCenter host, then use esxi_hosts to execute this function
        on a list of one or more ESXi machines.

    credstore
        Optionally set to path to the credential store file.

    :return: Dictionary with a top-level key of 'success' which indicates
             if all the parameters were reset, and individual keys
             for each parameter indicating which succeeded or failed, per host.

    CLI Example:

    .. code-block:: bash

        # Used for ESXi host connection information
        salt '*' vsphere.set_syslog_config my.esxi.host root bad-password             loghost ssl://localhost:5432,tcp://10.1.0.1:1514

        # Used for connecting to a vCenter Server
        salt '*' vsphere.set_syslog_config my.vcenter.location root bad-password             loghost ssl://localhost:5432,tcp://10.1.0.1:1514             esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'

    tloghosts'esxi_hosts' must be a list.R~RtsyslogR/R0RkRdReiRftmessageRutenable_firewallt
reset_serviceRcN(
RhRJRR�RbR)RiRvt_set_syslog_config_helperRE(R,R-R.t
syslog_configtconfig_valueR/R0tfirewallR�RkRdRSRcRl((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytset_syslog_config�sPN
)%
	cC@s�d}i}|r�t|t�s0td��nx�|D]V}	tjjj||||d|d|d|	d|�}
|jit|
�|	6�q7WnJtjjj||||d|d|d|�}
|jit|
�|6�|S(s�
    Retrieve the syslog configuration.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    esxi_hosts
        If ``host`` is a vCenter host, then use esxi_hosts to execute this function
        on a list of one or more ESXi machines.

    credstore
        Optionally set to path to the credential store file.

    :return: Dictionary with keys and values corresponding to the
             syslog configuration, per host.

    CLI Example:

    .. code-block:: bash

        # Used for ESXi host connection information
        salt '*' vsphere.get_syslog_config my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.get_syslog_config my.vcenter.location root bad-password             esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'
    ssystem syslog config gets'esxi_hosts' must be a list.R/R0RcRd(	RhRJRR9R:RHRRit_format_syslog_config(R,R-R.R/R0RkRdRoRSRcRl((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_syslog_configas+
!	cC@sR|std��nddddddg}d}	d	|krjg|jd	�D]}
|
j�^qO}n|d
kr|}n	|g}i}|r
t|t�s�td��nx�|D]M}
t||||	||d|d
|d|
d|�}|ji||
6�q�WnAt||||	||d|d
|d|�}|ji||6�|S(s"
    Reset the syslog service to its default settings.

    Valid syslog_config values are ``logdir``, ``loghost``, ``logdir-unique``,
    ``default-rotate``, ``default-size``, ``default-timeout``,
    or ``all`` for all of these.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    syslog_config
        List of parameters to reset, provided as a comma-delimited string, or 'all' to
        reset all syslog configuration parameters. Required.

    esxi_hosts
        If ``host`` is a vCenter host, then use esxi_hosts to execute this function
        on a list of one or more ESXi machines.

    credstore
        Optionally set to path to the credential store file.

    :return: Dictionary with a top-level key of 'success' which indicates
             if all the parameters were reset, and individual keys
             for each parameter indicating which succeeded or failed, per host.

    CLI Example:

    ``syslog_config`` can be passed as a quoted, comma-separated string, e.g.

    .. code-block:: bash

        # Used for ESXi host connection information
        salt '*' vsphere.reset_syslog_config my.esxi.host root bad-password             syslog_config='logdir,loghost'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.reset_syslog_config my.vcenter.location root bad-password             syslog_config='logdir,loghost' esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'
    sFThe 'reset_syslog_config' function requires a 'syslog_config' setting.tlogdirR�sdefault-rotatesdefault-sizesdefault-timeouts
logdir-uniques!system syslog config set --reset=t,talls'esxi_hosts' must be a list.R/R0RcRd(RtsplittstripRhRJt_reset_syslog_config_paramsRi(R,R-R.R/R0R�RkRdtvalid_resetsRot	ind_resettresetsRSRct
response_dict((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytreset_syslog_config�s4>	+		
	RdcC@sM|dkrd}n|dkr*d}ndj|||�}i}	d}
y�|r�tjjj|dtdtddd|d	|d
|d|�}
nN|r�tjjj|dtdtddd|d	|d|d
td|�}
n|
jd�dkrt|	d<nt|	d<|
d|	d<Wn't	k
rH}t|	d<||	d<nX|	S(s�
    Upload an ssh key for root to an ESXi host via http PUT.
    This function only works for ESXi, not vCenter.
    Only one ssh key can be uploaded for root.  Uploading a second key will
    replace any existing key.

    :param host: The location of the ESXi Host
    :param username: Username to connect as
    :param password: Password for the ESXi web endpoint
    :param ssh_key: Public SSH key, will be added to authorized_keys on ESXi
    :param ssh_key_file: File containing the SSH key.  Use 'ssh_key' or
                         ssh_key_file, but not both.
    :param protocol: defaults to https, can be http if ssl is disabled on ESXi
    :param port: defaults to 443 for https
    :param certificate_verify: If true require that the SSL connection present
                               a valid certificate
    :return: Dictionary with a 'status' key, True if upload is successful.
             If upload is unsuccessful, 'status' key will be False and
             an 'Error' key will have an informative message.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.upload_ssh_key my.esxi.host root bad-password ssh_key_file='/etc/salt/my_keys/my_key.pub'

    thttpsi�s+{0}://{1}:{2}/host/ssh_root_authorized_keyststatusttexttmethodtPUTR-R.tdatat
verify_sslt	data_filetdata_renderi�terrorRgN(
RER5R9R:thttptqueryRbRvR)RL(R,R-R.tssh_keytssh_key_fileR/R0tcertificate_verifyturlRStresulttmsg((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytupload_ssh_keysJ				


c
C@s�|dkrd}n|dkr*d}ndj|||�}i}y�tjjj|dtdtddd|d	|d
|�}|jd�dkr�t|d<|d|d<nt|d<|d
|d<Wn't	k
r�}	t|d<|	|d<nX|S(s�
    Retrieve the authorized_keys entry for root.
    This function only works for ESXi, not vCenter.

    :param host: The location of the ESXi Host
    :param username: Username to connect as
    :param password: Password for the ESXi web endpoint
    :param protocol: defaults to https, can be http if ssl is disabled on ESXi
    :param port: defaults to 443 for https
    :param certificate_verify: If true require that the SSL connection present
                               a valid certificate
    :return: True if upload is successful

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.get_ssh_key my.esxi.host root bad-password certificate_verify=True

    R�i�s+{0}://{1}:{2}/host/ssh_root_authorized_keysR�R�R�tGETR-R.R�i�tkeyR�RgN(
RER5R9R:R�R�RbR)RvRL(
R,R-R.R/R0R�R�RSR�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_ssh_keyNs2					


cC@s�tjjjd|d|d|d|d|�}t|||�}i}xO|D]G}t||d|�}	t|	�}
|
j�}|ji||6�qOW|S(sj
    Get the date/time information for a given host or list of host_names.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to tell
        vCenter the hosts for which to get date/time information.

        If host_names is not provided, the date/time information will be retrieved for the
        ``host`` location instead. This is useful for when service instance connection
        information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.get_host_datetime my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.get_host_datetime my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0t	host_name(	R9R:RHRIt_check_hostst
_get_host_reft_get_date_time_mgrt
QueryDateTimeRi(R,R-R.R/R0t
host_namesRDRSR�thost_reftdate_time_managert	date_time((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_host_datetime�s+	
cC@s�tjjjd|d|d|d|d|�}t|||�}i}xL|D]D}t||d|�}	|	jjjj	j
}
|ji|
|6�qOW|S(sp
    Get the NTP configuration information for a given host or list of host_names.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to tell
        vCenter the hosts for which to get ntp configuration information.

        If host_names is not provided, the NTP configuration will be retrieved for the
        ``host`` location instead. This is useful for when service instance connection
        information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.get_ntp_config my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.get_ntp_config my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�(R9R:RHRIR�R�t
configManagertdateTimeSystemtdateTimeInfot	ntpConfigtserverRi(R,R-R.R/R0R�RDRSR�R�t
ntp_config((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_ntp_config�s+	
cC@s�tjjjd|d|d|d|d|�}dddd	d
ddd
ddddddg}t|||�}i}	xN|D]F}
||kr�|	jiidj|�d6|
6�|	St||d|
�}|jj	j
j}|dks�|d	krd}
n|}
xl|D]d}|j|
krE|	jii|j
|6|
6�Pqdj||
�}|	jii|d6|
6�qW|	j|
�dkrdj|
�}tj|�|	jii|d6|
6�qqW|	S(s�
    Get the service name's policy for a given host or list of hosts.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    service_name
        The name of the service for which to retrieve the policy. Supported service names are:
          - DCUI
          - TSM
          - SSH
          - lbtd
          - lsassd
          - lwiod
          - netlogond
          - ntpd
          - sfcbd-watchdog
          - snmpd
          - vprobed
          - vpxa
          - xorg

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to tell
        vCenter the hosts for which to get service policy information.

        If host_names is not provided, the service policy information will be retrieved
        for the ``host`` location instead. This is useful for when service instance
        connection information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.get_service_policy my.esxi.host root bad-password 'ssh'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.get_service_policy my.vcenter.location root bad-password 'ntpd'         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0tDCUItTSMtSSHtsshtlbtdtlsassdtlwiodt	netlogondtntpdssfcbd-watchdogtsnmpdtvprobedtvpxatxorgs {0} is not a valid service name.RgR�sTSM-SSHs,Could not find service '{0}' for host '{1}'.s1'vsphere.get_service_policy' failed for host {0}.N(R9R:RHRIR�RiR5R�R�t
serviceSystemtserviceInfotserviceR�tpolicyR)REtlogtdebug(R,R-R.tservice_nameR/R0R�RDtvalid_servicesRSR�R�tservicesttemp_service_nameR�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_service_policy�s>;	
$	
			
"cC@s�tjjjd|d|d|d|d|�}dddd	d
ddd
ddddddg}t|||�}i}	xN|D]F}
||kr�|	jiidj|�d6|
6�|	St||d|
�}|jj	j
j}|dks�|d	krd}
n|}
xl|D]d}|j|
krE|	jii|j
|6|
6�Pqdj||
�}|	jii|d6|
6�qW|	j|
�dkrdj|
�}tj|�|	jii|d6|
6�qqW|	S(s�
    Get the service name's running state for a given host or list of hosts.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    service_name
        The name of the service for which to retrieve the policy. Supported service names are:
          - DCUI
          - TSM
          - SSH
          - lbtd
          - lsassd
          - lwiod
          - netlogond
          - ntpd
          - sfcbd-watchdog
          - snmpd
          - vprobed
          - vpxa
          - xorg

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to tell
        vCenter the hosts for which to get the service's running state.

        If host_names is not provided, the service's running state will be retrieved
        for the ``host`` location instead. This is useful for when service instance
        connection information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.get_service_running my.esxi.host root bad-password 'ssh'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.get_service_running my.vcenter.location root bad-password 'ntpd'         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�R�R�R�R�R�R�R�R�ssfcbd-watchdogR�R�R�R�s {0} is not a valid service name.RgR�sTSM-SSHs,Could not find service '{0}' for host '{1}'.s2'vsphere.get_service_running' failed for host {0}.N(R9R:RHRIR�RiR5R�R�R�R�R�R�trunningR)RER�R�(R,R-R.R�R/R0R�RDR�RSR�R�R�R�R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_service_runninggs>;	
$	
			
"cC@s�tjjjd|d|d|d|d|�}t|||�}i}xt|D]l}t||d|�}	|	jjjj	}
|
r�|j
iitd6|6�qO|j
iitd6|6�qOW|S(s�
    Get the VMotion enabled status for a given host or a list of host_names. Returns ``True``
    if VMotion is enabled, ``False`` if it is not enabled.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter which hosts to check if VMotion is enabled.

        If host_names is not provided, the VMotion status will be retrieved for the
        ``host`` location instead. This is useful for when service instance
        connection information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.get_vmotion_enabled my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.get_vmotion_enabled my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�sVMotion Enabled(
R9R:RHRIR�R�R�t
vmotionSystemt	netConfigtselectedVnicRiRbRv(R,R-R.R/R0R�RDRSR�R�tvmotion_vnic((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_vmotion_enabled�s,	
cC@s�tjjjd|d|d|d|d|�}t|||�}i}x�|D]�}t||d|�}	|	jj}
|
d
kr�dj	|�}t
j|�|jii|d6|6�qO|jii|
j
d	6|6�qOW|S(s�
    Get the VSAN enabled status for a given host or a list of host_names. Returns ``True``
    if VSAN is enabled, ``False`` if it is not enabled, and ``None`` if a VSAN Host Config
    is unset, per host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter which hosts to check if VSAN enabled.

        If host_names is not provided, the VSAN status will be retrieved for the
        ``host`` location instead. This is useful for when service instance
        connection information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.get_vsan_enabled my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.get_vsan_enabled my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�s3VSAN System Config Manager is unset for host '{0}'.RgsVSAN EnabledN(R9R:RHRIR�R�tconfigtvsanHostConfigRER5R�R�RiRq(R,R-R.R/R0R�RDRSR�R�tvsan_configR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_vsan_enableds -	

"cC@s8tjjjd|d|d|d|d|�}t|||�}t|||�}i}x�tj|�D]�\}	}
|
jd�}|r�|j	ii|d6|	6�qjn|
jd�}|rt
|t�rg}
x|D]}|
j|j
�q�W|j	ii|
d6|	6�qj|j	ii|d6|	6�qjW|S(s�
    Returns a list of VSAN-eligible disks for a given host or list of host_names.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter which hosts to check if any VSAN-eligible disks are available.

        If host_names is not provided, the VSAN-eligible disks will be retrieved
        for the ``host`` location instead. This is useful for when service instance
        connection information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.get_vsan_eligible_disks my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.get_vsan_eligible_disks my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0RgtEligible(R9R:RHRIR�t_get_vsan_eligible_disksRt	iteritemsR)RiRhRJtappendt
canonicalName(R,R-R.R/R0R�RDRlRSR�tvalueR�tdiskst
disk_namestdisk((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_vsan_eligible_disksSs*+	
cC@s6ytjjj|�rtSWntk
r1tSXtS(s�
    Checks if a connection is to a vCenter

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.test_vcenter_connection
    (R9R:RHtis_connection_to_a_vcenterRbRRv(RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyttest_vcenter_connection�s

cC@s�tjjjd|d|d|d|d|�}tjjj|�jj}d|kr�|ddkr�tj|tjjj	|��}q�n|S(su
    Return system information about a VMware environment.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.system_info 1.2.3.4 root bad-password
    R,R-R.R/R0tapiTypet	HostAgent(
R9R:RHRIt
get_inventorytaboutt__dict__t
dictupdateRitget_hardware_grains(R,R-R.R/R0RDRS((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytsystem_info�s	'cC@sCtjjjd|d|d|d|d|�}tjjj|�S(s
    Returns a list of datacenters for the the specified host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_datacenters 1.2.3.4 root bad-password

    R,R-R.R/R0(R9R:RHRItlist_datacenters(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��s	cC@sCtjjjd|d|d|d|d|�}tjjj|�S(sy
    Returns a list of clusters for the the specified host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_clusters 1.2.3.4 root bad-password

    R,R-R.R/R0(R9R:RHRIt
list_clusters(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�s	cC@sCtjjjd|d|d|d|d|�}tjjj|�S(s�
    Returns a list of datastore clusters for the the specified host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_datastore_clusters 1.2.3.4 root bad-password
    R,R-R.R/R0(R9R:RHRItlist_datastore_clusters(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�(s	cC@sCtjjjd|d|d|d|d|�}tjjj|�S(s|
    Returns a list of datastores for the the specified host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_datastores 1.2.3.4 root bad-password
    R,R-R.R/R0(R9R:RHRItlist_datastores(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�Ms	cC@sCtjjjd|d|d|d|d|�}tjjj|�S(s�
    Returns a list of hosts for the the specified VMware environment.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_hosts 1.2.3.4 root bad-password
    R,R-R.R/R0(R9R:RHRIt
list_hosts(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�rs	cC@sCtjjjd|d|d|d|d|�}tjjj|�S(s�
    Returns a list of resource pools for the the specified host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_resourcepools 1.2.3.4 root bad-password
    R,R-R.R/R0(R9R:RHRItlist_resourcepools(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��s	cC@sCtjjjd|d|d|d|d|�}tjjj|�S(sx
    Returns a list of networks for the the specified host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_networks 1.2.3.4 root bad-password
    R,R-R.R/R0(R9R:RHRIt
list_networks(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��s	cC@sCtjjjd|d|d|d|d|�}tjjj|�S(sn
    Returns a list of VMs for the the specified host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_vms 1.2.3.4 root bad-password
    R,R-R.R/R0(R9R:RHRItlist_vms(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��s	cC@sCtjjjd|d|d|d|d|�}tjjj|�S(sv
    Returns a list of folders for the the specified host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_folders 1.2.3.4 root bad-password
    R,R-R.R/R0(R9R:RHRItlist_folders(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�	s	cC@sCtjjjd|d|d|d|d|�}tjjj|�S(s�
    Returns a list of distributed virtual switches for the the specified host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_dvs 1.2.3.4 root bad-password
    R,R-R.R/R0(R9R:RHRItlist_dvs(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR+	s	cC@sCtjjjd|d|d|d|d|�}tjjj|�S(s�
    Returns a list of vApps for the the specified host.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        # List vapps from all minions
        salt '*' vsphere.list_vapps 1.2.3.4 root bad-password
    R,R-R.R/R0(R9R:RHRIt
list_vapps(R,R-R.R/R0RD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRP	s	c
C@s�tjjjd|d|d|d|d|�}t|||�}i}g}xd|D]\}	t||d|	�}
t|
�}x|D]}|j|j�q�W|j	i||	6�qUW|S(s4
    Returns a list of SSDs for the given host or list of host_names.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter the hosts for which to retrieve SSDs.

        If host_names is not provided, SSDs will be retrieved for the
        ``host`` location instead. This is useful for when service instance
        connection information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.list_ssds my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.list_ssds my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�(
R9R:RHRIR�R�t_get_host_ssdsR�R�Ri(
R,R-R.R/R0R�RDRStnamesR�R�R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt	list_ssdsv	s+	

c
C@s�tjjjd|d|d|d|d|�}t|||�}i}g}xd|D]\}	t||d|	�}
t|
�}x|D]}|j|j�q�W|j	i||	6�qUW|S(s�
    Returns a list of Non-SSD disks for the given host or list of host_names.

    .. note::

        In the pyVmomi StorageSystem, ScsiDisks may, or may not have an ``ssd`` attribute.
        This attribute indicates if the ScsiDisk is SSD backed. As this option is optional,
        if a relevant disk in the StorageSystem does not have ``ssd = true``, it will end
        up in the ``non_ssds`` list here.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter the hosts for which to retrieve Non-SSD disks.

        If host_names is not provided, Non-SSD disks will be retrieved for the
        ``host`` location instead. This is useful for when service instance
        connection information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.list_non_ssds my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.list_non_ssds my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�(
R9R:RHRIR�R�t_get_host_non_ssdsR�R�Ri(
R,R-R.R/R0R�RDRSRR�R�R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt
list_non_ssds�	s2	

cC@s^tjjjd|d|d|d|d|�}t|t�sNtd��ntjd|�}tj	d|�}	t
|||�}i}
x�|D]�}t||d	|�}t|�}
t
jd
j||��y|
jd|	�WnStjjk
r:}dj|�}t
j|�|
jii|d
6|6�q�nX|
jii|d6|6�q�W|
S(s

    Set NTP configuration for a given host of list of host_names.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    ntp_servers
        A list of servers that should be added to and configured for the specified
        host's NTP configuration.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to tell
        vCenter which hosts to configure ntp servers.

        If host_names is not provided, the NTP servers will be configured for the
        ``host`` location instead. This is useful for when service instance connection
        information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.ntp_configure my.esxi.host root bad-password '[192.174.1.100, 192.174.1.200]'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.ntp_configure my.vcenter.location root bad-password '[192.174.1.100, 192.174.1.200]'         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0s'ntp_servers' must be a list.R�R�R�s-Configuring NTP Servers '{0}' for host '{1}'.R�s)vsphere.ntp_configure_servers failed: {0}RgsNTP Servers(R9R:RHRIRhRJRRt
HostNtpConfigtHostDateTimeConfigR�R�R�R�R�R5tUpdateDateTimeConfigtfaulttHostConfigFaultRi(R,R-R.tntp_serversR/R0R�RDR�tdate_configRSR�R�R�terrR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytset_ntp_config�	s0/	

cC@s�tjjjd|d|d|d|d|�}t|||�}dddd	d
ddd
ddddddg}i}	|dks�|d	kr�d}
n|}
xG|D]?}||kr�|	jiidj|�d6|6�|	St||d|�}t|�}
t	j
dj||��y|
jd|
�Wn�tj
jk
r�}dj||�}t	j
|�|	jii|d6|6�q�nDtj
jk
r�}t	j
|�|	jii|d6|6�q�nX|	jiitd6|6�q�W|	S(s�
    Start the named service for the given host or list of hosts.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    service_name
        The name of the service for which to set the policy. Supported service names are:
          - DCUI
          - TSM
          - SSH
          - lbtd
          - lsassd
          - lwiod
          - netlogond
          - ntpd
          - sfcbd-watchdog
          - snmpd
          - vprobed
          - vpxa
          - xorg

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to tell
        vCenter the hosts for which to start the service.

        If host_names is not provided, the service will be started for the ``host``
        location instead. This is useful for when service instance connection information
        is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.service_start my.esxi.host root bad-password 'ntpd'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.service_start my.vcenter.location root bad-password 'ntpd'         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�R�R�R�R�R�R�R�R�ssfcbd-watchdogR�R�R�R�sTSM-SSHs {0} is not a valid service name.RgR�s"Starting the '{0}' service on {1}.tids0'vsphere.service_start' failed for host {0}: {1}sService Started(R9R:RHRIR�RiR5R�t_get_service_managerR�R�tStartServiceRR
RtRestrictedVersionRb(R,R-R.R�R/R0R�RDR�RSR�R�R�tservice_managerRR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt
service_startG
s@A		
$

cC@s�tjjjd|d|d|d|d|�}t|||�}dddd	d
ddd
ddddddg}i}	|dks�|d	kr�d}
n|}
xG|D]?}||kr�|	jiidj|�d6|6�|	St||d|�}t|�}
t	j
dj||��y|
jd|
�Wn�tj
jk
r�}dj||�}t	j
|�|	jii|d6|6�q�nDtj
jk
r�}t	j
|�|	jii|d6|6�q�nX|	jiitd6|6�q�W|	S(s�
    Stop the named service for the given host or list of hosts.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    service_name
        The name of the service for which to set the policy. Supported service names are:
          - DCUI
          - TSM
          - SSH
          - lbtd
          - lsassd
          - lwiod
          - netlogond
          - ntpd
          - sfcbd-watchdog
          - snmpd
          - vprobed
          - vpxa
          - xorg

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to tell
        vCenter the hosts for which to stop the service.

        If host_names is not provided, the service will be stopped for the ``host``
        location instead. This is useful for when service instance connection information
        is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.service_stop my.esxi.host root bad-password 'ssh'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.service_stop my.vcenter.location root bad-password 'ssh'         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�R�R�R�R�R�R�R�R�ssfcbd-watchdogR�R�R�R�sTSM-SSHs {0} is not a valid service name.RgR�s"Stopping the '{0}' service on {1}.Rs/'vsphere.service_stop' failed for host {0}: {1}sService Stopped(R9R:RHRIR�RiR5R�RR�R�tStopServiceRR
RRRb(R,R-R.R�R/R0R�RDR�RSR�R�R�RRR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytservice_stop�
s@A		
$

cC@s�tjjjd|d|d|d|d|�}t|||�}dddd	d
ddd
ddddddg}i}	|dks�|d	kr�d}
n|}
xG|D]?}||kr�|	jiidj|�d6|6�|	St||d|�}t|�}
t	j
dj||��y|
jd|
�Wn�tj
jk
r�}dj||�}t	j
|�|	jii|d6|6�q�nDtj
jk
r�}t	j
|�|	jii|d6|6�q�nX|	jiitd6|6�q�W|	S(s�
    Restart the named service for the given host or list of hosts.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    service_name
        The name of the service for which to set the policy. Supported service names are:
          - DCUI
          - TSM
          - SSH
          - lbtd
          - lsassd
          - lwiod
          - netlogond
          - ntpd
          - sfcbd-watchdog
          - snmpd
          - vprobed
          - vpxa
          - xorg

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to tell
        vCenter the hosts for which to restart the service.

        If host_names is not provided, the service will be restarted for the ``host``
        location instead. This is useful for when service instance connection information
        is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.service_restart my.esxi.host root bad-password 'ntpd'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.service_restart my.vcenter.location root bad-password 'ntpd'         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�R�R�R�R�R�R�R�R�ssfcbd-watchdogR�R�R�R�sTSM-SSHs {0} is not a valid service name.RgR�s$Restarting the '{0}' service on {1}.Rs2'vsphere.service_restart' failed for host {0}: {1}sService Restarted(R9R:RHRIR�RiR5R�RR�R�tRestartServiceRR
RRRb(R,R-R.R�R/R0R�RDR�RSR�R�R�RRR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytservice_restart%s@A		
$

cC@s�tjjjd|d|d|d|d|�}t|||�}dddd	d
ddd
ddddddg}	i}
x|D]}||	kr�|
jiidj|�d6|6�|
St||d|�}t|�}
|j	j
jj}x�|D]�}d}|j|kr|j}n3|d	ks2|dkrM|jdkrMd}qMn|r-y|
jd|d|�Wn�tjjk
r�dj|�}tj|�|
jii|d6|6�q�nVtjjk
r}dj||�}tj|�|
jii|d6|6�q�nX|
jit|6�n|
j|�dkr�dj||�}tj|�|
jii|d6|6�q�q�WqW|
S(sE
    Set the service name's policy for a given host or list of hosts.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    service_name
        The name of the service for which to set the policy. Supported service names are:
          - DCUI
          - TSM
          - SSH
          - lbtd
          - lsassd
          - lwiod
          - netlogond
          - ntpd
          - sfcbd-watchdog
          - snmpd
          - vprobed
          - vpxa
          - xorg

    service_policy
        The policy to set for the service. For example, 'automatic'.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to tell
        vCenter the hosts for which to set the service policy.

        If host_names is not provided, the service policy information will be retrieved
        for the ``host`` location instead. This is useful for when service instance
        connection information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.set_service_policy my.esxi.host root bad-password 'ntpd' 'automatic'

        # Used for connecting to a vCenter Server
        salt '*' vsphere.set_service_policy my.vcenter.location root bad-password 'ntpd' 'automatic'         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�R�R�R�R�R�R�R�R�ssfcbd-watchdogR�R�R�R�s {0} is not a valid service name.RgR�sTSM-SSHRR�s%The service name '{0}' was not found.s5'vsphere.set_service_policy' failed for host {0}: {1}s,Could not find service '{0}' for host '{1}'.N(R9R:RHRIR�RiR5R�RR�R�R�R�RER�tUpdateServicePolicyRR
tNotFoundR�R�RRbR)(R,R-R.R�tservice_policyR/R0R�RDR�RSR�R�RR�R�tservice_keyR�R((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytset_service_policy�sTE	
$



&c
C@stjjjd|d|d|d|d|�}t|||�}i}x�|D]�}t||d|�}	t|	�}
y|
jtjj	��WnVt
jjk
r�}dj
||�}tj|�|jii|d6|6�qOnX|jiitd	6|6�qOW|S(
s�
    Update the date/time on the given host or list of host_names. This function should be
    used with caution since network delays and execution delays can result in time skews.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter which hosts should update their date/time.

        If host_names is not provided, the date/time will be updated for the ``host``
        location instead. This is useful for when service instance connection
        information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.update_date_time my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.update_date_time my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�s3'vsphere.update_date_time' failed for host {0}: {1}RgsDatetime Updated(R9R:RHRIR�R�R�tUpdateDateTimetdatetimetutcnowRR
RR5R�R�RiRb(
R,R-R.R/R0R�RDRSR�R�R�RR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytupdate_host_datetimes&,	

c
C@s�tjjjd|d|d|d|d|�}tjjj|�j}tjjj	�}||_
||_y|j|�Wnit
jjk
r�}	t|	j��nBtjjk
r�tdj|���ntjjk
r�nXtS(sq
    Update the password for a given host.

    .. note:: Currently only works with connections to ESXi hosts. Does not work with vCenter servers.

    host
        The location of the ESXi host.

    username
        The username used to login to the ESXi host, such as ``root``.

    password
        The password used to login to the ESXi host.

    new_password
        The new password that will be updated for the provided username on the ESXi host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.update_host_password my.esxi.host root original-bad-password new-bad-password

    R,R-R.R/R0sG'vsphere.update_host_password' failed for host {0}: User was not found.(R9R:RHRIR�taccountManagerRR,tLocalAccountManagertAccountSpecificationRR.t
UpdateUserRR
tSystemErrorRR�tUserNotFoundR5t
AlreadyExistsRb(
R,R-R.tnew_passwordR/R0RDtaccount_managertuser_accountR((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytupdate_host_passwordXs&#				c
C@stjjjd|d|d|d|d|�}t|||�}i}x�|D]�}t||d|�}	|	jj}
y|
j�WnZt	j
jk
r�}dj|�}t
j|�|jii|d6td	6|6�qOnX|jiitd	6|6�qOW|S(
s7
    Disable vMotion for a given host or list of host_names.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter which hosts should disable VMotion.

        If host_names is not provided, VMotion will be disabled for the ``host``
        location instead. This is useful for when service instance connection
        information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.vmotion_disable my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.vmotion_disable my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�s#vsphere.vmotion_disable failed: {0}RgsVMotion Disabled(R9R:RHRIR�R�R�R�tDeselectVnicRR
RR5R�R�RiRvRb(
R,R-R.R/R0R�RDRSR�R�tvmotion_systemRR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytvmotion_disable�s(+	

cC@stjjjd|d|d|d|d|�}t|||�}i}x�|D]�}	t||d|	�}
|
jj}y|j|�WnZt	j
jk
r�}dj|�}
t
j|
�|jii|
d6td	6|	6�qOnX|jiitd	6|	6�qOW|S(
s�
    Enable vMotion for a given host or list of host_names.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter which hosts should enable VMotion.

        If host_names is not provided, VMotion will be enabled for the ``host``
        location instead. This is useful for when service instance connection
        information is used for a single ESXi host.

    device
        The device that uniquely identifies the VirtualNic that will be used for
        VMotion for each host. Defaults to ``vmk0``.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.vmotion_enable my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.vmotion_enable my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�s#vsphere.vmotion_disable failed: {0}RgsVMotion Enabled(R9R:RHRIR�R�R�R�t
SelectVnicRR
RR5R�R�RiRvRb(R,R-R.R/R0R�tdeviceRDRSR�R�R/RR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytvmotion_enable�s(/	

cC@s�tjjjd|d|d|d|d|�}t|||�}t|||�}i}xUtj|�D]D\}	}
t||d|	�}|j	j
}|dkr�dj|	�}
t
j|
�|jii|
d6|	6�qj|
jd	�}|
jd�}|r9t|t�r9y2|j|�}tjjj||	d
dd�Wn�tjjk
r�}t
j|j�|jii|jd6|	6�qjnPtk
r�}d
j|	|�}
t
j|
�|jii|
d6|	6�qjnXt
jdj|	��g}x|D]}|j|j�qW|jii|d6|	6�qj|rot|tj�ro|jii|d6|	6�qj|r�|jii|d6|	6�qj|jiidd6|	6�qjW|S(s�
    Add any VSAN-eligible disks to the VSAN System for the given host or list of host_names.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter which hosts need to add any VSAN-eligible disks to the host's
        VSAN system.

        If host_names is not provided, VSAN-eligible disks will be added to the hosts's
        VSAN system for the ``host`` location instead. This is useful for when service
        instance connection information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.vsan_add_disks my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.vsan_add_disks my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�szVSAN System Config Manager is unset for host '{0}'. VSAN configuration cannot be changed without a configured VSAN System.RgR�sAdding disks to VSANt
sleep_secondsis1'vsphere.vsan_add_disks' failed for host {0}: {1}s;Successfully added disks to the VSAN system for host '{0}'.sDisks Addeds-No new VSAN-eligible disks were found to add.N(R9R:RHRIR�R�RR�R�R�t
vsanSystemRER5R�R�RiR)RhRJtAddDiskst
wait_for_taskRR
tInsufficientDisksR�RLR�R�tstring_types(R,R-R.R/R0R�RDRlRSR�R�R�tvsan_systemR�teligibleR�ttaskRR�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytvsan_add_disks%
sT,		
#

cC@s�tjjjd|d|d|d|d|�}tjjj�}t|_	t
|||�}i}x^|D]V}	t||d|	�}
|
jj
}|dkr�dj|	�}tj|�|jii|d6|	6�qjy2|j|�}
tjjj|
|	d	d
d�Wn�tjjk
rU}tj|j�|jii|jd6|	6�qjnPtk
r�}dj|	|�}tj|�|jii|d6|	6�qjnX|jiitd
6|	6�qjW|S(s(
    Disable VSAN for a given host or list of host_names.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter which hosts should disable VSAN.

        If host_names is not provided, VSAN will be disabled for the ``host``
        location instead. This is useful for when service instance connection
        information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.vsan_disable my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.vsan_disable my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�szVSAN System Config Manager is unset for host '{0}'. VSAN configuration cannot be changed without a configured VSAN System.RgsDisabling VSANR4is/'vsphere.vsan_disable' failed for host {0}: {1}s
VSAN DisabledN(R9R:RHRIRtvsanR,t
ConfigInfoRvRqR�R�R�R5RER5R�R�RitUpdateVsan_TaskR7RR
R'R�RLRb(R,R-R.R/R0R�RDR�RSR�R�R:R�R<R((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytvsan_disable�
s>+		
	
#
cC@s�tjjjd|d|d|d|d|�}tjjj�}t|_	t
|||�}i}xd|D]\}	t||d|	�}
|
jj
}|dkr�dj|	�}tj|�|jii|d6|	6�qjy2|j|�}
tjjj|
|	d	d
d�Wn�tjjk
rU}tj|j�|jii|jd6|	6�qjnVtjjk
r�}dj|	|�}tj|�|jii|d6|	6�qjnX|jiitd
6|	6�qjW|S(s#
    Enable VSAN for a given host or list of host_names.

    host
        The location of the host.

    username
        The username used to login to the host, such as ``root``.

    password
        The password used to login to the host.

    protocol
        Optionally set to alternate protocol if the host is not using the default
        protocol. Default protocol is ``https``.

    port
        Optionally set to alternate port if the host is not using the default
        port. Default port is ``443``.

    host_names
        List of ESXi host names. When the host, username, and password credentials
        are provided for a vCenter Server, the host_names argument is required to
        tell vCenter which hosts should enable VSAN.

        If host_names is not provided, VSAN will be enabled for the ``host``
        location instead. This is useful for when service instance connection
        information is used for a single ESXi host.

    CLI Example:

    .. code-block:: bash

        # Used for single ESXi host connection information
        salt '*' vsphere.vsan_enable my.esxi.host root bad-password

        # Used for connecting to a vCenter Server
        salt '*' vsphere.vsan_enable my.vcenter.location root bad-password         host_names='[esxi-1.host.com, esxi-2.host.com]'
    R,R-R.R/R0R�szVSAN System Config Manager is unset for host '{0}'. VSAN configuration cannot be changed without a configured VSAN System.Rgs
Enabling VSANR4is.'vsphere.vsan_enable' failed for host {0}: {1}sVSAN EnabledN(R9R:RHRIRR>R,R?RbRqR�R�R�R5RER5R�R�RiR@R7RR
R'R�t	VsanFault(R,R-R.R/R0R�RDR�RSR�R�R:R�R<R((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytvsan_enable�
s>+		
	
#
cC@s�tjdj|��i|d6|jjd6|jjd6|jd6|jd6|jd6|jd6|j	d	6}t
|jtj
�r�|ji|jjd
6�n|S(s�
    Returns the dict representation of the DVS config

    dvs_name
        The name of the DVS

    dvs_config
        The DVS config
    s)Building the dict of the DVS '{0}' configtnamet
contact_emailtcontact_nametdescriptiontlacp_api_versiont network_resource_control_versiont#network_resource_management_enabledtmax_mtutuplink_names(R�ttraceR5tcontactRDRGtlacpApiVersiontnetworkResourceControlVersiont networkResourceManagementEnabledtmaxMtuRhtuplinkPortPolicyRtDVSNameArrayUplinkPortPolicyRituplinkPortName(tdvs_namet
dvs_configt	conf_dict((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_dvs_config_dict7s








	cC@s.tjdj|��i|jd6|jd6S(s�
    Returns the dict representation of the DVS link discovery protocol

    dvs_name
        The name of the DVS

    dvs_link_disc_protocl
        The DVS link discovery protocol
    s:Building the dict of the DVS '{0}' link discovery protocolt	operationR/(R�RMR5RZR/(RVtdvs_link_disc_protocol((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt _get_dvs_link_discovery_protocolSs


cC@s8tjdj|��i|jd6|jd6|jd6S(s�
    Returns the dict representation of the DVS product_info

    dvs_name
        The name of the DVS

    dvs_product_info
        The DVS product info
    s/Building the dict of the DVS '{0}' product infoRDtvendortversion(R�RMR5RDR]R^(RVtdvs_product_info((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_dvs_product_infocs




cC@s8tjdj|��i|jd6|jd6|jd6S(s�
    Returns the dict representation of the DVS product_info

    dvs_name
        The name of the DVS

    dvs_capability
        The DVS capability
    s-Building the dict of the DVS '{0}' capabilitytoperation_supportedtportgroup_operation_supportedtport_operation_supported(R�RMR5tdvsOperationSupportedtdvPortGroupOperationSupportedtdvPortOperationSupported(RVtdvs_capability((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_dvs_capabilityts




cC@s�tjdj|��g}x�|D]y}i|jd6|jjd6|jjd6}|jjr�|ji|jjjd6|jjj	d6�n|j
|�q#W|S(s�
    Returns a list of dict representations of the DVS infrastructure traffic
    resource

    dvs_name
        The name of the DVS

    dvs_infra_traffic_ress
        The DVS infrastructure traffic resources
    sDBuilding the dicts of the DVS '{0}' infrastructure traffic resourcesR�tlimittreservationt
num_sharestshare_level(R�RMR5R�tallocationInfoRiRjtsharesRitlevelR�(RVtdvs_infra_traffic_resst	res_dictstrestres_dict((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt)_get_dvs_infrastructure_traffic_resources�s



c	C@s�g}t�}|dkr;td�d}t|�}n8|dkrstd�d}tjjj||�}nx5tjjj|||�D]}i}tjjj|dddd	g�}t	|d|d�}|j
it|d|dj�d
6�|dj
r7|j
it|d|dj
�d6�n|j
it|d|d�d6�t|dd�r�|j
it|d|dj�d
6�n|j|�q�W|S(s�
    Returns a list of distributed virtual switches (DVSs).
    The list can be filtered by the datacenter or DVS names.

    datacenter
        The datacenter to look for DVSs in.
        Default value is None.

    dvs_names
        List of DVS names to look for. If None, all DVSs are returned.
        Default value is None.

    .. code-block:: bash

        salt '*' vsphere.list_dvss

        salt '*' vsphere.list_dvss dvs_names=[dvs1,dvs2]
    R!sesxdatacenter.get_detailst
datacenterR sesxcluster.get_detailsRDR�t
capabilitytnetworkResourcePooltproduct_infotlink_discovery_protocolt#infrastructureTrafficResourceConfigt%infrastructure_traffic_resource_pools(R+R4t_get_proxy_targetR9R:RHtget_datacentertget_dvsst get_properties_of_managed_objectRYRiR`tproductInfotlinkDiscoveryProtocolConfigR\RhthasattrRtRzR�(	Rut	dvs_namesRDtret_listR>tdc_reftdvstdvs_dicttprops((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt	list_dvss�sB	#

	
	cC@sm|jd�r|d|_n|jd�s=|jd�r�|jsXtj�|_n|jd�|j_|jd�|j_n|jd�r�|jd�|_n|jd�r�|jd�|_n|jd�r�|jd�|_n|jd�r|jd�|_n|jd�ri|j	sDt
|j	tj�rVtj�|_	n|d|j	_nd	S(
si
    Applies the values of the config dict dictionary to a config spec
    (vim.VMwareDVSConfigSpec)
    RDRERFRGRKRHRIRLN(
R)RDRNRtDVSContactInfoRGRRRORPRSRhRTRU(tconfig_spectconfig_dict((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_dvs_config�s*	
	
cC@s|d|_|d|_dS(s�
    Applies the values of the disc_prot_dict dictionary to a link discovery
    protocol config object (vim.LinkDiscoveryProtocolConfig)
    RZR/N(RZR/(tdisc_prot_configtdisc_prot_dict((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt"_apply_dvs_link_discovery_protocols
cC@sa|jd�r|d|_n|jd�r>|d|_n|jd�r]|d|_ndS(s�
    Applies the values of the product_info_dict dictionary to a product info
    spec (vim.DistributedVirtualSwitchProductSpec)
    RDR]R^N(R)RDR]R^(tproduct_info_spectproduct_info_dict((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_dvs_product_infoscC@sXd|kr|d|_nd|kr8|d|_nd|krT|d|_ndS(su
    Applies the values of the capability_dict dictionary to a DVS capability
    object (vim.vim.DVSCapability)
    RaRcRbN(RdRfRe(tcapability_spectcapability_dict((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_dvs_capabilityscC@sbx[|D]S}g|D]}|j|dkr|^q}|rL|d}n5tj�}|d|_tj�|_|j|�|jd�r�|d|j_n|jd�r�|d|j_n|jd�s�|jd�r|jj	stj
�|j_	qn|jd�r5tj|d�|jj	_n|jd�r|d|jj	_	qqWdS(s�
    Applies the values of the resource dictionaries to infra traffic resources,
    creating the infra traffic resource if required
    (vim.DistributedVirtualSwitchProductSpec)
    R�iRiRjRkRlN(
R�Rt$DvsHostInfrastructureTrafficResourcet.DvsHostInfrastructureTrafficResourceAllocationRmR�R)RiRjRnt
SharesInfotSharesLevelRo(tinfra_traffic_resourcestresource_dictsRstrtfiltered_traffic_resourcesttraffic_res((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt+_apply_dvs_infrastructure_traffic_resources(s&
,


cC@sx|D]
}g|D]}|j|dkr|^q}|rL|d}n5tj�}|d|_tj�|_|j|�|jd�r�|d|j_n|jd�r|jd�r|jjs�tj	�|j_n|d|jj_tj
|d�|jj_qqWdS(s�
    Applies the values of the resource dictionaries to network resource pools,
    creating the resource pools if required
    (vim.DVSNetworkResourcePoolConfigSpec)
    R�iRiRkRlN(R�Rt DVSNetworkResourcePoolConfigSpect$DVSNetworkResourcePoolAllocationInfoRmR�R)RiRnR�R�Ro(tnetwork_resource_poolsR�RsR�tressRr((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt!_apply_dvs_network_resource_poolsJs
,


c	C@s:tjdj||��t�}|dkrNtd�d}t|�}n8|dkr�td�d}tjjj	||�}n||d<t
j�}t
j�|_
t|j
|�|jd�r�t
j�|_t|j|d�n|jd	�r%t
j�|_t|j|d	�n|jd
�r`t
j�|j
_t|j
j|d
�n|jd�r�g|j
_t|j
j|d�ntjdj|��tjjj|||�d
|kr6tjjj|d|g�}|stdj||���n|d}tjjj||d
�ntS(s�
    Creates a distributed virtual switch (DVS).

    Note: The ``dvs_name`` param will override any name set in ``dvs_dict``.

    dvs_dict
        Dict representation of the new DVS (example in salt.states.dvs)

    dvs_name
        Name of the DVS to be created.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.create_dvs dvs dict=$dvs_dict dvs_name=dvs_name
    s"Creating dvs '{0}' with dict = {1}R!sesxdatacenter.get_detailsRuR sesxcluster.get_detailsRDRxRvRyR{sdvs_create_spec = {}RJR�s*DVS '{0}' wasn't found in datacenter '{1}'i( R�RMR5R+R4R|R9R:RHR}Rt
DVSCreateSpectVMwareDVSConfigSpect
configSpecR�R)t#DistributedVirtualSwitchProductSpecR�R�t
DVSCapabilityRvR�tLinkDiscoveryProtocolConfigR�R�RzR�t
create_dvsR~Rt+set_dvs_network_resource_management_enabledRb(	R�RVRDR>RuR�tdvs_create_spectdvs_refstdvs_ref((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�dsX
	
				
cC@sytjdj||��x0ddddgD]}||kr,||=q,q,Wt�}|dkr�td�d}t|�}n8|d	kr�td
�d}tjjj	||�}ntjjj
|d|g�}|s�tdj||���n|d
}tjjj|ddg�}	t
j�}
dg}x\|
jj�D]K}||kr]qEnt|	d|�rEt|
|t|	d|��qEqEWt|
|�|jd�r�|
js�t
j�|
_nt|
j|d�n|jd�r|
jsg|
_nt|
j|d�ntjdj|
��tjjj|d|
�d|krutjjj||d�ntS(sH
    Updates a distributed virtual switch (DVS).

    Note: Updating the product info, capability, uplinks of a DVS is not
          supported so the corresponding entries in ``dvs_dict`` will be
          ignored.

    dvs_dict
        Dictionary with the values the DVS should be update with
        (example in salt.states.dvs)

    dvs
        Name of the DVS to be updated.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.update_dvs dvs_dict=$dvs_dict dvs=dvs1
    s"Updating dvs '{0}' with dict = {1}RxRvRLRDR!sesxdatacenter.get_detailsRuR sesxcluster.get_detailsR�s*DVS '{0}' wasn't found in datacenter '{1}'iR�R,RyR{sdvs_config= {}tdvs_config_specRJ(R�RMR5R+R4R|R9R:RHR}R~RRRR�R�tkeysR�tsetattrtgetattrR�R)R�R�R�RzR�t
update_dvsR�Rb(R�R�RDtpropR>RuR�R�R�t	dvs_propsRWtskipped_properties((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��sX		
	$
		cC@satjdj|��|j}|s)iSi|jjd6|jjd6|jjd6|jjd6S(s�
    Returns the out shaping policy of a distributed virtual portgroup

    pg_name
        The name of the portgroup

    pg_default_port_config
        The dafault port config of the portgroup
    s/Retrieving portgroup's '{0}' out shaping configtaverage_bandwidtht
burst_sizeRqtpeak_bandwidth(	R�RMR5toutShapingPolicytaverageBandwidthR�t	burstSizeRqt
peakBandwidth(tpg_nametpg_default_port_configtout_shaping_policy((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_dvportgroup_out_shaping�s

	

cC@sTtjdj|��|j}|s)iSi|jjd6|jjd6|jjd6S(s�
    Returns the security policy of a distributed virtual portgroup

    pg_name
        The name of the portgroup

    pg_default_port_config
        The dafault port config of the portgroup
    s3Retrieving portgroup's '{0}' security policy configtallow_promiscuoustforged_transmitstmac_changes(R�RMR5tsecurityPolicytallowPromiscuousR�tforgedTransmitst
macChanges(R�R�t
sec_policy((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt _get_dvportgroup_security_policys

	
cC@s(tjdj|��|j}|s)iSi|jjd6|jjd6|jjd6|jjd6}|j	r�|j	}|j
ii|jjd6|jjd6|j
jd6|jjd	6|jjd
6|jjd6|jjd6d
6�n|jr$|j}|j
ii|jd6|jd6d6�n|S(s�
    Returns the teaming of a distributed virtual portgroup

    pg_name
        The name of the portgroup

    pg_default_port_config
        The dafault port config of the portgroup
    s*Retrieving portgroup's '{0}' teamingconfigtnotify_switchesR�treverse_policyt
rolling_ordertcheck_beacontcheck_duplextcheck_error_percenttcheck_speedtfull_duplext
percentagetspeedtfailure_criteriatactivetstandbyt
port_order(R�RMR5tuplinkTeamingPolicytnotifySwitchesR�R�t
reversePolicytrollingOrdertfailureCriteriaRitcheckBeacontcheckDuplextcheckErrorPercentt
checkSpeedt
fullDuplexR�R�tuplinkPortOrdertactiveUplinkPorttstandbyUplinkPort(R�R�tteaming_policytret_dictR�tuplink_order((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_dvportgroup_teaming#s2

	

		





		
cC@s#tjjj|dddddg�}i|dd6|jd�d6|dd6|dd6}|dr|d}|jr�t|jtj�r�|j	i|jj
d	6�n|j	it|d|d�d
6�|j	it|d|d�d6�|j	it
|d|d�d6�n|S(
sq
    Returns a dictionary with a distributed virutal portgroup data


    pg_ref
        Portgroup reference
    RDsconfig.descriptionsconfig.numPortssconfig.typesconfig.defaultPortConfigRGt	num_portsttypetvlan_idtout_shapingtsecurity_policytteaming(R9R:RHRR)tvlanRhRt(VmwareDistributedVirtualSwitchVlanIdSpecRitvlanIdR�R�R�(tpg_refR�tpg_dicttdpg((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_dvportgroup_dictHs4

					cC@s&g}t�}|dkr;td�d}t|�}n8|dkrstd�d}tjjj||�}n|r�tjjj|d|g�}|s�tdj	|���n|d}n|s�t
nt}	xKtjjjd	|r�|n|d
|d|	�D]}
|j
t|
��qW|S(s�
    Returns a list of distributed virtual switch portgroups.
    The list can be filtered by the portgroup names or by the DVS.

    dvs
        Name of the DVS containing the portgroups.
        Default value is None.

    portgroup_names
        List of portgroup names to look for. If None, all portgroups are
        returned.
        Default value is None

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_dvporgroups

        salt '*' vsphere.list_dvportgroups dvs=dvs1

        salt '*' vsphere.list_dvportgroups portgroup_names=[pg1]

        salt '*' vsphere.list_dvportgroups dvs=dvs1 portgroup_names=[pg1]
    R!sesxdatacenter.get_detailsRuR sesxcluster.get_detailsR�sDVS '{0}' was not retrievedit
parent_reftportgroup_namestget_all_portgroups(R+R4R|R9R:RHR}R~RR5RbRvtget_dvportgroupsR�R�(R�R�RDR�R>RuR�R�R�R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_dvportgroupsms*		

cC@s�t�}|dkr5td�d}t|�}n8|dkrmtd�d}tjjj||�}ntjjj|d|g�}|s�tdj	|���ntjjj
|d�}t|�S(	sI
    Returns the uplink portgroup of a distributed virtual switch.

    dvs
        Name of the DVS containing the portgroup.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_uplink_dvportgroup dvs=dvs_name
    R!sesxdatacenter.get_detailsRuR sesxcluster.get_detailsR�sDVS '{0}' was not retrievedi(R+R4R|R9R:RHR}R~RR5tget_uplink_dvportgroupR�(R�RDR>RuR�R�t
uplink_pg_ref((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_uplink_dvportgroup�s		cC@s�tjdj|��|jd�rGtj�|_|d|j_n|jd�rxtj�|_|d|j_nd|kr�tj	�|_
|d|j
_n|jd�r�tj�|_|d|j_ndS(s�
    Applies the values in out_shaping_conf to an out_shaping object

    pg_name
        The name of the portgroup

    out_shaping
        The vim.DVSTrafficShapingPolicy to apply the config to

    out_shaping_conf
        The out shaping config
    s-Building portgroup's '{0}' out shaping policyR�R�RqR�N(R�RMR5R)Rt
LongPolicyR�R�R�t
BoolPolicyRqR�(R�R�tout_shaping_conf((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_dvportgroup_out_shaping�s

cC@s�tjdj|��d|krDtj�|_|d|j_nd|krrtj�|_|d|j_nd|kr�tj�|_|d|j_ndS(s�
    Applies the values in sec_policy_conf to a security policy object

    pg_name
        The name of the portgroup

    sec_policy
        The vim.DVSTrafficShapingPolicy to apply the config to

    sec_policy_conf
        The out shaping config
    s+Building portgroup's '{0}' security policy R�R�R�N(	R�RMR5RRR�R�R�R�(R�R�tsec_policy_conf((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt"_apply_dvportgroup_security_policy�s
cC@s�tjdj|��d|krDtj�|_|d|j_nd|krrtj�|_|d|j_nd|kr�tj�|_	|d|j	_nd|kr�tj�|_
|d|j
_nd|krn|js�tj�|_n|d}d|kr3tj�|j_
|d|jj
_nd|krgtj�|j_|d|jj_nd	|kr�tj�|j_|d	|jj_nd
|kr�tj�|j_|d
|jj_nd|krtj�|j_|d|jj_nd|kr7tj�|j_|d|jj_nd
|krntj�|j_|d
|jj_qnnd|kr�|js�tj�|_nd|dkr�|dd|j_nd|dkr�|dd|j_q�ndS(s�
    Applies the values in teaming_conf to a teaming policy object

    pg_name
        The name of the portgroup

    teaming
        The vim.VmwareUplinkPortTeamingPolicy to apply the config to

    teaming_conf
        The teaming config
    s"Building portgroup's '{0}' teamingR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�N(R�RMR5RRR�R�tStringPolicyR�R�R�R�tDVSFailureCriteriaR�R�R�R�R�t	IntPolicyR�R�R�tVMwareUplinkPortOrderPolicyR�R�(R�R�tteaming_conftfailure_criteria_conf((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_dvportgroup_teaming�sZ
	
	cC@s�tjdj|��d|kr2|d|_nd|krN|d|_nd|krj|d|_nd|kr�|d|_n|js�x;dddd	gD]$}||kr�tj	�|_q�q�Wnd|krtj
�|j_|d|jj_nd|krK|jj
s.tj�|j_
nt||jj
|d�nd|kr�|jjsxtj�|j_nt||jj|d�nd	|kr�|jjs�tj�|j_nt||jj|d	�nd
S(s�
    Applies the values in conf to a distributed portgroup spec

    pg_name
        The name of the portgroup

    pg_spec
        The vim.DVPortgroupConfigSpec to apply the config to

    pg_conf
        The portgroup config
    sBuilding portgroup's '{0}' specRDRGR�R�R�R�R�R�N(R�RMR5RDRGtnumPortsR�tdefaultPortConfigRtVMwareDVSPortSettingR�R�R�R�tDVSTrafficShapingPolicyRR�tDVSSecurityPolicyRR�tVmwareUplinkPortTeamingPolicyR
(R�tpg_spectpg_confR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_dvportgroup_configBsD
	c	C@s	tjdj|||��t�}|dkrQtd�d}t|�}n8|dkr�td�d}tjjj	||�}ntjjj
|d|g�}|s�tdj|���n||d	<tj
�}t|||�tjjj|d
|�tS(s�
    Creates a distributed virtual portgroup.

    Note: The ``portgroup_name`` param will override any name already set
    in ``portgroup_dict``.

    portgroup_dict
        Dictionary with the config values the portgroup should be created with
        (example in salt.states.dvs).

    portgroup_name
        Name of the portgroup to be created.

    dvs
        Name of the DVS that will contain the portgroup.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.create_dvportgroup portgroup_dict=<dict>
            portgroup_name=pg1 dvs=dvs1
    s4Creating portgroup'{0}' in dvs '{1}' with dict = {2}R!sesxdatacenter.get_detailsRuR sesxcluster.get_detailsR�sDVS '{0}' was not retrievedRDi(R�RMR5R+R4R|R9R:RHR}R~RRtDVPortgroupConfigSpecRtcreate_dvportgroupRb(	tportgroup_dicttportgroup_nameR�RDR>RuR�R�tspec((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRxs$		
cC@s�tjdj|||��t�}|dkrQtd�d}t|�}n8|dkr�td�d}tjjj	||�}ntjjj
|d|g�}|s�tdj|���ntjjj|d	d
|g�}|stdj|���ntjjj
|d	dg�}	tj�}
xLd
ddddddddddgD]#}t|
|t|	d|��qXWt||
|�tjjj|d	|
�tS(sv
    Updates a distributed virtual portgroup.

    portgroup_dict
        Dictionary with the values the portgroup should be update with
        (example in salt.states.dvs).

    portgroup
        Name of the portgroup to be updated.

    dvs
        Name of the DVS containing the portgroups.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.update_dvportgroup portgroup_dict=<dict>
            portgroup=pg1

        salt '*' vsphere.update_dvportgroup portgroup_dict=<dict>
            portgroup=pg1 dvs=dvs1
    s4Updating portgroup'{0}' in dvs '{1}' with dict = {2}R!sesxdatacenter.get_detailsRuR sesxcluster.get_detailsR�sDVS '{0}' was not retrievediR�s!Portgroup '{0}' was not retrievedR�t
autoExpandt
configVersionRRGRDRR�tportNameFormattscopeR�tvendorSpecificConfig(R�RMR5R+R4R|R9R:RHR}R~RR�RRRR�R�Rtupdate_dvportgroupRb(Rt	portgroupR�RDR>RuR�R�tpg_refstpg_propsRR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR!�s8			!cC@stjdj||��t�}|dkrNtd�d}t|�}n8|dkr�td�d}tjjj	||�}ntjjj
|d|g�}|s�tdj|���ntjjj|d	d
|g�}|stdj|���ntjjj
|d	�tS(sv
    Removes a distributed virtual portgroup.

    portgroup
        Name of the portgroup to be removed.

    dvs
        Name of the DVS containing the portgroups.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.remove_dvportgroup portgroup=pg1 dvs=dvs1
    s%Removing portgroup'{0}' in dvs '{1}' R!sesxdatacenter.get_detailsRuR sesxcluster.get_detailsR�sDVS '{0}' was not retrievediR�s!Portgroup '{0}' was not retrieved(R�RMR5R+R4R|R9R:RHR}R~RR�tremove_dvportgroupRb(R"R�RDR>RuR�R�R#((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR%�s(
			c
C@s�i|jd6|jd6|jjd6}g}t|tjj�r�t|jtjj�r�x2|jj	D]!}i|jd6|j
d6}g}x�|jD]�}i|jj
d6|jjd6}|jdjdj}t|tjjj�ridd	6|jd
6|jd6}	nFt|tjjj�rBidd	6|jd
6}	nidd	6|d6}	|	|d<|j|�q�W||d<|j|�qgWn||d<|S(s/Returns a dictionary representation of a policyRDRGt
resource_typetforce_provisiont	namespaceRiRR�tmintmaxtsettvaluestscalarR�tsettingtcapabilitiestsubprofiles(RDRGtresourceTypeRhRtprofiletCapabilityBasedProfiletconstraintstSubProfileCapabilityConstraintstsubProfilestforceProvisionRvRR(t
constrainttpropertyInstanceR�ttypestRangeR)R*tDiscreteSetR,R�(
R�tprofile_dicttsubprofile_dictst
subprofiletsubprofile_dictt	cap_dictstcaptcap_dicttvaltval_dict((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_policy_dicts<

	









cC@sntjjj|�}|s9tjjj|dt�}ntjjj||�}g|D]}t|�^qXS(s�
    Returns a list of storage policies.

    policy_names
        Names of policies to list. If None, all policies are listed.
        Default is None.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_storage_policies

        salt '*' vsphere.list_storage_policy policy_names=[policy_name]
    tget_all_policies(R9R:Rtget_profile_managertget_storage_policiesRbRF(tpolicy_namesRDtprofile_managertpoliciestp((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_storage_policies7s	cC@s{tjjj|�}tjjj|dt�}g|D]}|jdkr7|^q7}|smtd��nt|d�S(s3
    Returns the default vsan storage policy.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_storage_policies

        salt '*' vsphere.list_storage_policy policy_names=[policy_name]
    RGtVsanDefaultProfiles%Default VSAN policy was not retrievedi(	R9R:RRHRIRbtsystemCreatedProfileTypeRRF(RDRKRLRMtdef_policies((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_default_vsan_policyVs	
cC@sIi|jjd6|jjd6|jd6|jjd6|jdjjd6S(NR(Rt	mandatoryRGiR�(RR(RStsummarytpropertyMetadataR�ttypeName(tcap_metadata((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_capability_definition_dictrs



cC@sGtjjj|�}gtjjj|�D]}t|�^q+}|S(s
    Returns a list of the metadata of all capabilities in the vCenter.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_capabilities
    (R9R:RRHtget_capability_definitionsRX(RDRKtcR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_capability_definitions}s+c

C@sMtjdj|��|jd�r5|d|_n|jd�rT|d|_n|jd�r3tjj�|_	g}x�|dD]�}tjjj
d|d�}g}|jd�r�|d|_nx:|dD].}tjj
d|d�}|dd	}|d
kr=tjjj�|_|dd|j_nl|dkr�tjjj�|_|dd
|j_|dd|j_n |dkr�|dd|_ntjjdtjjjd|dd|d�dtjjd|g�g�}	|j|	�q�W||_|j|�q�W||j	_ntjdj|��|S(s,Applies a policy dictionary to a policy specspolicy_dict = {0}RDRGR0R'R/RR.R�R+R,RR*R)R-R�R(R8R9supdated policy_spec = {0}(R�RMR5R)RDRGRR2R5R4t
SubProfileR7RvtPropertyInstanceR:R<R�R,R;R*R)tCapabilityInstancetCapabilityMetadatatUniqueIdtConstraintInstanceR�R6(
tpolicy_spectpolicy_dictR0R@tsubprofile_spect	cap_specsRCtprop_inst_spectsetting_typetcap_spec((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_policy_config�sN



	cC@s�tjdj||��tjjj|�}tjj�}tjj	dtjj
j�|_||d<tjd�t
||�tjjj||�itd6S(s^
    Creates a storage policy.

    Supported capability types: scalar, set, range.

    policy_name
        Name of the policy to create.
        The value of the argument will override any existing name in
        ``policy_dict``.

    policy_dict
        Dictionary containing the changes to apply to the policy.
        (example in salt.states.pbm)

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.create_storage_policy policy_name='policy name'
            policy_dict="$policy_dict"
    s'create storage policy '{0}', dict = {1}R1RDs+Setting policy values in policy_update_spectcreate_storage_policy(R�RMR5R9R:RRHR2t CapabilityBasedProfileCreateSpectResourceTypetResourceTypeEnumtSTORAGER1RiRjRb(tpolicy_nameRcRDRKtpolicy_create_spec((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRj�s



cC@s�tjdj|��tjjj|�}tjjj||g�}|sdtdj|���n|d}tj	j
�}tjd�x-ddgD]}t||t||��q�Wt
||�tjjj|||�itd6S(s�
    Updates a storage policy.

    Supported capability types: scalar, set, range.

    policy
        Name of the policy to update.

    policy_dict
        Dictionary containing the changes to apply to the policy.
        (example in salt.states.pbm)

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.update_storage_policy policy='policy name'
            policy_dict="$policy_dict"
    s#updating storage policy, dict = {0}sPolicy '{0}' was not foundis+Setting policy values in policy_update_specRGR4tupdate_storage_policy(R�RMR5R9R:RRHRIRR2t CapabilityBasedProfileUpdateSpecR�R�RiRqRb(R�RcRDRKRLt
policy_reftpolicy_update_specR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRq�s	


cC@s�tjdj|��t|�}tjjj||d|g�}|satdj|���ntjj	j
|�}tjj	j||d�}t|�S(s�
    Returns a list of datastores assign the the storage policies.

    datastore
        Name of the datastore to assign.
        The datastore needs to be visible to the VMware entity the proxy
        points to.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_default_storage_policy_of_datastore datastore=ds1
    s5Listing the default storage policy of datastore '{0}'tdatastore_namessDatastore '{0}' was not foundi(
R�RMR5R|R9R:RHtget_datastoresRRRHt'get_default_storage_policy_of_datastoreRF(t	datastoreRDt
target_reftds_refsRKR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt(list_default_storage_policy_of_datastores
	c	C@s�tjdj||��tjjj|�}tjjj||g�}|sgtdj|���n|d}t	|�}tjj
j||d|g�}|s�tdj|���n|d}tjjj|||�t
S(s
    Assigns a storage policy as the default policy to a datastore.

    policy
        Name of the policy to assign.

    datastore
        Name of the datastore to assign.
        The datastore needs to be visible to the VMware entity the proxy
        points to.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.assign_storage_policy_to_datastore
            policy='policy name' datastore=ds1
    s%Assigning policy {0} to datastore {1}sPolicy '{0}' was not foundiRusDatastore '{0}' was not found(R�RMR5R9R:RRHRIRR|RHRvt*assign_default_storage_policy_to_datastoreRb(	R�RxRDRKRLRsRyRztds_ref((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR|:s$
	
	

cC@si|s$tjjj|dt�}ntjjj||�}g|D]"}itjjj|�d6^qCS(sp
    Returns a list of dict representations of VMware datacenters.
    Connection is done via the proxy details.

    Supported proxies: esxdatacenter

    datacenter_names
        List of datacenter names.
        Default is None.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_datacenters_via_proxy

        salt '*' vsphere.list_datacenters_via_proxy dc1

        salt '*' vsphere.list_datacenters_via_proxy dc1,dc2

        salt '*' vsphere.list_datacenters_via_proxy datacenter_names=[dc1, dc2]
    tget_all_datacentersRD(R9R:RHtget_datacentersRbtget_managed_object_name(tdatacenter_namesRDtdc_refsR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_datacenters_via_proxyis	cC@s!tjjj||�itd6S(s.
    Creates a datacenter.

    Supported proxies: esxdatacenter

    datacenter_name
        The datacenter name

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.create_datacenter dc1
    tcreate_datacenter(R9R:RHR�Rb(tdatacenter_nameRD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��scC@s-tjdj|��tjjj|ddg�}ii|djjd6d6i|dj	jd6d6}|dj}tjdj|��|j
|dd<|jr�t|jt
j�r�|j}i|jd	6|jd
6|dd<n|jr!|j}i|jd6|jd
6|dd<n|j|dd<|jrO|j|dd<n|jr�g|jD] }i|jd6|jd6^qb|dd<n|j|dd<|dj	}tjdj|��d|j|dd<|j|dd<|dj|d<tjjj|�}	tjjj|	�r)tjjj |	�}
t!|
j"�dkr�tjjj#|�}tjdj|��i|jd6|j$j%d6|d<|j&r&|j&}|dj'i|j(p�t)d6|j*d6�q&q)|dj+r)|dj+j$}
i|dj+jd6|
j%d6|d<q)n|S( s�
    Returns a cluster dict representation from
    a vim.ClusterComputeResource object.

    cluster_name
        Name of the cluster

    cluster_ref
        Reference to the cluster
    s5Building a dictionary representation of cluster '{0}'t
propertiestconfigurationExRqthatdrss
ha_conf = {0}tadmission_control_enabledtcpu_failover_percenttmemory_failover_percenttadmission_control_policytisolation_responsetrestart_prioritytdefault_vm_settingsthb_ds_candidate_policythost_monitoringR�R�toptionst
vm_monitoringsdrs_conf = {0}itvmotion_ratetdefault_vm_behaviortvm_swap_placementijv7svsan_conf = {0}tauto_claim_storageR>tcompression_enabledt
dedup_enabled(,R�RMR5R9R:RHRt	dasConfigRqt	drsConfigtadmissionControlEnabledtadmissionControlPolicyRhRt.ClusterFailoverResourcesAdmissionControlPolicytcpuFailoverResourcesPercenttmemoryFailoverResourcesPercenttdefaultVmSettingstisolationResponsetrestartPrioritythBDatastoreCandidatePolicythostMonitoringtoptionR�R�tvmMonitoringtvmotionRatetdefaultVmBehaviortvmSwapPlacementt(get_service_instance_from_managed_objectR>tvsan_supportedtget_service_infotinttbuildtget_cluster_vsan_infot
defaultConfigtautoClaimStoragetdataEfficiencyConfigRitcompressionEnabledRvtdedupEnabledtvsanConfigInfo(tcluster_nametcluster_refR�Rrtha_conftpolt
def_vm_settotdrs_conftsitvcenter_infot	vsan_conftdata_efftdefault_config((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_cluster_dict�sh

			
		
		8
	
		

cC@s�t�}|dkrQt|�}|s6td��ntjjj||�}n,|dkr}t|�}td�d}ntj	dj
||��t||�S(s�
    Returns a dict representation of an ESX cluster.

    datacenter
        Name of datacenter containing the cluster.
        Ignored if already contained by proxy details.
        Default value is None.

    cluster
        Name of cluster.
        Ignored if already contained by proxy details.
        Default value is None.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        # vcenter proxy
        salt '*' vsphere.list_cluster datacenter=dc1 cluster=cl1

        # esxdatacenter proxy
        salt '*' vsphere.list_cluster cluster=cl1

        # esxcluster proxy
        salt '*' vsphere.list_cluster
    R!s'cluster' needs to be specifiedR sesxcluster.get_detailstclusters9Retrieving representation of cluster '{0}' in a {1} proxy(R+R|R	R9R:RHtget_clusterR4R�RMR5R�(RuR�RDR>R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_cluster�s 	
c
C@stjdj|��|jd�rB|d}|jsJtj�|_n|j}d|kr�|d|_|dr�d|_q�nd|kr�|d|_	nd|kr|d}|j
s�t|j
tj�rtjd|dd	|d
�|_
qnd|krr|d}|j
s1tj�|_
nd|krP|d|j
_nd
|krr|d
|j
_qrnd|kr�|d|_nd|kr�|d|_nd|krg|_xX|dD]I}|jjtjd|d��d|kr�|d|jd_q�q�Wnd|kr6|d|_n||_n|jd�r�|d}	tj�}
d|	kr�|	d|
_nd|	kr�d|	d|
_nd|	kr�tj|	d�|
_n|
|_n|jd�r�|d|_n|jd�r�|d}|sTd|krR|js?tjj j!�|_n|d|j_nd|kr�|jstjj j!�|_n|jj"s�tj#�|j_"n!|jj"j$r�d|jj"_$n|d|jj"_&nd|kr|j'stjj(�|_'n|d|j'_)nd|krT|j's>tjj(�|_'n|d|j'_*qTn|j+sotj,�|_+n|j+}d|kr�|d|_nd|kr�|j"s�tj#�|_"n|j"j$r�d|j"_$n|d|j"_&q�ntjdj|��dS( s�
    Applies the values of cluster_dict dictionary to a cluster spec
    (vim.ClusterConfigSpecEx).

    All vsan values (cluster_dict['vsan']) will be applied to
    vsan_spec (vim.vsan.cluster.ConfigInfoEx). Can be not omitted
    if not required.

    VSAN 6.1 config needs to be applied differently than the post VSAN 6.1 way.
    The type of configuration desired is dictated by the flag vsan_61.
    sApplying cluster dict {0}R�RqiR�R�R�R�R�R�R�R�R�R�R�R�R�R�i����R�R�R�iR�R�R>R�R�R�scluster_spec = {0}N(-R�RMR5R)R�RtClusterDasConfigInfoRqt
failoverLevelR�R�RhR�R�tClusterDasVmSettingsR�R�R�R�R�R�tOptionValueR�R�tClusterDrsConfigInfoR�tDrsBehaviorR�R�R�tvsanClusterConfigR>R�R?R�t$VsanClusterConfigInfoHostDefaultInfotuuidRER�R�tDataEfficiencyConfigR�R�t
vsanConfigtVsanClusterConfigInfo(
tcluster_spectcluster_dictt	vsan_spectvsan_61tha_dictt
das_configtadm_pol_dicttvm_set_dicttopt_dicttdrs_dictt
drs_configt	vsan_dictR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_cluster_dict(s�

		




	

			

							cC@s�tj�}ytj||�Wn%tjjk
rG}t|��nXt�}|dkr�td�d}t	|�}|s�t
d��q�nI|dkr�td�d}tjj
j||�}td�d}n|jd�rtjjj|�rtd	��n|}tj�}	d}
d}d}|jd�r�tjj
j|�}
t|
j�d
kr�t|
j�dkr�tjjdt�}
t}|jd
i�jd�r�t}|d
}|d
=q�q�t}nt|	||
|�tjj
j|||	�|s�|
rFtjj
j ||�}tjjj!||
�n|r�t|	i|d
6�tjj
j"||	�||d
<q�nitd6S(s#
    Creates a cluster.

    Note: cluster_dict['name'] will be overridden by the cluster param value

    config_dict
        Dictionary with the config values of the new cluster.

    datacenter
        Name of datacenter containing the cluster.
        Ignored if already contained by proxy details.
        Default value is None.

    cluster
        Name of cluster.
        Ignored if already contained by proxy details.
        Default value is None.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        # esxdatacenter proxy
        salt '*' vsphere.create_cluster cluster_dict=$cluster_dict cluster=cl1

        # esxcluster proxy
        salt '*' vsphere.create_cluster cluster_dict=$cluster_dict
    R!sesxdatacenter.get_detailsRus'cluster' needs to be specifiedR sesxcluster.get_detailsR�R>s!VSAN operations are not supportedg@ijv7tmodifyR�Rqtcreate_clusterN(#Rt	serializet
jsonschematvalidatet
exceptionstValidationErrorR
R+R4R|R	R9R:RHR}R)R>R�RRtClusterConfigSpecExRER�tfloatt
apiVersionR�R�tReconfigSpecRbRvR�R�R�treconfigure_cluster_vsantupdate_cluster(R�RuR�RDtschematexcR>R�R�R�R�t	ha_configR�R�t	enable_haR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��sZ%	

	c	C@sDtj�}ytj||�Wn%tjjk
rG}t|��nXt�}|dkr�td�d}t	|�}|s�t
d��q�nI|dkr�td�d}tjj
j||�}td�d}n|jd�rtjjj|�rtd	��ntjj
j||�}tj�}	tjj
j|d
dg�}
x1dd
gD]#}t|	|t|
d|��q^W|
djr�|
dj|	_nd}d}
|jd�rPtjj
j|�}t|j�dkrGt|j �dkrGt!}
tjjj"|�}tjj#dt$�}|j%|_%d|_%qPt$}
nt&|	|||
�|r#t'j(dj)|��tjjj*||�tj�}	tjj
j|d
dg�}
x1dd
gD]#}t|	|t|
d|��q�W|
djr|
dj|	_nt&|	|�ntjj
j+||	�it$d6S(s�
    Updates a cluster.

    config_dict
        Dictionary with the config values of the new cluster.

    datacenter
        Name of datacenter containing the cluster.
        Ignored if already contained by proxy details.
        Default value is None.

    cluster
        Name of cluster.
        Ignored if already contained by proxy details.
        Default value is None.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        # esxdatacenter proxy
        salt '*' vsphere.update_cluster cluster_dict=$cluster_dict cluster=cl1

        # esxcluster proxy
        salt '*' vsphere.update_cluster cluster_dict=$cluster_dict

    R!sesxdatacenter.get_detailsRus'cluster' needs to be specifiedR sesxcluster.get_detailsR�R>s!VSAN operations are not supportedR�R�R�R�g@ijv7R�svsan_spec = {0}R�N(,RR�R�R�R�R�R
R+R4R|R	R9R:RHR}R)R>R�RR�RR�RR�R�R�R�RER�R�R�R�R�RvR�R�RbR�R�R�RMR5R�R�(R�RuR�RDR�R�R>R�R�R�R�RMR�R�R�t	vsan_info((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�sh$	!
	!
c	C@sIt|�}tjjj|�}tjdj|��|pF|pF|sOtnt	}|r�tj
dj|��gtjjj|d|�D]}|j^q�}tj
dj|��|r�|j
|�n|}ntjjj|||||�}	g}
t|tj�rZtjjj|||�}tjjj|dg�}|jdg�}
ng}
x�|	D]�}i|jd6|jjd6|jjd6|jjd	6}g}xtg|
D]9}|jj|jkr�t|jtj�r�|j^q�D],}|j
g|jD]}|j^q�q�W|r4||d
<n|
j|�qgW|
S(s�
    Returns a list of dict representations of the datastores visible to the
    proxy object. The list of datastores can be filtered by datastore names,
    backing disk ids (canonical names) or backing disk scsi addresses.

    Supported proxy types: esxi, esxcluster, esxdatacenter

    datastore_names
        List of the names of datastores to filter on

    backing_disk_ids
        List of canonical names of the backing disks of the datastores to filer.
        Default is None.

    backing_disk_scsi_addresses
        List of scsi addresses of the backing disks of the datastores to filter.
        Default is None.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_datastores_via_proxy

        salt '*' vsphere.list_datastores_via_proxy datastore_names=[ds1, ds2]
    starget name = {}s,Retrieving disk ids for scsi addresses '{0}'tscsi_addressessFound disk ids '{}'sfileSystemVolumeInfo.mountInfoRDR�t
free_spacetcapacitytbacking_disk_ids(R|R9R:RHR�R�RMR5RbRvR�t	get_disksR�textendRvRhRt
HostSystemtget_storage_systemRR)RDRTR�t	freeSpaceR�tvolumetHostVmfsVolumetextenttdiskNameR�(RuR�tbacking_disk_scsi_addressesRDttargetttarget_nametget_all_datastorestdtdisk_idst
datastorestmount_infoststorage_systemR�R�tdstds_dicttitvolRT((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_datastores_via_proxy{sP"
"	



(*
cC@s�tjd�tj�}y0tjii|d6|d6|d6d6|�Wn%tjjk
rp}t|��nXt	|�}t
d�d}|r�tjj
j|d|g�}	|	s�td	j||���q�ntjj
j|||	d
|�}
tS(s�
    Creates a ESXi host disk group with the specified cache and capacity disks.

    datastore_name
        The name of the datastore to be created.

    disk_id
        The disk id (canonical name) on which the datastore is created.

    vmfs_major_version
        The VMFS major version.

    safety_checks
        Specify whether to perform safety check or to skip the checks and try
        performing the required task. Default is True.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.create_vmfs_datastore datastore_name=ds1 disk_id=
            vmfs_major_version=5
    sValidating vmfs datastore inputRDtbacking_disk_idtvmfs_versionRxsesxi.get_detailsRcRs&Disk '{0}' was not found in host '{1}'i(R�R�RR�R�R�R�R�R	R|t	__proxy__R9R:RHR�RR5tcreate_vmfs_datastoreRb(tdatastore_nametdisk_idtvmfs_major_versiont
safety_checksRDR�R�R�thostnameR�R}((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�s*

	cC@s�tjdj||��t|�}tjjj||d|g�}|sdtdj|���n|d}tjjj	||�t
S(s�
    Renames a datastore. The datastore needs to be visible to the proxy.

    datastore_name
        Current datastore name.

    new_datastore_name
        New datastore name.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.rename_datastore old_name new_name
    sRenaming datastore {0} to {1}RusDatastore '{0}' was not foundi(R�RMR5R|R9R:RHRvRtrename_datastoreRb(Rtnew_datastore_nameRDRRR	((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRs
	
cC@s�tjdj|��t|�}tjjj|d|d|g�}|sdtdj|���nt	|�dkr�tdj|���ntjjj
||d�tS(s4
    Removes a datastore. If multiple datastores an error is raised.

    datastore
        Datastore name

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.remove_datastore ds_name
    sRemoving datastore '{0}'t	referenceRusDatastore '{0}' was not foundis$Multiple datastores '{0}' were foundi(R�RMR5R|R9R:RHRvRRGtremove_datastoreRb(RxRDRR((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR,scC@s�tjd�tjjj|�}g|D]{}i|jd6|jd6|jr_|jdj	ndd6|jdkr~|jntj
d6|jr�|jndd6^q)}|S(	s�
    Lists all licenses on a vCenter.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_licenses
    sRetrieving all licensesR�RDiRGR�tusedN(R�RMR9R:RHtget_licensest
licenseKeyRDtlabelsR�REttotalRNtmaxsizeR(RDtlicensestlR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt
list_licensesNs

�cC@s3tjdj|��tjjj|||�tS(s�
    Adds a license to the vCenter or ESXi host

    key
        License key.

    description
        License description added in as a label.

    safety_checks
        Specify whether to perform safety check or to skip the checks and try
        performing the required task

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.add_license key=<license_key> desc='License desc'
    sAdding license '{0}'(R�RMR5R9R:RHtadd_licenseRb(R�RGRRD((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR$iscC@s�tjdj|��|ddkr\tjjj||d�}tjjj||d�S|ddkrpdSt	dj|d���dS(s�
    Returns the entity associated with the entity dict representation

    Supported entities: cluster, vcenter

    Expected entity format:

    .. code-block:: python

        cluster:
            {'type': 'cluster',
             'datacenter': <datacenter_name>,
             'cluster': <cluster_name>}
        vcenter:
            {'type': 'vcenter'}

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.

    entity
        Entity dict in the format above
    sRetrieving entity: {0}R�R�RuR"sUnsupported entity type '{0}'N(
R�RMR5R9R:RHR}R�RER	(RDtentityR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_entity�s
	cC@s�|ddkrtj�}n8|ddkr>tj�}ntdj|d���ytj||�Wn%tjjk
r�}t	|��nXdS(s�
    Validates the entity dict representation

    entity
        Dictionary representation of an entity.
        See ``_get_entity`` docstrings for format.
    R�R�R"sUnsupported entity type '{0}'N(
RR�RR	R5R�R�R�R�R
(R%R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_validate_entity�s
	cC@s�tjdj|��t|�tjjj|dt||�d|�}g|D]}}|d	ksr|j
|krQi|j
d6|jd6|jr�|jdj
nd	d6|jdkr�|jntjd6^qQS(
sP
    Lists the licenses assigned to an entity

    entity
        Dictionary representation of an entity.
        See ``_get_entity`` docstrings for format.

    entity_display_name
        Entity name used in logging

    license_keys:
        List of license keys to be retrieved. Default is None.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_assigned_licenses
            entity={type:cluster,datacenter:dc,cluster:cl}
            entiy_display_name=cl
    s'Listing assigned licenses of entity {0}t
entity_reftentity_nameR�RDiRGR�N(R�RMR5R'R9R:RHtget_assigned_licensesR&RERRDRR�RRNR (R%tentity_display_nametlicense_keysRDtassigned_licensesR"((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_assigned_licenses�s

	cC@s�tjdj||��t|�|r�tjjj|�}g|D]}|j|krE|^qEs�t	dj|���q�ntjjj
|||dt||�d|�dS(s�
    Assigns a license to an entity

    license_key
        Key of the license to assign
        See ``_get_entity`` docstrings for format.

    license_name
        Display name of license

    entity
        Dictionary representation of an entity

    entity_display_name
        Entity name used in logging

    safety_checks
        Specify whether to perform safety check or to skip the checks and try
        performing the required task. Default is False.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.assign_license license_key=00000:00000
            license name=test entity={type:cluster,datacenter:dc,cluster:cl}
    s#Assigning license {0} to entity {1}sLicense '{0}' wasn't foundR(R)N(R�RMR5R'R9R:RHRRRtassign_licenseR&(tlicense_keytlicense_nameR%R+RRDR!R"((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR/�s#

(	c
C@s�|r$|s$tjjd��q$nt}|s9t}ntjjj|d|d|d|d|�}g|D]}tjjj|�^qmS(s�
    Returns a list of hosts for the the specified VMware environment. The list
    of hosts can be filtered by datacenter name and/or cluster name

    hostnames
        Hostnames to filter on.

    datacenter_name
        Name of datacenter. Only hosts in this datacenter will be retrieved.
        Default is None.

    cluster_name
        Name of cluster. Only hosts in this cluster will be retrieved. If a
        datacenter is not specified the first cluster with this name will be
        considerred. Default is None.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    CLI Example:

    .. code-block:: bash

        salt '*' vsphere.list_hosts_via_proxy

        salt '*' vsphere.list_hosts_via_proxy hostnames=[esxi1.example.com]

        salt '*' vsphere.list_hosts_via_proxy datacenter=dc1 cluster=cluster1
    s0Datacenter is required when cluster is specifiedR�R�R�t
get_all_hosts(	R9R�R	RvRbR:RHt	get_hostsR�(t	hostnamesRuR�RDR2thoststh((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_hosts_via_proxy$s#			c
C@st|�}td�d}tjdj|��tjdj|��tjdj|��|ph|sqtnt}g}tjj	j
|d|�}d�tj|�D�}xKtjj	j
||||�D]+}	|ji|	jd6||	jd	6�q�W|S(
s�
    Returns a list of dict representations of the disks in an ESXi host.
    The list of disks can be filtered by disk canonical names or
    scsi addresses.

    disk_ids:
        List of disk canonical names to be retrieved. Default is None.

    scsi_addresses
        List of scsi addresses of disks to be retrieved. Default is None


    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_disks

        salt '*' vsphere.list_disks disk_ids='[naa.00, naa.001]'

        salt '*' vsphere.list_disks
            scsi_addresses='[vmhba0:C0:T0:L0, vmhba1:C0:T0:L0]'
    sesxi.get_detailsRcsRetrieving disks if host '{0}'sdisk ids = {0}sscsi_addresses = {0}RcS@s"i|]\}}||j�qS((R�(t.0t	scsi_addrtlun((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pys
<dictcomp>~s	Rtscsi_address(R|RR�RMR5RbRvR9R:RHtget_scsi_address_to_lun_mapRR�R�R�R�(
RR�RDR�Rt
get_all_disksR�tscsi_address_to_luntcanonical_name_to_scsi_addressR((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt
list_disksVs 
cC@s�|r|rtd��nt|�}td�d}|s�tjjj|�}||kr|tdj||���n||j	}t
jdj|||��nt
jdj||��tjjj|||d|�t
j
dj||��tS(	s�
    Erases the partitions on a disk.
    The disk can be specified either by the canonical name, or by the
    scsi_address.

    disk_id
        Canonical name of the disk.
        Either ``disk_id`` or ``scsi_address`` needs to be specified
        (``disk_id`` supersedes ``scsi_address``.

    scsi_address
        Scsi address of the disk.
        ``disk_id`` or ``scsi_address`` needs to be specified
        (``disk_id`` supersedes ``scsi_address``.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.erase_disk_partitions scsi_address='vmhaba0:C0:T0:L0'

        salt '*' vsphere.erase_disk_partitions disk_id='naa.000000000000001'
    s8Either 'disk_id' or 'scsi_address' needs to be specifiedsesxi.get_detailsRcs7Scsi lun with address '{0}' was not found on host '{1}'s.[{0}] Got disk id '{1}' for scsi address '{2}'s3Erasing disk partitions on disk '{0}' in host '{1}'Rs2Erased disk partitions on disk '{0}' on host '{1}'(R	R|RR9R:RHR<RR5R�R�RMterase_disk_partitionstinfoRb(RR;RDR�RR>((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRA�s*

	
cC@s�|r|rtd��nt|�}td�d}|s�tjjj|�}||kr|tdj||���n||j	}t
jdj|||��nt
jdj||��tjjj||�}g}x�|j
jD]�}g|jjD]}	|	j|jkr�|	^q�d}
i|d6|d	6|j
jd
6|jd6|jd6|j|jd
d6|
jj|
jjd
|
jjdd6}|j|�q�W|S(s�
    Lists the partitions on a disk.
    The disk can be specified either by the canonical name, or by the
    scsi_address.

    disk_id
        Canonical name of the disk.
        Either ``disk_id`` or ``scsi_address`` needs to be specified
        (``disk_id`` supersedes ``scsi_address``.

    scsi_address`
        Scsi address of the disk.
        ``disk_id`` or ``scsi_address`` needs to be specified
        (``disk_id`` supersedes ``scsi_address``.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_disk_partitions scsi_address='vmhaba0:C0:T0:L0'

        salt '*' vsphere.list_disk_partitions disk_id='naa.000000000000001'
    s8Either 'disk_id' or 'scsi_address' needs to be specifiedsesxi.get_detailsRcs7Scsi lun with address '{0}' was not found on host '{1}'s.[{0}] Got disk id '{1}' for scsi address '{2}'s3Listing disk partitions on disk '{0}' in host '{1}'iRR2R5t	partitionR�itsectorsitsize_KB(R	R|RR9R:RHR<RR5R�R�RMtget_disk_partition_infoRRCtlayouttpartitionFormatR�t	endSectortstartSectortendtblocktstartt	blockSizeR�(RR;RDR�RR>tpartition_infoR�t	part_specRMtpart_layoutt	part_dict((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_disk_partitions�s:

"



,cC@s�t|�}td�d}tjdj|��|s?tnt}g}x]tjj	j
|||�D]@}|ji|jj
d6g|jD]}|j
^q�d6�qgW|S(s�
    Returns a list of disk group dict representation on an ESXi host.
    The list of disk groups can be filtered by the cache disks
    canonical names. If no filtering is applied, all disk groups are returned.

    cache_disk_ids:
        List of cache disk canonical names of the disk groups to be retrieved.
        Default is None.

    use_proxy_details
        Specify whether to use the proxy minion's details instead of the
        arguments

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.list_diskgroups

        salt '*' vsphere.list_diskgroups cache_disk_ids='[naa.000000000000001]'
    sesxi.get_detailsRcsListing diskgroups in '{0}'t
cache_disktcapacity_disks(R|RR�RMR5RbRvR9R:RHtget_diskgroupsR�tssdR�tnonSsd(tcache_disk_idsRDR�Rtget_all_diskgroupsR�tdgR((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytlist_diskgroupss
(cC@s�tjd�tj�}y,tjii|d6|d6gd6|�Wn%tjjk
rl}t|��nXt	|�}t
d�d}|r�tjj
j||g�}|r�tdj||���q�n|}	|	jd|�tjj
j|d	|	�}
xQ|	D]I}g|
D]}|j|kr|^qstd
j||���qqWg|
D]}|j|kr\|^q\d}
g|
D]}|j|kr�|^q�}tjjj|�}tjjj||||
|�}tS(s%
    Creates disk group on an ESXi host with the specified cache and
    capacity disks.

    cache_disk_id
        The canonical name of the disk to be used as a cache. The disk must be
        ssd.

    capacity_disk_ids
        A list containing canonical names of the capacity disks. Must contain at
        least one id. Default is True.

    safety_checks
        Specify whether to perform safety check or to skip the checks and try
        performing the required task. Default value is True.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.create_diskgroup cache_disk_id='naa.000000000000001'
            capacity_disk_ids='[naa.000000000000002, naa.000000000000003]'
    sValidating diskgroup inputtcache_idtcapacity_idst
diskgroupssesxi.get_detailsRcsADiskgroup with cache disk id '{0}' already exists ESXi host '{1}'iRs2No disk with id '{0}' was found in ESXi host '{1}'(R�RMRR�R�R�R�R�R	R|RR9R:RHRVRR5tinsertR�R�RR>tget_vsan_disk_management_systemtcreate_diskgroupRb(t
cache_disk_idtcapacity_disk_idsRRDR�R�R�RR_RR�RRRTRUtvsan_disk_mgmt_systemR[((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRb,sD


(,(	c
C@s}tjd�tj�}y,tjii|d6|d6gd6|�Wn%tjjk
rl}t|��nXt	|�}t
d�d}tjj
j|d|�}|rxT|D]I}	g|D]}
|
j|	kr�|
^q�s�tdj|	|���q�q�Wntjj
j|d	|g�}|sAtd
j||���ntjjj|�}tjjj||||d|�tS(s�
    Adds capacity disks to the disk group with the specified cache disk.

    cache_disk_id
        The canonical name of the cache disk.

    capacity_disk_ids
        A list containing canonical names of the capacity disks to add.

    safety_checks
        Specify whether to perform safety check or to skip the checks and try
        performing the required task. Default value is True.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.add_capacity_to_diskgroup
            cache_disk_id='naa.000000000000001'
            capacity_disk_ids='[naa.000000000000002, naa.000000000000003]'
    sValidating diskgroup inputR]R^R_sesxi.get_detailsRcRs2No disk with id '{0}' was found in ESXi host '{1}'RYsBNo diskgroup with cache disk id '{0}' was found in ESXi host '{1}'i(R�RMRR�R�R�R�R�R	R|RR9R:RHR�R�RR5RVR>Ratadd_capacity_to_diskgroupRb(
RcRdRRDR�R�R�RR�RRR_Re((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRfqs>


(c
	C@s�tjd�tj�}y,tjii|d6|d6gd6|�Wn+tjjk
rr}tt	|���nXt
|�}td�d}tj
jj|d|�}	|rxT|D]I}
g|	D]}|j|
kr�|^q�s�tdj|
|���q�q�Wntj
jj|d	|g�}|sGtd
j||���ntjdj|��tj
jj|||dd
g|	D]}|j|kr�|^q�d|�tS(s�
    Remove capacity disks from the disk group with the specified cache disk.

    cache_disk_id
        The canonical name of the cache disk.

    capacity_disk_ids
        A list containing canonical names of the capacity disks to add.

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

    safety_checks
        Specify whether to perform safety check or to skip the checks and try
        performing the required task. Default value is True.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.remove_capacity_from_diskgroup
            cache_disk_id='naa.000000000000001'
            capacity_disk_ids='[naa.000000000000002, naa.000000000000003]'
    sValidating diskgroup inputR]R^R_sesxi.get_detailsRcRs2No disk with id '{0}' was found in ESXi host '{1}'RYsBNo diskgroup with cache disk id '{0}' was found in ESXi host '{1}'sdata_evacuation = {0}iRUtdata_evacuation(R�RMRR�R�R�R�R�R	tstrR|RR9R:RHR�R�RR5RVR>tremove_capacity_from_diskgroupRb(
RcRdRgRRDR�R�R�RR�RRR_((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRi�s>"


(
cC@s�tjd�t|�}td�d}tjjj|d|g�}|sitdj	||���ntjdj	|��tjj
j|||dd|�tS(	s�
    Remove the diskgroup with the specified cache disk.

    cache_disk_id
        The canonical name of the cache disk.

    data_accessibility
        Specifies whether to ensure data accessibility. Default value is True.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.remove_diskgroup cache_disk_id='naa.000000000000001'
    sValidating diskgroup inputsesxi.get_detailsRcRYsBNo diskgroup with cache disk id '{0}' was found in ESXi host '{1}'sdata accessibility = {0}itdata_accessibility(
R�RMR|RR9R:RHRVRR5R>tremove_diskgroupRb(RcRjRDR�RR_((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRk�s
cC@s�i}t|�}td�d}tjjj|�}|sbtjdj|��t	|d<|Sit
d6i|jjd6d6dj|j
�d6S(	s�
    Returns the host cache configuration on the proxy host.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.get_host_cache
    sesxi.get_detailsRcs'Host cache not configured on host '{0}'RqRDRxs{}MiBt	swap_size(R|RR9R:RHtget_host_cacheR�R�R5RvRbR�RDtswapSize(RDR�R�Rthci((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRms

cC@stjd�tj�}y)tji|d6|d6|d6|�Wn%tjjk
ri}t|��nX|std��nit	d6}t
|�}td�d}|r�tj
jj||d|g�}	|	s�td	j||���n|	d
}
ntj
jj||
|�tS(s�
    Configures the host cache on the selected host.

    enabled
        Boolean flag specifying whether the host cache is enabled.

    datastore
        Name of the datastore that contains the host cache. Must be set if
        enabled is ``true``.

    swap_size_MiB
        Swap size in Mibibytes. Needs to be set if enabled is ``true``. Must be
        smaller than the datastore size.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.configure_host_cache enabled=False

        salt '*' vsphere.configure_host_cache enabled=True datastore=ds1
            swap_size_MiB=1024
    sValidating host cache inputRqRt
swap_size_MiBs)Disabling the host cache is not supportedsesxi.get_detailsRcRus+Datastore '{0}' was not found on host '{1}'i(R�R�RR�R�R�R�R�R	RvR|RR9R:RHRvRR5tconfigure_host_cacheRb(RqRxRpRDR�R�R�R�RRzR}((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRq<s0


cC@sX|s6t||�}|r'|g}qTtd��nt|t�sTtd��n|S(sg
    Helper function that checks to see if the host provided is a vCenter Server or
    an ESXi host. If it's an ESXi host, returns a list of a single host_name.

    If a host reference isn't found, we're trying to find a host object for a vCenter
    server. Raises a CommandExecutionError in this case, as we need host references to
    check against.
    sdNo host reference found. If connecting to a vCenter Server, a list of 'host_names' must be provided.s'host_names' must be a list.(R�RRhRJ(RDR,R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�vs	cC@si}x|dj�D]}|j�j�}|jd�rx|jd�}d|dkrjt|d<qxt|d<Pn|jd�r�|jd�}|dj�|d<n|jd	�r�|jd�}|dj�|d
<n|jd�r|jd�}|dj�|d<qqW|S(
s�
    Helper function to format the stdout from the get_coredump_network_config function.

    cmd_ret
        The return dictionary that comes from a cmd.run_all call.
    Rfsenabled:t:ttrueiRqs
host vnic:Rxsnetwork server ip:tipsnetwork server port:R0(t
splitlinesR�tlowert
startswithR�RbRv(tcmd_retR�tlineRqRxRttip_port((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRn�s&

cC@s�itd6id6}xj|dj�D]X}|jd�r@q%n|jd�rUq%n|j�}t|d�|d|d<q%W|S(s�
    Helper function to format the stdout from the get_firewall_status function.

    cmd_ret
        The return dictionary that comes from a cmd.run_all call.
    RuR{RftNames---ii(RbRuRwR�tbool(RxR�Rytruleset_status((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR|�s

 cC@s�i|ddkd6}|ddkr8|d|d<n`x]|dj�D]K}|j�}|jd�}|dj�}|dj�}|||<qIW|S(s�
    Helper function to format the stdout from the get_syslog_config function.

    cmd_ret
        The return dictionary that comes from a cmd.run_all call.
    ReiRuRfR�s: i(RuR�R�(RxR�RytcfgvarsR�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��scC@s
|jjS(s?
    Helper function that returns a dateTimeManager object
    (R�R�(thost_reference((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��scC@s|tjjj|�j}|r9|jd|dt�}n|jd|dt�}|dkrx|jd|dt�}n|S(s,
    Helper function that returns a host object either from the host location or the host_name.
    If host_name is provided, that is the host_object that will be returned.

    The function will first search for hosts by DNS Name. If no hosts are found, it will
    try searching by IP Address.
    tdnsNametvmSearchRtN(	R9R:RHR�tsearchIndext
FindByDnsNameRvREtFindByIp(RDR,R�tsearch_indexR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��scC@st|�jd�S(sN
    Helper function that returns a list of ssd objects for a given host.
    tSSDs(t_get_host_disksR)(R((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�scC@st|�jd�S(sR
    Helper function that returns a list of Non-SSD objects for a given host.
    sNon-SSDs(R�R)(R((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�scC@s�|jj}|jj}g}g}xX|D]P}y
|j}Wntk
rWt}nX|rn|j|�q+|j|�q+Wi|d6|d6S(s_
    Helper function that returns a dictionary containing a list of SSD and Non-SSD disks.
    R�sNon-SSDs(R�t
storageSystemtstorageDeviceInfotscsiLunRWR\RvR�(RRR�tssdstnon_ssdsR�thas_ssd_attr((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�s



cC@s
|jjS(sY
    Helper function that returns a service manager object from a given host object.
    (R�R�(R((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRscC@s�i}x{|D]s}t||d|�}|jj}|dkr}dj|�}tj|�|jii|d6|6�q
ng}|j�}	x-|	D]%}
|
j	dkr�|j
|
�q�q�W|sdj|�}tj|�|jii|d6|6�q
nt|�t
|�}g}xD|D]<}
x3|D]+}|
j|jjkr2|j
|
�q2q2Wq%W|jii|d6|6�q
W|S(s
    Helper function that returns a dictionary of host_name keys with either a list of eligible
    disks that can be added to VSAN or either an 'Error' message or a message saying no
    eligible disks were found. Possible keys/values look like:

    return = {'host_1': {'Error': 'VSAN System Config Manager is unset ...'},
              'host_2': {'Eligible': 'The host xxx does not have any VSAN eligible disks.'},
              'host_3': {'Eligible': [disk1, disk2, disk3, disk4],
              'host_4': {'Eligible': []}}
    R�szVSAN System Config Manager is unset for host '{0}'. VSAN configuration cannot be changed without a configured VSAN System.RgR;s5The host '{0}' does not have any VSAN eligible disks.R�N(R�R�R5RER5R�R�RitQueryDisksForVsantstateR�twarningRRR�R�(RDR,R�RSR�R�R:R�tsuitable_disksR�titemR�tmatchingR�t
suitable_disk((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�s8
	




c
C@si}
t}t|t�s'|g}nx�|D]�}||kr�tjjj|||||d|d|d|d|	�}
i|
|<|
ddk|
|d<|
ddkr�t}|
d|
|d	<q�q.t}i|
|<t|
|d<d
|
|d	<q.W||
d<|
S(sm
    Helper function for reset_syslog_config that resets the config and populates the return dictionary.
    R/R0RcRdReiRuRfR�s&Invalid syslog configuration parameter(RbRhRJR9R:RHRRv(R,R-R.RoR�R�R/R0RcRdR�tall_successtreset_paramRS((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�Us(



c

C@sqdj||�}
i}ddddddg}||krd|jitd6d	j|�d
6�|Stjjj||||
d|d|d
|d|	�}
|
ddkr�|jiitd6|
dd
6|6�n|jiitd6|6�|rm|r|}|g}n|}t|||d|d|d|d|	�j	|�}
|jii|
ddkd6d6�n|S(si
    Helper function for set_syslog_config that sets the config and populates the return dictionary.
    s"system syslog config set --{0} {1}R�R�sdefault-rotatesdefault-sizesdefault-timeouts
logdir-uniqueRus%'{0}' is not a valid config variable.R�R/R0RcRdReiRfRktsyslog_restart(
R5RiRvR9R:RHRRbR�R)(R,R-R.R�R�R/R0R�RcRdRoR�R�RlR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�vs2	(c)C@s�i}t|d<g|d<tjjjd|d|d|d|d|	�}tjjj||�}
|
s�|djdj|��t|d<ntjjj	|
|�}|s�|djd	j|��t|d<ntjjj
|
|�}|s|djd
j|��t|d<nt|d�dkr3|S|
jj
}yt|||
�}
Wn*tk
r�}dj|j�|d<|SXxV|
D]N}i||<||jitd
6|d6|d6|d6|d6|d6�t|||�}|s||jidj|�d6�t|d<q�ntjjjd|�}tjjd|�}tjjj|�}g|D]}|j|krf|^qf}t|�dkr�||jidj|�d6�t|d<q�ntjjj|�}g|D]}|j|kr�|^q�}t|�dkrJ||jidj|�d6�t|d<q�ntjjj|�}|s�||jidd6�t|d<q�ntjjjd|d|j�}tjjjd|g�}tjjjd|dd�}tjd|
jj d|g�}|
j!d|�} y#tjjj"| |dd d!�Wn�t#k
r�}t$|d�r�t$|j%d"�r�||j%jko�d#|j%jks�t|d<||ji|j%jd6�q�q�q��nX|j&j'}!d7}"x:|jj)j*D])}#|#j+j,|dj*kr�|#}"Pq�q�W|"sI||jid$d6�t|d<q�ntj-d%d&d'|djd|"j+j,dtj.d(tj/d)|jd*|jj0j
���}$|jj)j1dj2}%tj3d%d&d+d,dtj4d-|%��}&tj5d%d&d.|dtj6d/|��}'tj7d0|&gd1|'gdtj8d%d2d|"j+�gd3|$g�}(y2|!j9d4d5d|(�||jitd
6�Wq�t#k
r�}t$|d"�r�||jid6j|j�d6�q�q��q�Xq�W|S(8s|
    Adds an ESXi host to a vSphere Distributed Virtual Switch and migrates
    the desired adapters to the DVS from the standard switch.

    host
        The location of the vCenter server.

    username
        The username used to login to the vCenter server.

    password
        The password used to login to the vCenter server.

    vmknic_name
        The name of the virtual NIC to migrate.

    vmnic_name
        The name of the physical NIC to migrate.

    dvs_name
        The name of the Distributed Virtual Switch.

    target_portgroup_name
        The name of the distributed portgroup in which to migrate the
        virtual NIC.

    uplink_portgroup_name
        The name of the uplink portgroup in which to migrate the
        physical NIC.

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

    host_names:
        An array of VMware host names to migrate

    CLI Example:

    .. code-block:: bash

        salt some_host vsphere.add_host_to_dvs host='vsphere.corp.com'
            username='administrator@vsphere.corp.com' password='vsphere_password'
            vmknic_name='vmk0' vmnic_name='vnmic0' dvs_name='DSwitch'
            target_portgroup_name='DPortGroup' uplink_portgroup_name='DSwitch1-DVUplinks-181'
            protocol='https' port='443', host_names="['esxi1.corp.com','esxi2.corp.com','esxi3.corp.com']"

    Return Example:

    .. code-block:: yaml

        somehost:
            ----------
            esxi1.corp.com:
                ----------
                dvs:
                    DSwitch
                portgroup:
                    DPortGroup
                status:
                    True
                uplink:
                    DSwitch-DVUplinks-181
                vmknic:
                    vmk0
                vmnic:
                    vmnic0
            esxi2.corp.com:
                ----------
                dvs:
                    DSwitch
                portgroup:
                    DPortGroup
                status:
                    True
                uplink:
                    DSwitch-DVUplinks-181
                vmknic:
                    vmk0
                vmnic:
                    vmnic0
            esxi3.corp.com:
                ----------
                dvs:
                    DSwitch
                portgroup:
                    DPortGroup
                status:
                    True
                uplink:
                    DSwitch-DVUplinks-181
                vmknic:
                    vmk0
                vmnic:
                    vmnic0
            message:
            success:
                True

    This was very difficult to figure out.  VMware's PyVmomi documentation at

    https://github.com/vmware/pyvmomi/blob/master/docs/vim/DistributedVirtualSwitch.rst
    (which is a copy of the official documentation here:
    https://www.vmware.com/support/developer/converter-sdk/conv60_apireference/vim.DistributedVirtualSwitch.html)

    says to create the DVS, create distributed portgroups, and then add the
    host to the DVS specifying which physical NIC to use as the port backing.
    However, if the physical NIC is in use as the only link from the host
    to vSphere, this will fail with an unhelpful "busy" error.

    There is, however, a Powershell PowerCLI cmdlet called Add-VDSwitchPhysicalNetworkAdapter
    that does what we want.  I used Onyx (https://labs.vmware.com/flings/onyx)
    to sniff the SOAP stream from Powershell to our vSphere server and got
    this snippet out:

    .. code-block:: xml

        <UpdateNetworkConfig xmlns="urn:vim25">
          <_this type="HostNetworkSystem">networkSystem-187</_this>
          <config>
            <vswitch>
              <changeOperation>edit</changeOperation>
              <name>vSwitch0</name>
              <spec>
                <numPorts>7812</numPorts>
              </spec>
            </vswitch>
            <proxySwitch>
                <changeOperation>edit</changeOperation>
                <uuid>73 a4 05 50 b0 d2 7e b9-38 80 5d 24 65 8f da 70</uuid>
                <spec>
                <backing xsi:type="DistributedVirtualSwitchHostMemberPnicBacking">
                    <pnicSpec><pnicDevice>vmnic0</pnicDevice></pnicSpec>
                </backing>
                </spec>
            </proxySwitch>
            <portgroup>
              <changeOperation>remove</changeOperation>
              <spec>
                <name>Management Network</name><vlanId>-1</vlanId><vswitchName /><policy />
              </spec>
            </portgroup>
            <vnic>
              <changeOperation>edit</changeOperation>
              <device>vmk0</device>
              <portgroup />
              <spec>
                <distributedVirtualPort>
                  <switchUuid>73 a4 05 50 b0 d2 7e b9-38 80 5d 24 65 8f da 70</switchUuid>
                  <portgroupKey>dvportgroup-191</portgroupKey>
                </distributedVirtualPort>
              </spec>
            </vnic>
          </config>
          <changeMode>modify</changeMode>
        </UpdateNetworkConfig>

    The SOAP API maps closely to PyVmomi, so from there it was (relatively)
    easy to figure out what Python to write.
    RuR�R,R-R.R/R0s1No Distributed Virtual Switch found with name {0}s'No target portgroup found with name {0}s'No uplink portgroup found with name {0}isError retrieving hosts: {0}R�tuplinkR"tvmknictvmnicR�sHost {1} not foundR�sPhysical nic {0} not foundsVirtual nic {0} not founds-Unable to get the host's virtual nic manager.t
pnicDevicetuplinkPortgroupKeytpnicSpecRZtaddRRsAdding host to the DVSR4iR�salready existss$No matching portgroup on the vSwitchtchangeOperationteditR2tdistributedVirtualPorttportgroupKeyt
switchUuidRDtvSwitch0RR�tbackingtvswitchtproxySwitchtremovetvnict
changeModeR�s Failed to migrate adapters ({0})N(:RbR9R:RHRIt_get_dvsR�R5Rvt_get_dvs_portgroupt_get_dvs_uplink_portgroupRGR�R�R�RR�RiR�RR�t
HostMemberR?t
_get_pnicsR2t
_get_vnicst_get_vnic_managertPnicSpecR�tPnicBackingt
ConfigSpect
DVSConfigSpecRtReconfigureDvs_TaskR7RLR�R�R�t
networkSystemREtnetworkR"RRDtHostVirtualNicConfigtHostVirtualNicSpect&DistributedVirtualSwitchPortConnectiontdistributedVirtualSwitchR�RtHostVirtualSwitchConfigtHostVirtualSwitchSpectHostProxySwitchConfigtHostProxySwitchSpectHostNetworkConfigtHostPortGroupConfigtUpdateNetworkConfig()R,R-R.tvmknic_namet
vmnic_nameRVttarget_portgroup_nametuplink_portgroup_nameR/R0R�RSRDR�ttarget_portgrouptuplink_portgrouptdvs_uuidRTR�R�tdvs_hostmember_configtdvs_hostmembertp_nicstxtp_nictv_nicstv_nict	v_nic_mgrt
dvs_pnic_spectpnic_backingtdvs_hostmember_config_specRWR<tnetwork_systemtsource_portgrouptpgtvirtual_nic_configtcurrent_vswitch_portstvswitch_configtproxyswitch_configthost_network_config((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytadd_host_to_dvs�s�

	
	
	


!
		(!
(!

		!$
	
	
									$c
C@s�t�}tjjj|�s-td��nd
}|dkr�t�\
}}}}}}}	}
}}tjjj||�}
tjjj	|
|�}n�|dkr�t
�\	}}}}}}}	}
}tjjj||�}n�|dkrtjjj|�}n�|dkr�td�}d|kr<t
d��ntjjj|d|d	�}|s}td
j|d	���n|d}ntjdj|��|S(s�
    Returns the target object of a proxy.

    If the object doesn't exist a VMwareObjectRetrievalError is raised

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
    sB'_get_proxy_target' not supported when connected via the ESXi hostR R!R"Rsesxi.get_detailss:Proxies connected directly to ESXi hosts are not supportedR�RcsESXi host '{0}' was not foundisreference = {0}N(R+R9R:RHR�RREt_get_esxcluster_proxy_detailsR}R�t _get_esxdatacenter_proxy_detailstget_root_folderRR
R3RR5R�RM(RDR>RR,R-R.R/R0R1R2R3RuR�R�R6t
references((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR|�s4	'$

c
C@s}td�}|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd	�|jd
�f	S(s;
    Returns the running esxdatacenter's proxy details
    sesxdatacenter.get_detailsR"R-R.R/R0R1R2R3Ru(R4R)(tdet((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�s
$$cC@s�td�}|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd	�|jd
�|jd�f
S(s8
    Returns the running esxcluster's proxy details
    sesxcluster.get_detailsR"R-R.R/R0R1R2R3RuR�(R4R)(R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�%s

$$$c	C@s�td�}|jd�}|jd�r8|d}nd}|jd�r]|dg}n||jd�|jd�|jd�|jd�|jd	�|jd
�|jd�|f	S(
s2
    Returns the running esxi's proxy details
    sesxi.get_detailsR,R"RcR-R.R/R0R1R2R3N(RR)RE(R�R,Rk((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_esxi_proxy_details0s

$cC@s4tjjj||d|d|d|d|�}|S(s�
    Returns vm object properties.

    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.

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.
    Rut
vm_propertiesttraversal_specR�(R9R:RHtget_vm_by_property(RDRuR�R�R�RDtvirtual_machine((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_vm@s	cC@sHtjjj�}|}tjjj�g|_tjjj	||�}d|krstjjj
||d�}nZtjjj|d|d|dg�}	|	s�tjj
dj|d���n|	d}tjjj|||g||�}
|
r%t|
dj�dkr%tjjd��n|
r@|
djr@|
dSd	Sd	S(
s�
    Queries the virtual machine config file and returns
    vim.host.DatastoreBrowser.SearchResults object on success None on failure

    name
        Name of the virtual machine

    datacenter
        Datacenter name

    datastore
        Datastore where the virtual machine files are stored

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.
    R�R�R�R,s#ESXi host named '{0}' wasn't found.iisEMultiple configuration files found in the same virtual machine folderN(RR,tDatastoreBrowsert
SearchSpect
VmConfigQueryR�R9R:RHR}R�R3R�RR5tget_datastore_filesRGtfiletVMwareMultipleObjectsErrorRE(RDRut	placementRxRDtbrowser_spect	directorytdatacenter_objecttcontainer_objecttcontainer_objectstfiles((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_vm_config_fileds8		
		R�cC@s�tjdj|��|dkretjdj|��tjj�}d|_||_||_n|dkr�t	|�|_
ndS(s�
    Specifies vm container version or schedules upgrade,
    returns True on change and False if nothing have been changed.

    hardware_version
        Hardware version string eg. vmx-08

    config_spec
        Configuration spec object

    operation
        Defines the operation which should be used,
        the possibles values: 'add' and 'edit', the default value is 'add'
    s8Configuring virtual machine hardware version version={0}R�s*Scheduling hardware version upgrade to {0}talwaysR�N(R�RMR5RtvmtScheduledHardwareUpgradeInfot
upgradePolicyt
versionKeytscheduledHardwareUpgradeInfoRhR^(thardware_versionR�RZtscheduled_hardware_upgrade((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_hardware_version�s

		cC@s�tjdj|��d|kr8t|d�|_nd|krZt|d�|_nd|kr�|dr�|d|_nd|kr�|dr�|d|_nd|kr�|dr�|d|_ndS(s�
    Sets CPU core count to the given value

    config_spec
        vm.ConfigSpec object

    cpu_props
        CPU properties dict
    s6Configuring virtual machine CPU settings cpu_props={0}tcounttcores_per_sockettnestedthotaddt	hotremoveN(	R�RMR5R�tnumCPUstnumCoresPerSockettnestedHVEnabledtcpuHotAddEnabledtcpuHotRemoveEnabled(R�t	cpu_props((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_cpu_config�s

cC@s!tjdj|��d|kr�d|kr�y�|dj�dkrX|dd}nV|dj�dkr{|d}n3|dj�dkr�tt|d�d�}nWn'ttfk
r�t|d�}nX||_nd|kr|d|_	nd	|kr|d	|_
nd
S(s�
    Sets memory size to the given value

    config_spec
        vm.ConfigSpec object

    memory
        Memory size and unit
    s6Configuring virtual machine memory settings memory={0}tsizetunittkbitmbtgbtreservation_maxRN(R�RMR5RvR�R�t	TypeErrort
ValueErrortmemoryMBtmemoryReservationLockedToMaxtmemoryHotAddEnabled(R�tmemoryt	memory_mb((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_memory_config�s"


!cC@s&t|d|dtd|�}|dS(s&
    Returns extra config parameters from a virtual machine advanced config list

    vm_name
        Virtual machine name

    datacenter
        Datacenter name where the virtual machine is available

    service_instance
        vCenter service instance for connection and configuration
    RutobjectsRDtadvanced_configs(t
get_vm_configRb(tvm_nameRuRDtcurrent_config((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytget_advanced_configs�s
		cC@s�tjdj|��t|t�r:tjjd��nx�tj	|�D]{\}}|r�xf|D]0}|j
|krc|jt|�krcqcqcqcWqJtj
jd|d|�}|jj|�qJWdS(s�
    Sets configuration parameters for the vm

    config_spec
        vm.ConfigSpec object

    advanced_config
        config key value pairs

    vm_extra_config
        Virtual machine vm_ref.config.extraConfig object
    s1Configuring advanced configuration parameters {0}scThe specified 'advanced_configs' configuration option cannot be parsed, please check the parametersR�R�N(R�RMR5RhRhR9R�R	RR�R�R�RR�R�textraConfigR�(R�tadvanced_configtvm_extra_configR�R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_advanced_configs

	
$
c
C@s�t|d|dtd|�}ti|d6|d6|�}tjjj||�}tjjj|tj	|ddd|�}tj
j�}|dj}	t
||dj|jj�|	r�tjjj||�ni|	d6S(	su
    Appends extra config parameters to a virtual machine advanced config list

    vm_name
        Virtual machine name

    datacenter
        Datacenter name where the virtual machine is available

    advanced_configs
        Dictionary with advanced parameter key value pairs

    service_instance
        vCenter service instance for connection and configuration
    RuRRDRDRt
property_namet
container_reftadvanced_config_changes(RRbtcompare_vm_configsR9R:RHR}tget_mor_by_propertyRtVirtualMachineR�R�tdiffsR$t
new_valuesR�R!t	update_vm(
RRuRRDRR+tdatacenter_reftvm_refR�tchanges((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytset_advanced_configs"s*		
			

cC@s�tjdj|��t|t�r:tjjd��ng}xi|D]a}xX|D]P}|j|krTt	j
jd|dd�}|jj
|�|j
|�qTqTWqGW|S(s�
    Removes configuration parameters for the vm

    config_spec
        vm.ConfigSpec object

    advanced_config
        List of advanced config keys to be deleted

    vm_extra_config
        Virtual machine vm_ref.config.extraConfig object
    s.Removing advanced configuration parameters {0}scThe specified 'advanced_configs' configuration option cannot be parsed, please check the parametersR�R�t(R�RMR5RhRhR9R�R	R�RR�R�R!R�(R�R"R#tremoved_configsR�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_delete_advanced_configMs

	

cC@s�tjjj||�}tjjj|tj|ddd|�}tjj�}t	|||j
j�}|r�tjjj||�ni|d6S(s\
    Removes extra config parameters from a virtual machine

    vm_name
        Virtual machine name

    datacenter
        Datacenter name where the virtual machine is available

    advanced_configs
        List of advanced config values to be removed

    service_instance
        vCenter service instance for connection and configuration
    R%RDR&R3(
R9R:RHR}R)RR*R�R�R4R�R!R-(RRuRRDR.R/R�R3((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytdelete_advanced_configsjs			cC@s]g|D]$}|r|j|kr|j^q}|sUtjjdj|���n|dS(s�
    Returns key number of the SCSI controller keys

    bus_number
        Controller bus number from the adapter

    scsi_ctrls
        List of SCSI Controller objects (old+newly created)
    s(SCSI controller number {0} doesn't existi(t	busNumberR�R9R�tVMwareVmCreationErrorR5(t
bus_numbert
scsi_ctrlstctrlR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_scsi_controller_key�s

$	tGBc

C@s�tjdj|||||||	|
��tjjj�}tjjj�|_||j_||j_	tj
�|j_|r�tj
jj||�}|d|j_n|r�||jj_n|dk	s�|dk	r
tjjjj�|j_d|jj_n|dk	r(||jj_n|dk	rR|dkrR||jj_n|rg||j_n|dkr�tjjjjj|_djtj
jj|	�|
�|jj_tjjjjj|_ n'|dkr�tjjjjj!|_n|S(	s�
    Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit
    a virtual disk device

    unit_number
        Add network adapter to this address

    key
        Device key number

    operation
        Action which should be done on the device add or edit

    disk_label
        Label of the new disk, can be overridden

    size
        Size of the disk

    unit
        Unit of the size, can be GB, MB, KB

    controller_key
        Unique umber of the controller key

    thin_provision
        Boolean for thin provision

    eagerly_scrub
        Boolean for eagerly scrubbing

    datastore
        Datastore name where the disk will be located

    filename
        Full file name of the vm disk
    s�Configuring hard disk {0} size={1}, unit={2}, controller_key={3}, thin_provision={4}, eagerly_scrub={5}, datastore={6}, filename={7}R
t
persistentRER�s	[{0}] {1}R�N("R�RMR5RR�R2tVirtualDeviceSpectVirtualDiskR�t
unitNumbertDescriptiont
deviceInfoR9R:RHt
convert_to_kbtcapacityInKBtlabelREtFlatVer2BackingInfoR�tdiskModetthinProvisionedteagerlyScrubt
controllerKeyt	OperationR�RZR�tfileNamet
FileOperationtcreatet
fileOperationR�(
tunit_numberR�RZt
disk_labelR
Rtcontroller_keytthin_provisiont
eagerly_scrubRxtfilenamet	disk_spectconvert_size((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_hard_disk�s@(	
$R2cC@stjdj|��|d
kr�tjjj|�}t|t|��rU|}q|rtjdj|j	j
t|�jjdd	�d	d
j
�|��qnh|r�|r�tjdj|j	j
|��n|}n1|s�tjdj|��ntjjj�}|S(s
    Returns a vim.vm.device.VirtualEthernetCard object specifying a virtual
    ethernet card information

    network_adapter
        None or VirtualEthernet object

    adapter_type
        String, type of adapter

    network_adapter_label
        string, network adapter name
    s<Configuring virtual machine network adapter adapter_type={0}tvmxnettvmxnet2tvmxnet3te1000te1000es*Changing type of '{0}' from '{1}' to '{2}'t.iis7Cannot change type of '{0}' to '{1}'. Not changing typesLThe type of '{0}' has not been specified. Creating of default type 'vmxnet3'(RYRZR[R\R](R�RMR5R9R:RHtget_network_adapter_typeRhR�RBRER8trsplitRvR�RR�R2tVirtualVmxnet3(tnetwork_adaptertadapter_typetnetwork_adapter_labeltedited_network_adapter((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_create_adapter_type�s0
			&	
	
cC@s`tjdj||tjjj|���i}|r\|dkr�tjjj|d|g�}|s�tjj	dj|���n|d}t
jjj
j�}||_||_q\|dkr\tjjj|d|g�}|stjj	dj|���n|d}t
jjd	|jd
|jjj�}t
jjj
j�}||_q\n|S(s
    Returns a vim.vm.device.VirtualDevice.BackingInfo object specifying a
    virtual ethernet card backing information

    network_name
        string, network name

    switch_type
        string, type of switch

    parent_ref
        Parent reference to search for network
    sWConfiguring virtual machine network backing network_name={0} switch_type={1} parent={2}tstandardt
network_namess)The network '{0}' could not be retrieved.itdistributedR�s,The port group '{0}' could not be retrieved.R�R�(R�RMR5R9R:RHR�tget_networksR�RRR�R2tVirtualEthernetCardtNetworkBackingInfot
deviceNameR�R�R�tPortConnectionR�R�R�R�t!DistributedVirtualPortBackingInfoR0(tnetwork_nametswitch_typeR�R�tnetworkstnetwork_reftdvs_port_connection((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_create_network_backing s@	
		
	c	
C@s�|j�j�|j�j�tjdj|||||��tjjj�}	t	|	j|d|�|	_tj
�|	j_|dkr�tjjjjj
|	_n'|dkr�tjjjjj|	_n|r|rt|||�|	j_||	jj_n|r||	j_n|r2||	jj_n|rS||	j_d|	j_nt|	j_|r�tjjjj�|	j_|d|	jj_|d|	jj_n|	S(sc
    Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a
    network device

    network_adapter_label
        Network adapter label

    key
        Unique key for device creation

    network_name
        Network or port group name

    adapter_type
        Type of the adapter eg. vmxnet3

    switch_type
        Type of the switch: standard or distributed

    operation
        Type of operation: add or edit

    connectable
        Dictionary with the device connection properties

    mac
        MAC address of the network adapter

    parent
        Parent object reference
    sConfiguring virtual machine network adapter network_adapter_label={0} network_name={1} adapter_type={2} switch_type={3} mac={4}RdR�R�tManualtstart_connectedtallow_guest_control(R�RvR�RMR5RR�R2R>RfRARBRKR�RZR�RuR�RTR�REt
macAddresstaddressTypeRbtwakeOnLanEnabledt
VirtualDevicetConnectInfotconnectabletstartConnectedtallowGuestControl(
R�RpRcRqRdRZR~tmactparenttnetwork_spec((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_network_adapter_configRsH"
cC@s�tjdj|||||��tjjj�}|dkr^d}tjjj�|_n~|dkr�d}tjjj�|_nT|dkr�d}tjjj	�|_n*|dkr�d	}tjjj
�|_n|d
krtjjjjj|_
n'|dkr*tjjjjj|_
n||j_||j_tj�|j_||jj_||jj_|dkr�tjjjjj|j_nT|d
kr�tjjjjj|j_n*|dkr�tjjjjj|j_n|S(s�
    Returns a vim.vm.device.VirtualDeviceSpec object specifying to
    add/edit a SCSI controller

    adapter
        SCSI controller adapter name

    adapter_type
        SCSI controller adapter type eg. paravirtual

    bus_sharing
         SCSI controller bus sharing eg. virtual_sharing

    key
        SCSI controller unique key

    bus_number
        Device bus number property

    operation
        Describes the operation which should be done on the object,
        the possibles values: 'add' and 'edit', the default value is 'add'

    .. code-block: bash

        scsi:
          adapter: 'SCSI controller 0'
          type: paravirtual or lsilogic or lsilogic_sas
          bus_sharing: 'no_sharing' or 'virtual_sharing' or 'physical_sharing'
    s_Configuring scsi controller adapter={0} adapter_type={1} bus_sharing={2} key={3} bus_number={4}tlsilogics	LSI Logictlsilogic_sass
LSI Logic SastparavirtualsVMware paravirtual SCSItbuslogics	Bus LogicR�R�tvirtual_sharingtphysical_sharingt
no_sharing(R�RMR5RR�R2R>tVirtualLsiLogicControllertVirtualLsiLogicSASControllertParaVirtualSCSIControllertVirtualBusLogicControllerRKR�RZR�R�R6RARBRERTtVirtualSCSIControllertSharingtvirtualSharingt	sharedBustphysicalSharingt	noSharing(tadapterRctbus_sharingR�R8RZt	scsi_specRT((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_scsi_controller�s> c	C@s�g}tddd�}|r�g|D]}|d^q%}tjdj|��xJt||�D]6\}}|jt|dd|t|d���qaWn|S(s�
    Returns a list of vim.vm.device.VirtualDeviceSpec objects representing
    IDE controllers

    ide_controllers
        IDE properties
    i8���i���i����R�sCreating IDE controllers {0}R�i�(RR�RMR5RR�t_apply_ide_controller_configtabs(tide_controllerst	ide_ctrlsR�tidetdevsR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_create_ide_controllers�s	(cC@s�tjdj|��tjjj�}tjjj�|_|dkrdtjjjjj	|_
n|dkr�tjjjjj|_
n||j_||j_
|r�tj�|j_||jj_||jj_n|S(s@
    Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit an
    IDE controller

    ide_controller_label
        Controller label of the IDE adapter

    operation
        Type of operation: add or edit

    key
        Unique key of the device

    bus_number
        Device bus number property
    s3Configuring IDE controller ide_controller_label={0}R�R�(R�RMR5RR�R2R>tVirtualIDEControllerRKR�RZR�R�R6RARBRERT(tide_controller_labelRZR�R8tide_spec((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR��s
cC@s�g}tddd�}|r�g|D]}|d^q%}tjdj|��xDt||�D]0\}}|jt|dd||d��qaWn|S(s�
    Returns a list of vim.vm.device.VirtualDeviceSpec objects representing
    SATA controllers

    sata_controllers
        SATA properties
    ih��i6��i����R�sCreating SATA controllers {0}R�R8(RR�RMR5RR�t_apply_sata_controller_config(tsata_controllerst
sata_ctrlsR�tsataR�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_create_sata_controllers"s	"cC@s�tjdj|��tjjj�}tjjj�|_|dkrdtjjjjj	|_
n'|dkr�tjjjjj|_
n||j_d|j_
||j_|r�tj�|j_||jj_||jj_n|S(sB
    Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a
    SATA controller

    sata_controller_label
        Controller label of the SATA adapter

    operation
        Type of operation: add or edit

    key
        Unique key of the device

    bus_number
        Device bus number property
    s5Configuring SATA controller sata_controller_label={0}R�R�id(R�RMR5RR�R2R>tVirtualAHCIControllerRKR�RZR�R�RJR6RARBRERT(tsata_controller_labelRZR�R8t	sata_spec((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�5s 
i�c	C@sOtjdj||||��tjjj�}	tjjj�|	_tj�|	j_	|dkrtjjjj
j|	_n'|dkr�tjjjj
j
|	_n|dkrotjjjj�|	j_|d|	jj_|djd�djd�d	}
tjjjtjjj|�|d
|
g�d	}|rP||	jj_ndj|d�|	jj	_nk|dkr�|d
dkr�tjjjj�|	j_q�|d
dkr�tjjjj�|	j_q�n||	j_||	jj	_||	j_tjjjj �|	j_!|rK|d|	jj!_"|d|	jj!_#n|	S(s�
    Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a
    CD/DVD drive

    drive_label
        Leble of the CD/DVD drive

    key
        Unique key of the device

    device_type
        Type of the device: client or iso

    operation
        Type of operation: add or edit

    client_device
        Client device properties

    datastore_iso_file
        ISO properties

    connectable
        Connection info for the device

    controller_key
        Controller unique identifier to which we will attach this device

    parent_ref
        Parent object

    .. code-block: bash

        cd:
            adapter: "CD/DVD drive 1"
            device_type: datastore_iso_file or client_device
            client_device:
              mode: atapi or passthrough
            datastore_iso_file:
              path: "[share] iso/disk.iso"
            connectable:
              start_connected: True
              allow_guest_control:
    saConfiguring CD/DVD drive drive_label={0} device_type={1} client_device={2} datastore_iso_file={3}R�R�tdatastore_iso_filetpatht[i����t]iRus{0}t
client_devicetmodetpassthroughtatapiRwRx($R�RMR5RR�R2R>tVirtualCdromRARBRKR�RZR�tIsoBackingInfoR�RLRCt
rpartitionR9R:RHRvR�RxRTtRemotePassthroughBackingInfotRemoteAtapiBackingInfoR�RERJR|R}R~RR�(tdrive_labelR�tdevice_typeRZR�R�R~RRR�t
drive_specRxtdatastore_object((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_cd_driveYs@/$!cC@s�tjjj�}||_tjjj�|_|rE||j_n|rZ||j_n|r�tjjj	d|�|j_
||j_ntjjj�|j_
|S(s4
    Returns a vim.vm.customization.AdapterMapping object containing the IP
    properties of a network adapter card

    domain
        Domain of the host

    gateway
        Gateway address

    ip_addr
        IP address

    subnet_mask
        Subnet mask

    mac
        MAC address of the guest
    t	ipAddress(
RR�t
customizationtAdapterMappingRyt
IPSettingsR�t	dnsDomaintgatewaytFixedIpRtt
subnetMasktDhcpIpGenerator(R3R�tip_addrtsubnet_maskR�tadapter_mapping((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_set_network_adapter_mapping�s	cC@sgtjdj|d|d|d|d��tjjj�}tjjj�|_|dkr}tjjjjj	|_
n'|dkr�tjjjjj|_
ntjjjj
�}d}|ddkr�tjjjj�}d	|d
j�kr	td��nd	|d
j�kr.td��nd
|d
j�krStd��n|d
d	|_|d
d|_|d
d
|_n|ddkr�tjjjj�}n|ddkr�tjjjj�}n|ddkrtjjjj�}n|dd|_|dd|_||j_||j_d|j_||j_|d|j_|S(sp
    Returns a vim.vm.device.VirtualSerialPort representing a serial port
    component

    serial_device_spec
        Serial device properties

    key
        Unique key of the device

    operation
        Add or edit the given device

    .. code-block:: bash

        serial_ports:
            adapter: 'Serial port 1'
            backing:
              type: uri
              uri: 'telnet://something:port'
              direction: <client|server>
              filename: 'service_uri'
            connectable:
              allow_guest_control: True
              start_connected: True
            yield: False
    sCCreating serial port adapter={0} type={1} connectable={2} yield={3}R�R�R~tyieldR�R�R�turiR�s&vSPC proxy URI not specified in configs&vSPC Direction not specified in configRUs%vSPC Filename not specified in configt	directiontpipeR�R2RxRwiN(R�RMR5RR�R2R>tVirtualSerialPortRKR�RZR�R|R}REtURIBackingInfoR�RtproxyURIR�t
serviceURItPipeBackingInfotFileBackingInfotDeviceBackingInfoR�RR�R~R@R�tyieldOnPoll(tserial_device_specR�RZtdevice_spectconnect_infottype_backing((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_apply_serial_port�sJcC@sdg}tddd�}|rTg|D]}|d^q%}tjdj|��nx	t||�D]�\}}d\}	}
}t|d�}d}
d|kr�|djd	�\}}t|�}t|�}t	|d
|�}
nad|krHxR|D](}|d|dkr�|d
}
Pq�q�Wt
jjdj|d���nd|kr�t
j
jj||d|dg�d}|d}
nd|kr�|d}	n|	r�|
s�|	r�|
r�t
jjdj|
|	���nt||d|dd|d|dd|
ddd|ddd|kr0|dndd|d|	�	}|j|�|d7}qdW|S(s�
    Returns a list of disk specs representing the disks to be created for a
    virtual machine

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    disks
        List of disks with properties

    scsi_controllers
        List of SCSI controllers

    parent
        Parent object reference

    .. code-block: bash

        disk:
          adapter: 'Hard disk 1'
          size: 16
          unit: GB
          address: '0:0'
          controller: 'SCSI controller 0'
          thin_provision: False
          eagerly_scrub: False
          datastore: 'myshare'
          filename: 'vm/mydisk.vmdk'
    i0���i����i����R�sCreating disks {0}R
i�taddressRrR9t
controllerRER�s(The given controller does not exist: {0}RxRuiRUskYou must specify both filename and datastore attributes to place your disk to a specific datastore {0}, {1}RQRRRRZR�RSRTiN(NNN(RR�RMR5RRER�R�R�R;R9R�tVMwareObjectNotFoundErrorR:RHRvR	RXR�(RDR�tscsi_controllersR�t
disk_specsR�R�R�R�RURxt
datastore_refR
RRtcontroller_bus_numberRPtcontrRV((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt
_create_disks sd

		

	


	
cC@s�tddd�}g}|r�g|D]}|d^q%}tjdj|��xXt||�D]D\}}t|d|d|d||dd	�}|j|�qaWn|S(
s�
    Returns a list of vim.vm.device.VirtualDeviceSpec objects representing
    SCSI controllers

    scsi_devices:
        List of SCSI device properties
    i���i��i����R�sCreating SCSI devices {0}R�R�R8R�(RR�RMR5RR�R�(tscsi_devicesR�t
scsi_specstscsiR�R�tscsi_controllerR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_create_scsi_devicesy s
	cC@sFg}g}tddd�}|r<g|D]}|d^q+}tjdj|��x�t||�D]�\}}t||d|d|dd	|dd
ddd|kr�|dndd
|d
d|�}	|j|	�d|krgt|dd|dd|dd|dd|d
�}
|j|
�qgqgWn||fS(s
    Returns a list of vim.vm.device.VirtualDeviceSpec objects representing
    the interfaces to be created for a virtual machine

    network_interfaces
        List of network interfaces and properties

    parent
        Parent object reference

    .. code-block: bash

        interfaces:
          adapter: 'Network adapter 1'
          name: vlan100
          switch_type: distributed or standard
          adapter_type: vmxnet3 or vmxnet, vmxnet2, vmxnet3, e1000, e1000e
          mac: '00:11:22:33:44:55'
    i`�i.�i����R�sCreating network interfaces {0}RDRcRqRdRZR�R~R�R�tmappingR3R�R�R�N(	RR�RMR5RR�RER�R�(tnetwork_interfacesR�t
network_specst
nics_settingsR�tinterR�t	interfaceR�R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_create_network_adapters� s2




cC@s�g}tddd�}|r�g|D]}|d^q%}tjdj|��x?t||�D]+\}}t||d�}|j|�qaWn|S(s�
    Returns a list of vim.vm.device.VirtualDeviceSpec objects representing the
    serial ports to be created for a virtual machine

    serial_ports
        Serial port properties
    i���i���i����R�sCreating serial ports {0}R�(RR�RMR5RR�R�(tserial_portstportsR�tserialR�R0R�tserial_port_device((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_create_serial_ports� scC@s'g}tddd�}|r#g|D]}|d^q%}tjdj|��x�t||�D]�\}}d}	|r�t||d�}
|
j}	n|jt|d||dd	d
d
|kr�|d
nddd|kr�|dnddd|kr|dndd
|	d|��qaWn|S(s'
    Returns a list of vim.vm.device.VirtualDeviceSpec objects representing the
    CD/DVD drives to be created for a virtual machine

    cd_drives
        CD/DVD drive properties

    controllers
        CD/DVD drive controllers (IDE, SATA)

    parent_ref
        Parent object reference
    iH�i�i����R�sCreating cd/dvd drives {0}i�R�R�R�R�R�R~RRR�N(
RR�RMR5Rt_get_device_by_labelR�R�R�RE(t	cd_drivestcontrollersR�tcd_drive_specsR�tdvdR�tdriveR�RRR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_create_cd_drives� s*	cC@sUg|D]}|j|kr|^q}|r6|dStjjdj|���dS(s�
    Returns the device with the given key, raises error if the device is
    not found.

    devices
        list of vim.vm.device.VirtualDevice objects

    key
        Unique key of device
    is9Virtual machine device with unique key {0} does not existN(R�R9R�R�R5(tdevicesR�Rtdevice_keys((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_get_device_by_key� s(	cC@sXg|D]}|jj|kr|^q}|r9|dStjjdj|���dS(s�
    Returns the device with the given label, raises error if the device is
    not found.

    devices
        list of vim.vm.device.VirtualDevice objects

    key
        Unique key of device
    is4Virtual machine device with label {0} does not existN(RBRER9R�R�R5(R�RERt
device_labels((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�!s+	cC@sd|r\xW|D]H}d|kr
d|kr
|jtjjj|d|d��q
q
WntStS(s
    Updates the size and unit dictionary values with the new unit values

    devices
        List of device data objects
    RR
(RiR9R:RHRCRvRb(R�R2((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_convert_units'!s
+c
C@si}t|j��}|jd�|jd�|jd�xedD]]}||krFti|||6i|||6�}|jr�|||<n|j|�qFqFWd|kr�|jd�t|d|d�}|jr�||d<q�nd|kr[|jd�t|dg�t|dg�t|d|d�}|jr[||d<q[nd|kr�|jd�d}t||||�}	|	jr�|	||<q�nd	|krB|jd	�t|d	�t|d	�t|d	|d	d
�}
|
jdd�|
jdd
�|
jdd�|
jrB|
|d	<qBnd|kr�|jd�t|d|dd�}|jdd�|jr�||d<q�nxn|D]f}||ks�||kr�t	dj
|���nt||||d�}|jr�|||<q�q�W|S(s�
    Compares virtual machine current and new configuration, the current is the
    one which is deployed now, and the new is the target config. Returns the
    differences between the objects in a dictionary, the keys are the
    configuration parameter keys and the values are differences objects: either
    list or recursive difference

    new_config:
        New config dictionary with every available parameter

    current_config
        Currently deployed configuration
    RDRuRxR^timagetcpuRRR�R�tdiff_keyRTRUR�t
interfacesR�seA general device {0} configuration was not supplied or it was not retrieved from remote configuration(sversionsimage(R+R�tdiscardRR+R�RRtremove_diffRR5(
t
new_configRR+R�tproperty_keytsingle_value_difftcpu_difftmemory_diffR�t
advanced_difft
disk_diffstinterface_diffstdevice_diffs((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR(8!sz



	

	


	
	

		

	
	
		c
C@s8	ddddddddd	d
ddd
g
}tjjj||d|d|�}tjjjd|d|�}i|d
6}i|dd6|dd6|dd6|dd6|dd6|d<i|dd6dd6|dd6|d	d6|d<|d|d<|d
|d<i|d<xX|dD]L}yt|j�|d|j<Wq tk
rk|j|d|j<q Xq Wg|d <g|d!<g|d"<g|d#<g|d$<g|d%<x�|dD]y}	t	|	t
jjj
�r!i}
|	jj|
d&<|	j|
d'<|	j}|d(krd)|
d*<n2|d+kr3d,|
d*<n|d-krLd.|
d*<nt	|	t
jjj�rqd/|
d0<not	|	t
jjj�r�d1|
d0<nJt	|	t
jjj�r�d2|
d0<n%t	|	t
jjj�r�d3|
d0<n|r
|	j|
d4<|	j|
d5<|	|
d6<n|d!j|
�nt	|	t
jjj�rJi}|	jj|d&<|	j|d<d7|d<t|d|	j�}
|
jj|d8<t|
j�d9t|	j�|d:<tjjj|	jj�|d;<|	jj |d<<|	jj!|d=<|r6|	j|d5<|	j|d><|
j|d'<|	j|d?<|	|d6<n|d j|�nt	|	t
jjj"�r�i}
|	jj|
d&<tjjj#|	�|
d@<i|	j$j%dA6|	j$j&dB6|	j$j'dC6|
dD<|	j(|
dE<t	|	jt
jjj"j)�r3dF|
dG<|	jj*j+}tjjj,|t
j-|dHd5dI|�}n7t	|	jt
jjj"j.�rjdJ|
dG<|	jj/}ntjjj|�|
d
<|r�|	j|
d5<|	|
d6<n|d"j|
�nt	|	t
jjj0�r7i}|	jj|d&<t|d|	j�}
|
jj|d8<t	|	jt
jjj0j1�rGdK|dL<idMdN6|dK<nt	|	jt
jjj0j2�r�dK|dL<idOdN6|dK<nt	|	jt
jjj0j3�r�dP|dL<i|	jj4dQ6|dP<ni|	j$j%dA6|	j$j&dB6|	j$j'dC6|dD<|r#|	j|d5<|	j|d?<|	|d6<n|d$j|�nt	|	t
jjj5�r�i}|	jj|d&<t	|	jt
jjj5j6�r�dR|d0<i|	jj7dS6|	jj8dT6|	jj9dU6|dV<nt	|	jt
jjj5j:�r�dW|d0<nt	|	jt
jjj5j;�rdX|d0<nt	|	jt
jjj5j<�rBd4|d0<n|	j=|dY<i|	j$j%dA6|	j$j&dB6|	j$j'dC6|dD<|r�|	j|d5<|	|d6<n|d#j|�nt	|	t
jjj>�r�i}|	jj|d&<|	j|d'<|r	|	j|d4<|	j|d5<|	|d6<n|d%j|�q�q�W|S(Zs�
    Queries and converts the virtual machine properties to the available format
    from the schema. If the objects attribute is True the config objects will
    have extra properties, like 'object' which will include the
    vim.vm.device.VirtualDevice, this is necessary for deletion and update
    actions.

    name
        Name of the virtual machine

    datacenter
        Datacenter's name where the virtual machine is available

    objects
        Indicates whether to return the vmware object properties
        (eg. object, key) or just the properties which can be set

    service_instance
        vCenter service instance for connection and configuration
    sconfig.hardware.devicesconfig.hardware.numCPUs!config.hardware.numCoresPerSocketsconfig.nestedHVEnabledsconfig.cpuHotAddEnabledsconfig.cpuHotRemoveEnabledsconfig.hardware.memoryMBs#config.memoryReservationLockedToMaxsconfig.memoryHotAddEnabledsconfig.versionsconfig.guestIdsconfig.extraConfigRDR�RuRDR�RRRRRRR
tMBRRRRR^RR�R�RR�R�R�R�R8R�R�R�R�R�R�R�R�R�R�R�R�R2R�tobjecttKBR�RrR�RxRSRTRPRRRcRxt	connectedRwR~R�RiRqR%R&RgR�R�R�R�R�R�R�R�R�R�RUR�R�R�R�(?R9R:RHR�R}R�R�R�RRhRR�R2R�RBRER6R�R�R�R�R�R�R?RDR�RJRhR@R�R�RxRHRIRktget_network_adapter_object_typeR~R�RRRyRoR0R�R)tDistributedVirtualPortgroupRlR�R�R�R�R�RLR�R�R�R�R�R�R�R�R�tVirtualSATAController(RDRuRRDR�R�R�Rt
extra_confR2R�R�R�R�tpg_keyRsR�R0R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR�!sf	









	











$






	
	


	
	
	




	

	
	
	








c	C@shg}|rdg|D]}|dd^q}tjdj|��x|D]}|d}|d}t||�}t|_|j�rJ|d|dkr�tjj	dj|d|d|d|d	���ntjd
j|d|d|d|d	��t
|d	|ddd|dd|dd|d�}|d
j|j_|j
|�qJqJWn|S(sC
    Changes the disk size and returns the config spec objects in a list.
    The controller property cannot be updated, because controller address
    identifies the disk by the unit and bus number properties.

    disks_diffs
        List of old and new disk properties, the properties are dictionary
        objects
    toldR�sUpdating disks {0}tnewR
sMDisk cannot be downsized size={0} unit={1} controller_key={2} unit_number={3}RRRRPsYVirtual machine disk will be updated size={0} unit={1} controller_key={2} unit_number={3}R�R�R(R�RMR5RRvtignore_unset_valuestchangedR9R�RRXR�R2R�(	t
disks_old_newtdisk_changesR�R�R�tcurrent_diskt	next_diskt
differencetdevice_config_spec((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt
_update_disksr"s>
!


		



c	C@s�g}|r�g|D]}|dd^q}tjdj|��x�|D]�}|d}|d}t||�}t|_|j�rJtjdj|d|d|d|d	��|d|dkr�|jt|d
��|jt	|d|d|d	|d|dd��g}	xE|dD]9}
g|D]}|d
^q6}|	jt
||
��q)Wxx|	D]7}
tjj
j�}|
|_
d
|_|j|�qmWq�|jt	|d|d|d	|d|dd
��qJqJWn|S(s�
    Returns a list of vim.vm.device.VirtualDeviceSpec specifying  the scsi
    properties as input the old and new configs are defined in a dictionary.

    scsi_diffs
        List of old and new scsi properties
    RR�sUpdating SCSI controllers {0}Rs[Virtual machine scsi device will be updated key={0} bus_number={1} type={2} bus_sharing={3}R�R8R�R�RR�R2R�(R�RMR5RRvRRR�t_delete_deviceR�R�RR�R2R>RZ(t
scsis_old_newt
current_diskstdevice_config_specsR�R�R�t	next_scsitcurrent_scsiR"tdisks_to_updatetdisk_keyR�tdisk_objectsR RV((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_update_scsi_devices�"sR!


		
			c
C@s
g}|r	g|D]}|dd^q}tjdj|��x�|D]�}|d}|d}t||�}t|_|j�rJtjdj|d|d|d|d��t|d	|d|d|dd
dd|dd|�}	|j|	�qJqJWn|S(
s�
    Returns a list of vim.vm.device.VirtualDeviceSpec specifying
    configuration(s) for changed network adapters, the adapter type cannot
    be changed, as input the old and new configs are defined in a dictionary.

    interface_old_new
        Dictionary with old and new keys which contains the current and the
        next config for a network device

    parent
        Parent managed object reference
    RR�sUpdating network interfaces {0}RsaVirtual machine network adapter will be updated switch_type={0} name={1} adapter_type={2} mac={3}RqRDRcR�RZR�R�(	R�RMR5RRvRRR�R�(
tinterface_old_newR�tnetwork_changesR�R�R�tcurrent_interfacetnext_interfaceR"R#((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_update_network_adapters�"s2
!


	

	cC@s�g}|r�g|D]}|dd^q}tjdj|��xf|D]^}|d}|d}t||�}t|_|j�rJ|jt||dd��qJqJW|SdS(s
    Returns a list of vim.vm.device.VirtualDeviceSpec specifying to edit a
    deployed serial port configuration to the new given config

    serial_old_new
         Dictionary with old and new keys which contains the current and the
          next config for a serial port device
    RR�sUpdating serial ports {0}RR�R�N(	R�RMR5RRvRRR�R�(tserial_old_newtserial_changesR�R�R�tcurrent_serialtnext_serialR"((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_update_serial_ports
#s	!


	cC@s;g}|r7g|D]}|dd^q}tjdj|��x�|D]�}|d}|d}t||�}	t|	_|	j�rJ|r�t||d�}
|
j}n
|d}|j	t
|d|d|dd	d
d
|kr�|d
nddd|kr
|dndd|dd|d
|��qJqJWn|S(s�
    Returns a list of vim.vm.device.VirtualDeviceSpec specifying to edit a
    deployed cd drive configuration to the new given config

    drives_old_new
        Dictionary with old and new keys which contains the current and the
        next config for a cd drive

    controllers
        Controller device list

    parent
        Managed object reference of the parent object
    RR�sUpdating cd/dvd drives {0}RR�RRR�R�R�R�R�R~R�N(R�RMR5RRvRRR�R�R�R�RE(tdrives_old_newR�R�t
cd_changesR�R�R�t
current_drivet	new_driveR"R�RR((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt_update_cd_drives##s2!


	

	

cC@sStjdjt|���tjjj�}tjjjjj	|_
||_|S(s�
    Returns a vim.vm.device.VirtualDeviceSpec specifying to remove a virtual
    machine device

    device
        Device data type object
    sDeleting device with type {0}(R�RMR5R�RR�R2R>RKR�RZ(R2R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR%N#s
	c#C@setjjj||�}tjjj||d|�\}}tjjj|||�}tjj�}||_	||_
tjj�|_tjjj
||d|g�d}|s�tjjdj|���nyutjjj|d�}d|kr/|ddkr/tjd�dj|�|j_nd	j||�|j_Wn/tjjk
ryd	j||�|j_nXg}|r�t||d
�n|r�t||�n|r�t||�n|
r�t|
�}|jj|�n|	r:g|D]}|j^q�}t||	d|d|�}|jj|�n|rkt|d|�\}}|jj|�n|r�t|�}|jj|�n|r�t |�} |jj| �|j| �n|
r�t!|
�}!|jj|!�|j|!�n|r%t"|d
|d|�}"|jj|"�n|r;t#||�ntjjj$|||||�it%d6S(s�

    Creates a virtual machine container.

    CLI Example:

    .. code-block:: bash

        salt vm_minion vsphere.create_vm vm_name=vmname cpu='{count: 2, nested: True}' ...

    vm_name
        Name of the virtual machine

    cpu
        Properties of CPUs for freshly created machines

    memory
        Memory size for freshly created machines

    image
        Virtual machine guest OS version identifier
        VirtualMachineGuestOsIdentifier

    version
        Virtual machine container hardware version

    datacenter
        Datacenter where the virtual machine will be deployed (mandatory)

    datastore
        Datastore where the virtual machine files will be placed

    placement
        Resource pool or cluster or host or folder where the virtual machine
        will be deployed

    devices
        interfaces

        .. code-block:: bash

            interfaces:
              adapter: 'Network adapter 1'
              name: vlan100
              switch_type: distributed or standard
              adapter_type: vmxnet3 or vmxnet, vmxnet2, vmxnet3, e1000, e1000e
              mac: '00:11:22:33:44:55'
              connectable:
                allow_guest_control: True
                connected: True
                start_connected: True

        disks

        .. code-block:: bash

            disks:
              adapter: 'Hard disk 1'
              size: 16
              unit: GB
              address: '0:0'
              controller: 'SCSI controller 0'
              thin_provision: False
              eagerly_scrub: False
              datastore: 'myshare'
              filename: 'vm/mydisk.vmdk'

        scsi_devices

        .. code-block:: bash

            scsi_devices:
              controller: 'SCSI controller 0'
              type: paravirtual
              bus_sharing: no_sharing

        serial_ports

        .. code-block:: bash

            serial_ports:
              adapter: 'Serial port 1'
              type: network
              backing:
                uri: 'telnet://something:port'
                direction: <client|server>
                filename: 'service_uri'
              connectable:
                allow_guest_control: True
                connected: True
                start_connected: True
              yield: False

        cd_drives

        .. code-block:: bash

            cd_drives:
              adapter: 'CD/DVD drive 0'
              controller: 'IDE 0'
              device_type: datastore_iso_file
              datastore_iso_file:
                path: path_to_iso
              connectable:
                allow_guest_control: True
                connected: True
                start_connected: True

    advanced_config
        Advanced config parameters to be set for the virtual machine
    R�Ruis*Specified datastore: '{0}' does not exist.ssummary.typeR>sIThe vmPathName should be the datastore name if the datastore type is vsans[{0}]s[{0}] {1}/{1}.vmxR�R�R�R�R�t	create_vm(&R9R:RHR}t
get_placementt
get_folderRR�R�RDtguestIdtFileInfoR�RvR�R	R5RR�RMt
vmPathNameRRRRR�tdeviceChangeR�R2R�R�R�R�R�R�R$R>Rb(#RRRRR^RuRxR�RR�R�R�R�R�R�RRDR�tresourcepool_objecttplacement_objectt
folder_objectR�R�t
ds_summarytcd_controllersR�RR�R�tinterface_specstnic_settingstserial_port_specst	ide_specst
sata_specsR�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR>]#s�w						
					
c'	C@s�t|d|	dtd|�}ti|d6|d6|d6|d6|d6|d	6|d
6|d6|d6|	d6|
d
6|d6|d6|
d6|�}tjj�}tjjj	||	�}tjjj
|tj|ddd|�}|j�}d|kr+|dj
�t�kr+t||dj�q+nd|krj|dj
�t�krjt||dj�qjnd|kr�t||dj|jj�nd|kr�t||d�nd|kr�||_ng}d|krtd
|krtg}|jt|dj|d
��x,|djD]}|jt|d��q Wt|dj�}|j|�|j j|�nd
|krOg}|jt!|d
j��x,|d
jD]}|jt|d��q�Wg|dD]}|d^q�}|jg|D]}|j"^q��|jt#||d
jd|d|��|j j|�nd	|kr�g}|jt$|d	j|��x,|d	jD]}|jt|d��q�Wt%|d	j|�\}}|j|�|j j|�nd|krqg}|jt&|dj��x,|djD]}|jt|d��q#W|jt'|dj��|j j|�ng} d|kr�t(|dj�}!x,|djD]}|!jt|d��q�W| j|!�|j j|!�nd|kr�g}"g|dD]}|d^q}#|#jg| D]}|j"^q%�|"jt)|djd|#d|��x,|djD]}|"jt|d��qoW|"jt*|djd|#d|��|j j|"�n|r�tjjj+||�ni}$x�t,j-|�D]�\}%}&t.|&tjj/j0�r}|&j1dddd�|&j1dddd�|&j1dddd�|&j1dddd�n|&j2|$|%<q�W|$S(s
    Updates the configuration of the virtual machine if the config differs

    vm_name
        Virtual Machine name to be updated

    cpu
        CPU configuration options

    memory
        Memory configuration options

    version
        Virtual machine container hardware version

    image
        Virtual machine guest OS version identifier
        VirtualMachineGuestOsIdentifier

    interfaces
        Network interfaces configuration options

    disks
        Disks configuration options

    scsi_devices
        SCSI devices configuration options

    serial_ports
        Serial ports configuration options

    datacenter
        Datacenter where the virtual machine is available

    datastore
        Datastore where the virtual machine config files are available

    cd_dvd_drives
        CD/DVD drives configuration options

    advanced_config
        Advanced config parameters to be set for the virtual machine

    service_instance
        vCenter service instance for connection and configuration
    RuRRDRDRRRR^RR�R�R�RxR�R�RR%R&R�RR�R�R�R�Rt	diff_listt	intersectR�tremoved(3RRbR(RR�R�R9R:RHR}R)R*R�RR+Rtcurrent_dictRR$R,R�R!RRAR�R.RPRQR�R%R�taddedRDR$R2R�R3R�R8R�R�R=R�R-RR�Rht
listdiffertListDictDifferRR+('RRRRR^RR�R�R�RuRxt
cd_dvd_drivesR�RRDRR+R�R.R/tdifference_keystnew_scsi_devicestscsi_changesR�RtdevR�R�R0tadapterstnicsR5tnew_controllersRNR:R�R0R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyR-&$s�6		
			


	






	

cC@stjdj|||��tjjj||�}d|kr�tjjj||d�}tjjj|ddg�}d|kr�|d}ntj	j
d��tjjj||||�nd|kr�tjjj|d|d|dg�}	|	s tj	j
d	j|d���n|	d
}
tjjj|
ddg�}d|kr�|d}tjjj|ddg�}
d|
kr�|
d}q�tj	j
d��ntj	j
d
��tjjj||||d|
�nidd6it
d6d6}|S(s�
    Registers a virtual machine to the inventory with the given vmx file.
    Returns comments and change list

    name
        Name of the virtual machine

    datacenter
        Datacenter of the virtual machine

    placement
        Placement dictionary of the virtual machine, host or cluster

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

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.
    sWRegistering virtual machine with properties datacenter={0}, placement={1}, vmx_path={2}R�R�tresourcePools:The cluster's resource pool object could not be retrieved.R,R�R�s#ESXi host named '{0}' wasn't found.iR�s7The host parent's parent object could not be retrieved.s0The host's parent object could not be retrieved.thost_objects-Virtual machine registration action succeededtcommenttregister_vmR0(R�RMR5R9R:RHR}R�RR�RRaR3Rb(RDRuR�tvmx_pathRDR�tcluster_objt
cluster_propstresourcepoolR5thost_objt
host_propsthost_parentR�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRa�$sZ	

		
	


			

cC@s�tjdj|��ddg}tjjj||d|d|�}|ddkruidd6itd	6d
6}|Stjjj|ddd
�idd6itd	6d
6}|S(s_
    Powers on a virtual machine specified by it's name.

    name
        Name of the virtual machine

    datacenter
        Datacenter of the virtual machine

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.power_on_vm name=my_vm

    sPowering on virtual machine {0}RDssummary.runtime.powerStateRuR�t	poweredOns%Virtual machine is already powered onR`tpower_onR0Rtactiontons)Virtual machine power on action succeeded(	R�RMR5R9R:RHR�Rbtpower_cycle_vm(RDRuRDR�R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytpower_on_vm,%s 		

cC@s�tjdj|��ddg}tjjj||d|d|�}|ddkruidd6itd	6d
6}|Stjjj|ddd
�idd6itd	6d
6}|S(sa
    Powers off a virtual machine specified by it's name.

    name
        Name of the virtual machine

    datacenter
        Datacenter of the virtual machine

    service_instance
        Service instance (vim.ServiceInstance) of the vCenter.
        Default is None.

    .. code-block:: bash

        salt '*' vsphere.power_off_vm name=my_vm

    s Powering off virtual machine {0}RDssummary.runtime.powerStateRuR�t
poweredOffs&Virtual machine is already powered offR`t	power_offR0RRktoffs*Virtual machine power off action succeeded(	R�RMR5R9R:RHR�RbRm(RDRuRDR�R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pytpower_off_vmV%s 		

c	C@s�i}|r0tjjj|||�\}}ntjjj||�}|rkt|||�t|d<ntjjj|tj	|ddd|�}|s�tj
jdj||���n||fS(s9
    Helper function to remove a virtual machine

    name
        Name of the virtual machine

    service_instance
        vCenter service instance for connection and configuration

    datacenter
        Datacenter of the virtual machine

    placement
        Placement information of the virtual machine
    tpowered_offR%RDR&s>The virtual machine object {0} in datacenter {1} was not found(
R9R:RHR?R}RrRbR)RR*R�RR5(	RDRuRDR�RptresultsRERFR/((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt
_remove_vm�%s*	
		c		C@s�i}tj�}y)tji|d6|d6|d6|�Wn%tjjk
rb}t|��nXt||d|d|d|�\}}tj	j
j|�t|d<|S(s�
    Deletes a virtual machine defined by name and placement

    name
        Name of the virtual machine

    datacenter
        Datacenter of the virtual machine

    placement
        Placement information of the virtual machine

    service_instance
        vCenter service instance for connection and configuration

    .. code-block:: bash

        salt '*' vsphere.delete_vm name=my_vm datacenter=my_datacenter

    RDRuR�RDRpt
deleted_vm(
RR�R�R�R�R�R
RuR9R:RHt	delete_vmRb(	RDRuR�RpRDRtR�R�R/((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRw�%s"
c		C@s�i}tj�}y)tji|d6|d6|d6|�Wn%tjjk
rb}t|��nXt||d|d|d|�\}}tj	j
j|�t|d<|S(s�
    Unregisters a virtual machine defined by name and placement

    name
        Name of the virtual machine

    datacenter
        Datacenter of the virtual machine

    placement
        Placement information of the virtual machine

    service_instance
        vCenter service instance for connection and configuration

    .. code-block:: bash

        salt '*' vsphere.unregister_vm name=my_vm datacenter=my_datacenter

    RDRuR�RDRptunregistered_vm(
RR�R�R�R�R�R
RuR9R:RHt
unregister_vmRb(	RDRuR�RpRDRtR�R�R/((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyRy�%s"
(t__doc__t
__future__RR tloggingRNRZt	functoolsRtsalt.extRtsalt.ext.six.movesRRtsalt.utils.argsR9tsalt.utils.dictupdateR:R�tsalt.utils.httptsalt.utils.pathtsalt.utils.pbmtsalt.utils.vmwaretsalt.utils.vsantsalt.utils.listdifferRtsalt.utils.dictdifferRtsalt.exceptionsRRR	R
RRR
Rtsalt.utils.decoratorsRRtsalt.config.schemas.esxclusterRRtsalt.config.schemas.vcenterRtsalt.config.schemas.esxiRRRtsalt.config.schemas.esxvmRRt	getLoggerR8R�R�RbtHAS_JSONSCHEMAtImportErrorRvtpyVmomiRRRRt
versionMaptversion_infoR�tHAS_PYVMOMIR�twhichtesx_clitHAS_ESX_CLIR$t__proxyenabled__R%R+R7RCR`RERaRKRmRpRsRzR}R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RRRRRRRRRR"R-R0R3R=RARCRYR\R`RhRtR�R�R�R�R�R�R�R�R�R�R�R�R�R�RRRR
RRR!R%RFRNRRRXR[RiRjRqR{R|R�R�R�R�R�R�R�R
RRRR#R$R&R'R.R/R7R@RARSR\RbRfRiRkRmRqR�RnR|R�R�R�RRR�RR�R�R�R�R|R�R�R�R�R�RRRR R$R1R4R5R;RXRfRuR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RR(RR$R.R3R8R=R%R>R-RaRnRrRuRwRy(((s8/usr/lib/python2.7/site-packages/salt/modules/vsphere.pyt<module>�s,:


"-



						_		$	!H	K	M	W	N	G	@		B	Z	F	3		9		8		i		i		<		A		I			'		$		$		#		#		#		#		#		#		#		#		$		;		B		N		g		g		g		x		A		=		C		G		f		S		S						?	 			
		"		E	K			%	%	4				E	6	/	9	(	%					1	'	'	 	+	$		R	+�		[		k	P			1	"				#			*		.	.		/		3		A		%			@			;			>			#					5										8!(		�I	!/	
				!	6				'				M/	3O	I	"	$W	$H[	/	)				`�	3	<	)	+			�				�	I	'	')	(	

Zerion Mini Shell 1.0