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/runners/__pycache__/survey.cpython-310.pyc
o

�N�g[�@s4dZddlZddlmZdd�Zdd�Zdd	�ZdS)
a
A general map/reduce style salt runner for aggregating results
returned by several different minions.

.. versionadded:: 2014.7.0

Aggregated results are sorted by the size of the minion pools which returned
matching results.

Useful for playing the game: *"some of these things are not like the others..."*
when identifying discrepancies in a large infrastructure managed by salt.
�N)�SaltClientErrorcOst|i|��S)a�
    Return the MATCHING minion pools from the aggregated and sorted results of
    a salt command

    .. versionadded:: 2014.7.0

    This command is submitted via a salt runner using the
    general form::

        salt-run survey.hash [survey_sort=up/down] <target>
                  <salt-execution-module> <salt-execution-module parameters>

    Optionally accept a ``survey_sort=`` parameter. Default: ``survey_sort=down``

    CLI Example #1: (functionally equivalent to ``salt-run manage.up``)

    .. code-block:: bash

        salt-run survey.hash "*" test.ping

    CLI Example #2: (find an "outlier" minion config file)

    .. code-block:: bash

        salt-run survey.hash "*" file.get_hash /etc/salt/minion survey_sort=up
    )�_get_pool_results)�args�kwargs�r�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/survey.py�hashsrcOs^ddl}t|i|��}d}|D]�}td�t|d�td�tdtt|d���|rAd}td	�td|dd
�t�qd�|ddd�}t|�tdt|�d
�|dd
��}t|�D]\}}	||d7<qf|d
��}
t|
�D]\}}	|
|d7<q}d}|d�|j	||
|ddd|dddd��7}t|�t�q|S)a&
    Return the DIFFERENCE of the result sets returned by each matching minion
    pool

    .. versionadded:: 2014.7.0

    These pools are determined from the aggregated and sorted results of
    a salt command.

    This command displays the "diffs" as a series of 2-way differences --
    namely the difference between the FIRST displayed minion pool
    (according to sort order) and EACH SUBSEQUENT minion pool result set.

    Differences are displayed according to the Python ``difflib.unified_diff()``
    as in the case of the salt execution module ``file.get_diff``.

    This command is submitted via a salt runner using the general form::

        salt-run survey.diff [survey_sort=up/down] <target>
                     <salt-execution-module> <salt-execution-module parameters>

    Optionally accept a ``survey_sort=`` parameter. Default:
    ``survey_sort=down``

    CLI Example #1: (Example to display the "differences of files")

    .. code-block:: bash

        salt-run survey.diff survey_sort=up "*" cp.get_file_str file:///etc/hosts
    rNTzminion pool :
------------�poolzpool size :
----------z    Fzpool result :
------------�resultzdifferences from "{}" results :�-��
�)�fromfile�tofile�n)
�difflibr�print�str�len�format�
splitlines�	enumerate�joinZunified_diff)rrrZbulk_retZ
is_first_time�kZoutsZfrom_result�idx�_Z	to_resultrrr�diff1sH#
��	rcs�ddl}|d}|d}i�|�dd�}|dk}|�dd�}|d	vr$d}d
d�|��D�}tj�td��;}	z|	j|||d
d�td||d�}
Wntyh}zt	|��WYd}~Wd�Sd}~wwWd�n1sswYt
|
�D]1}|�t|
|��
t����}
|
�vr�i�|
<g�|
d<t|
|��|
d<�|
d�|�q|g}t
��fdd�|d�D]	}|��|�q�|S)a�
    A helper function which returns a dictionary of minion pools along with
    their matching result sets.
    Useful for developing other "survey style" functions.
    Optionally accepts a "survey_sort=up" or "survey_sort=down" kwargs for
    specifying sort order.
    Because the kwargs namespace of the "salt" and "survey" command are shared,
    the name "survey_sort" was chosen to help avoid option conflicts.
    rNrZsurvey_sortZdownZup�tgt_type�compound)rZpcrecSs i|]\}}|�d�s||�qS)r)�
startswith)�.0�key�valuerrr�
<dictcomp>�s
��z%_get_pool_results.<locals>.<dictcomp>Z	conf_file��timeout)r&r�kwargr	r
cst�|d�S)Nr	)r)r��retrr�<lambda>�sz#_get_pool_results.<locals>.<lambda>)r"�reverse)�hashlib�pop�items�salt�clientZget_local_clientZ__opts__�cmdrr�sorted�sha256r�encodeZ__salt_system_encoding__�	hexdigest�append)rrr,Ztgtr1�sort�	directionrZkwargs_passthrur0ZminionsZclient_errorZminion�digestZ
sorted_retrrr(rr~sZ�

���
����r)�__doc__Zsalt.clientr/Zsalt.exceptionsrrrrrrrr�<module>s
M