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/modules/__pycache__/saltutil.cpython-310.pyc
o

�N�g���@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z
ddlZddlZddl
ZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZm Z m!Z!m"Z"zddl#Z#ddl#m$Z$dZ%Wne&y�dZ%Ynwzddl'Z'dZ(Wne&y�dZ(Ynwzej)Z*Wne+y�ej,Z*YnwdgZ-e�.e/�Z0dd	�Z1drd
d�Z2dsdd
�Z3	dtdd�Z4drdd�Z5	dtdd�Z6	dtdd�Z7dd�Z8					dudd�Z9	dtdd�Z:	dtdd�Z;	dvdd�Z<	dvd d!�Z=	dvd"d#�Z>	dvd$d%�Z?	dtd&d'�Z@ejAjB�Ce@d(�ZD	dtd)d*�ZE	dtd+d,�ZF	dtd-d.�ZGd/d0�ZH	dtd1d2�ZI					dud3d4�ZJ	dtd5d6�ZK					dud7d8�ZLd9d:�ZMd;d<�ZNdwd>d?�ZOejAjB�CeOd@�ZPdAdB�ZQdCdD�ZRdEdF�ZSdGdH�ZTdxdJdK�ZUdLdM�ZVdNdO�ZWdPdQ�ZXdRdS�ZYdTdU�ZZdVdW�Z[dXdY�Z\dZd[�Z]dyd\d]�Z^dyd^d_�Z_		dzd`da�Z`	b		c	d		d{dedf�Za	b		c	d		d{dgdh�Zb	d|djdk�Zcdldm�ZdGdndo�do�Zedpdq�ZfdS)}z�
The Saltutil module is used to manage the state of the salt minion itself. It
is used to manage minion modules as well as automate updates to the salt
minion.

:depends:   - esky Python module for update functionality
�N)�CommandExecutionError�SaltInvocationError�SaltRenderError�SaltReqTimeoutError)�EskyVersionErrorTF�*cCs�ztdWStyXtjjtt��d��2}z|��}|r*t	|�
|����p(d}nd}Wnty@}zt
d|����d}~wwWd�n1sKwY|td<|YSw)z0
    Get all environments from the top file
    zsaltutil._top_file_envs)Zinitial_pillar�basezUnable to render top file(s): N)�__context__�KeyError�salt�stateZ	HighState�__opts__Z
__pillar__�valueZget_top�listZtop_matches�keysrr)Zst_�topZenvs�exc�r�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/saltutil.py�_get_top_file_envsHs&
�����	�rcCs�|durt�}t|t�r|�d�}tjjjt||||d�\}}|rBt	j
�tdd�}tjj�
|d��Wd�n1s=wY|dkrwt�d�rwt	j
�t	j
�tdd	��rwzt	�t	j
�tdd	��W|Styvt�d
�Y|Sw|S)z;
    Sync the given directory in the given environment
    N�,)�saltenv�extmod_whitelist�extmod_blacklist�cachedir�module_refresh�a�grainsZgrains_cachezgrains.cache.pzCould not remove grains cache!)r�
isinstance�str�splitr�utils�extmods�syncr
�os�path�join�files�fopen�get�isfile�remove�OSError�log�error)Zformrrr�retZtouchedZmod_filerrr�_sync\s:


������r0c
Cs�i}ts
d|d<|Sttdd�sd|d<|Stdd�s"d|d<|St�tjtd�}td	}|sUz|�	�}Wnt
jjyT}zd
|��|d<|WYd}~Sd}~ww|s]d|d<|Sz|�
|�Wnty�}zd
|�d|��|d<|WYd}~Sd}~wwz|�|�Wnty�}zd|�d|��|d<|WYd}~Sd}~wwz|��Wnty�}z
d|��|d<WYd}~nd}~wwi}tdD]
}td|�||<q�d|�d|��|d<||d<|S)a�
    Update the salt minion from the URL defined in opts['update_url']
    Broadcom, Inc provides the latest builds here:
    update_url: https://packages.broadcom.com/artifactory/saltproject-generic/windows/

    Be aware that as of 2014-8-11 there's a bug in esky such that only the
    latest version available in the update_url can be downloaded and installed.

    This feature requires the minion to be running a bdist_esky build.

    The version number is optional and will default to the most recent version
    available at opts['update_url'].

    Returns details about the transaction upon completion.

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.update
        salt '*' saltutil.update 0.10.3
    zEsky not available as import�_error�frozenFz#Minion is not running an Esky buildz
config.optionZ
update_urlz*"update_url" not configured on this minionZsaltversionz(Could not connect to update_url. Error: NzNo updates availablezUnable to fetch version z	. Error: zUnable to install version zUnable to cleanup. Error: Zupdate_restart_serviceszservice.restartz
Updated from z to Zcomment�	restarted)�HAS_ESKY�getattr�sys�__salt__�eskyZEsky�
executabler
�
__grains__Zfind_update�urllibr.�URLErrorZ
fetch_versionrZinstall_versionZcleanup�	Exception)�versionr/ZappZ
oldversionrr3Zservicerrr�update|sb��������r?cC�td|||�}|rt�|S)a
    .. versionadded:: 2015.5.1

    Sync beacons from ``salt://_beacons`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for beacons to sync. If no top files are
        found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available beacons on the minion. This refresh
        will be performed even if no new beacons are synced. Set to ``False``
        to prevent this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.sync_beacons
        salt '*' saltutil.sync_beacons saltenv=dev
        salt '*' saltutil.sync_beacons saltenv=base,dev
    �beacons)r0�refresh_beacons�r�refreshrrr/rrr�sync_beacons��#rEcCstd|||�}|S)a�
    .. versionadded:: 2015.5.8,2015.8.3

    Sync sdb modules from ``salt://_sdb`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for sdb modules to sync. If no top files
        are found, then the ``base`` environment will be synced.

    refresh : False
        This argument has no affect and is included for consistency with the
        other sync functions.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.sync_sdb
        salt '*' saltutil.sync_sdb saltenv=dev
        salt '*' saltutil.sync_sdb saltenv=base,dev
    �sdb)r0)rrrr/rrr�sync_sdb�s rHcCr@)aY
    .. versionadded:: 0.10.0

    Sync execution modules from ``salt://_modules`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for execution modules to sync. If no top
        files are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new execution modules are
        synced. Set to ``False`` to prevent this refresh.

    .. important::

        If this function is executed using a :py:func:`module.run
        <salt.states.module.run>` state, the SLS file will not have access to
        newly synced execution modules unless a ``refresh`` argument is
        added to the state, like so:

        .. code-block:: yaml

            load_my_custom_module:
              module.run:
                - name: saltutil.sync_modules
                - refresh: True

        See :ref:`here <reloading-modules>` for a more detailed explanation of
        why this is necessary.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.sync_modules
        salt '*' saltutil.sync_modules saltenv=dev
        salt '*' saltutil.sync_modules saltenv=base,dev
    �modules�r0�refresh_modulesrCrrr�sync_moduless4rLcCr@)a
    .. versionadded:: 0.10.0

    Sync state modules from ``salt://_states`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for state modules to sync. If no top
        files are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available states on the minion. This refresh
        will be performed even if no new state modules are synced. Set to
        ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_states
        salt '*' saltutil.sync_states saltenv=dev
        salt '*' saltutil.sync_states saltenv=base,dev
    �statesrJrCrrr�sync_statesErFrNcKsZtjjjdi|��}|�dd�}|�dd�}|rtjj�|�|r(t|d�dSt�dS)a=
    .. versionadded:: 2016.3.6,2016.11.4,2017.7.0

    Refresh the minion's grains without syncing custom grains modules from
    ``salt://_grains``.

    .. note::
        The available execution modules will be reloaded as part of this
        proceess, as grains can affect which modules are available.

    refresh_pillar : True
        Set to ``False`` to keep pillar data from being refreshed.

    clean_pillar_cache : False
        Set to ``True`` to refresh pillar cache.

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.refresh_grains
    �refresh_pillarT�clean_pillar_cacheF��clean_cacheNr)rr!�args�clean_kwargs�popZinvalid_kwargsrOrK)�kwargsZ_refresh_pillarrPrrr�refresh_grainsns
�rWcCs td|||�}|rt|d�|S)a�
    .. versionadded:: 0.10.0

    Sync grains modules from ``salt://_grains`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for grains modules to sync. If no top
        files are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules and recompile
        pillar data for the minion. This refresh will be performed even if no
        new grains modules are synced. Set to ``False`` to prevent this
        refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    clean_pillar_cache : False
        Set to ``True`` to refresh pillar cache.

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_grains
        salt '*' saltutil.sync_grains saltenv=dev
        salt '*' saltutil.sync_grains saltenv=base,dev
    rrQ)r0rO�rrDrrrPr/rrr�sync_grains�s+
rYcCr@)aQ
    .. versionadded:: 0.10.0

    Sync renderers from ``salt://_renderers`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for renderers to sync. If no top files
        are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new renderers are synced.
        Set to ``False`` to prevent this refresh. Set to ``False`` to prevent
        this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_renderers
        salt '*' saltutil.sync_renderers saltenv=dev
        salt '*' saltutil.sync_renderers saltenv=base,dev
    �	renderersrJrCrrr�sync_renderers�s$r[cCr@)a�
    .. versionadded:: 0.10.0

    Sync returners from ``salt://_returners`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for returners to sync. If no top files
        are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new returners are synced. Set
        to ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_returners
        salt '*' saltutil.sync_returners saltenv=dev
    �	returnersrJrCrrr�sync_returners��"r]cCr@)a2
    .. versionadded:: 2015.8.2

    Sync proxy modules from ``salt://_proxy`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for proxy modules to sync. If no top
        files are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new proxy modules are synced.
        Set to ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_proxymodules
        salt '*' saltutil.sync_proxymodules saltenv=dev
        salt '*' saltutil.sync_proxymodules saltenv=base,dev
    �proxyrJrCrrr�sync_proxymodulesrFr`cCr@)a�
    .. versionadded:: 2019.2.0

    Sync engine modules from ``salt://_matchers`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for engines to sync. If no top files are
        found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new matcher modules are synced.
        Set to ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_matchers
        salt '*' saltutil.sync_matchers saltenv=base,dev
    �matchersrJrCrrr�
sync_matchersBr^rbcCr@)a�
    .. versionadded:: 2016.3.0

    Sync engine modules from ``salt://_engines`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for engines to sync. If no top files are
        found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new engine modules are synced.
        Set to ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_engines
        salt '*' saltutil.sync_engines saltenv=base,dev
    �enginesrJrCrrr�sync_enginesjr^rdcCr@)a�
    .. versionadded:: 2018.3.0

    Sync Thorium modules from ``salt://_thorium`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for engines to sync. If no top files are
        found, then the ``base`` environment will be synced.

    refresh: ``True``
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new Thorium modules are synced.
        Set to ``False`` to prevent this refresh.

    extmod_whitelist
        comma-separated list of modules to sync

    extmod_blacklist
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_thorium
        salt '*' saltutil.sync_thorium saltenv=base,dev
    �thoriumrJrCrrr�sync_thorium�r^rfcCr@)a�
    Sync outputters from ``salt://_output`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for outputters to sync. If no top files
        are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new outputters are synced.
        Set to ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_output
        salt '*' saltutil.sync_output saltenv=dev
        salt '*' saltutil.sync_output saltenv=base,dev
    �outputrJrCrrr�sync_output�s!rh�sync_outputterscCr@)aG
    .. versionadded:: 2017.7.0

    Sync cloud modules from ``salt://_cloud`` to the minion

    saltenv : base
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new utility modules are
        synced. Set to ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_clouds
        salt '*' saltutil.sync_clouds saltenv=dev
        salt '*' saltutil.sync_clouds saltenv=base,dev
    �cloudsrJrCrrr�sync_clouds�srkcCr@)a#
    .. versionadded:: 2014.7.0

    Sync utility modules from ``salt://_utils`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for utility modules to sync. If no top
        files are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new utility modules are
        synced. Set to ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_utils
        salt '*' saltutil.sync_utils saltenv=dev
        salt '*' saltutil.sync_utils saltenv=base,dev
    r!rJrCrrr�
sync_utils	rFrlcCr@)a=
    .. versionadded:: 2019.2.0

    Sync serializers from ``salt://_serializers`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for serializer modules to sync. If no top
        files are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new serializer modules are
        synced. Set to ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-seperated list of modules to sync

    extmod_blacklist : None
        comma-seperated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_serializers
        salt '*' saltutil.sync_serializers saltenv=dev
        salt '*' saltutil.sync_serializers saltenv=base,dev
    �serializersrJrCrrr�sync_serializers2rFrncCs�i}tj�tdd�}t�|�}|D]2}t�||<tjj�tj�||��D]\}}}|D]}||�	|�
d�d�q,q%t||�||<q|S)z�
    .. versionadded:: 2017.7.0

    List Salt modules which have been synced externally

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.list_extmods
    rr"�.r)r$r%r&r
�listdir�setrr!Zos_walk�addr r)r/Zext_dirZ	mod_typesZmod_type�_r'Zfh_rrr�list_extmods[s

"�rtcCr@)a6
    .. versionadded:: 2015.8.0

    Sync log handlers from ``salt://_log_handlers`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for log handlers to sync. If no top files
        are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new log handlers are synced.
        Set to ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_log_handlers
        salt '*' saltutil.sync_log_handlers saltenv=dev
        salt '*' saltutil.sync_log_handlers saltenv=base,dev
    �log_handlersrJrCrrr�sync_log_handlerssrFrvcCs4tddkr
td��td|||�}|rt|d�|S)a�
    .. versionadded:: 2015.8.11,2016.3.2

    Sync pillar modules from the ``salt://_pillar`` directory on the Salt
    fileserver. This function is environment-aware, pass the desired
    environment to grab the contents of the ``_pillar`` directory from that
    environment. The default environment, if none is specified,  is ``base``.

    refresh : True
        Also refresh the execution modules available to the minion, and refresh
        pillar data.

    extmod_whitelist : None
        comma-separated list of modules to sync

    extmod_blacklist : None
        comma-separated list of modules to blacklist based on type

    clean_pillar_cache : False
        Set to ``True`` to refresh pillar cache.

    .. note::
        This function will raise an error if executed on a traditional (i.e.
        not masterless) minion

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_pillar
        salt '*' saltutil.sync_pillar saltenv=dev
    �file_client�localz7Pillar modules can only be synced to masterless minions�pillarrQ)r
rr0rOrXrrr�sync_pillar�s'�
rzcCr@)a#
    .. versionadded:: 3000

    Sync executors from ``salt://_executors`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for log handlers to sync. If no top files
        are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new log handlers are synced.
        Set to ``False`` to prevent this refresh.

    extmod_whitelist : None
        comma-seperated list of modules to sync

    extmod_blacklist : None
        comma-seperated list of modules to blacklist based on type

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_executors
        salt '*' saltutil.sync_executors saltenv=dev
        salt '*' saltutil.sync_executors saltenv=base,dev
    �	executorsrJrCrrr�sync_executors�rFr|cCsnt�d�i}t|d||�|d<t|d||�|d<t|d||�|d<t|d||�|d<t|||�|d<t|d||�|d<t|d||�|d	<t	|d||�|d
<t
|d||�|d<t|d||�|d<t|d||�|d
<t
|d||�|d<t|d||�|d<t|d||�|d<t|d||�|d<t|d||�|d<t|d||�|d<tddkr�t|d||�|d<|r�t|d�|S)a�
    .. versionchanged:: 2015.8.11,2016.3.2
        On masterless minions, pillar modules are now synced, and refreshed
        when ``refresh`` is set to ``True``.

    Sync down all of the dynamic modules from the file server for a specific
    environment. This function synchronizes custom modules, states, beacons,
    grains, returners, output modules, renderers, and utils.

    refresh : True
        Also refresh the execution modules and recompile pillar data available
        to the minion. This refresh will be performed even if no new dynamic
        modules are synced. Set to ``False`` to prevent this refresh.

    .. important::

        If this function is executed using a :py:func:`module.run
        <salt.states.module.run>` state, the SLS file will not have access to
        newly synced execution modules unless a ``refresh`` argument is
        added to the state, like so:

        .. code-block:: yaml

            load_my_custom_module:
              module.run:
                - name: saltutil.sync_all
                - refresh: True

        See :ref:`here <reloading-modules>` for a more detailed explanation of
        why this is necessary.

    extmod_whitelist : None
        dictionary of modules to sync based on type

    extmod_blacklist : None
        dictionary of modules to blacklist based on type

    clean_pillar_cache : False
        Set to ``True`` to refresh pillar cache.

    CLI Examples:

    .. code-block:: bash

        salt '*' saltutil.sync_all
        salt '*' saltutil.sync_all saltenv=dev
        salt '*' saltutil.sync_all saltenv=base,dev
        salt '*' saltutil.sync_all extmod_whitelist={'modules': ['custom_module']}
    zSyncing allFrjrArIrMrGrrZr\rgr!rur{ZproxymodulesrcrermrarwrxryrQ)r-�debugrkrErLrNrHrYr[r]rhrlrvr|r`rdrfrnrbr
rzrOrXrrr�sync_all�sH
8������
r~cC�8z
tdid�}W|Styt�d�d}Y|Sw)z�
    Signal the minion to refresh the beacons.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.refresh_beacons
    �
event.fireZbeacons_refresh�2Event module not available. Module refresh failed.F�r7r
r-r.�r/rrrrBV�
�
�rBcCr)z�
    Signal the minion to refresh its matchers.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.refresh_matchers
    r�Zmatchers_refreshz3Event module not available. Matcher refresh failed.Fr�r�rrr�refresh_matchershr�r��cCs�d|i}zP|rKtjjjdtdd��,}td|d�}t�d�|jtjj	j
|d�}|r0|d	d
ur6t�d|�Wd�n1s@wYW|SW|Std|d�}W|Styet�
d
�d
}Y|Sw)a
    Signal the minion to refresh the in-memory pillar data. See :ref:`pillar-in-memory`.

    :param wait:            Wait for pillar refresh to complete, defaults to False.
    :type wait:             bool, optional
    :param timeout:         How long to wait in seconds, only used when wait is True, defaults to 30.
    :type timeout:          int, optional
    :param clean_cache:     Clean the pillar cache, only used when `pillar_cache` is True. Defaults to True
    :type clean_cache:      bool, optional
        .. versionadded:: 3005
    :return:                Boolean status, True when the pillar_refresh event was fired successfully.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.refresh_pillar
        salt '*' saltutil.refresh_pillar wait=True timeout=60
    rR�minionT��opts�listenr��pillar_refreshz5refresh_pillar waiting for pillar refresh to complete��tag�waitZcompleteFz1Pillar refresh did not complete within timeout %sNz2Event module not available. Pillar refresh failed.)rr!�event�	get_eventr
r7r-�trace�defaults�eventsZMINION_PILLAR_REFRESH_COMPLETE�warningr
r.)r��timeoutrR�data�eventerr/Z	event_retrrrrOzs:�
�������
�rOr�cKs�t|�dd��}zC|rtdid�}W|Stjjjdtdd��"}tdddid�}t�	d�|jtj
jjd	d
�Wd�W|S1sDwYW|St
y\t�d�d
}Y|Sw)a#
    Signal the minion to refresh the module and grain data

    The default is to refresh module asynchronously. To block
    until the module refresh is complete, set the 'async' flag
    to False.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.refresh_modules
    �asyncTr�rr�r��notifyz6refresh_modules waiting for module refresh to completer�r�Nr�F)�boolr)r7rr!r�r�r
r-r�r�r�ZMINION_MOD_REFRESH_COMPLETEr
r.)rVZasynchronousr/r�rrrrK�s.��

��
�
�
�rKcCs6t�}g}|D]}t�|�dd�|�r|�|�q|S)z�
    If the named function is running return the data associated with it/them.
    The argument can be a glob

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.is_running state.highstate
    �fun�)�running�fnmatchr)�append)r��runr/r�rrr�
is_running�s
�r�cCstjj�t�S)z�
    Return the data on all running salt processes on the minion

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.running
    )rr!r�r�r
rrrrr��s
r�cCs~tjjjtddd�D]1\}}}|D])}zt�tj�||��Wqt	y;}zt
�d|�WYd}~dSd}~wwqdS)a6
    Forcibly removes all caches on a minion.

    .. versionadded:: 2014.7.0

    WARNING: The safest way to clear a minion cache is by first stopping
    the minion and then deleting the cache files before restarting it.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.clear_cache
    rF��followlinksz@Attempt to clear cache with saltutil.clear_cache FAILED with: %sNT)rr!r'�	safe_walkr
r$r+r%r&r,r-r.)�root�dirsr'�namerrrr�clear_cache�s �����	r��c	Cs�t��|d}tjjjtj�tdd�dd�D]=\}}}|D]5}ztj�||�}tj�	|�}||kr8t
�|�WqtyT}zt
�d|�WYd}~dSd}~wwqdS)	aT
    Forcibly removes job cache folders and files on a minion.

    .. versionadded:: 2018.3.0

    WARNING: The safest way to clear a minion cache is by first stopping
    the minion and then deleting the cache files before restarting it.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.clear_job_cache hours=12
    ir�minion_jobsFr�zDAttempt to clear cache with saltutil.clear_job_cache FAILED with: %sNT)�timerr!r'r�r$r%r&r
�getmtime�shutil�rmtreer,r-r.)	�hoursZ	thresholdr�r�r'r��	directory�mtimerrrr�clear_job_caches*�
�����
r�cCs$t�D]}|d|kr|SqiS)am
    Return the data for a specific job id that is currently running.

    jid
        The job id to search for and return data.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.find_job <job id>

    Note that the find_job function only returns job information when the job is still running. If
    the job is currently running, the output looks something like this:

    .. code-block:: bash

        # salt my-minion saltutil.find_job 20160503150049487736
        my-minion:
            ----------
            arg:
                - 30
            fun:
                test.sleep
            jid:
                20160503150049487736
            pid:
                9601
            ret:
            tgt:
                my-minion
            tgt_type:
                glob
            user:
                root

    If the job has already completed, the job cannot be found and therefore the function returns
    an empty dictionary, which looks like this on the CLI:

    .. code-block:: bash

        # salt my-minion saltutil.find_job 20160503150049487736
        my-minion:
            ----------
    �jid)r�)r�r�rrr�find_job1s

.�r�cCs�tj�tdd�}tj�|t|��}tj�|�s&t�d�s 	dSd|�d�Stj�|d�}tjj	�
|d��}|��}Wd	�n1sDwY|reztj�
|�}Wn
ty]Yd	Swt|t�re|Sd	S)
z�
    Return the data for a specific cached job id. Note this only works if
    cache_jobs has previously been set to True on the minion.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.find_cached_job <job id>
    rr�Z
cache_jobszVLocal jobs cache directory not found; you may need to enable cache_jobs on this minionzLocal jobs cache directory z
 not foundzreturn.p�rbN)r$r%r&r
r�isdirr)rr!r'r(�read�payload�loads�	NameErrorr�dict)r�Zproc_dirZjob_dirr%Zfp_�bufr�rrr�find_cached_jobes*
�
��
r�c
Cstdur	t�d�t�D]u}|d|kr�zEtr+tj|dd�jdd�D]}|�|�q#t�	t
|d�|�tdurLd|vrL|dD]
}t�	t
|�|�qAd	�t
|�||d�WSty�tj
�td
dt|��}tj
�|�rwt�|�d�|�YSwqd
S)z�
    Sends a signal to the named salt job's process

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.signal_job <job id> 15
    Fz|saltutil.signal job called, but psutil is not installed. Install psutil to ensure more reliable and accurate PID management.r��pid)r�T)�	recursiveZ
child_pidsz"Signal {} sent to job {} at pid {}r�procz7Job {} was not running and job data has been cleaned upr�)�
HAS_PSUTILr-r�r��psutilZProcess�children�send_signalr$�kill�int�formatr,r%r&r
rr*r+)r��sigr�r�r�r%rrr�
signal_job�s:
�

�
�
���r�cCst|tj�S)z�
    Sends a termination signal (SIGTERM 15) to the named salt job's process

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.term_job <job id>
    )r��signal�SIGTERM�r�rrr�term_job�s
r�cCs*g}t�D]
}|�t|dtj��q|S)z�
    Sends a termination signal (SIGTERM 15) to all currently running jobs

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.term_all_jobs
    r�)r�r�r�r�r��r/r�rrr�
term_all_jobs�s

r�cCs
t|t�S)z�
    Sends a kill signal (SIGKILL 9) to the named salt job's process

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.kill_job <job id>
    )r��salt_SIGKILLr�rrr�kill_job�s
r�cCs(g}t�D]}|�t|dt��q|S)z�
    Sends a kill signal (SIGKILL 9) to all currently running jobs

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.kill_all_jobs
    r�)r�r�r�r�r�rrr�
kill_all_jobs�s
r�c	Cs�t�td�D]}tj�td|�}zt�|�Wqty"Yqwtjj	j
�t��}t�
d�Wd�dS1s<wYdS)z
    Used to regenerate the minion keys.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.regen_keys
    Zpki_dirz%Recreating channel to force key regenN)r$rpr
r%r&r+r,r�channel�client�
ReqChannel�factoryr-r})Zfn_r%r�rrr�
regen_keys�s
�"�r�c
Cs�t�}d}dtvrtdD]}|�|�q
n|�td�|D]>}tjjjjt|d��*}|j�	d�}dtd||d�}z|�
|�WntyMd	}YnwWd
�n1sXwYq|S)a�
    The minion sends a request to the master to revoke its own key.
    Note that the minion session will be revoked and the minion may
    not be able to return the result of this command back to the master.

    If the 'preserve_minion_cache' flag is set to True, the master
    cache for this minion will not be removed.

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.revoke_auth
    TZmaster_uri_list�
master_uri)r�ssalt�revoke_auth�id)�cmdr��tok�preserve_minion_cacheFN)rr
r�rr�r�r�r�ZauthZ	gen_token�sendr)r�Zmastersr/r��masterr�r��loadrrrr�s6�
������r�cCs(|rtjjj�|�}|Stj�|�}|S�N)rr��ssh�	SSHClient�get_local_client)�cfgfiler�r�rrr�_get_ssh_or_api_client0s
�r�c
Ks�i}d}|||||||d�}
|r|j}|
�d|i�n|	r)|j}|
�|	dd��n|j}|
�|
�|di|
��D]}|�|�|d7}|dkrOt|�|krOnq8|rr|i}}|��D]\}}t|t�rj|�dd	�nd	|d
�||<q[|S)Nr)�tgtr��argr��tgt_typer/�kwarg�batchT)�subsetZcli�r�outZ	highstate)r�r/r)	Z	cmd_batchr?Z
cmd_subset�cmd_iter�len�itemsrr�r))r�r�r�r�r�r�r/r�r�r�rV�fcn_ret�seenZ
cmd_kwargsZ_cmdZret_compZold_ret�keyrrrr�_exec8sB
�


�
��	r�r�globr�c

Ks�td}	t|	|��}
t|
|||||||fi|��}Wd�n1s#wY|	dd��d�}|si|	�d�tjjd��ritj�|�rit||��}
t|
|||||||fi|��}Wd�|S1sdwY|S)a%
    .. versionchanged:: 2017.7.0
        The ``expr_form`` argument has been renamed to ``tgt_type``, earlier
        releases must use ``expr_form``.

    Assuming this minion is a master, execute a salt command

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.cmd
    �	conf_fileNi����r�z{}{}r�)	r
r�r��endswithr�r$r%�sep�exists)
r�r�r�r�r�r/r�r�rVr�r�r�Zmaster_cfgfilerrrr�ts* ���
���
��r�c
ksZ�|rtjjj�td�}	ntj�td�}	|	j|||||||fi|��D]}|Vq%dS)a*
    .. versionchanged:: 2017.7.0
        The ``expr_form`` argument has been renamed to ``tgt_type``, earlier
        releases must use ``expr_form``.

    Assuming this minion is a master, execute a salt command

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.cmd_iter
    r�N)rr�r�r�r
r�r�)
r�r�r�r�r�r/r�r�rVr�rrrr��s�"�r�rcKs(|durg}|duri}i}|�d|�}|�d|�}|�dd�|d<tjjjdi|��}|r3|�|�dtvrQtj�	tj�
td�d	�}tj�|�}	tj
�|	�}
ntj
�t�}
||
jvrotjj�|
j|�}d
|jvro||d
<|dvrw||d<|r�tjjjt|d
|||d�dd�|
j||||d|d�S)a[
    Execute a runner function. This function must be run on the master,
    either by targeting a minion running on a master or by using
    salt-call on a master.

    .. versionadded:: 2014.7.0

    name
        The name of the function to run

    kwargs
        Any keyword arguments to pass to the runner function

    CLI Example:

    In this example, assume that `master_minion` is a minion running
    on a master.

    .. code-block:: bash

        salt master_minion saltutil.runner jobs.list_jobs
        salt master_minion saltutil.runner test.arg arg="['baz']" kwarg="{'foo': 'bar'}"
    N�__orchestration_jid__�__env__Z
__pub_user�UNKNOWN�userZmaster_job_cacher�r�r)zstate.orchestratez
state.orchz	state.slsZorchestration_jid�runner)�typer�rSrVr���prefixF�r��pub_datar�Zprint_event�full_returnr)rUrr!rSrTr?r
r$r%r&�dirname�config�
master_configr�ZRunnerClient�	functions�get_function_argspecr��	fire_argsr�)r�r�r�rrr�rVrr�master_optsZrclient�aspecrrrr��sJ


��r�cOs |�dd�}|�dd�}tddkr,tj�tj�td�d�}tj�|�}tj	�
|�}ntj	�
t�}i}i}	|��D]\}
}|
�d	�rH|||
<q:||	|
<q:z7||j
vrftjj�|j
|�}d
|jvrf||	d
<|rwtjjjt|d||	d�d
d�|j||||	ddd�}
W|
Sty�td��w)a�
    Execute a wheel module and function. This function must be run against a
    minion that is local to the master.

    .. versionadded:: 2014.7.0

    name
        The name of the function to run

    args
        Any positional arguments to pass to the wheel function. A common example
        of this would be the ``match`` arg needed for key functions.

        .. versionadded:: 2015.8.11

    kwargs
        Any keyword arguments to pass to the wheel function

    CLI Example:

    .. code-block:: bash

        salt my-local-minion saltutil.wheel key.accept jerry
        salt my-local-minion saltutil.wheel minions.connected

    .. note::

        Since this function must be run against a minion that is running locally
        on the master in order to get accurate returns, if this function is run
        against minions that are not local to the master, "empty" returns are
        expected. The remote minion does not have access to wheel functions and
        their return data.

    r�Nr�rZ__roler�r�r��__r�wheel)rr�rSr�rFTrzLThis command can only be executed on a minion that is located on the master.)rUr
r$r%r&rrrZ
client_configrZWheelClientr��
startswithr	r!rSr
r�rr�rr)r�rSrVr�rrrZwheel_clientrZvalid_kwargsr��valr
r/rrrrsN#





�����rc@seZdZddd�ZdS)�_MMinionFcCs�dt�vria|tvs
|r@t�t�}|d=t�t�}tj�|�}|a||j	d<|j	d|}dd�|D�|j	d<|�
�|t|<t|S)N�	_mminionsZ
file_rootsrcSsg|]}|d�qS)z	/_modulesr)�.0�fprrr�
<listcomp>xsz$_MMinion.__new__.<locals>.<listcomp>Zmodule_dirs)�globalsr�copy�deepcopyr
r:rr�ZMasterMinionr�Zgen_modules)�clsrZ
reload_envr�r�mZ	env_rootsrrr�__new__`s



z_MMinion.__new__N�F)�__name__�
__module__�__qualname__rrrrrr_srcOst|�}|j||i|��S)z�
    Loads minion modules from an environment so that they can be used in pillars
    for that environment

    CLI Example:

    .. code-block:: bash

        salt '*' saltutil.mmodule base test.ping
    )rr	)rr�rSrVZmminionrrr�mmodule~sr!)NNNr�)NTNN)NTNNF)NFNN)Fr�T)r�r)FF)rNr�r�NF)NNFrN)g�__doc__rr��loggingr$r�r�r6r��urllib.errorr;rZsalt.channel.clientZsalt.clientZsalt.client.ssh.clientZsalt.configZsalt.defaults.eventsZsalt.payloadZsalt.runnerZ
salt.stateZsalt.utils.argsZsalt.utils.eventZsalt.utils.extmodsZsalt.utils.filesZsalt.utils.functoolsZsalt.utils.minionZsalt.utils.pathZsalt.utils.processZsalt.utils.urlZ
salt.wheelZsalt.exceptionsrrrrr8rr4�ImportErrorr�r��SIGKILLr��AttributeErrorr�Z__proxyenabled__�	getLoggerrr-rr0r?rErHrLrNrWrYr[r]r`rbrdrfrhr!�	functoolsZalias_functionrirkrlrnrtrvrzr|r~rBr�rOr�rKr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr!rrrr�<module>s$��

�


 C
�
)%
�;
�)(
�3
�+
�)
�*
�)
�)
�)
�'
�&
�*
�)
�*
�3
�*
�_
/$
#4%)


)
�?
�/
�!
�GX