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/output/__pycache__/highstate.cpython-310.pyc
o

�N�gsz�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
Ze�e�Z
dd�Zdd�Zddd	�Zd
d�Zdd
d�Zdd�ZdS)a�
Outputter for displaying results of state runs
==============================================

The return data from the Highstate command is a standard data structure
which is parsed by the highstate outputter to deliver a clean and readable
set of information about the HighState run on minions.

Two configurations can be set to modify the highstate outputter. These values
can be set in the master config to change the output of the ``salt`` command or
set in the minion config to change the output of the ``salt-call`` command.

state_verbose:
    By default `state_verbose` is set to `True`, setting this to `False` will
    instruct the highstate outputter to omit displaying anything in green, this
    means that nothing with a result of True and no changes will not be printed

state_output:
    The highstate outputter has six output modes,
    ``full``, ``terse``, ``mixed``, ``changes`` and ``filter``

    * The default is set to ``full``, which will display many lines of detailed
      information for each executed chunk.

    * If ``terse`` is used, then the output is greatly simplified and shown in
      only one line.

    * If ``mixed`` is used, then terse output will be used unless a state
      failed, in which case full output will be used.

    * If ``changes`` is used, then terse output will be used if there was no
      error and no changes, otherwise full output will be used.

    * If ``filter`` is used, then either or both of two different filters can be
      used: ``exclude`` or ``terse``.

        * for ``exclude``, state.highstate expects a list of states to be excluded (or ``None``)
          followed by ``True`` for terse output or ``False`` for regular output.
          Because of parsing nuances, if only one of these is used, it must still
          contain a comma. For instance: `exclude=True,`.

        * for ``terse``, state.highstate expects simply ``True`` or ``False``.

      These can be set as such from the command line, or in the Salt config as
      `state_output_exclude` or `state_output_terse`, respectively.

    The output modes have one modifier:

    ``full_id``, ``terse_id``, ``mixed_id``, ``changes_id`` and ``filter_id``
    If ``_id`` is used, then the corresponding form will be used, but the value for ``name``
    will be drawn from the state ID. This is useful for cases where the name
    value might be very long and hard to read.

state_tabular:
    If `state_output` uses the terse output, set this to `True` for an aligned
    output format.  If you wish to use a custom format, this can be set to a
    string.

state_output_pct:
    Set `state_output_pct` to `True` in order to add "Success %" and "Failure %"
    to the "Summary" section at the end of the highstate output.

state_compress_ids:
    Set `state_compress_ids` to `True` to aggregate information about states
    which have multiple "names" under the same state ID in the highstate output.
    This is useful in combination with the `terse_id` value set in the
    `state_output` option when states are using the `names` state parameter.

Example usage:

If ``state_output: filter`` is set in the configuration file:

.. code-block:: bash

    salt '*' state.highstate exclude=None,True


means to exclude no states from the highstate and turn on terse output.

.. code-block:: bash

    salt twd state.highstate exclude=problemstate1,problemstate2,False


means to exclude states ``problemstate1`` and ``problemstate2``
from the highstate, and use regular output.

Example output for the above highstate call when ``top.sls`` defines only
one other state to apply to minion ``twd``:

.. code-block:: text

    twd:

    Summary for twd
    ------------
    Succeeded: 1 (changed=1)
    Failed:    0
    ------------
    Total states run:     1


Example output with no special settings in configuration files:

.. code-block:: text

    myminion:
    ----------
              ID: test.ping
        Function: module.run
          Result: True
         Comment: Module function test.ping executed
         Changes:
                  ----------
                  ret:
                      True

    Summary for myminion
    ------------
    Succeeded: 1
    Failed:    0
    ------------
    Total:     0
�Nc	Csnt|t�s|Si}�z|��D�]\}}i||<t�dd�|��D��}|��D]�\}}|�d�}d�tt|d|d|d|dg��}||d	krR||||<q(d�ttd
|d|d|dg��|d<d�	|d||�|d	<d�|�}|||vr�||||<q(t
|d
|||d
�|||d
<tt|d|||dg�d�|||d<t
|d|||dg�d|||d<|||�d��r|�d��r|||d�d�s�d|||d|||dii|||d<|||dd�|d|di�q(|�d��r!d|d|dii|||d<q(qW|St�y6t�d�|YSw)a�
    Function to take incoming raw state data and roll IDs with multiple names
    into a single state block for reporting purposes. This functionality is most
    useful for any "_id" state_output options, such as ``terse_id``.

    The following example state has one ID and four names.

    .. code-block:: yaml

    mix-matched results:
      cmd.run:
        - names:
          - "true"
          - "false"
          - "/bin/true"
          - "/bin/false"

    With ``state_output: terse_id`` set, this can create many lines of output
    which are not unique enough to be worth the screen real estate they occupy.

    .. code-block:: text

        19:10:10.969049 [  8.546 ms]        cmd.run        Changed   Name: mix-matched results
        19:10:10.977998 [  8.606 ms]        cmd.run        Failed    Name: mix-matched results
        19:10:10.987116 [  7.618 ms]        cmd.run        Changed   Name: mix-matched results
        19:10:10.995172 [  9.344 ms]        cmd.run        Failed    Name: mix-matched results

    Enabling ``state_compress_ids: True`` consolidates the state data by ID and
    result (e.g. success or failure). The earliest start time is chosen for
    display, duration is aggregated, and the total number of names if shown in
    parentheses to the right of the ID.

    .. code-block:: text

        19:10:46.283323 [ 16.236 ms]        cmd.run        Changed   Name: mix-matched results (2)
        19:10:46.292181 [ 16.255 ms]        cmd.run        Failed    Name: mix-matched results (2)

    A better real world use case would be passing dozens of files and
    directories to the ``names`` parameter of the ``file.absent`` state. The
    amount of lines consolidated in that case would be substantial.
    cSs>g|]\}}d�tt|�d�d|d|d|dg���qS)�_�_|-r�__id__�__sls__�result)�join�map�str�split)�.0�tname�info�r�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/output/highstate.py�
<listcomp>�s�����z!_compress_ids.<locals>.<listcomp>rrrrrr�Zstate_compressed�z{} ({})�__run_num__�duration��
start_time�changes�compressed changes�namezAUnable to compress state output by ID! Returning output normally.)�
isinstance�dict�items�collections�Counterr
rrr	�format�min�round�sum�sorted�get�update�	Exception�log�warning)	�data�
compressed�host�hostdataZid_countrr
�comps�_idrrr�
_compress_ids�s�
*��
�����
���� ���������V�
�r/cs8t|t�r
d|vr
|d}t|t�rd|vr|d}t|t�rFt|���dkrFtt|����}t|t�rFd|vrFd|vrF|�di��d|�}t|t�sPt|t	�rR|S|durXdSdd	�|��D�}d
|��volt|�dk}|rr|d
=t
�dd�r|t|�}|�d
d���fdd	�|��D�}|r�d�
|�St�d|�dS)z�
    The HighState Outputter is only meant to be used with the state.highstate
    function, or a function that returns highstate return data.
    �returnr)rZjidZfunN�NonecSsg|]	}|�d�r|�qS)Z_master)�endswith)r�keyrrrr8szoutput.<locals>.<listcomp>�retcode�state_compress_idsF�indent_levelcs"g|]
\}}t||�d�d�qS)�r6r)�_format_host)rr+r,r7rrrCs���
zFData passed to highstate outputter is not a valid highstate return: %s�)rr�len�keys�next�iter�valuesr$�intr	�__opts__r/rrr'�error)r)�kwargs�_dataZ
local_mastersZorchestrator_output�retrr7r�outputs:

�
�rFrc9stjj�|�}tjj�t�d�t�d��}t�dd�}i}g}g}|d}g}	d}
t�dd�}t�t	�rFd	}
|	�
d
�|�|��|d}�n�t�t�rdd	}
��
�D]�|	�
d
�|�|��qQ|d}�n�t�t�r�|d}|	�
d
�||���D]}|r�tj�tjj�|��}|	�
d�|||��qx�n\t�t��r�i}
���D]1\}}t|t�r�|dkr�|r�d|vr�d}|	�dt�|��|	�d|�t|t�r�d|vr�||
|<q�|
�t��fdd�d�D�]_}�|}|�|dd�d	}t�dd��rd|v�r|�d�\}}}}t�d|�}|�rt	|�d	��}||d|7<d|v�rc|�dd�}z	|�
t|��Wnpt�yb|�d�\}}}z	|�
t|��Wnt�y_t� d|�dd��YnwYnAw|�dd�}z	|�
t|��Wn0t�y�|�d�\}}}z	|�
t|��Wnt�y�t� d|�dd��YnwYnw|d}|�d�dv�r�t|d|d	d �}tj!d!d"|d#|tj"d$�}d}|
d	7}
n)t#|d�\}}|�r�|d	k�r�|
t$|d�d%i���p�d	7}
n	|
|�r�d	nd7}
t�d&d��r|d�r|�sq�t�d'd��s|d�r|�sq�|�r|d}|ddu�r-|d(}|d(}|dd)u�r<|d*}|d*}t�d+d,��%�}|�d�}|�&d-��rU|d	|d.<|�'d/��r�t�d0g�}i}|D]}t|t��rvd1|v�rv|�(�}�qe|�d2t�d3g��} t| t��r�t| ��d4�} |�d5t�d6g��}!t|!t��r�t|!��d4�}!t|d�|!v�r�t)|||||�}"|	�
|"�q�t|d�| v�r�q�n/t*|�'d5�|�'d7��o�|ddu|�'d��o�|d�o�|f��r�t)|||||�}"|	�
|"�q�gd8�}#t�d9��r
d:|v�r
|#�+d;d<g�|d	|d.k�r|#�d=d>�zt|d?t��s-t|d?�|d?<Wnt,�yCtjj-�.|d?�|d?<Ynwztjj�|d?�}$|$�/��0d#d@�}$Wn0t1�y�z
|d?�2dA��0d#dB�}$Wnt1�y�t|d?�}$|$�/��0d#d@�}$YnwYnwdC|v�r�t|dCt��r�|dCD]
}|$�dA|��}$�q�n't|dCt��r�|dC��D]\}%}&|$�dD|%�dE|&��}$�q�ndF�|$|dC�}$dGD]	}'|�|'dH��q�|ddHk�r�dI�|d�|d<|||tjj�|$�|dJ��|	�+�fdKdL�|#D��dM|}(|	�
dN�||(|��dO|v�r>|�dOd�|dOd	7<t3j4dPd"d"dQ�})|	�
dRj|)�5d#�2|dO���6�|dS��q�dN}*dTdUdVdWdX�}+t7dYdL�|�8�D��pUdg�},t7dZdL�|+�8�D��pddg�}-|-|,d.�|	�
|*�|dd[�|d\��|���fd]d^�}.g}/d)|v�r�|�d)d�dk�r�|/�
|*�|d*d_|�d)d���|��|
dk�r�|/�
|*�|dd`|
��|��|/�r�da�db�2|/��}/ndH}/|	�
|*�|d|.|+d|�dd�|�d)d��|�|/�|�dd�}0|	�
|*�|0�r�|d(n|d|.|+d|0�|��t�dcd��rzz.t9|�dd�|�d)d�t:|�8��|�dOd�ddd.�}1|	�
|*�|d|.de|1�|��Wn
t;�yCYnwz+t9|0t:|�8��|�dOd�ddd.�}2|	�
|*�|0�rc|d(n|d|.df|2�|��Wn
t;�yyYnw|�dOd�}3|3�r�|	�
|*�|d|.|+dO|3�|��dg�d\�t:|�8��|�dOd��dh�}4|	�
|*�|d|4|��t�d9��r�t:|�}5|�r�t7|�}6|5|6}5di}7|5djk�r�|5dk}5dl}7dm�|5dn��<�do�|7�}8|	�
|*�|d|8|��|�r�tj�|�}|	�ddp�|||��d#�2|	�|
dkfS)qz�
    Main highstate formatter. can be called recursively if a nested highstate
    contains other highstates (ie in an orchestration)
    �colorZcolor_themeZ
state_tabularFZGREENr�strip_colorsTrz{0}    {1}{2[ENDC]}ZCYANZ	LIGHT_REDz'    {0}Data failed to compile:{1[ENDC]}z{0}----------
    {1}{2[ENDC]}rrzsThe State execution failed to record the order in which all states were executed. The state return missing data is:rcs�|�dd�S)Nrr)r$)�k)r)rr�<lambda>�sz_format_host.<locals>.<lambda>)r3r5z_|-state_compressed_rz
\((\d+)\)$Z__parallel__rz msz%Cannot parse a float from duration %sr)z
state.orchzstate.orchestratez	state.slsr7�^�              r9)�flagsrZstate_output_diffZ
state_verboseZREDNZLIGHT_YELLOW�state_output�fullr.r�filter�argZ	__kwarg__�excludeZstate_output_exclude�,�terseZstate_output_terse�mixed)z {tcolor}----------{colors[ENDC]}z.    {tcolor}      ID: {comps[1]}{colors[ENDC]}z9    {tcolor}Function: {comps[0]}.{comps[3]}{colors[ENDC]}z3    {tcolor}  Result: {ret[result]!s}{colors[ENDC]}z-    {tcolor} Comment: {comment}{colors[ENDC]}�state_output_profilerz7    {tcolor} Started: {ret[start_time]!s}{colors[ENDC]}z5    {tcolor}Duration: {ret[duration]!s}{colors[ENDC]}rz.    {tcolor}    Name: {comps[2]}{colors[ENDC]}�commentz
              � z
             r)z
		z: z{} {})rrr:z{} ms)�tcolorr-rErW�colorscsg|]
}|jdi����qS)r)r)r�sline)�svarsrrrPsz _format_host.<locals>.<listcomp>z     Changes:   z{0}{1}{2[ENDC]}�warnings�P)�width�initial_indent�subsequent_indentz2   {colors[LIGHT_RED]} Warnings: {0}{colors[ENDC]})rZZ	Succeeded�FailedzNot RunZWarnings)TFNr]cSsg|]}tt|���qSr)r;r	�r�xrrrrhscSsg|]}t|��qSr)r;rcrrrrisz
Summary for {}
{}�-csd�||�t|�d�S)Nz
{0}: {1:>{2}}r)rr;)Zlabel�count)�line_max_lenrr�_countsssz_format_host.<locals>._countsz
unchanged=zchanged=z ({})z, Zstate_output_pct�dz	Success %z	Failure %z{0}
Total states run: {1:>{2}}��msi�i��szTotal run time: {} {}z.3f�z{0}{1}:{2[ENDC]})=�salt�utilsr)�decoderGZ
get_colorsrAr$rr@�appendrr	�
splitlines�listrFZstrip_esc_sequencerr�insert�pprintZpformatr#�
setdefaultr
�re�search�group�float�
ValueError�	partitionr'rB�sub�	MULTILINE�_format_changesr;�lowerr2�
startswith�copy�
_format_terse�any�extend�UnicodeDecodeErrorZstringutilsZ
to_unicode�strip�replace�AttributeErrorr�textwrap�TextWrapper�fill�lstrip�maxr?r!r"�ZeroDivisionError�rjust)9r+r)r6rZ�tabularZrcountsZ
rdurationsZ
pdurationsZhcolorZhstrsZnchangesrH�errZdata_tmprr
rEZcompressed_countrr.Zcount_matchZ	pdurationZ	rdurationrY�nested�ctextZschangedrNr-ZcliargsZ	clikwargs�itemrRrT�msgZstate_linesrWr3�valueZdetailr�wrapperZcolorfmtZrlabelZ
count_max_lenZ
label_max_lenrhZchangestatsZ
num_failedZsuccess_pctZ
failed_pctZnum_warningsZtotalsZsum_durationZ
max_pdurationZ
duration_unitZtotal_durationr)r)rgr\rr8Ps��


�����
�


����

����
�
 
���
���
	��
�
���
�������
���
���������
� ���
�����	�����������
�r8cCs d}|tjj|dtdd�7}|S)z;
    Print the changes data using the nested outputter
    r9r��)Z
nested_indent)rnrFZ
out_formatrA)rrErrr�_nested_changes�sr�Fc	Cs�|sdS|rdt|�fSt|t�sdd|��fS|�d�}|durT|�d�dkrTd}d	}|��D]\}}t||�\}}|d
d
�dd�|��D��7}|pN|}q0||fSd}t|�}||fS)
z;
    Format the changes dict based on what the data is
    )Fr:TzInvalid Changes data: rEN�outZ	highstater:Fr9css�|]}d|VqdS)rLNr)r�lrrr�	<genexpr>s�z"_format_changes.<locals>.<genexpr>)r�rrr$rr8rrr)	rZ
orchestrationrEr��changedr+r,rl�crrrr�s$

 
�rc	Csd}|drd}|ddurd}n|ddurd}|d	urGd
}d|vr1|dj|d
�|d�d�7}|d7}t�d�rBd|vrB|d7}|d7}n1t|t�rO|}n)d
}d|vrc|dj|d
�|d�d�7}|d7}t�d�rtd|vrt|d7}|d7}|�||d|d|d||d|�}|S)z(
    Terse formatting of a message.
    ZCleanrZChangedrFrbNZDiffersTr:r]z%{c[LIGHT_RED]}Warnings:
{w}{c[ENDC]}
r9)r��wz{0}rVrz*{6[start_time]!s} [{6[duration]!s:>7} ms] z${2:>10}.{3:<10} {4:7}   Name: {1}{5}z${c[LIGHT_RED]}Warnings:
{w}{c[ENDC]}z0 {0} Name: {1} - Function: {2}.{3} - Result: {4}z< - Started: {6[start_time]!s} - Duration: {6[duration]!s} msz{5}rr���ZENDC)rrrAr$rr	)rYr-rErZr�rZ
fmt_stringr�rrrr�
s@�

��r�)r)F)�__doc__r�loggingrurwr�Zsalt.outputrnZsalt.utils.colorZsalt.utils.dataZsalt.utils.stringutils�	getLogger�__name__r'r/rFr8r�rr�rrrr�<module>s*}

9