HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/state.cpython-310.pyc
o

�N�g I�@sdZddlZddlZddlZddlZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlZ	ddl
Z	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	ddlmZmZddlmZddl m!a"ddl#m$Z$dgZ%dddddddddddddd	�
Z&d
diZ'e�(e)�Z*dZ+d
d�Z,dd�Z-drdd�Z.drdd�Z/dsdd�Z0dd�Z1dd�Z2drdd�Z3drdd�Z4drdd �Z5dtd!d"�Z6drd#d$�Z7	dud&d'�Z!dvd)d*�Z8d+d,�Z9d-d.�Z:d/d0�Z;drd1d2�Z<drd3d4�Z=dtd5d6�Z>drd7d8�Z?drd9d:�Z@drd;d
�ZAd<d=�ZBdrd>d?�ZCdrd@dA�ZDdrdBdC�ZEdwdEdF�ZFdxdGd�ZG					dydHdI�ZHdtdJdK�ZIdrdLdM�ZJdrdNdO�ZKdrdPdQ�ZLdrdRdS�ZMdxdTdU�ZNdtdVdW�ZOdtdXdY�ZPdtdZd[�ZQdtd\d]�ZRdrd^d_�ZSdtd`da�ZTdbdc�ZUdrddde�ZVdfdg�ZWdhdi�ZXdjdk�ZYdldm�ZZ	odzdpdq�Z[dS){aB
Control the state system on the minion.

State Caching
-------------

When a highstate is called, the minion automatically caches a copy of the last
high data. If you then run a highstate with cache=True it will use that cached
highdata and won't hit the fileserver except for ``salt://`` links in the
states themselves.
�N)�CommandExecutionError�SaltInvocationError)�_format_cached_grains)�orchestrate)�OrderedDict�*�	highstate)
�sls�sls_id�pkg�top�singler�template�template_str�apply_�test�request�
check_request�run_requestrZapply�statecCstjj�tt��atS)z
    Set the virtualname
    )�salt�utils�	functoolsZnamespaced_function�_orchestrate�globals�__virtualname__�rr�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/state.py�__virtual__EsrcCsdd�|��D�}|S)z7
    Filter out the result: True + no changes data
    cSs&i|]\}}|dr|dr||�qS)�resultZchangesr)�.0�tag�valuerrr�
<dictcomp>Ts���z#_filter_running.<locals>.<dictcomp>)�items)Zrunnings�retrrr�_filter_runningPs�r&cCsPtjjjtd<t|t�rtjjjtd<dStd||d�s&tjjj	td<dSdS)zJ
    Set the return code based on the data back from the state system
    �retcodeN�state.check_result�r)
r�defaults�	exitcodes�EX_OK�__context__�
isinstance�list�EX_STATE_COMPILER_ERROR�	__utils__�EX_STATE_FAILURE)r%rrrr�_set_retcode\s
�r3cCs|�d�rdS|p
t�d�S)ae
    Check pillar for errors.

    If a pillar is passed, it will be checked. Otherwise, the in-memory pillar
    will checked instead. Passing kwargs['force'] = True short cuts the check
    and always returns None, indicating no errors.

    :param kwargs: dictionary of options
    :param pillar: pillar
    :return: None or a list of error messages
    �forceN�_errors)�get�
__pillar__)�kwargs�pillarrrr�_get_pillar_errorsksr:cCsP|durtjj�t�}t|�}|rt|�|kr&|r$t�d�t|�}|sdSdS)zF
    Wait for all previously started state jobs to finish running
    N�TF)	rr�jidZgen_jid�__opts__�_prior_running_states�len�time�sleep)r<�	max_queue�statesrrr�_waitzs
�rDcCsld}z#|ds t�d�r#tdt�dd�dd|��|d	�}W|SW|SW|Sty5t�d
|�Y|Sw)z'
    Create a snapper pre snapshot
    Nr�snapper_states�snapper.create_snapshot�snapper_states_config�rootZpre�Salt State run for jid )�config�
snapshot_type�description�	__pub_jid�1Failed to create snapper pre snapshot for jid: %s�r=r6�__salt__�	Exception�log�error)�optsr<�snapper_prerrr�_snapper_pre�s$
��
�
��rVcCstz)|ds!t�d�r$|r'tdt�dd�d|d|��|d�Wd
SWd
SWd
SWd
Sty9t�d	|�Yd
Sw)z)
    Create the post states snapshot
    rrErFrGrHZpostrI)rJrKZ
pre_numberrLrMrNNrO)rTr<Zpre_numrrr�
_snapper_post�s
��	�rWcCs�tj�tdd�}tj�||�}tj�|�s'zt�|�Wn	ty&Ynwi}|dur5||vr5i||<tj�|�r_tjj	�
|d��}tjj�|�
��}Wd�||fS1sZwY||fS)z6
    Return the pause information for a given jid
    �cachedir�state_pauseN�rb)�os�path�joinr=�exists�makedirs�OSErrorrr�files�fopen�msgpack�loads�read)r<�state_id�	pause_dir�
pause_path�data�fp_rrr�
_get_pause�s&�
��rkc
	Cs�i}tdd�}tj�tdd�}tj�|�s|S|dur#t�|�}nt|t�r0t	j
j�|�}nt
|�g}|D]6}d}|D]
}|d|krGd}q=|scztj�||�}t�|�Wn	tyaYnwq7t|�\}	}|	||<q7|S)	z�
    Get a report on all of the currently paused state runs and pause
    run settings.
    Optionally send in a jid if you only desire to see a single pause
    data set.
    �saltutil.is_running�state.*rXrYNFr<T)rPr[r\r]r=r^�listdirr.r/rrriZ	stringify�str�remover`rk)
r<r%�activergZjidsZscan_jidZ	is_activeZactive_datarhrirrr�
get_pauses�s6

��
rrcCsxt|�}|dur
d}t||�\}}d||d<tjj�|d��}|�tjj�|��Wd�dS1s5wYdS)a�
    Set up a state run to die before executing the given state id,
    this instructs a running state to safely exit at a given
    state id. This needs to pass in the jid of the running state.
    If a state_id is not passed then the jid referenced will be safely exited
    at the beginning of the next state run.

    The given state id is the id got a given state execution, so given a state
    that looks like this:

    .. code-block:: yaml

        vim:
          pkg.installed: []

    The state_id to pass to `soft_kill` is `vim`

    CLI Examples:

    .. code-block:: bash

        salt '*' state.soft_kill 20171130110407769519
        salt '*' state.soft_kill 20171130110407769519 vim
    N�__all__T�kill�wb)	rorkrrrarb�writerc�dumps�r<rfrirhrjrrr�	soft_kill�s"�rycCs�t|�}|dur
d}t||�\}}|rt|�||d<tjj�|d��}|�tjj�	|��Wd�dS1s9wYdS)a�
    Set up a state id pause, this instructs a running state to pause at a given
    state id. This needs to pass in the jid of the running state and can
    optionally pass in a duration in seconds. If a state_id is not passed then
    the jid referenced will be paused at the beginning of the next state run.

    The given state id is the id got a given state execution, so given a state
    that looks like this:

    .. code-block:: yaml

        vim:
          pkg.installed: []

    The state_id to pass to `pause` is `vim`

    CLI Examples:

    .. code-block:: bash

        salt '*' state.pause 20171130110407769519
        salt '*' state.pause 20171130110407769519 vim
        salt '*' state.pause 20171130110407769519 vim 20
    Nrs�durationru)
rork�intrrrarbrvrcrw)r<rfrzrirhrjrrr�pause
s"�r|cCs�t|�}|dur
d}t||�\}}||vr|�|�|dkr i}tjj�|d��}|�tjj�	|��Wd�dS1s>wYdS)a
    Remove a pause from a jid, allowing it to continue. If the state_id is
    not specified then the a general pause will be resumed.

    The given state_id is the id got a given state execution, so given a state
    that looks like this:

    .. code-block:: yaml

        vim:
          pkg.installed: []

    The state_id to pass to `rm_pause` is `vim`

    CLI Examples:

    .. code-block:: bash

        salt '*' state.resume 20171130110407769519
        salt '*' state.resume 20171130110407769519 vim
    Nrsru)
rork�poprrrarbrvrcrwrxrrr�resume-s
"�r~�basecCst||||||d�S)a
    .. versionadded:: 2016.11.0

    Execute the orchestrate runner from a masterless minion.

    .. seealso:: More Orchestrate documentation

        * :ref:`Full Orchestrate Tutorial <orchestrate-runner>`
        * Docs for the salt state module :py:mod:`salt.states.saltmod`

    CLI Examples:

    .. code-block:: bash

        salt-call --local state.orchestrate webserver
        salt-call --local state.orchestrate webserver saltenv=dev test=True
        salt-call --local state.orchestrate webserver saltenv=dev pillarenv=aws
    ��mods�saltenvr�excluder9�	pillarenv)rr�rrrrOs�rFc	CsZg}|r|Stdd�}|D]}d�|d|dtjj�|d�|d�}|�|�q|S)a
    Return a list of strings that contain state return data if a state function
    is already running. This function is used to prevent multiple state calls
    from being run at the same time.

    CLI Example:

    .. code-block:: bash

        salt '*' state.running
    rlrmzHThe function "{}" is running as PID {} and was started at {} with jid {}�fun�pidr<)rP�formatrrr<Zjid_to_time�append)�
concurrentr%rqri�errrrr�runningns��	r�c	CsXg}tdd�}|D]}zt|d�}Wn	tyYq
w|t|�kr)|�|�q
|S)z�
    Return a list of dicts of prior calls to state functions.  This function is
    used to queue state calls so only one is run at a time.
    rlrmr<)rPr{�
ValueErrorr�)r<r%rqriZdata_jidrrrr>�s�
�r>cCs�|durtddd�}|durt|�d��dSd}t|t�s-t|t�r-t|�d�|d�}|sCt|�dd�d	�}|rCtjj	j
td
<|SdS)zy
    Utility function to queue the state run if requested
    and to check for conflicts in currently running states
    N�
config.optionZstate_queueFTrM)rBr�)r�r')rPrDr6r.�boolr{r�rr*r+r0r-)�queuer8Z	queue_ret�conflictrrr�_check_queue�s�r�cCs,t�dd�dkr|dtdkrt��SdS)NZ__cliz	salt-callr�)r=r6r7r")rTrrr�_get_initial_pillar�s���r�cKs�t||�}|dur|Sz
tjjttd�}Wnty$tj�t�}Ynw|�|�}|r5tjj	j
td<|S|�|�}t
|t�rFtjj	j
td<td|�rStjj	jtd<|S)a
    Execute a single low data call

    This function is mostly intended for testing the state system and is not
    likely to be needed in everyday usage.

    CLI Example:

    .. code-block:: bash

        salt '*' state.low '{"state": "pkg", "fun": "installed", "name": "vi"}'
    N)�proxyr'r()r�rr�Stater=�	__proxy__�	NameError�verify_datar*r+r0r-�callr.r/r1r2)rir�r8r��st_r�r%rrr�low�s$

�


r�cKs`d}|dur,tjjjdd|i|��rd}|Stdddd�dur$d}|St�dd�}|S|}|S)z8
    Determine the correct value for the test flag.
    TNrz
config.get)Z	omit_optsr)rr�argsZ	test_moderPr=r6)rr8r%rrr�_get_test_value�s���r�c
	Ks�t||�}|dur|Stjjjtfi|��}t|fi|��|d<|�d�}|�d�}|dur;|dur;t|t	�s;t
d��ztjj|||t	t�t	t
�t|�d�}Wntydtjj|||t|�d�}Ynw|�|�}	t|	|d�|	S)	a,
    Execute the compound calls stored in a single set of high data

    This function is mostly intended for testing the state system and is not
    likely to be needed in everyday usage.

    CLI Example:

    .. code-block:: bash

        salt '*' state.high '{"vim": {"pkg": ["installed"]}}'
    Nrr9�
pillar_enc�NPillar data must be formatted as a dictionary, unless pillar_enc is specified.)r�r��context�initial_pillar�r�r�r))r�rrr�get_sls_optsr=r�r6r.�dictrr�r�r-r�r��	call_highr3)
rirr�r8r�rT�pillar_overrider�r�r%rrr�high�sD



��
�
��
r�c	Ks\d|vr	|�d�t||�}|dur|Stjjjtfi|��}ztjj|tt	�tt
�t|�d�}WntyGtjj|tt	�t|�d�}Ynw|�Zt
||jdd�}|rctjjjt	d<td|d	��|�d
�sm|�d
�}|j||�dd�ddd
d�\}}|r�tjjjt	d<|Wd�S|j�|�}t||d�|Wd�S1s�wYdS)aL
    Execute the information stored in a template file on the minion.

    This function does not ask a master for a SLS file to render but
    instead directly processes the file at the provided path on the minion.

    CLI Example:

    .. code-block:: bash

        salt '*' state.template '<Path to template on the minion>'
    �envN)r�r�r�)r�r�r9�r9r'�Pillar failed to render��infoz.slsr��T)�localr))r}r�rrrr�r=�	HighStater�r-r�r�r�r:rTr*r+�EX_PILLAR_FAILUREr�endswithZrender_stater6r0r�r3)	�temr�r8r�rTr��errorsZ
high_stater%rrrr%sH


�
��


��$�rcKs�t||�}|dur|Stjjjtfi|��}z
tjj|tt|�d�}Wnt	y6tjj|t|�d�}Ynw|�
|�}t|�|S)z�
    Execute the information stored in a string from an sls template

    CLI Example:

    .. code-block:: bash

        salt '*' state.template_str '<Template String>'
    N�r�r��r�)r�rrrr�r=r�r�r�r�Zcall_template_strr3)r�r�r8r�rTr�r%rrrrZs



��
rcKs"|r
t|fi|��Stdi|��S)aa
    .. versionadded:: 2015.5.0

    This function will call :mod:`state.highstate
    <salt.modules.state.highstate>` or :mod:`state.sls
    <salt.modules.state.sls>` based on the arguments passed to this function.
    It exists as a more intuitive way of applying states.

    .. rubric:: APPLYING ALL STATES CONFIGURED IN TOP.SLS (A.K.A. :ref:`HIGHSTATE <running-highstate>`)

    To apply all configured states, simply run ``state.apply`` with no SLS
    targets, like so:

    .. code-block:: bash

        salt '*' state.apply

    The following additional arguments are also accepted when applying all
    states configured in top.sls:

    test
        Run states in test-only (dry-run) mode

    mock
        The mock option allows for the state run to execute without actually
        calling any states. This then returns a mocked return which will show
        the requisite ordering as well as fully validate the state run.

        .. versionadded:: 2015.8.4

    pillar
        Custom Pillar values, passed as a dictionary of key-value pairs

        .. code-block:: bash

            salt '*' state.apply stuff pillar='{"foo": "bar"}'

        .. note::
            Values passed this way will override Pillar values set via
            ``pillar_roots`` or an external Pillar source.

    exclude
        Exclude specific states from execution. Accepts a list of sls names, a
        comma-separated string of sls names, or a list of dictionaries
        containing ``sls`` or ``id`` keys. Glob-patterns may be used to match
        multiple states.

        .. code-block:: bash

            salt '*' state.apply exclude=bar,baz
            salt '*' state.apply exclude=foo*
            salt '*' state.apply exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"

    queue : False
        Instead of failing immediately when another state run is in progress,
        a value of ``True`` will queue the new state run to begin running once
        the other has finished.

        This option starts a new thread for each queued state run, so use this
        option sparingly.

        .. versionchanged:: 3006.0
            This parameter can also be set via the ``state_queue`` configuration
            option. Additionally, it can now be set to an integer representing
            the maximum queue size which can be attained before the state runs
            will fail to be queued. This can prevent runaway conditions where
            new threads are started until system performance is hampered.

    localconfig
        Optionally, instead of using the minion config, load minion opts from
        the file specified by this argument, and then merge them with the
        options from the minion config. This functionality allows for specific
        states to be run with their own custom minion configuration, including
        different pillars, file_roots, etc.

        .. code-block:: bash

            salt '*' state.apply localconfig=/path/to/minion.yml

    state_events
        The state_events option sends progress events as each function in
        a state run completes execution.

        .. versionadded:: 3006.0


    .. rubric:: APPLYING INDIVIDUAL SLS FILES (A.K.A. :py:func:`STATE.SLS <salt.modules.state.sls>`)

    To apply individual SLS files, pass them as a comma-separated list:

    .. code-block:: bash

        # Run the states configured in salt://stuff.sls (or salt://stuff/init.sls)
        salt '*' state.apply stuff

        # Run the states configured in salt://stuff.sls (or salt://stuff/init.sls)
        # and salt://pkgs.sls (or salt://pkgs/init.sls).
        salt '*' state.apply stuff,pkgs

        # Run the states configured in a more deeply nested directory such as salt://my/organized/stuff.sls (or salt://my/organized/stuff/init.sls)
        salt '*' state.apply my.organized.stuff

    The following additional arguments are also accepted when applying
    individual SLS files:

    test
        Run states in test-only (dry-run) mode

    mock
        The mock option allows for the state run to execute without actually
        calling any states. This then returns a mocked return which will show
        the requisite ordering as well as fully validate the state run.

        .. versionadded:: 2015.8.4

    pillar
        Custom Pillar values, passed as a dictionary of key-value pairs

        .. code-block:: bash

            salt '*' state.apply stuff pillar='{"foo": "bar"}'

        .. note::
            Values passed this way will override Pillar values set via
            ``pillar_roots`` or an external Pillar source.

    queue : False
        Instead of failing immediately when another state run is in progress,
        a value of ``True`` will queue the new state run to begin running once
        the other has finished.

        This option starts a new thread for each queued state run, so use this
        option sparingly.

        .. versionchanged:: 3006.0
            This parameter can also be set via the ``state_queue`` configuration
            option. Additionally, it can now be set to an integer representing
            the maximum queue size which can be attained before the state runs
            will fail to be queued. This can prevent runaway conditions where
            new threads are started until system performance is hampered.

    concurrent : False
        Execute state runs concurrently instead of serially

        .. warning::

            This flag is potentially dangerous. It is designed for use when
            multiple state runs can safely be run at the same time. Do *not*
            use this flag for performance optimization.

    saltenv
        Specify a salt fileserver environment to be used when applying states

        .. versionchanged:: 0.17.0
            Argument name changed from ``env`` to ``saltenv``

        .. versionchanged:: 2014.7.0
            If no saltenv is specified, the minion config will be checked for an
            ``environment`` parameter and if found, it will be used. If none is
            found, ``base`` will be used. In prior releases, the minion config
            was not checked and ``base`` would always be assumed when the
            saltenv was not explicitly set.

    pillarenv
        Specify a Pillar environment to be used when applying states. This
        can also be set in the minion config file using the
        :conf_minion:`pillarenv` option. When neither the
        :conf_minion:`pillarenv` minion config option nor this CLI argument is
        used, all Pillar environments will be merged together.

    localconfig
        Optionally, instead of using the minion config, load minion opts from
        the file specified by this argument, and then merge them with the
        options from the minion config. This functionality allows for specific
        states to be run with their own custom minion configuration, including
        different pillars, file_roots, etc.

        .. code-block:: bash

            salt '*' state.apply stuff localconfig=/path/to/minion.yml

    sync_mods
        If specified, the desired custom module types will be synced prior to
        running the SLS files:

        .. code-block:: bash

            salt '*' state.apply stuff sync_mods=states,modules
            salt '*' state.apply stuff sync_mods=all

        .. note::
            This option is ignored when no SLS files are specified, as a
            :ref:`highstate <running-highstate>` automatically syncs all custom
            module types.

        .. versionadded:: 2017.7.8,2018.3.3,2019.2.0

    state_events
        The state_events option sends progress events as each function in
        a state run completes execution.

        .. versionadded:: 3006.0
    Nr)r	r)r�r8rrrrusMcOsd|d<t|i|��}|S)z�
    .. versionadded:: 3001

    Alias for `state.apply` with the kwarg `test` forced to `True`.

    This is a nicety to avoid the need to type out `test=True` and the possibility of
    a typo causing changes you do not intend.
    Tr)r)r�r8r%rrrrFs	rc	Ksd|d<t|fi|��}tj�tdd�}t�}|�|�dd�|||d�i�tj	j
�d��Rz1tj	j�
�r@td	d
|�d��tj	j
�|d��}tj�||�Wd
�n1sZwYWntyot�d|�Yn	wWd
�|SWd
�|S1s�wY|S)aJ
    .. versionadded:: 2015.5.0

    Request that the local admin execute a state run via
    `salt-call state.run_request`.
    All arguments match those of state.apply.

    CLI Example:

    .. code-block:: bash

        salt '*' state.request
        salt '*' state.request stuff
        salt '*' state.request stuff,pkgs
    TrrX�req_state.p�name�default)Ztest_runr�r8�?�cmd.run�attrib -R "�"�w+bN�8Unable to write state request file %s. Check permission.)rr[r\r]r=r�updater6rrra�	set_umask�platform�
is_windowsrPrb�payload�dumpr`rRrS)r�r8r%�notify_path�reqrjrrrrUsB
���	�����
��
��rcCsntj�tdd�}tj�|�r5tjj�|d��}tj	�
|�}Wd�n1s(wY|r3||S|SiS)z�
    .. versionadded:: 2015.5.0

    Return the state request information, if any

    CLI Example:

    .. code-block:: bash

        salt '*' state.check_request
    rXr�rZN)r[r\r]r=�isfilerrrarbr��load)r�r�rjr�rrrr�s�rc	Cs0tj�tdd�}tj�|�sdS|s&zt�|�WdSty%YdSwt�}||vr3|�|�ndSt	j
j�d��Rz1t	j
j
��rNtdd|�d��t	j
j�|d	��}t	j�||�Wd
�n1shwYWnty}t�d|�Yn	wWd
�dSWd
�dS1s�wYdS)z�
    .. versionadded:: 2015.5.0

    Clear out the state execution request without executing it

    CLI Example:

    .. code-block:: bash

        salt '*' state.clear_request
    rXr�TFr�r�r�r�r�Nr�)r[r\r]r=r�rpr`rr}rrrar�r�r�rPrbr�r�rRrS)r�r�r�rjrrr�
clear_request�sJ�������
��
��r�r�cKs�t�}||vr	iS||}d|vsd|vriS||d�|�d|dvr-|d�d�|rUt|dfi|d��}zt�tj�tdd��W|St	yTY|SwiS)z�
    .. versionadded:: 2015.5.0

    Execute the pending state request

    CLI Example:

    .. code-block:: bash

        salt '*' state.run_request
    r�r8rrXr�)
rr�r}rr[rpr\r]r=r`)r�r8r�Zn_reqr%rrrr�s&��rcKs�tdg�rt�d�dddd�}|St||�}|dur|St�dd�}tjjj	tfi|��}t
|fi|��|d<d|vrA|�d�d	|vrK|d	|d	<d
|vrU|d
|d
<|�d�}|�d�}	|	durp|durpt|t
�sptd
��|durx||d<ztjj|||�d�|	t
t�t
t�|�dd�t|�d�}
Wnty�tjj|||�d�|	|�dd�t|�d�}
Ynw|
��t||
jd�}|r�tjjjtd<dg|Wd�S|
��|�d�}t||�dd��}
z$|
j|�dg�|�dd�|�dd�|�dd�|�d�|d�}W|
��n|
��wt|t
��r*tddd �d!k�s&|�d!��r*t|�}t||
j d"�t!||�dd�|
�|td<|Wd�S1�sLwYdS)#a�
    Retrieve the state data from the salt master for this minion and execute it

    test
        Run states in test-only (dry-run) mode

    pillar
        Custom Pillar values, passed as a dictionary of key-value pairs

        .. code-block:: bash

            salt '*' state.highstate stuff pillar='{"foo": "bar"}'

        .. note::
            Values passed this way will override Pillar values set via
            ``pillar_roots`` or an external Pillar source.

        .. versionchanged:: 2016.3.0
            GPG-encrypted CLI Pillar data is now supported via the GPG
            renderer. See :ref:`here <encrypted-cli-pillar-data>` for details.

    pillar_enc
        Specify which renderer to use to decrypt encrypted data located within
        the ``pillar`` value. Currently, only ``gpg`` is supported.

        .. versionadded:: 2016.3.0

    exclude
        Exclude specific states from execution. Accepts a list of sls names, a
        comma-separated string of sls names, or a list of dictionaries
        containing ``sls`` or ``id`` keys. Glob-patterns may be used to match
        multiple states.

        .. code-block:: bash

            salt '*' state.highstate exclude=bar,baz
            salt '*' state.highstate exclude=foo*
            salt '*' state.highstate exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"

    saltenv
        Specify a salt fileserver environment to be used when applying states

        .. versionchanged:: 0.17.0
            Argument name changed from ``env`` to ``saltenv``.

        .. versionchanged:: 2014.7.0
            If no saltenv is specified, the minion config will be checked for a
            ``saltenv`` parameter and if found, it will be used. If none is
            found, ``base`` will be used. In prior releases, the minion config
            was not checked and ``base`` would always be assumed when the
            saltenv was not explicitly set.

    pillarenv
        Specify a Pillar environment to be used when applying states. This
        can also be set in the minion config file using the
        :conf_minion:`pillarenv` option. When neither the
        :conf_minion:`pillarenv` minion config option nor this CLI argument is
        used, all Pillar environments will be merged together.

    queue : False
        Instead of failing immediately when another state run is in progress,
        a value of ``True`` will queue the new state run to begin running once
        the other has finished.

        This option starts a new thread for each queued state run, so use this
        option sparingly.

        .. versionchanged:: 3006.0
            This parameter can also be set via the ``state_queue`` configuration
            option. Additionally, it can now be set to an integer representing
            the maximum queue size which can be attained before the state runs
            will fail to be queued. This can prevent runaway conditions where
            new threads are started until system performance is hampered.

    concurrent : False
        Execute state runs concurrently instead of serially

        .. warning::

            This flag is potentially dangerous. It is designed for use when
            multiple state runs can safely be run at the same time. Do *not*
            use this flag for performance optimization.

    localconfig
        Optionally, instead of using the minion config, load minion opts from
        the file specified by this argument, and then merge them with the
        options from the minion config. This functionality allows for specific
        states to be run with their own custom minion configuration, including
        different pillars, file_roots, etc.

    mock
        The mock option allows for the state run to execute without actually
        calling any states. This then returns a mocked return which will show
        the requisite ordering as well as fully validate the state run.

        .. versionadded:: 2015.8.4

    state_events
        The state_events option sends progress events as each function in
        a state run completes execution.

        .. versionadded:: 3006.0

    CLI Examples:

    .. code-block:: bash

        salt '*' state.highstate

        salt '*' state.highstate whitelist=sls1_to_run,sls2_to_run
        salt '*' state.highstate exclude=sls_to_exclude
        salt '*' state.highstate exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"

        salt '*' state.highstate pillar="{foo: 'Foo!', bar: 'Bar!'}"
    rzHSalt highstate run is disabled. To re-enable, run state.enable highstate�FalseZDisabled)r�rZcommentNrr�r�r�r9r�r��state_eventsrM�mockF�r�r�r��mockedr��r�r�r�r'�4Pillar failed to render with the following messages:�orchestration_jid�
called localyr��cache�
cache_namer4�	whitelist)r�r�r�r4r�r�r��
state_datar��terser))"�	_disabledrR�debugr�r=r6rrrr�r�r}r.r�rr�r�r-r�r�r:rTr*r+r��push_activerV�call_highstate�
pop_activerPr&r3�building_highstaterW)rr�r�r8r%r��	orig_testrTr�r�r�r�r�rUrrrr�s�
t��



��

�


��
�




�	�&�cKs�|�dd�}d|vr|�d�t||�}|dur|St|t�r$t|�}	nt|g�}	|	r@|	D]	}
t�d|
|
�q-tj	j
jtd<|	St
�dd�}tjjjt
fi|��}t|fi|��|d<|ddured	|d<|�d
�}
|�d�}|dur�|
dur�t|
t�s�td��tj�t
d
d�|�dd���}|dur�dg}|dur�tjj�|�}ng}d|vr�|dgkr�dg}|D]}ztd|��|dd�Wq�ty�t�d|�Yq�w|dur�||d<ztjj||
|�d�|tt�tt�|�dd�t|�d�}Wnt �ytjj||
|�d�||�dd�t|�d�}Ynw|��t!||j"d
d�}|�r:tj	j
j#td<dg|Wd�S|�d�}tjj$�%d��I|�d��r�tj�&|��r�tjj$�'|d ��#}tj(�)|�}|j�*||�Wd�Wd�Wd�S1�s�wYWd�n	1�s�wYt|t+��r�tjj,�-t.|��}tjj�|�}|�/�zT|�0|d|i�\}}|�r�tj	j
jtd<|W|�1�Wd�S|�r�tjj�|�}d!|v�r�|d!�2|�n||d!<t3||�dd"��}|j�*||�}W|�1�n|�1�wWd�n	1�swYtd#d$d%�d&k�s,|�d&��r0t4|�}tj�t
d
d'�}tjj$�%d���z4tjj5�6��rTtd(d)d*|gdd+�tjj$�'|d,��}tj(�7||�Wd�n	1�sowYWnt8�y�t�9d-|�Ynwt:||�|t
d<z/tjj$�'|d,��}z	tj(�7||�Wn
t;�y�YnwWd�n	1�s�wYWnt8�y�t�9d.|�YnwWd�n	1�s�wYt<||�dd"�|�|S)/a�
    Execute the states in one or more SLS files

    test
        Run states in test-only (dry-run) mode

    pillar
        Custom Pillar values, passed as a dictionary of key-value pairs

        .. code-block:: bash

            salt '*' state.sls stuff pillar='{"foo": "bar"}'

        .. note::
            Values passed this way will override existing Pillar values set via
            ``pillar_roots`` or an external Pillar source.  Pillar values that
            are not included in the kwarg will not be overwritten.

        .. versionchanged:: 2016.3.0
            GPG-encrypted CLI Pillar data is now supported via the GPG
            renderer. See :ref:`here <encrypted-cli-pillar-data>` for details.

    pillar_enc
        Specify which renderer to use to decrypt encrypted data located within
        the ``pillar`` value. Currently, only ``gpg`` is supported.

        .. versionadded:: 2016.3.0

    exclude
        Exclude specific states from execution. Accepts a list of sls names, a
        comma-separated string of sls names, or a list of dictionaries
        containing ``sls`` or ``id`` keys. Glob-patterns may be used to match
        multiple states.

        .. code-block:: bash

            salt '*' state.sls foo,bar,baz exclude=bar,baz
            salt '*' state.sls foo,bar,baz exclude=ba*
            salt '*' state.sls foo,bar,baz exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"

    queue : False
        Instead of failing immediately when another state run is in progress,
        a value of ``True`` will queue the new state run to begin running once
        the other has finished.

        This option starts a new thread for each queued state run, so use this
        option sparingly.

        .. versionchanged:: 3006.0
            This parameter can also be set via the ``state_queue`` configuration
            option. Additionally, it can now be set to an integer representing
            the maximum queue size which can be attained before the state runs
            will fail to be queued. This can prevent runaway conditions where
            new threads are started until system performance is hampered.

    concurrent : False
        Execute state runs concurrently instead of serially

        .. warning::

            This flag is potentially dangerous. It is designed for use when
            multiple state runs can safely be run at the same time. Do *not*
            use this flag for performance optimization.

    saltenv
        Specify a salt fileserver environment to be used when applying states

        .. versionchanged:: 0.17.0
            Argument name changed from ``env`` to ``saltenv``.

        .. versionchanged:: 2014.7.0
            If no saltenv is specified, the minion config will be checked for an
            ``environment`` parameter and if found, it will be used. If none is
            found, ``base`` will be used. In prior releases, the minion config
            was not checked and ``base`` would always be assumed when the
            saltenv was not explicitly set.

    pillarenv
        Specify a Pillar environment to be used when applying states. This
        can also be set in the minion config file using the
        :conf_minion:`pillarenv` option. When neither the
        :conf_minion:`pillarenv` minion config option nor this CLI argument is
        used, all Pillar environments will be merged together.

    localconfig
        Optionally, instead of using the minion config, load minion opts from
        the file specified by this argument, and then merge them with the
        options from the minion config. This functionality allows for specific
        states to be run with their own custom minion configuration, including
        different pillars, file_roots, etc.

    mock
        The mock option allows for the state run to execute without actually
        calling any states. This then returns a mocked return which will show
        the requisite ordering as well as fully validate the state run.

        .. versionadded:: 2015.8.4

    sync_mods
        If specified, the desired custom module types will be synced prior to
        running the SLS files:

        .. code-block:: bash

            salt '*' state.sls stuff sync_mods=states,modules
            salt '*' state.sls stuff sync_mods=all

        .. versionadded:: 2017.7.8,2018.3.3,2019.2.0

    state_events
        The state_events option sends progress events as each function in
        a state run completes execution.

        .. versionadded:: 3006.0

    CLI Example:

    .. code-block:: bash

        # Run the states configured in salt://example.sls (or salt://example/init.sls)
        salt '*' state.apply example

        # Run the states configured in salt://core.sls (or salt://core/init.sls)
        # and salt://edit/vim.sls (or salt://edit/vim/init.sls)
        salt '*' state.sls core,edit.vim

        # Run the states configured in a more deeply nested directory such as salt://my/nested/state.sls (or salt://my/nested/state/init.sls)
        salt '*' state.sls my.nested.state

        salt '*' state.sls core exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"
        salt '*' state.sls myslsfile pillar="{foo: 'Foo!', bar: 'Bar!'}"
    r�Fr�Nz<Salt state %s is disabled. To re-enable, run state.enable %sr'rr�rr9r�r�rXz
{}.cache.pr�rT�allzsaltutil.sync_)r�z)Invalid custom module type '%s', ignoringr�rMr�r�r�r�r�r�r�r�rZZ__exclude__r�r�r�r�r�zsls.pr�Zattribz-R)Zpython_shellr�z7Unable to write to SLS cache file %s. Check permission.zDUnable to write to highstate cache file %s. Do you have permissions?)=r6r}r�r.r/r�rRr�rr*r+r0r-r=rrr�r�r�rr[r\r]r�r��split_inputrP�KeyError�warningr�r�r�r�r:rTr�rar�r�rbr�r�r�r{�stringutils�
to_unicoderor��render_highstater��extendrVr&r�r�r�r`rSr3�	TypeErrorrW)r�rr�r�Z	sync_modsr�r8r�r��disabledrr�rTr�r�Zcfn�module_typer�r�r�rj�high_rUr%Z
cache_filerrrr	�s,




�

����

�


��
�
���
���
� &����
��������r	c
Kst||�}|dur|St�dd�}tjjjtfi|��}t|fi|��|d<|�d�}|�d�}|durA|durAt|t	�sAt
d��ztjj|||t	t�t	t
�t|�d�}	Wntymtjj|||t	t�t|�d�}	Ynw|	��t||	jdd�}
|
r�tjjjtd	<d
g|
Wd�S|	��tjj�|�|	jd<i}|�d�}d
|vr�|d
|	jd<z$t||�dd��}
|	j|�dg�|�dd�|�dd�|d�}W|	��n|	��wt||	jd�t||�dd�|
�|td<|Wd�S1s�wYdS)a�
    Execute a specific top file instead of the default. This is useful to apply
    configurations from a different environment (for example, dev or prod), without
    modifying the default top file.

    queue : False
        Instead of failing immediately when another state run is in progress,
        a value of ``True`` will queue the new state run to begin running once
        the other has finished.

        This option starts a new thread for each queued state run, so use this
        option sparingly.

        .. versionchanged:: 3006.0
            This parameter can also be set via the ``state_queue`` configuration
            option. Additionally, it can now be set to an integer representing
            the maximum queue size which can be attained before the state runs
            will fail to be queued. This can prevent runaway conditions where
            new threads are started until system performance is hampered.

    saltenv
        Specify a salt fileserver environment to be used when applying states

    pillarenv
        Specify a Pillar environment to be used when applying states. This
        can also be set in the minion config file using the
        :conf_minion:`pillarenv` option. When neither the
        :conf_minion:`pillarenv` minion config option nor this CLI argument is
        used, all Pillar environments will be merged together.

        .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' state.top reverse_top.sls
        salt '*' state.top prod_top.sls exclude=sls_to_exclude
        salt '*' state.top dev_top.sls exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"
    Nrr9r�r�)r�r�r�r�)r�r�r�r�r'r�Z	state_topr�r�Zstate_top_saltenvrMr�r�r�r�r)r�r�r�r�r))r�r=r6rrrr�r�r.r�rr�r-r�r�r�r:rTr*r+r�r��url�createrVr�r�r3r�rW)Ztopfnrr�r8r�r�rTr�r�r�r�r%r�rUrrrr�sv
)

��
�
��	�



�$�rc		Ks8t||�}|dur|S|�d�}|�d�}|dur&|dur&t|t�s&td��tjjjt	fi|��}ztjj
|||tt|�d�}Wnt
yUtjj
|||t|�d�}Ynw|�:t||jdd�}|rqtjjjtd<td	|d
��|��z
|��}W|��n|��wt|�|Wd�S1s�wYdS)z�
    Retrieve the highstate data from the salt master and display it

    Custom Pillar data can be passed with the ``pillar`` kwarg.

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_highstate
    Nr9r�r��r�r�r�r�r�r'r�r�)r�r6r.r�rrrrr�r=r�r�r�r�r:rTr*r+r�r-rr�Zcompile_highstater�r3)	r�r8r�r�r�rTr�r�r%rrr�show_highstate[sR


��
�
��
$�r�c	Ks�t||�}|durJ�tjjjtfi|��}z
tjj|tt|�d�}Wnt	y6tjj|t|�d�}Ynw|�6t
||jdd�}|rRtjj
jtd<td|d	��|��z
|��}W|��n|��w|Wd�S1srwYdS)
z�
    List out the low data that will be applied to this minion

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_lowstate
    NFr�r�r9r�r'r�r�)r�rrrr�r=r�r�r�r�r:rTr*r+r�r-rr��compile_low_chunksr�)r�r8r�rTr�r�r%rrr�
show_lowstate�s,



��
$�r�c	Ks�t||�}|dur|S|�d�}|�d�}|dur&|dur&t|t�s&td��tjjt||d��"}|�	�z
|�
�}W|��n|��wt|�|Wd�S1sTwYdS)z�
    Retrieve the highstate data from the salt master to analyse used and unused states

    Custom Pillar data can be passed with the ``pillar`` kwarg.

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_state_usage
    Nr9r�r�)r�)
r�r6r.r�rrrr�r=r�Zcompile_state_usager�r3)r�r8r�r9r�r�r%rrr�show_state_usage�s"


�
$�r�c		KsZt||�}|dur|Stjjjtfi|��}z
tjj|tt|�d�}Wnt	y6tjj|t|�d�}Ynw|�jt
||jdd�}|rRtjj
jtd<td|d��|��t�}z7|��}t|t�sgt|��|D]!}t|t�s�t|�|W|��Wd�Sd	||d
<qiW|��n|��wt|���Wd�S1s�wYdS)z�
    Returns the list of states that will be applied on highstate.

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_states

    .. versionadded:: 2019.2.0

    Nr�r�r9r�r'r�r�TZ__sls__)r�rrrr�r=r�r�r�r�r:rTr*r+r�r-rr�rr�r.r/rQr�r3r��keys)	r�r8r�rTr�r�rCr�srrr�show_states�sB



��

��
$�r�c	Ksbt||�}|dur|St�dd�}tjjjtfi|��}t|fi|��|d<|ddur0d|d<|�d�}	|�d�}
|
durK|	durKt|	t	�sKt
d��|durS||d<ztjj||	|
tt
|�d	�}Wntywtjj||	|
t
|�d
�}Ynw|��t||jdd�}|r�tjjjtd<d
g|Wd�Stjj�|�}
|��z|�|d|
i�\}}W|��n|��w||j�|�7}|j�|�\}}|r�|�|�|r�tjjjtd<|Wd�S|j�|�}i}|D]}|�dd�|k�r|�|j� |i|��q�t!|t"d�|td<|�st
d�#|||d���|Wd�S1�s*wYdS)ad
    Call a single ID from the named module(s) and handle all requisites

    The state ID comes *before* the module ID(s) on the command line.

    id
        ID to call

    mods
        Comma-delimited list of modules to search for given id and its requisites

    .. versionadded:: 2014.7.0

    saltenv : base
        Specify a salt fileserver environment to be used when applying states

    pillarenv
        Specify a Pillar environment to be used when applying states. This
        can also be set in the minion config file using the
        :conf_minion:`pillarenv` option. When neither the
        :conf_minion:`pillarenv` minion config option nor this CLI argument is
        used, all Pillar environments will be merged together.

    pillar
        Custom Pillar values, passed as a dictionary of key-value pairs

        .. code-block:: bash

            salt '*' state.sls_id my_state my_module pillar='{"foo": "bar"}'

        .. note::
            Values passed this way will override existing Pillar values set via
            ``pillar_roots`` or an external Pillar source.  Pillar values that
            are not included in the kwarg will not be overwritten.

        .. versionadded:: 2018.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' state.sls_id my_state my_module

        salt '*' state.sls_id my_state my_module,a_common_module
    Nrr�rr9r�r�r�r�r�r�r'r��__id__r�r)z<No matches for ID '{}' found in SLS '{}' within saltenv '{}')$r�r=r6rrrr�r�r.r�rr�r�r�r�r:rTr*r+r�r-r�r�r�r�r��verify_highZrequisite_inr�r0�compile_high_datar�Z
call_chunkr3rr�)Zid_r�rr�r�r8r�r�rTr�r�r�r�Z
split_modsr�Z
req_in_errors�chunksr%�chunkrrrr
s�
.

��
�
���
��
��&�r
c
	Ks�d|vr	|�d�t||�}|dur|St�dd�}tjjjtfi|��}t|fi|��|d<|ddur9d|d<|�d�}|�d�}|durT|durTt	|t
�sTtd��ztjj||t
t|�d	�}	Wntyvtjj||t|�d
�}	Ynw|	�ht||	jdd�}
|
r�tjjjtd<td
|
d��tjj�|�}|	��z|	�|d|i�\}}
W|	��n|	��w|
|	j�|�7}
|
r�tjjjtd<|
Wd�S|	j�|�}|td<|Wd�S1s�wYdS)a 
    Display the low data from a specific sls. The default environment is
    ``base``, use ``saltenv`` to specify a different environment.

    saltenv
        Specify a salt fileserver environment to be used when applying states

    pillar
        Custom Pillar values, passed as a dictionary of key-value pairs

        .. code-block:: bash

            salt '*' state.show_low_sls stuff pillar='{"foo": "bar"}'

        .. note::
            Values passed this way will override Pillar values set via
            ``pillar_roots`` or an external Pillar source.

    pillarenv
        Specify a Pillar environment to be used when applying states. This
        can also be set in the minion config file using the
        :conf_minion:`pillarenv` option. When neither the
        :conf_minion:`pillarenv` minion config option nor this CLI argument is
        used, all Pillar environments will be merged together.

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_low_sls foo
        salt '*' state.show_low_sls foo saltenv=dev
    r�Nrr�rr9r�r�r�r�r�r'r�r�)r}r�r=r6rrrr�r�r.r�rr�r�r�r�r:rTr*r+r�r-rr�r�r�r�r�r�r0r�)
r�rr�r8r�r�rTr�r�r�r�r�r%rrr�show_low_sls�sd!



��
�

���$�r�c	Ks�d|vr	|�d�t||�}|dur|St�dd�}tjjjtfi|��}t|fi|��|d<|ddur9d|d<|�d�}|�d�}|durT|durTt	|t
�sTtd��ztjj|||t
t|�d	�}	Wntyxtjj|||t|�d
�}	Ynw|	�bt||	jdd�}
|
r�tjjjtd<td
|
d��tjj�|�}|	��z|	�|d|i�\}}
W|	��n|	��w|
|	j�|�7}
|td<|
r�tjjjtd<|
Wd�S|Wd�S1s�wYdS)a~
    Display the state data from a specific sls or list of sls files on the
    master. The default environment is ``base``, use ``saltenv`` to specify a
    different environment.

    This function does not support topfiles.  For ``top.sls`` please use
    ``show_top`` instead.

    Custom Pillar data can be passed with the ``pillar`` kwarg.

    saltenv
        Specify a salt fileserver environment to be used when applying states

    pillarenv
        Specify a Pillar environment to be used when applying states. This
        can also be set in the minion config file using the
        :conf_minion:`pillarenv` option. When neither the
        :conf_minion:`pillarenv` minion config option nor this CLI argument is
        used, all Pillar environments will be merged together.

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_sls core,edit.vim saltenv=dev
    r�Nrr�rr9r�r�r�r�r�r'r�r�)r}r�r=r6rrrr�r�r.r�rr�r�r�r�r:rTr*r+r�r-rr�r�r�r�r�r�r0)r�rr�r8r�r�rTr�r�r�r�r�rrr�show_sls�sj



��
�
���$�r�cKstt|f||d�|��t�S)aT
    Tests for the existence the of a specific SLS or list of SLS files on the
    master. Similar to :py:func:`state.show_sls <salt.modules.state.show_sls>`,
    rather than returning state details, returns True or False. The default
    environment is ``base``, use ``saltenv`` to specify a different environment.

    .. versionadded:: 2019.2.0

    saltenv
        Specify a salt fileserver environment from which to look for the SLS files
        specified in the ``mods`` argument

    CLI Example:

    .. code-block:: bash

        salt '*' state.sls_exists core,edit.vim saltenv=dev
    �rr�)r.r�r�)r�rr�r8rrr�
sls_existsOsr�cKs@tjj�|�}t|�}dd�t|f||d�|��D�}|�|�S)aR
    Tests for the existence of a specific ID or list of IDs within the
    specified SLS file(s). Similar to :py:func:`state.sls_exists
    <salt.modules.state.sls_exists>`, returns True or False. The default
    environment is base``, use ``saltenv`` to specify a different environment.

    .. versionadded:: 2019.2.0

    saltenv
        Specify a salt fileserver environment from which to look for the SLS files
        specified in the ``mods`` argument

    CLI Example:

    .. code-block:: bash

        salt '*' state.id_exists create_myfile,update_template filestate saltenv=dev
    cSsh|]}|d�qS)r�r)r �xrrr�	<setcomp>zs�zid_exists.<locals>.<setcomp>r�)rrr�r��setr��issubset)Zidsr�rr�r8Zsls_idsrrr�	id_existses�
rcKs$d|vr	|�d�t||�}|dur|Stjjjtfi|��}z
tjj|tt	|�d�}Wnt
y?tjj|t	|�d�}Ynw|�Ft||jdd�}|r[tj
jjtd<td|d	��g}|��}||�|�7}|rztj
jjtd<|Wd�S|�|�}|Wd�S1s�wYdS)
z�
    Return the top data that the minion will use for a highstate

    CLI Example:

    .. code-block:: bash

        salt '*' state.show_top
    r�Nr�r�r9r�r'r�r�)r}r�rrrr�r=r�r�r�r�r:rTr*r+r�r-rZget_topZverify_topsr0Ztop_matches)r�r8r�rTr�r�Ztop_�matchesrrr�show_top�s8




���
$�rc	Ks�t||�}|dur|S|�d�}t|�dkrtjjjtd<dS|�|d|d||d��t	�
d	d�}tjjj
t	fi|��}t|fi|��|d	<|�
d
�}	|�
d�}
|
durc|	durct|	t�sctd��ztjj||	|
tt|�d
�}Wnty�tjj||	|
t|�d�}Ynw|�|�}|r�tjjjtd<|S|�|�t||�
dd��}
d�|�|�|�i}t|�t||�
dd�|
�|t	d	<|S)a�
    Execute a single state function with the named kwargs, returns False if
    insufficient data is sent to the command

    By default, the values of the kwargs will be parsed as YAML. So, you can
    specify lists values, or lists of single entry key-value maps, as you
    would in a YAML salt file. Alternatively, JSON format of keyword values
    is also supported.

    CLI Example:

    .. code-block:: bash

        salt '*' state.single pkg.installed name=vim

    N�.�r'zInvalid function passedrr;)rr�r�r�rr9r�r�r�r�rMr�z/{0[state]}_|-{0[__id__]}_|-{0[name]}_|-{0[fun]})r��splitr?rr*r+r0r-r�r=r6rrr�r�r.r�rr�r�r�r�r�Z	_mod_initrVr�r�r3rW)r�r�rr�r8r��compsr�rTr�r�r�r�rUr%rrrr
�sd



��
�
��

��r
cCsZg}t�td�D]!}|�d�r*tj�td|�}tj�|�s q	t�|�|�|�q	|S)aK
    Clear out cached state files, forcing even cache runs to refresh the cache
    on the next state execution.

    Remember that the state cache is completely disabled by default, this
    execution only applies if cache=True is used in states

    CLI Example:

    .. code-block:: bash

        salt '*' state.clear_cache
    rXz.cache.p)	r[rnr=r�r\r]r�rpr�)r%�fn_r\rrr�clear_cache�s


�r	cKs�tjjjtfi|��}tj�|�siStjj�	||�|ksiSt
��}t�
|d�}|��}|D]*}	tjj�|	j��tjdtj��f�rGiSdtj��tjj�|	j�vrYiSq/|�|�|��tj�|d�}
tjj�|
d��}tjj�|�}Wd�n1s�wY|D]}
t|
t�s�|Sq�tj�|d�}tj�|�r�tjj�|d��}tjj�|�}Wd�n1s�wYnd}tj�|d�}tj�|�r�tjj�|d��}ttjj�|��}Wd�n1s�wYtj�|�r�||d<d	|d
<i|d<t|fi|��|d<t�|�}|D]}tj�||�}tj�|��s)�q|g|d|<�qtjj ||d
�}t!||�"dd��}|�#|�}|�$||�}zt%�&|�Wn
t'�y_Ynwt(|�t)||�"dd�|�|S)a'
    Execute a packaged state run, the packaged state run will exist in a
    tarball available locally. This packaged state
    can be generated using salt-ssh.

    CLI Example:

    .. code-block:: bash

        salt '*' state.pkg /tmp/salt_state.tgz 760a9353810e36f6d81416366fc426dc md5
    zr:gzz..z
lowstate.json�rNzpillar.jsonzroster_grains.jsonZgrainsr�Z
fileclientZ
file_rootsr)r�rMr�)*rrrr�r=r[r\r�Z	hashutilsZget_hash�tempfileZmkdtemp�tarfile�open�
getmembersr�r��
startswith�sep�
extractall�closer]rarb�jsonr�r.r�rr�rn�isdirr�rVr6Zcall_chunksZcall_listen�shutil�rmtreer`r3rW)Zpkg_pathZpkg_sumZ	hash_typerr8ZpoptsrHZs_pkg�members�memberZ
lowstate_jsonrjZlowstater�Zpillar_jsonr�Zroster_grains_jsonZ
roster_grainsZenvsr�fullr�rUr%rrrr	sz
��
�
����

�rcCs�ddd�}tjj�|�}g}tdd�}t|t�sg}d}|D] }||vr/|�d|�d��q|�d|�d	��|�|�d}q|rItd
d|�d�|�|d<td
�|S)ak
    Disable state runs.

    CLI Example:

    .. code-block:: bash

        salt '*' state.disable highstate

        salt '*' state.disable highstate,test.succeed_without_changes

    .. note::
        To disable a state file from running provide the same name that would
        be passed in a state.sls call.

        salt '*' state.disable bind.config

    Tr���res�msg�
grains.get�state_runs_disabledF�Info: z state already disabled.z state disabled.�
grains.setval�
r�saltutil.refresh_modules)	rrr�r�rPr.r/r�r]�rCr%r�_disabled_state_runsZ_changed�_staterrr�disableY	s$



r&cCs�ddd�}tjj�|�}t�d|�g}tdd�}t|t�s!g}d}|D]&}t�d|�||vr;|�	d	|�d
��q%|�	d	|�d��|�
|�d}q%|rUtdd|�d
�|�|d<td�|S)ak
    Enable state function or sls run

    CLI Example:

    .. code-block:: bash

        salt '*' state.enable highstate

        salt '*' state.enable test.succeed_without_changes

    .. note::
        To enable a state file from running provide the same name that would
        be passed in a state.sls call.

        salt '*' state.disable bind.config

    Tr�rz	states %srrFz	_state %srz state already enabled.z state enabled.r r!rr")rrr�r�rRr�rPr.r/r�rpr]r#rrr�enable�	s(



r'cCstdd�S)z�
    List the states which are currently disabled

    CLI Example:

    .. code-block:: bash

        salt '*' state.list_disabled
    rr)rPrrrr�
list_disabled�	s
r(cCs�g}tdd�}t|t�sg}|D]>}|D]9}d|vr?|�d�d}|�d�s+|dn|}|�|�r>d�||�}|�|�qq||krNd�|�}|�|�qqq|S)zU
    Return messages for disabled states
    that match state functions in funs.
    rrz.*rrzXThe state file "{0}" is currently disabled by "{1}", to re-enable, run state.enable {1}.zOThe state file "{0}" is currently disabled, to re-enable, run state.enable {0}.)rPr.r/rr�rr�r�)Zfunsr%r$rr%Ztarget_stater�rrrr��	sB

��
��
���
��r�����minioncCstjjj||p
tdtdd��j}	|jddd�}|durqtjj�|d|�rg|sStjj�d�tjj�	|d�tjj
jtjj�
|d�||sHdnd	d
���tj��|dkra|d8}t�d
|�|dkrfnn	t�d|d�qqWd�dS1s|wYdS)a*
    Watch Salt's event bus and block until the given tag is matched

    .. versionadded:: 2016.3.0
    .. versionchanged:: 2019.2.0
        ``tagmatch`` can now be either a glob or regular expression.

    This is useful for utilizing Salt's event bus from shell scripts or for
    taking simple actions directly from the CLI.

    Enable debug logging to see ignored events.

    :param tagmatch: the event is written to stdout for each tag that matches
        this glob or regular expression.
    :param count: this number is decremented for each event that matches the
        ``tagmatch`` parameter; pass ``-1`` to listen forever.
    :param quiet: do not print to stdout; just block
    :param sock_dir: path to the Salt master's event socket file.
    :param pretty: Output the JSON all on a single line if ``False`` (useful
        for shell tools); pretty-print the JSON output if ``True``.
    :param node: Watch the minion-side or master-side event bus.

    CLI Example:

    .. code-block:: bash

        salt-call --local state.event pretty=True
    �sock_dirT)rT�listen)rZauto_reconnectNr!z{}	{}ri�)�	sort_keys�indentrr;zRemaining event matches: %szSkipping event tag: %s)rr�eventZ	get_eventr=r�Z
expr_matchZ	print_clir�Zto_strrrwri�decode�sys�stdout�flushrRr�)Ztagmatch�count�quietr+Zpretty�nodeZseventr%rrrr0�	sF
�
���

��"�r0)N)r)NN)rNNNN)F)r�)NNN)NNNNN)rr)FNFr*)\�__doc__�loggingr[rr2rrr@Zsalt.configrZsalt.defaults.exitcodesZsalt.payloadZ
salt.stateZsalt.utils.argsZsalt.utils.dataZsalt.utils.eventZsalt.utils.filesZsalt.utils.functoolsZsalt.utils.hashutilsZsalt.utils.jidZsalt.utils.jsonZsalt.utils.msgpackZsalt.utils.platformZsalt.utils.stateZsalt.utils.stringutilsZsalt.utils.urlZsalt.utils.versionsZsalt.exceptionsrrZsalt.loaderrZsalt.runners.staterrZsalt.utils.odictrZ__proxyenabled__Z
__outputter__Z__func_alias__�	getLogger�__name__rRrrr&r3r:rDrVrWrkrrryr|r~r�r>r�r�r�r�r�rrrrrrr�rrr	rr�r�r�r�r
r�r�r�rrr
r	rr&r'r(r�r0rrrr�<module>s��






$
"
##
�

	
 

5
5
R

+

)
`
�
6
l
;
%
"
2

`
^


*L
J02
*�