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

�N�g�I�@sdZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
ZddlZddlZddlmZegd��ZdgZe�e�Zdd�Zdd	�Zd
d�Zdd
�Zd dd�Zd!dd�Zdd�Zd"dd�Zdd�Z dd�Z!d#dd�Z"dd�Z#dS)$zp
The function cache system allows for data to be stored on the master so it can be easily read by other minions
�N)�SaltClientError)Z
__pub_userZ	__pub_argZ	__pub_funZ	__pub_jidZ	__pub_tgtZ__pub_tgt_typeZ	__pub_ret�*cCsNdtvr#z
tj�t�td<WtdSty"t�d�YtdSwtdS)z 
    Return the auth object
    ZauthzFCould not authenticate with master. Mine data will not be transmitted.)�__context__�saltZcryptZSAuth�__opts__r�log�error�r	r	�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/mine.py�_auth's���rcCs|tvrt�d|�dSdS)Nz+Function %s in mine_functions not availableFT)�__salt__rr)�funcr	r	r
�_mine_function_available5srcCs,tjjj|dd�}|�|d�}t�d�|S)NF)�listenZ_minion_mineg�?)r�utils�eventZMinionEventZ
fire_event�time�sleep)�load�optsZeventerZ	event_retr	r	r
�
_mine_send<s
rcCs�|�dd�tjjvr$z
t��d�|d<Wnty#t�d�YdSwtj	j
j�|��
}|�
|�Wd�S1s<wYdS)N�	transport�ssalt�tokzEMine could not authenticate with master. Mine could not be retrieved.F)�getrrZ
TRANSPORTSrZ	gen_token�AttributeErrorrr�channel�clientZ
ReqChannel�factory�send)rrrr	r	r
�	_mine_getEs��$�r FcCs^tddkr!|stdd�}t|t�r|�|�|}tdd|�Sd|td|d�}t|t�S)	a�
    Helper function to store the provided mine data.
    This will store either locally in the cache (for masterless setups), or in
    the master's cache.

    :param dict mine_data: Dictionary with function_name: function_data to store.
    :param bool clear: Whether or not to clear (`True`) the mine data for the
        function names present in ``mine_data``, or update it (`False`).
    �file_client�local�data.get�
mine_cache�data.updateZ_mine�id)�cmd�datar&�clear)rr�
isinstance�dict�updater)�	mine_datar)�oldrr	r	r
�_mine_storeRs

�
r/c	Cs|stddi�}|s
dSnt|t�rdd�|D�}nt|t�r!ndSi}|��D]]\}}tjj�|�\}}}}t	|p<|�s?q)ztjj
jt|pH|g|�Ri|��}	Wntynt
��}
t�d|pd|�t�d|
�Yq)w|�d�r�tjjj|	fi|��||<q)|	||<q)t||�S)	a�
    Call the configured functions and send the data back up to the master.
    The functions to be called are merged from the master config, pillar and
    minion config under the option `mine_functions`:

    .. code-block:: yaml

        mine_functions:
          network.ip_addrs:
            - eth0
          disk.usage: []

    This function accepts the following arguments:

    :param bool clear: Default: ``False``
        Specifies whether updating will clear the existing values (``True``), or
        whether it will update them (``False``).

    :param dict mine_functions:
        Update (or clear, see ``clear``) the mine data on these functions only.
        This will need to have the structure as defined on
        https://docs.saltproject.io/en/latest/topics/mine/index.html#mine-functions

        This feature can be used when updating the mine for functions
        that require a refresh at different intervals than the rest of
        the functions specified under `mine_functions` in the
        minion/master config or pillar.
        A potential use would be together with the `scheduler`, for example:

        .. code-block:: yaml

            schedule:
              lldp_mine_update:
                function: mine.update
                kwargs:
                    mine_functions:
                      net.lldp: []
                hours: 12

        In the example above, the mine for `net.lldp` would be refreshed
        every 12 hours, while  `network.ip_addrs` would continue to be updated
        as specified in `mine_interval`.

    The function cache will be populated with information from executing these
    functions

    CLI Example:

    .. code-block:: bash

        salt '*' mine.update
    �config.merge�mine_functionsNcSsi|]}|i�qSr	r	)�.0�funr	r	r
�
<dictcomp>�szupdate.<locals>.<dictcomp>z,Function %s in mine.update failed to execute�	Error: %s�	allow_tgt)rr*�listr+�itemsrr�mine�parse_function_definitionr�	functools�
call_function�	Exception�	traceback�
format_excrr�debugr�wrap_acl_structurer/)r)r1r-�function_alias�
function_data�
function_name�
function_args�function_kwargs�
minion_acl�res�tracer	r	r
r,nsZ5�

�
��
���
��

r,c

Os�tjjjd	i|��}|�dd�}|�dd�}|�dd�}i}ztjjjt|p'|g|�Ri|��}Wn%tyW}zt	�
�}	t�d|pD|�t�
d|	�WYd}~dSd}~ww|rjtjjj|||d�||<t|�S|||<t|�S)
a�
    Send a specific function and its result to the salt mine.
    This gets stored in either the local cache, or the salt master's cache.

    :param str name: Name of the function to add to the mine.

    The following pameters are extracted from kwargs if present:

    :param str mine_function: The name of the execution_module.function to run
        and whose value will be stored in the salt mine. Defaults to ``name``.
    :param str allow_tgt: Targeting specification for ACL. Specifies which minions
        are allowed to access this function. Please note both your master and
        minion need to be on, at least, version 3000 for this to work properly.

    :param str allow_tgt_type: Type of the targeting specification. This value will
        be ignored if ``allow_tgt`` is not specified. Please note both your
        master and minion need to be on, at least, version 3000 for this to work
        properly.

    Remaining args and kwargs will be passed on to the function to run.

    :rtype: bool
    :return: Whether executing the function and storing the information was successful.

    .. versionchanged:: 3000

        Added ``allow_tgt``- and ``allow_tgt_type``-parameters to specify which
        minions are allowed to access this function.
        See :ref:`targeting` for more information about targeting.

    CLI Example:

    .. code-block:: bash

        salt '*' mine.send network.ip_addrs interface=eth0
        salt '*' mine.send eth0_ip_addrs mine_function=network.ip_addrs interface=eth0
        salt '*' mine.send eth0_ip_addrs mine_function=network.ip_addrs interface=eth0 allow_tgt='G@grain:value' allow_tgt_type=compound
    �
mine_functionNr6�allow_tgt_typez*Function %s in mine.send failed to executer5F)r6rKr	)rr�argsZclean_kwargs�popr;r<rr=r>r?rrr@r9rAr/)
�namerL�kwargsrJr6rKr-rH�excrIr	r	r
r�s6'
��
���
��r�globcCs.tddkryi}td|��|�}|s|Stdd�}t|t�s"|St|t�r7tt|�d���}t|�dk}nt|t�rA|}d}n|S|D]1}	|	|vrLqEt	j
jj||	vr_||	t	j
jj
}
n||	}
|rp|
|�|	i�td	<qE|
|td	<qE|Sd
td	|||d�}t|t�}|r�td	|vr�|td	=|S)a
    Get data from the mine.

    :param str tgt: Target whose mine data to get.
    :param fun: Function to get the mine data of. You can specify multiple functions
        to retrieve using either a list or a comma-separated string of functions.
    :type fun: str or list
    :param str tgt_type: Default ``glob``. Target type to use with ``tgt``.
        See :ref:`targeting` for more information.
        Note that all pillar matches, whether using the compound matching system or
        the pillar matching system, will be exact matches, with globbing disabled.
    :param bool exclude_minion: Excludes the current minion from the result set.

    CLI Example:

    .. code-block:: bash

        salt '*' mine.get '*' network.interfaces
        salt '*' mine.get 'os:Fedora' network.interfaces grain
        salt '*' mine.get 'G@os:Fedora and S@192.168.5.0/24' network.ipaddrs compound

    .. seealso:: Retrieving Mine data from Pillar and Orchestrate

        This execution module is intended to be executed on minions.
        Master-side operations such as Pillar or Orchestrate that require Mine
        data should use the :py:mod:`Mine Runner module <salt.runners.mine>`
        instead; it can be invoked from a Pillar SLS file using the
        :py:func:`saltutil.runner <salt.modules.saltutil.runner>` module. For
        example:

        .. code-block:: jinja

            {% set minion_ips = salt.saltutil.runner('mine.get',
                tgt='*',
                fun='network.ip_addrs',
                tgt_type='glob') %}
    r!r"zmatch.r#r$�,�Tr&r )r'r&�tgtr3�tgt_type)rrr*r+�strr7�set�split�lenrrr9ZMINE_ITEM_ACL_IDZMINE_ITEM_ACL_DATA�
setdefaultr )rTr3rUZexclude_minion�retZ	is_targetr(Z	functionsZ	_ret_dict�functionrHrr	r	r
rsF'


�

rcCsXtddkrtdd�}t|t�r||vr||=tdd|�Sdtd|d�}t|t�S)	z�
    Remove specific function contents of minion.

    :param str fun: The name of the function.
    :rtype: bool
    :return: True on success.

    CLI Example:

    .. code-block:: bash

        salt '*' mine.delete 'network.interfaces'
    r!r"r#r$r%Z_mine_deleter&)r'r&r3)rrr*r+r)r3r(rr	r	r
�deletegs�
r]cCs2tddkr
tddi�Sdtdd�}t|t�S)z�
    Remove all mine contents of minion.

    :rtype: bool
    :return: True on success

    CLI Example:

    .. code-block:: bash

        salt '*' mine.flush
    r!r"r%r$Z_mine_flushr&)r'r&)rrr)rr	r	r
�flush�s
�
r^c	Csh|rg}|�t|t�r
|n|g�|}|r&g}|�t|t�r |n|g�|}d}td|�}i}|��D]�}|�d�}	g}
|sZ|	d��D]}d|vrX|dD]	}|
�|d�qNqDn%|D]"}
|
|	dvr~d|	d|
vr~|	d|
dD]	}|
�|d�qtq\tt|
��}
|r�g}|D]}|
D]}tj	j
�||g�r�|�|�q�q�tt|��}
|��D]�}|dd}|d	|vr�i||d	<|d
D]l}|�d�}|dkr�|
D],}||d	�d
i��|dg�}d�
||d�}|r�||f}n|}||vr�|�|�q�q�|�r/||d	�d
i��|dg�}d�
|d|d�}|�r#||f}n|}||v�r/|�|�q�q�q3|S)a�
    .. versionchanged:: 2017.7.8,2018.3.3
        When :conf_minion:`docker.update_mine` is set to ``False`` for a given
        minion, no mine data will be populated for that minion, and thus none
        will be returned for it.
    .. versionchanged:: 2019.2.0
        :conf_minion:`docker.update_mine` now defaults to ``False``

    Get all mine data for :py:func:`docker.ps <salt.modules.dockermod.ps_>` and
    run an aggregation routine. The ``interfaces`` parameter allows for
    specifying the network interfaces from which to select IP addresses. The
    ``cidrs`` parameter allows for specifying a list of subnets which the IP
    address must match.

    with_container_id
        Boolean, to expose container_id in the list of results

        .. versionadded:: 2015.8.2

    CLI Example:

    .. code-block:: bash

        salt '*' mine.get_docker
        salt '*' mine.get_docker interfaces='eth0'
        salt '*' mine.get_docker interfaces='["eth0", "eth1"]'
        salt '*' mine.get_docker cidrs='107.170.147.0/24'
        salt '*' mine.get_docker cidrs='["107.170.147.0/24", "172.17.42.0/24"]'
        salt '*' mine.get_docker interfaces='["eth0", "eth1"]' cidrs='["107.170.147.0/24", "172.17.42.0/24"]'
    z	docker.psr�host�
interfacesZinet�addressZInfoZIdZImageZPortsZIPz0.0.0.0Zipv4ZPrivatePortz{}:{}Z
PublicPort)�extendr*r7r�valuesrM�appendrWrr�networkZ	in_subnetrZ�format)r`ZcidrsZwith_container_idZ
interface_Zcidr_r'Zdocker_hostsZproxy_listsZ
containersr_Zhost_ips�infoZip_Z	interface�itemZgood_ipsZcidr�	containerZcontainer_idZ	dock_port�
ip_addressZcontainer_network_footprint�valuer	r	r
�
get_docker�s� 

���
��

��

��
��


���(rlcCs�tddi�}|sdSi}|��D],\}}tjj�|�\}}}}t|p$|�s'q|r9||dd�|��D�i||<q|||<q|S)z|
    List valid entries in mine configuration.

    CLI Example:

    .. code-block:: bash

        salt '*' mine.valid
    r0r1NcSsg|]\}}||i�qSr	r	)r2�keyrkr	r	r
�
<listcomp>+szvalid.<locals>.<listcomp>)rr8rrr9r:r)r1r-rBrCrDrErFrGr	r	r
�valids(
��
�
ro)F)FN)rQF)NNF)$�__doc__�loggingrr>Zsalt.channel.clientrZ
salt.cryptZsalt.payloadZsalt.transportZsalt.utils.argsZsalt.utils.dictupdateZsalt.utils.eventZsalt.utils.functoolsZsalt.utils.mineZsalt.utils.minionsZsalt.utils.networkZsalt.exceptionsr�	frozensetZMINE_INTERNAL_KEYWORDSZ__proxyenabled__�	getLogger�__name__rrrrr r/r,rrr]r^rlror	r	r	r
�<module>sB�
	

b
?X
w