HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/state.cpython-310.pyc
o

;j�=�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
mZe�e
�Ze�Zed�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd$dd�Zd%d d!�Z d"d#�Z!dS)&zC
Utility functions for state functions

.. versionadded:: 2018.3.0
�N)�CommandExecutionErrorzAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-cCsR|durdSt|ttf�rd�dd�|D��}t|�}|sdSd�dd�|D��S)uU
    Return a filesystem-safe identifier for a master.

    In multimaster, each Minion has its own opts["master"] string. The string
    may contain characters (``:`` for host:port, ``/`` for IPv6 zone ids, etc.)
    that are not valid in path components on every OS we support — Windows
    in particular rejects ``:`` in filenames.
    N�_default�,css�|]}t|�VqdS�N)�str)�.0�m�r	�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/state.py�	<genexpr>'s�z&_sanitize_master_id.<locals>.<genexpr>�css �|]}|tvr
|ndVqdS)�_N)�_SAFE_MASTER_CHARS)r�cr	r	r
r+s�)�
isinstance�list�tuple�joinr)�masterr	r	r
�_sanitize_master_ids	rcCstj�|ddt|�d���S)z5
    Return the per-master queue base directory.
    �cachedirZqueuesr)�os�pathrr�get��optsr	r	r
�queue_base_dir.s�rcC�tj�t|�d�S)z5
    Return the per-master queue lock file path.
    z
queue.lock�rrrrrr	r	r
�queue_lock_path7�rcCr)z4
    Return the per-master job queue directory.
    Z	job_queuerrr	r	r
�
job_queue_dir>r r!cCr)z6
    Return the per-master state queue directory.
    Zstate_queuerrr	r	r
�state_queue_dirEr r"cCsJt|�}z
tjtj�|�dd�Wn	tyYnwtjjj	||dd�S)z&
    Acquire the state queue lock
    T��exist_oki�Q)�lock_fn�timeout)
rr�makedirsr�dirname�OSError�salt�utils�filesZ	wait_lock�rZ	lock_pathr	r	r
�acquire_queue_lockLs�r.cCsLt|�}z
tjtj�|�dd�Wn	tyYnwtjjj	||ddd�S)z3
    Acquire the job queue lock asynchronously
    Tr#g@g�������?)r%r&�sleep)
rrr'rr(r)r*r+r,Z
await_lockr-r	r	r
�acquire_async_queue_lock[s��r0cCs�g}tj�|dd�}tj�|�s|Szt�|�}Wn'tyA}z|jtjtjtj	fvr.�t
�d||�|WYd}~Sd}~ww|D]�}tj�||�}zZtj
j�|d��}|��}Wd�n1sewY|snWqDztj�|�}	Wn
ty�YWqDwt|	t�s�WqD|	�d�}
|
s�WqDtj
j�|
�r�|	�dd��d	�r�|�|	�WqDttfy�}zt|t�r�|jtjtjfvr��WYd}~qDd}~ww|S)
z�
    Return a list of active state jobs from the proc directory.
    Unlike saltutil.is_running, this does NOT filter out the current process.
    r�procz$Unable to list proc directory %s: %sN�rb�pid�funrzstate.)rrr�isdir�listdirr)�errnoZEMFILEZENFILEZENOMEM�log�errorr*r+r,Zfopen�read�payload�loads�	NameErrorr�dictr�processZ
os_is_running�
startswith�append�
ValueError)r�retZproc_dirZ
proc_files�excZfn_rZfp_�buf�datar3r	r	r
�get_active_statesjsT��
��


���rGcCsng}t|�}t|�t|�fD]f}tj�|�sqzDt�|�D]<}|�d�s)|�d�rY|�d�rY|dd��	d�}t
|�dkrY|d}t
|�dkrPd�|dd��}|�|d	d
d��qWqt
yt}z
t�d||�WYd}~qd}~ww|rx	|D]:}	|	�d
�}
|
dur�qz|dur�|�|	�qzzt|
�t|�kr�Wqzt|
�t|�kr�|�|	�Wqzttfy�Yqzw|S)z�
    Check for prior running states that would block the execution of the current job.
    Returns a list of blocking jobs.
    Zqueued_Zrunning_z.pN���r
��zstate.applyr)�jidr4r3z%Unable to list queue directory %s: %srK)rr"r!rr�existsr6r@�endswith�split�lenrrAr)r8r9rrrB�	TypeError)rrKZactive_jobsrCZ	queue_dir�fn�partsZjob_jidrDrFZdata_jidr	r	r
�check_prior_running_states�s\���
�����


��rScCs
d�|�S)zJ
    Generate the running dict tag string from the low data structure
    z/{0[state]}_|-{0[__id__]}_|-{0[name]}_|-{0[fun]})�format)�lowr	r	r
�gen_tag�s
rVcCs.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)r*rZ�
split_low_tag�itemsrrr@rr>rrA)Zsid�	highstate�onfails�st�fstateZfchunks�mod_�fchunkZonfail_handledZfdataZknobZfvalueZfreqs�fmodZfidr	r	r
�search_onfail_requisites�sP

�
�����!rdcCs�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

    NrWrXzno state id)rXrZrZ�result)FTF)
rr>rdr\r*rZr[rrB�_empty)�state_id�state_result�runningr]Znretr^�handlerr`rarbZrstateidZrstater_Zid_Zofresultr	r	r
�check_onfail_requisites!s0


��rkFcCs�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__re)�recurser])	rr>r\rrrf�check_result�boolrk)rirlr]rCrgrhZ
expected_typerer	r	r
rmLs4
��rmcCs�|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
    �namereFZcomment�
Zchanges)rr�
setdefault�extendr)Zoriginal_returnZ
sub_returnZsubkeyZsub_commentr	r	r
�merge_subreturnrs"
rscKs�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)r�kwargsrurvr	r	r
�get_sls_opts�s(

��rz)FNr)"�__doc__rwr7�loggingrZsalt.payloadr*Z
salt.stateZsalt.utils.filesZsalt.utils.processZsalt.exceptionsr�	getLogger�__name__r8�objectrf�	frozensetrrrrr!r"r.r0rGrSrVrdrkrmrsrzr	r	r	r
�<module>s<
�	7H1
+
&7