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/utils/__pycache__/state.cpython-310.pyc
o

�N�g�!�@s^dZddlZddlZddlmZe�Zdd�Zdd�Z	dd	�Z
ddd�Zdd
d�Zdd�Z
dS)zC
Utility functions for state functions

.. versionadded:: 2018.3.0
�N)�CommandExecutionErrorcCs
d�|�S)zJ
    Generate the running dict tag string from the low data structure
    z/{0[state]}_|-{0[__id__]}_|-{0[name]}_|-{0[fun]})�format)�low�r�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/state.py�gen_tags
rcCs.g}d|vr
tj�|�}nd|i}|��D]\}}||dkr q|��D]o\}}t|t�r2|�d�r3q$t|t�s9q$d}|D]}	t|	t�sEq=|	�	dd�du}|rQnq=|sUq$|D];}	t|	t�s_qW|	��D].\}
}|
dkrlqc|D]"}|��D]\}
}||dkr�|
|�	d|
�ks�qt|�
|||f�qtqnqcqWq$q|S)	zK
    For a particular low chunk, search relevant onfail related states
    �_|-�__id__�__FZonfail_stopTZonfail�state)�saltr�
split_low_tag�items�
isinstance�str�
startswith�list�dict�get�append)Zsid�	highstate�onfails�st�fstateZfchunks�mod_�fchunkZonfail_handledZfdataZknobZfvalueZfreqs�fmodZfidrrr�search_onfail_requisitessP

�
�����!rcCs�d}|rg|rg|rgt|t�rgt||�}|rg|D]P}|\}}}	|��D]>\}
}d|
vr0tj�|
�}n|�d|
�}
|
s<td��|
|d�}||dkr_||dkr_|�dt	�}|dvrY|}|d	ur_nq!|durfd	}q|S)
a�
    When a state fail and is part of a highstate, check
    if there is onfail requisites.
    When we find onfail requisites, we will consider the state failed
    only if at least one of those onfail requisites also failed

    Returns:

        True: if onfail handlers succeeded
        False: if one on those handler failed
        None: if the state does not have onfail requisites

    Nrr	zno state id)r	rr�result)FTF)
rrrrrrr
r�
ValueError�_empty)�state_id�state_result�runningrZnretr�handlerrrrZrstateidZrstaterZid_Zofresultrrr�check_onfail_requisitesGs0


��r%FcCs�t|t�sdS|sdSd}|��D]K\}}t}d|krt}|s&t||�s&d}|rLt|t�rL|�dt�}|dur:d}n|turLt|t�rL|rLt|d|d�}|sWtt||||��}|s\|Sq|S)zf
    Check the total return value of the run and determine if the running
    dict has any issues
    FTZ
__extend__r)�recurser)	rrrrrr �check_result�boolr%)r#r&r�retr!r"Z
expected_typerrrrr'rs4
��r'cCs�|s|d}|ddur|d|d<|d}t|t�s|g}|�dg�t|dt�r3|d�|�n|dr?|dd7<|dd�|�7<|dr\|�di�|d|d|<|S)a
    Update an existing state return (`original_return`) in place
    with another state return (`sub_return`), i.e. for a subresource.

    Returns:
        dict: The updated state return.

    The existing state return does not need to have all the required fields,
    as this is meant to be called from the internals of a state function,
    but any existing data will be kept and respected.

    It is important after using this function to check the return value
    to see if it is False, in which case the main state should return.
    Prefer to check `_ret['result']` instead of `ret['result']`,
    as the latter field may not yet be populated.

    Code Example:

    .. code-block:: python

        def state_func(name, config, alarm=None):
            ret = {'name': name, 'comment': '', 'changes': {}}
            if alarm:
                _ret = __states__['subresource.managed'](alarm)
                __utils__['state.merge_subreturn'](ret, _ret)
                if _ret['result'] is False:
                    return ret
    �namerFZcomment�
Zchanges)rr�
setdefault�extend�join)Zoriginal_returnZ
sub_returnZsubkeyZsub_commentrrr�merge_subreturn�s"
r/cKs�t�|�}d|vrtjj|d|d�Sd|vr<|d}|dur<t|t�s(t|�}|dr6||dkr6td��|d|d<d|vsF|�dd	�re|�d�pO|�d�}|durat|t�sat|�|d<|S||d<|S)
zR
    Return a copy of the opts for use, optionally load a local config on top
    Zlocalconfig)�defaults�saltenvNZlock_saltenvz2lock_saltenv is enabled, saltenv cannot be changed�	pillarenvZpillarenv_from_saltenvF)	�copy�deepcopyrZconfigZ
minion_configrrrr)�opts�kwargsr1r2rrr�get_sls_opts�s(

��r7)FN)N)�__doc__r3Z
salt.staterZsalt.exceptionsr�objectr rrr%r'r/r7rrrr�<module>s1
+
&7