HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/loop.cpython-310.pyc
o

�N�g��@s^dZddlZddlZddlZddlZe�e�ZdZdd�Z	d
dd	�Z
	
					ddd�ZdS)a|
Loop state

Allows for looping over execution modules.

.. versionadded:: 2017.7.0

In both examples below, the execution module function ``boto_elb.get_instance_health``
returns a list of dicts. The condition checks the ``state``-key of the first dict
in the returned list and compares its value to the string `InService`.

.. code-block:: yaml

    wait_for_service_to_be_healthy:
      loop.until:
        - name: boto_elb.get_instance_health
        - condition: m_ret[0]['state'] == 'InService'
        - period: 5
        - timeout: 20
        - m_args:
          - {{ elb }}
        - m_kwargs:
            keyid: {{ access_key }}
            key: {{ secret_key }}
            instances: "{{ instance }}"

.. warning::

    This state allows arbitrary python code to be executed through the condition
    parameter which is literally evaluated within the state. Please use caution.

.. versionchanged:: 3000

A version that does not use eval is now available. It uses either the python ``operator``
to compare the result of the function called in ``name``, which can be one of the
following: lt, le, eq (default), ne, ge, gt.
Alternatively, `compare_operator` can be filled with a function from an execution
module in ``__salt__`` or ``__utils__`` like the example below.
The function :py:func:`data.subdict_match <salt.utils.data.subdict_match>` checks if the
``expected`` expression matches the data returned by calling the ``name`` function
(with passed ``args`` and ``kwargs``).

.. code-block:: yaml

    Wait for service to be healthy:
      loop.until_no_eval:
        - name: boto_elb.get_instance_health
        - expected: '0:state:InService'
        - compare_operator: data.subdict_match
        - period: 5
        - timeout: 20
        - args:
          - {{ elb }}
        - kwargs:
            keyid: {{ access_key }}
            key: {{ secret_key }}
            instances: "{{ instance }}"
�NZloopcCsdS)NT�rrr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/loop.py�__virtual__Hsr��<cCs<|iddd�}|dur
d}|duri}|tvr d|��|d<|S|dur*d|d<|St|ttf�s7d	|d<|St|ttf�sDd
|d<|StdrVd|�d
�|d<d|d<|S|dur\g}|durbi}t��|}t��|kr�t||i|��}t|�r�d|d<d|�d�|d<	|St�|�t��|ksnd�|�|d<|S)aS
    Loop over an execution module until a condition is met.

    :param str name: The name of the execution module
    :param list m_args: The execution module's positional arguments
    :param dict m_kwargs: The execution module's keyword arguments
    :param str condition: The condition which must be met for the loop to break.
        This should contain ``m_ret`` which is the return from the execution module.
    :param period: The number of seconds to wait between executions
    :type period: int or float
    :param timeout: The timeout in seconds
    :type timeout: int or float
    F�)�name�changes�result�commentNrzCannot find module rz#An exit condition must be specified�.Period must be specified as a float in seconds�/Timeout must be specified as a float in seconds�testzThe execution module z will be runr
Tz
Condition z was metz(Timed out while waiting for condition {})	�__salt__�
isinstance�int�float�__opts__�time�eval�sleep�format)rZm_argsZm_kwargsZ	condition�period�timeout�retZm_retrrr�untilLsN�����
���r�eqcCs�|didd�}|tvrd|�d�|d<n=t|ttf�s d|d<n1t|ttf�s,d|d<n%|tvr5t|}	n|tvr>t|}	ntt|�sLd	|�d
�|d<ntt|�}	tdrad|d
<d�	||�|d<|drg|S|rnt
�|�|durtg}|durzi}g}
d}t
�
�|}t
�
�|kr�|d7}zt||i|��}Wnty�t
��\}
}}d�	||
|�|d<Y|Sw|
�|�|	||�}t�dt||||�|r�d|d
<d�	|�|d<	|St
�|�t
�
�|ks�d�	|�|d<t�dt|
�|S)aH
    Generic waiter state that waits for a specific salt function to produce an
    expected result.
    The state fails if the function does not exist or raises an exception,
    or does not produce the expected result within the allotted retries.

    :param str name: Name of the module.function to call
    :param expected: Expected return value. This can be almost anything.
    :param str compare_operator: Operator to use to compare the result of the
        module.function call with the expected value. This can be anything present
        in __salt__ or __utils__. Will be called with 2 args: result, expected.
    :param timeout: Abort after this amount of seconds (excluding init_wait).
    :type timeout: int or float
    :param period: Time (in seconds) to wait between attempts.
    :type period: int or float
    :param init_wait: Time (in seconds) to wait before trying anything.
    :type init_wait: int or float
    :param list args: args to pass to the salt module.function.
    :param dict kwargs: kwargs to pass to the salt module.function.

    .. versionadded:: 3000

    rF)rrr	r
zModule.function "z" is unavailable.rrr
zInvalid operator "z" supplied.rNr
z+Would have waited for "{}" to produce "{}".rrz,Exception occurred while executing {}: {}:{}zL%s:until_no_eval:
		Attempt %s, result: %s, expected: %s, compare result: %sTz1Call provided the expected results in {} attemptsz:Call did not produce the expected result after {} attemptsz/%s:until_no_eval:
		Results of all attempts: %s)rrrrZ	__utils__�hasattr�operator�getattrrrrr�	Exception�sys�exc_info�append�log�debug�__name__)r�expectedZcompare_operatorrrZ	init_wait�args�kwargsrZ
comparatorZres_archiveZcurrent_attempt�res�exc_type�	exc_value�_Zcmp_resrrr�
until_no_eval�s�!





�
��

�	�
�����r.)NNNrr)rrrrNN)�__doc__�loggingrr!r�	getLoggerr&r$Z__virtualname__rrr.rrrr�<module>s ;

8�