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/cli/__pycache__/batch.cpython-310.pyc
o

�N�g=5�@spdZddlZddlZddlZddlZddlmZmZddlZddl	Zddl
ZddlZe�e
�ZGdd�d�ZdS)z
Execute batch runs
�N)�datetime�	timedeltac@s:eZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�Batchz-
    Manage the execution of batch runs

    NFcCsH||_|r|ni|_|r|ni|_||_||_tjj|ddd�|_dS)a
        :param dict opts: A config options dictionary.

        :param dict eauth: An eauth config to use.

                           The default is an empty dict.

        :param bool quiet: Suppress printing to stdout

                           The default is False.
        Z	conf_fileT)�listenN)	�opts�eauth�
pub_kwargs�quiet�options�salt�clientZget_local_client�local)�selfrrr	Z_parser�r�B/opt/saltstack/salt/lib/python3.10/site-packages/salt/cli/batch.py�__init__szBatch.__init__c		Cs<|jddg|jdg}|j�dd�}|dur|�|�n
|�|j�dd��d|jd	<|jj|d
|jd
i|j��}t�}t�}|D]P}d|vrV|dD]}|�|�qMqCz
tt	|�
���}Wntyt|jsqt
jj�d
�Yn w|dur�d||vr�||ddur�t�d|�qC|�|�qCt|�||�|�fS)zC
        Return a list of minions to use for the batch run
        Ztgtz	test.ping�timeout�selected_target_optionNZtgt_type�globTZyield_pub_data�gather_job_timeout�minionsZjidzNo minions matched the target.�failedz@minion '%s' failed test.ping - will be returned as a down minion)r�get�appendrr
Zcmd_iter�set�add�next�iter�keys�
StopIterationr	r�utils�stringutils�	print_cli�log�debug�list�
difference)	r�argsr�ping_genZfretZnret�ret�minion�mrrr�gather_minions.sT�
������
�zBatch.gather_minionsc	s��fdd�}z4t�jdt�r3d�jdvr3|t�jd�d���}|dkr.tt�|��WSt|�WSt�jd�WStyW�j	sTt
jj�
d��jd��YdSYdSw)zA
        Return the active number of minions to maintain
        cst|�dt�j�S)NgY@)�float�lenr)�x�rrr�	partitionesz!Batch.get_bnum.<locals>.partitionZbatch�%�zEInvalid batch data sent: {}
Data must be in the form of %10, 10% or 3N)�
isinstancer�strr-�strip�int�math�ceil�
ValueErrorr	rr r!r"�format)rr1�resrr0r�get_bnum`s 

���zBatch.get_bnumcCsZt��}d}|t|�kr"|||kr"|d7}|t|�kr"|||ks|r+|d|�=dSdS)Nrr3)r�nowr.)r�waitr>�irrrZ
__update_waitxs��zBatch.__update_waitc	cs:�|��\|_|_|_g|jd|jd|jddg}|��}|js$dSt�|j�}g}i}g}|j�dd�}g}|j	rE|j	j
}	|j	j}
nd}	d}
i}|js^|jD]}t
jj�d	�|��qQt|�t|j�k�rg}
|rs|rs|�|�t|�|t|�kr�|s�|r�|
�|���|s�n)t|t|�t|��D]}|r�|��}t|t�r�|
�tt|���q�|
�|�q�||
7}|
|d<|
�r	|js�t
jj�d
t|
��d��|j�d|j�d
d��}|jj||j�dd�||	|
|jdd�|j��}|�|�i||<|
||d<d||d<nt� d�i}|jD]#}|du�rntt|�!���}||jv�r5|j�|�|�|��q|D]�}z�d}	t|�}|du�rYt� d�|d7}|dk�rWng�q>|j�d��r�|�"|dd|i�|dd||dv�r�||d�#|dd�n6t
jj�d�|d��n)|�"|�|D]!}|||dv�r�||d�#|��q�t
jj�d�|���q��q?W�q9t$�y�||v�r�d||d<||dD]}||v�r�i||<i||d
<�q�Y�q9w|�%�D]�\}}||v�r|�#|�|�r|�t&�'�t(|d��d}|�dd�}|�r@t)�*d||�|j�s2t
jj�d|�d ��|j�d!��r;d}|||<n�d}d"|v�r~t|d"t��rjzt+|d"�,��|d"<Wnt-�yid|d"<Ynw|j�d!��rz|d"dk�rzd}|d"}|j�d��r�|||<||fVn|d
||<||d
i|fV|j�s�|d
||<|�d
�||<d#|v�r�|�d#�}nd}t
j.�/|||j�|�r�t)�0d$|�dS�q�|D]7}||d�s||v�r|�#|�||dD]}||v�r	|�#|�|�r	|�t&�'�t(|d���q�q�t|�t|j�ksh|j�1�dS)%z'
        Execute the batch run
        Zfun�argrr%NZ
batch_waitrFz/Minion {} did not respond. No job will be sent.z
Executing run on �
�returnr)��rawr)rEr)�show_jid�verboserrT�activeg{�G�z�?g{�G�z�?r3��data�idzDminion {} was already deleted from tracker, probably a duplicate key)�secondsrz4Minion '%s' failed to respond to job sent, data '%s'zMinion 'z' failed to respond to job sent�failhard�retcode�outzMMinion %s returned with non-zero exit code. Batch run stopped due to failhard)2r,rr(Zdown_minionsrr=�copy�deepcopyrr
rFrGr	rr r!r"r;r.�_Batch__update_waitr�pop�ranger4�dictrr�sortedr
Zcmd_iter_no_blockr�time�sleepr�update�remover�itemsrr>rr#r$�max�valuesr:�outputZdisplay_output�errorZdestroy)rr'ZbnumZto_runrHr)ZitersZbwaitr?rFZshow_verboseZminion_trackerZdown_minionZnext_r@Z	minion_idZreturn_valueZnew_iter�partsZping_retr+�queueZncnt�partrKr*rJrMZfailed_checkrNrOrrr�run�sj��

��
��

����





�



�
�
��


��

�
�

�
��	


���3z	Batch.run)NFN)	�__name__�
__module__�__qualname__�__doc__rr,r=rRrcrrrrrs
2r)rgrP�loggingr8rWrrZsalt.clientrZsalt.exceptionsZsalt.outputZsalt.utils.stringutils�	getLoggerrdr#rrrrr�<module>s