%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s]dZddlmZmZmZddlZddlZddlZddlm	Z	ddl
Zddlm
Z
mZmZmZmZmZddlmZddlmZmZyddlZeZWnek
r�eZnXeje�Zyoddl m!Z!d	e!j"koAej#d
dfkoAej#d
ddfkr]ej$d
�e��neZ%Wnek
r}eZ%nXd�Z&ddd�Z'd�Z(e)e)eed�Z*dd�Z+ed�Z,e)e)e)eed�Z-eeee)d�Z.ee%�ee�ed���Z/ee%�ee�deed���Z0d�Z1d�Z2dS(uK
Manage VMware ESXi Hosts.

.. versionadded:: 2015.8.4

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.6,
    Python 2.7.9, or newer must be present. This is due to an upstream dependency
    in pyVmomi 6.0 that is not supported in Python versions 2.7 to 2.7.8. If the
    version of Python is not in the supported range, you will need to install an
    earlier version of pyVmomi. See `Issue #29537`_ for more information.

.. _Issue #29537: https://github.com/saltstack/salt/issues/29537

Based on the note above, to install an earlier version of pyVmomi than the
version currently listed in PyPi, run the following:

.. code-block:: bash

    pip install pyVmomi==5.5.0.2014.1.1

The 5.5.0.2014.1.1 is a known stable version that this original ESXi State
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 state module may depend on the
    type of license attached to the ESXi host.

    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 state module was written to be used in conjunction with Salt's
:mod:`ESXi Proxy Minion <salt.proxy.esxi>`. For a tutorial on how to use Salt's
ESXi Proxy Minion, please refer to the
:ref:`ESXi Proxy Minion Tutorial <tutorial-esxi-proxy>` for
configuration examples, dependency installation instructions, how to run remote
execution functions against ESXi hosts via a Salt Proxy Minion, and a larger state
example.
i(tabsolute_importtprint_functiontunicode_literalsN(tsix(tCommandExecutionErrortInvalidConfigErrortVMwareObjectRetrievalErrortVMwareSaltErrortVMwareApiErrortArgumentValueError(tdepends(tDiskGroupsDiskScsiAddressSchematHostCacheSchema(tVmomiSupportu	vim25/6.0iii	uFpyVmomi not loaded: Incompatible versions of Python. See Issue #29537.cC@s
dtkS(Nuesxi.cmd(t__salt__(((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pyt__virtual__�suvmk0idc	C@sZi|d6td6id6dd6}d}d}tdd	}t|d
�j|�}	|	jd�}
|
r�dj|
�|d<|S|	jd
�}	|	jd�}||kraii|d6|d6d6}tdsMt|dd|�j|�}
|
jd�}
|
rdj|
�|d<|S|sMt|d<||d<|dj|�|Sn|dj|�n|st|d<||d<|St}|	jd�}||kr�|djii|d6|d6d6�t}n|	jd�}||kr|djii|d6|d6d6�t}n|	jd�}|tj	|�kru|djii|d6tj	|�d6d6�t}ntdr
|tkr
t|dd|d|d|�j|�}
|
jd�tkr
|
jd�}|s�|
jd�}ndj|�|d<|Snt|d<|dikr5d |d<|StdrVd"|d<d!|d<n|S(#u�
    Ensures a host's core dump configuration.

    name
        Name of the state.

    enabled
        Sets whether or not ESXi core dump collection should be enabled.
        This is a boolean value set to ``True`` or ``False`` to enable
        or disable core dumps.

        Note that ESXi requires that the core dump must be enabled before
        any other parameters may be set. This also affects the ``changes``
        results in the state return dictionary. If ``enabled`` is ``False``,
        we can't obtain any previous settings to compare other state variables,
        resulting in many ``old`` references returning ``None``.

        Once ``enabled`` is ``True`` the ``changes`` dictionary comparisons
        will be more accurate. This is due to the way the system coredemp
        network configuration command returns data.

    dump_ip
        The IP address of host that will accept the dump.

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

    dump_port
        TCP port to use for the dump. Defaults to ``6500``.

    Example:

    .. code-block:: yaml

        configure-host-coredump:
          esxi.coredump_configured:
            - enabled: True
            - dump_ip: 'my-coredump-ip.example.com'

    unameuresultuchangesuucommentuesxi.cmduXESXi requires that the core dump must be enabled before any other parameters may be set.uproxyuhostuget_coredump_network_configuErroru
Error: {0}uCoredump Configuenableduoldunewutestucoredump_network_enabletenableduipudump_ipu	host_vnicuportu	dump_portuset_coredump_network_configtdump_ipt	host_vnict	dump_portusuccessustderrustdoutu8Core Dump configuration is already in the desired state.u$Core dump configuration will change.N(tFalset
__pillar__Rtgettformatt__opts__tTruetupdateRt	text_typetNone(tnameRRRRtrettesxi_cmdtenabled_msgthosttcurrent_configterrortcurrent_enabledtenabled_changestresponsetchangest
current_iptcurrent_vnictcurrent_porttmsg((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pytcoredump_configured�s�)









	

	

	





cC@s�i|d6td6idd6dd6d6dd	6}d
}tdrXd|d<d|d	<|Syt|d
d|�Wn1tk
r�}t|d<dj|�|d	<|SX|S(u�
    Ensures the given password is set on the ESXi host. Passwords cannot be obtained from
    host, so if a password is set in this state, the ``vsphere.update_host_password``
    function will always run (except when using test=True functionality) and the state's
    changes dictionary will always be populated.

    The username for which the password will change is the same username that is used to
    authenticate against the ESXi host via the Proxy Minion. For example, if the pillar
    definition for the proxy username is defined as ``root``, then the username that the
    password will be updated for via this state is ``root``.

    name
        Name of the state.

    password
        The new password to change on the host.

    Example:

    .. code-block:: yaml

        configure-host-password:
          esxi.password_present:
            - password: 'new-bad-password'
    unameuresultuunknownuoldu********unewuchangesuHost password was updated.ucommentuesxi.cmdutestuHost password will change.uupdate_host_passwordtnew_passwordu
Error: {0}N(RRRRRRR(RtpasswordRRterr((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pytpassword_presents$







cC@s�i|d6td6id6dd6}d}tdd}d	}	t|d
�j|�}
t|dd|	�j|�}|jd
�}|r�dj|�|d<|S|j|	�}|rNt|�t|
�krNtds%t|dd|�j|�}
|
jd
�}|r%dj|�|d<|Sn|djii|
d6|d6d6�n||kr5tds|tkr�t|dd|	�j|�}
|
jd
�}|r	dj|�|d<|Sqt|dd|	�j|�}
|
jd
�}|rdj|�|d<|Sn|djii|d6|d6d6�n|r+t|dd|	�j|�}|jd
�}|r�dj|�|d<|S|j|	�}||kr+tds�t|dd|	d|�j|�}
|
jd
�}|r�dj|�|d<|Sn|djii|d6|d6d6�q+n|r�tds�t|d�j|�}
|
jd
�}|r�dj|�|d<|Sn|djiidd6dd6d6�n|r3tds
t|dd|	�j|�}
|
jd
�}|r
dj|�|d<|Sn|djiidd6d d6d6�nt|d<|dikr[d!|d<|Stdr|d#|d<d"|d<n|S($ur
    Ensures a host's NTP server configuration such as setting NTP servers, ensuring the
    NTP daemon is running or stopped, or restarting the NTP daemon for the ESXi host.

    name
        Name of the state.

    service_running
        Ensures the running state of the ntp daemon for the host. Boolean value where
        ``True`` indicates that ntpd should be running and ``False`` indicates that it
        should be stopped.

    ntp_servers
        A list of servers that should be added to the ESXi host's NTP configuration.

    service_policy
        The policy to set for the NTP service.

        .. note::

            When setting the service policy to ``off`` or ``on``, you *must* quote the
            setting. If you don't, the yaml parser will set the string to a boolean,
            which will cause trouble checking for stateful changes and will error when
            trying to set the policy on the ESXi host.


    service_restart
        If set to ``True``, the ntp daemon will be restarted, regardless of its previous
        running state. Default is ``False``.

    update_datetime
        If set to ``True``, the date/time on the given host will be updated to UTC.
        Default setting is ``False``. This option should be used with caution since
        network delays and execution delays can result in time skews.

    Example:

    .. code-block:: yaml

        configure-host-ntp:
          esxi.ntp_configured:
            - service_running: True
            - ntp_servers:
              - 192.174.1.100
              - 192.174.1.200
            - service_policy: 'on'
            - service_restart: True

    unameuresultuchangesuucommentuesxi.cmduproxyuhostuntpduget_ntp_configuget_service_runningtservice_nameuErroru
Error: {0}utestuset_ntp_configtntp_serversuoldunewuntp_serversu
service_startuservice_stopuservice_runninguget_service_policyuset_service_policytservice_policyuservice_policyuupdate_host_datetimeuHost datetime was updated.uupdate_datetimeuservice_restartuNTP Daemon Restarted.u$NTP is already in the desired state.uNTP state will change.N(
RRRRRtsetRRRR(Rtservice_runningR2R3tservice_restarttupdate_datetimeRRR!tntpdt
ntp_configtntp_runningR#R&tcurrent_service_policy((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pytntp_configuredFs�7




























c	C@s�i|d6td6id6dd6}d}tdd}t|d	�j|�}|jd
�}||kr?tds|tkr�t|dd
|�j|�}|jd�}|rdj|�|d<|Sqt|d�j|�}|jd�}|rdj|�|d<|Sn|djii|d6|d6d6�nt|d<|dikrgd|d<|Stdr�d|d<d|d<n|S(u�
    Configures a host's VMotion properties such as enabling VMotion and setting
    the device VirtualNic that VMotion will use.

    name
        Name of the state.

    enabled
        Ensures whether or not VMotion should be enabled on a host as a boolean
        value where ``True`` indicates that VMotion should be enabled and ``False``
        indicates that VMotion should be disabled.

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

    Example:

    .. code-block:: yaml

        configure-vmotion:
          esxi.vmotion_configured:
            - enabled: True
            - device: sample-device

    unameuresultuchangesuucommentuesxi.cmduproxyuhostuget_vmotion_enableduVMotion Enabledutestuvmotion_enabletdeviceuErroru
Error: {0}uvmotion_disableuoldunewuenabledu6VMotion configuration is already in the desired state.u"VMotion configuration will change.N(	RRRRRRRRR(	RRR=RRR!tcurrent_vmotion_enabledR&R#((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pytvmotion_configured�sB










cC@s�i|d6td6id6dd6}d}tdd}t|d	�j|�}|jd
�}|r{dj|�|d<|S|jd�}||kretd
s<|tkr�t|d�j|�}|jd
�}|r9dj|�|d<|Sq<t|d�j|�}|jd
�}|r<dj|�|d<|Sn|djii|d6|d6d6�n|rRt|d�j|�}	|	jd
�}|r�dj|�|d<|S|	jd�}
|
rRt|
t	�rRtd
s&t|d�j|�}|jd
�}|r&dj|�|d<|Sn|djiidd6|
d6d6�qRnt|d<|dikrzd|d<|Std
r�d|d<d|d<n|S(u�
    Configures a host's VSAN properties such as enabling or disabling VSAN, or
    adding VSAN-eligible disks to the VSAN system for the host.

    name
        Name of the state.

    enabled
        Ensures whether or not VSAN should be enabled on a host as a boolean
        value where ``True`` indicates that VSAN should be enabled and ``False``
        indicates that VSAN should be disabled.

    add_disks_to_vsan
        If set to ``True``, any VSAN-eligible disks for the given host will be added
        to the host's VSAN system. Default is ``False``.

    Example:

    .. code-block:: yaml

        configure-host-vsan:
          esxi.vsan_configured:
            - enabled: True
            - add_disks_to_vsan: True

    unameuresultuchangesuucommentuesxi.cmduproxyuhostuget_vsan_enableduErroru
Error: {0}uVSAN Enabledutestuvsan_enableuvsan_disableuoldunewuenableduget_vsan_eligible_disksuEligibleuvsan_add_disksuadd_disks_to_vsanu3VSAN configuration is already in the desired state.uVSAN configuration will change.N(RRRRRRRRt
isinstancetlistR(RRtadd_disks_to_vsanRRR!tcurrent_vsan_enabledR#R&tcurrent_eligible_diskstdisks((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pytvsan_configured<sj












cC@si|d6td6id6dd6}d}tdd}	d	}
t|d
d|
�j|	�}|jd�}|r�d
j|�|d<|S|j|
�}||kr}tdsT|tkrt|dd|
�j|	�}
|
jd�}|rQd
j|�|d<|SqTt|dd|
�j|	�}|jd�}|rTd
j|�|d<|Sn|djii|d6|d6d6�ndt}}|s�|r�t|dd|�}|jd�}|r�d
j|�|d<|S|jd�}|r�t	|�j
d�}|sbd}tjj
j|d��7}x-|D]%}|jd�rKq0n||}q0WWdQXnt	|�j
d�}|d|dks�|d|dkr�t}q�q�t}n|rJtdst|dd|d|d|�}|jd�}|rd
j|�|d<|Sn|djii|d6|r8|n|d6d 6�n|r@t|d!d|
�j|	�}|jd�}|r�d
j|�|d<|S|j|
�}||kr@tdst|d"d|
d#|�j|	�}|jd�}|rd
j|�|d<|Sn|djii|d6|d6d$6�q@n|r�tds�t|d%d|
�j|	�}|jd�}|r�d
j|�|d<|Sn|djiidd6d&d6d%6�nt|d<|dikr�d'|d<|Stdrd|d<d(|d<n|S()u�
    Manage the SSH configuration for a host including whether or not SSH is running or
    the presence of a given SSH key. Note: Only one ssh key can be uploaded for root.
    Uploading a second key will replace any existing key.

    name
        Name of the state.

    service_running
        Ensures whether or not the SSH service should be running on a host. Represented
        as a boolean value where ``True`` indicates that SSH should be running and
        ``False`` indicates that SSH should stopped.

        In order to update SSH keys, the SSH service must be running.

    ssh_key
        Public SSH key to added to the authorized_keys file on the ESXi host. You can
        use ``ssh_key`` or ``ssh_key_file``, but not both.

    ssh_key_file
        File containing the public SSH key to be added to the authorized_keys file on
        the ESXi host. You can use ``ssh_key_file`` or ``ssh_key``, but not both.

    service_policy
        The policy to set for the NTP service.

        .. note::

            When setting the service policy to ``off`` or ``on``, you *must* quote the
            setting. If you don't, the yaml parser will set the string to a boolean,
            which will cause trouble checking for stateful changes and will error when
            trying to set the policy on the ESXi host.

    service_restart
        If set to ``True``, the SSH service will be restarted, regardless of its
        previous running state. Default is ``False``.

    certificate_verify
        If set to ``True``, the SSL connection must present a valid certificate.
        Default is ``False``.

    Example:

    .. code-block:: yaml

        configure-host-ssh:
          esxi.ssh_configured:
            - service_running: True
            - ssh_key_file: /etc/salt/ssh_keys/my_key.pub
            - service_policy: 'on'
            - service_restart: True
            - certificate_verify: True

    unameuresultuchangesuucommentuesxi.cmduproxyuhostusshuget_service_runningR1uErroru
Error: {0}utestu
service_startuservice_stopuoldunewuservice_runninguget_ssh_keytcertificate_verifyukeyu uru#Niiuupload_ssh_keytssh_keytssh_key_fileuSSH Keyuget_service_policyuset_service_policyR3uservice_policyuservice_restartuSSH service restarted.u,SSH service is already in the desired state.uSSH service state will change.(RRRRRRRRRt
_strip_keytsplittsalttutilstfilestfopent
startswith(RR5RHRIR3R6RGRRR!tsshtssh_runningR#tenabletdisabletcurrent_ssh_keytssh_key_changedtclean_current_keytkey_filetlinet
clean_ssh_keyR&R;((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pytssh_configured�s�=









	
(	

	















cC@si|d6td6id6dd6}d}tdd}|r"|sKd	}ntd
s�t|dd|�j|�}	x�tj|	�D]n\}
}t|t�r�q�n|jd
�s�|jd�}|s�dj	|�}ndj	|�|d<|Sq�Wn|dj
iidd6|d6d6�nt|d�j|�}
|
jd�}|rgdj	|�|d<|S|
jd�jd�}
|
|kr<td
st|dd|dd�j|�}|jd�dkr|jd�}|jd�}dj	|r�|n|�|d<|Sn|dj
ii|
d6|d6d6�nt|d�j|�}xrtj|�D]a\}
}yt|
�}Wn%tk
r�d j	|
�|d<|SX||}tj
|�tj
|�kretd
skt|d!d|
d"|d#|d$|�j|�}|j|
�jd
�}|sk|j|
�jd�}|sZd%j	|
�}n||d<|Sn|djd&�s�|dj
iid&6�n|dd&j
ii|d6|d6|
6�qeqeWt|d<|dikr�d'|d<|Std
rd)|d<d(|d<n|S(*u}
    Ensures the specified syslog configuration parameters. By default,
    this state will reset the syslog service after any new or changed
    parameters are set successfully.

    name
        Name of the state.

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

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

        Each syslog_config option also needs a configuration value to set.
        For example, ``loghost`` requires 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)

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

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

    reset_syslog_config
        Resets the syslog service to it's default settings. Defaults to ``False``.
        If set to ``True``, default settings defined by the list of syslog configs
        in ``reset_configs`` will be reset before running any other syslog settings.

    reset_configs
        A comma-delimited list of parameters to reset. Only runs if
        ``reset_syslog_config`` is set to ``True``. If ``reset_syslog_config`` is set
        to ``True``, but no syslog configs are listed in ``reset_configs``, then
        ``reset_configs`` will be set to ``all`` by default.

        See ``syslog_configs`` parameter above for a list of valid options.

    Example:

    .. code-block:: yaml

        configure-host-syslog:
          esxi.syslog_configured:
            - syslog_configs:
                loghost: ssl://localhost:5432,tcp://10.1.0.1:1514
                default-timeout: 120
            - firewall: True
            - reset_service: True
            - reset_syslog_config: True
            - reset_configs: loghost,default-timeout
    unameuresultuchangesuucommentuesxi.cmduproxyuhostuallutestureset_syslog_configt
syslog_configusuccessumessageuKThere was an error resetting a syslog config '{0}'.Please check debug logs.u
Error: {0}uoldunewuget_firewall_statusuErrorurulesetsusysloguenable_firewall_rulesettruleset_enabletruleset_nameuretcodeiustderrustdoutufirewalluget_syslog_configu%'{0}' is not a valid config variable.uset_syslog_configtconfig_valuetfirewallt
reset_serviceuHThere was an error setting syslog config '{0}'. Please check debug logs.u
syslog_configu'Syslog is already in the desired state.uSyslog state will change.N(RRRRRRt	iteritemsR@tboolRRt_lookup_syslog_configtKeyErrorRRR(Rtsyslog_configsR`Ratreset_syslog_configt
reset_configsRRR!tresettkeytvalR+tcurrent_firewallR#RR/touttcurrent_syslog_configt
lookup_keytcurrent_valR&tsuccess((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pytsyslog_configuredes�=

	


















c(C@s~	td�}|jd�s&|dn|d}tjdj||��i|d6d=d6id6d=d	6}t}t}g}i}	d=}
y�tjd
�tj	�}y"t
ji|d6|d6|�Wn%t
jj
k
r�}t|��nXtd
�}
tdd|
�}
|
s-tdj|���nd�|
D�}tjdj|��tdd|
�}d�|D�}Wnutk
r�}tjdj|��|
r�td|
�n|jitds�tnd=d6tj|�d6�|SXxt|�D]
\}}|d|krO|jdj|d��tj|d�t}q�n||dd}dj|d|�}g}g}g}xc|dD]W}||kr�|j|�q�n|j||d�|jdj||d��q�W|rP|jdj|d jg|D]}d!j|�^q���tj|d�t}q�n|j|�s�tjd"j|��|rPtdr�|jd#j|||d jg|D]}d$j|�^q����qPx,|g|D]}td%d&|d|
�q�W|jd'j||d jg|D]}d!j|�^q���tj|d�ntdr�|jd(j|||d jg|D]}d!j|�^q|���tj|d�t}q�ny!td)||d*td|
�WnFtk
r$}|jd+j||��tj|d�t}q�nX|jd,j|��tj|d�ii|d-6|d.6d/6|	tj|�<t}q�ntjd0j||��|j|�}g|d1D]C}djg|
D] }|d|kr�|d2^q�d3|�^q�}g}g} g}!g}"xx|D]p}||d1krg|
D] }|d|kr8|d2^q8d3}#|j|�| jdj|#|��qqWxx|d1D]l}||kr�g|
D] }|d|kr�|d2^q�d3}#|!j|�|"jdj|#|��q�q�Wtjd4j||| |"��|!r�|jd5jd jg|"D]}$d!j|$�^qH�|��tj|d�t}q�n|r�d jg| D]}$d!j|$�^q��}%tdr�|jd6j||%|��tj|d�t}q�ny!td7||d*td|
�WnItk
rj}|jd8j|%||��tj|d�t}q�nXd9j|%|�}&tj|&�|j|&�ii|d-6|d.6d/6i|d-6|d.6d:6|	tj|�<t}q�nd;j|�}%tj|%�|j|%�q�Wtd|
�|p$	|s-	tntdr=	d=n|rI	tnt}'|ji|'d6d<j|�d6|	d6�|S(>u
    Configures the disk groups to use for vsan.

    This function will do the following:

    1. Check whether or not all disks in the diskgroup spec exist, and raises
       and errors if they do not.

    2. Create diskgroups with the correct disk configurations if diskgroup
       (identified by the cache disk canonical name) doesn't exist

    3. Adds extra capacity disks to the existing diskgroup

    Example:

    .. code:: python

        {
            'cache_scsi_addr': 'vmhba1:C0:T0:L0',
            'capacity_scsi_addrs': [
                'vmhba2:C0:T0:L0',
                'vmhba3:C0:T0:L0',
                'vmhba4:C0:T0:L0',
            ]
        }

    name
        Mandatory state name

    diskgroups
        Disk group representation containing scsi disk addresses.
        Scsi addresses are expected for disks in the diskgroup:

    erase_disks
        Specifies whether to erase all partitions on all disks member of the
        disk group before the disk group is created. Default value is False.
    uesxi.get_detailsuvcenteruhostu	esxi_hostu Running state {0} for host '{1}'unameuresultuchangesucommentsu&Validating diskgroups_configured inputu
diskgroupsuerase_disksu&vsphere.get_service_instance_via_proxyuvsphere.list_diskstservice_instanceu"No disks retrieved from host '{0}'cS@si|]}||d�qS(uscsi_address((t.0td((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pys
<dictcomp>Is	uscsi_addr_to_disk_map = {0}uvsphere.list_diskgroupscS@si|]}||d�qS(u
cache_disk((Rttdg((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pys
<dictcomp>Ns	u
Error: {0}uvsphere.disconnectutestucommentucache_scsi_addru0No cache disk with scsi address '{0}' was found.i����uidu{0} (id:{1})ucapacity_scsi_addrsuOError in diskgroup #{0}: capacity disks with scsi addresses {1} were not found.u, u'{0}'uerase_disks = {0}u\State {0} will erase all disks of disk group #{1}; cache disk: '{2}', capacity disk(s): {3}.u'{}'uvsphere.erase_disk_partitionstdisk_iduHErased disks of diskgroup #{0}; cache disk: '{1}', capacity disk(s): {2}uTState {0} will create the disk group #{1}; cache disk: '{2}', capacity disk(s): {3}.uvsphere.create_diskgroupt
safety_checksu$Error creating disk group #{0}: {1}.uCreated disk group #'{0}'.ucacheucapacityunewu5Disk group #{0} exists. Checking capacity disks: {1}.ucapacity_disksuscsi_addressiunDisk group #{0}: existing capacity disk ids: {1}; added capacity disk ids: {2}; removed capacity disk ids: {3}uUError removing capacity disk(s) {0} from disk group #{1}; operation is not supported.u;State {0} will add capacity disk(s) {1} to disk group #{2}.u!vsphere.add_capacity_to_diskgroupu:Error adding capacity disk(s) {0} to disk group #{1}: {2}.u-Added capacity disk(s) {0} to disk group #{1}uoldu<Disk group #{0} is correctly configured. Nothing to be done.u
N(RRtlogtinfoRRRttraceRt	serializet
jsonschematvalidatet
exceptionstValidationErrorRRRR#RRRRt	enumeratetappendRtjoinRtdebug((Rt
diskgroupsterase_diskst
proxy_detailsthostnameRterrorsR'tcommentstdiskgroup_changestsitschematexct
host_diskstscsi_addr_to_disk_maptexisting_diskgroupst$cache_disk_to_existing_diskgroup_mapR/tidxRvt
cache_disk_idtcache_disk_displaytbad_scsi_addrstcapacity_disk_idstcapacity_disk_displayst	scsi_addrtaRwtexisting_diskgroupRutexisting_capacity_disk_displaystadded_capacity_disk_idstadded_capacity_disk_displaystremoved_capacity_disk_idstremoved_capacity_disk_displaystdisk_scsi_addrtidtstcomtresult((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pytdiskgroups_configuredst(





	
	
	&
	)
	&
		&



Q

$

$

	)	"




	
u100%c!	C@s[tjd|�tjd|�tjd|�tjd|�td�}|jd�sf|dn|d}tjd	|�tjd
|�i|d6dd
6dTd6id6}tdr�dTnt}	t}
g}i}dT}
ytj	d�t
j�}y0tj
i|d6|d6|d6|d6|�Wn%tjjk
rS}t|��nXtjd|�}t|jd��}|jd�}tjd||�td�}
tdd|
�}|d|kr�|jii|dd6|d6d6�t}
ndT}|jd�r4tdd |dgd|
�}ntd!d"|d#gd|
�}|sytd$j|d#|���n|d%}d&j|d'|d(�}tjd)|�dT}|s�|rAtdr�|jd*j|||��tj|d+�qAtd,d-|d(d|
�|jd.j||��tj|d+�ntdr�|jd/j||d||��tj|d+�n5|rtd0d-|d(d|
�}tjd1|�g|D]}|d2d3kr�|^q�}t|�d%krtd4j|���qntd5|d|d%d(|d6d|
�|jd7j|d||��tj|d+�|jiii|dd6|d86d6d6�tdd |dgd|
�d%}t}
n�|d%jd9�s�td:j|d���n|d(|d%d9krZtd;j|d|d(d<jg|d%d9D]}d=j|�^q3����n|jd>j|d||��|d%}tjd?|�tj|d+�|r�|d@kr�|dA|dBdCdC}n
|dC}tjdD|�t|dC�dC}tjdE|�d%}|jd�rBtjdF|jd��ndT}|rft|jd��}n||ks�t}
|jiidGj|dC�d6dGj|dC�d6d6�q�n|
rztdr|jdHj||i|d6|ddI6|d6��q�|dBdU|kr@tdKj|d|dBdV|���ntdL||ddM|d|
�|jdNj|��n|jdOj|��t}	tdP|
�tj|d+�|jidQj|�d
6|	d6|d6�|SWnotk
rV} tjdR| �|
rtdP|
�n|jitds7tndTd6dSj| �d
6�|SXdTS(WuV
    Configures the host cache used for swapping.

    It will do the following:

    1. Checks if backing disk exists

    2. Creates the VMFS datastore if doesn't exist (datastore partition will be
       created and use the entire disk)

    3. Raises an error if ``dedicated_backing_disk`` is ``True`` and partitions
       already exist on the backing disk

    4. Configures host_cache to use a portion of the datastore for caching
       (either a specific size or a percentage of the datastore)

    Examples

    Percentage swap size (can't be 100%)

    .. code:: python

        {
            'enabled': true,
            'datastore': {
                'backing_disk_scsi_addr': 'vmhba0:C0:T0:L0',
                'vmfs_version': 5,
                'name': 'hostcache'
                }
            'dedicated_backing_disk': false
            'swap_size': '98%',
        }

    Fixed sized swap size

    .. code:: python

        {
            'enabled': true,
            'datastore': {
                'backing_disk_scsi_addr': 'vmhba0:C0:T0:L0',
                'vmfs_version': 5,
                'name': 'hostcache'
                }
            'dedicated_backing_disk': true
            'swap_size': '10GiB',
        }

    name
        Mandatory state name.

    enabled
        Specifies whether the host cache is enabled.

    datastore
        Specifies the host cache datastore.

    swap_size
        Specifies the size of the host cache swap. Can be a percentage or a
        value in GiB. Default value is ``100%``.

    dedicated_backing_disk
        Specifies whether the backing disk is dedicated to the host cache which
        means it must have no other partitions. Default is False

    erase_backing_disk
        Specifies whether to erase all partitions on the backing disk before
        the datastore is created. Default value is False.
    uenabled = %sudatastore = %suswap_size = %suerase_backing_disk = %suesxi.get_detailsuvcenteruhostu	esxi_hostu
hostname = %su0Running host_cache_swap_configured for host '%s'unameuDefault commentsucommenturesultuchangesutestu&Validating host_cache_configured inputuenabledu	datastoreu	swap_sizeuerase_backing_disku(\d+)(%|GiB)iiu$swap_size_value = %s; swap_type = %su&vsphere.get_service_instance_via_proxyuvsphere.get_host_cacheRsuoldunewu!vsphere.list_datastores_via_proxytdatastore_namesuvsphere.list_diskstscsi_addressesubacking_disk_scsi_addru8Disk with scsi address '{0}' was not found in host '{1}'iu{0} (id:{1})uscsi_addressuidubacking_disk = %su:State {0} will erase the backing disk '{1}' on host '{2}'.i����uvsphere.erase_disk_partitionsRwu(Erased backing disk '{0}' on host '{1}'.uRState {0} will create the datastore '{1}', with backing disk '{2}', on host '{3}'.uvsphere.list_disk_partitionsupartitions = %suformatumbru,Backing disk '{0}' has unexpected partitionsuvsphere.create_vmfs_datastoreuvmfs_versionuBCreated vmfs datastore '{0}', backed by disk '{1}', on host '{2}'.ubacking_diskubacking_disk_idsu+Datastore '{0}' doesn't have a backing diskuJDatastore '{0}' is not backed by the correct disk: expected '{1}'; got {2}u, u'{0}'u]Datastore '{0}' already exists on host '{1}' and is backed by disk '{2}'. Nothing to be done.uexisting_datastore = %su%gY@ucapacityiuraw_size = %sMiBuadjusted swap_size = %sMiBu(\d+)MiBu{}GiBu>State {0} will configure the host cache on host '{1}' to: {2}.udatastore_nameg�@uaCapacity of host cache datastore '{0}' ({1} MiB) is smaller than the required swap size ({2} MiB)uvsphere.configure_host_cachet
swap_size_MiBu$Host cache configured on host '{0}'.uMHost cache on host '{0}' is already correctly configured. Nothing to be done.uvsphere.disconnectu
u
Error: %s.u{}.Ng0Ag0A( RyR{RRRzRRRRR�RR|R}R~RR�RtretmatchtinttgroupRRRR�tlenRRR�R	RR#(!RRt	datastoret	swap_sizetdedicated_backing_diskterase_backing_diskR�R�RR�t
needs_settingR�R'R�R�R�tmtswap_size_valuet	swap_typet
host_cachetexisting_datastorestexisting_diskstbacking_disktbacking_disk_displaytexisting_datastoret
partitionstptnon_mbr_partitionstdisktraw_size_MiBR�texisting_swap_size_MiBR/((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pythost_cache_configuredsXJ





	



	













		3



0"

	


	cC@s=idd6dd6dd6dd6d	d
6dd6}|j|�S(
ul
    Helper function that looks up syslog_config keys available from
    ``vsphere.get_syslog_config``.
    uDefault Network Retry Timeoutudefault-timeoutuLocal Log Outputulogdiru#Local Logging Default Rotation Sizeudefault-sizeuLog To Unique Subdirectoryu
logdir-uniqueuLocal Logging Default Rotationsudefault-rotateuRemote Hostuloghost(R(tconfigtlookup((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pyRd>s

cC@s.|j�|jdd�|jdd�|S(u�
    Strips an SSH key string of white space and line endings and returns the new string.

    key_string
        The string to be stripped.
    u
uu
(tstriptreplace(t
key_string((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pyRJMs
(3t__doc__t
__future__RRRtloggingtsysR�tsalt.extRtsalt.utils.filesRLtsalt.exceptionsRRRRRR	tsalt.utils.decoratorsR
tsalt.config.schemas.esxiRRR}RtHAS_JSONSCHEMAtImportErrorRt	getLoggert__name__RytpyVmomiR
t
versionMaptversion_infoR�tHAS_PYVMOMIRR,R0RR<R?RFR[RrR�R�RdRJ(((s4/usr/lib/python2.7/site-packages/salt/states/esxi.pyt<module>]sl.


-



	�	3�Hc��		�		�#	

Zerion Mini Shell 1.0