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__/match.cpython-310.pyc
o

�N�g4�@sdZddlZddlZddlZddlZddlmZddlZddl	m
Z
ddlmZddl
mZddiZe�e�Zd	d
�Zd'dd�Zd
d�Ze
fdd�Ze
fdd�Zdd�Ze
fdd�Ze
fdd�Zd'dd�Zd'dd�Zd'dd�Z					d(d d!�Zd)d"d#�Zed$�ddddd%�d&d$��Z dS)*zQ
The match module allows for match routines to be run and determine target specs
�N)�Mapping)�DEFAULT_TARGET_DELIM)�
SaltException)�jinja_global�list_�listcCstj�t�td<dS)zC
    Store matchers in __context__ so they're only loaded once
    �matchersN)�salt�loaderr�__opts__�__context__�r
r
�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/match.py�_load_matcherssrc
Csz|dur
t|t�s
t|�}dtvrt�ztdd|t|d�}W|Sty<}zt�|�d}WYd}~|Sd}~ww)a"
    Return True if the minion ID matches the given compound target

    minion_id
        Specify the minion ID to match against the target expression

        .. versionadded:: 2014.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' match.compound 'L@cheese,foo and *'
    Nrzcompound_match.match��opts�	minion_idF��
isinstance�strrrr�	Exception�log�	exception)�tgtr�ret�excr
r
r�compounds 

��
��rc
C�Vdtvrt�ztdd|td�WSty*}zt�|�WYd}~dSd}~ww)a/
    Return True if the minion matches the given ipcidr target

    CLI Example:

    .. code-block:: bash

        salt '*' match.ipcidr '192.168.44.0/24'

    delimiter
    Pillar Example:

    .. code-block:: yaml

       '172.16.0.0/12':
         - match: ipcidr
         - nodeclass: internal

    rzipcidr_match.match�rNF�rrrrrr�rrr
r
r�ipcidr;s
��r!c
C�Xdtvrt�ztdd||td�WSty+}zt�|�WYd}~dSd}~ww)ar
    Return True if the minion matches the given pillar_pcre target. The
    ``delimiter`` argument can be used to specify a different delimiter.

    CLI Example:

    .. code-block:: bash

        salt '*' match.pillar_pcre 'cheese:(swiss|american)'
        salt '*' match.pillar_pcre 'clone_url|https://github\.com/.*\.git' delimiter='|'

    delimiter
        Specify an alternate delimiter to use when traversing a nested dict

        .. versionadded:: 2014.7.0

    delim
        Specify an alternate delimiter to use when traversing a nested dict

        .. versionadded:: 0.16.4
        .. deprecated:: 2015.8.0
    rzpillar_pcre_match.match��	delimiterrNFr�rr$rr
r
r�pillar_pcreX�
�
��r&c
Cr")a`
    Return True if the minion matches the given pillar target. The
    ``delimiter`` argument can be used to specify a different delimiter.

    CLI Example:

    .. code-block:: bash

        salt '*' match.pillar 'cheese:foo'
        salt '*' match.pillar 'clone_url|https://github.com/saltstack/salt.git' delimiter='|'

    delimiter
        Specify an alternate delimiter to use when traversing a nested dict

        .. versionadded:: 2014.7.0

    delim
        Specify an alternate delimiter to use when traversing a nested dict

        .. versionadded:: 0.16.4
        .. deprecated:: 2015.8.0
    rzpillar_match.matchr#NFrr%r
r
r�pillarzr'r(c
Cr)z�
    Return True if the minion matches the given data target

    CLI Example:

    .. code-block:: bash

        salt '*' match.data 'spam:eggs'
    rzdata_match.matchrNFrr r
r
r�data�s

��r)c
Cr")aH
    Return True if the minion matches the given grain_pcre target. The
    ``delimiter`` argument can be used to specify a different delimiter.

    CLI Example:

    .. code-block:: bash

        salt '*' match.grain_pcre 'os:Fedo.*'
        salt '*' match.grain_pcre 'ipv6|2001:.*' delimiter='|'

    delimiter
        Specify an alternate delimiter to use when traversing a nested dict

        .. versionadded:: 2014.7.0

    delim
        Specify an alternate delimiter to use when traversing a nested dict

        .. versionadded:: 0.16.4
        .. deprecated:: 2015.8.0
    rzgrain_pcre_match.matchr#NFrr%r
r
r�
grain_pcre�r'r*c
Cr")aH
    Return True if the minion matches the given grain target. The ``delimiter``
    argument can be used to specify a different delimiter.

    CLI Example:

    .. code-block:: bash

        salt '*' match.grain 'os:Ubuntu'
        salt '*' match.grain 'ipv6|2001:db8::ff00:42:8329' delimiter='|'

    delimiter
        Specify an alternate delimiter to use when traversing a nested dict

        .. versionadded:: 2014.7.0

    delim
        Specify an alternate delimiter to use when traversing a nested dict

        .. versionadded:: 0.16.4
        .. deprecated:: 2015.8.0
    rzgrain_match.matchr#NFrr%r
r
r�grain�r'r+c
C�r|dur
t|t�s
t|�}dtvrt�ztdd|t|d�WSty8}zt�|�WYd}~dSd}~ww)a
    Return True if the minion ID matches the given list target

    minion_id
        Specify the minion ID to match against the target expression

        .. versionadded:: 2014.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' match.list 'server1,server2'
    Nrzlist_match.matchrFr�rrrr
r
rr��

�
��c
Cr,)a

    Return True if the minion ID matches the given pcre target

    minion_id
        Specify the minion ID to match against the target expression

        .. versionadded:: 2014.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' match.pcre '.*'
    Nrzpcre_match.matchrFrr-r
r
r�pcrer.r/c
Cr,)a	
    Return True if the minion ID matches the given glob target

    minion_id
        Specify the minion ID to match against the target expression

        .. versionadded:: 2014.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' match.glob '*'
    Nrzglob_match.matchrFrr-r
r
r�glob-s

�
��r0F�defaultc	Cs�ttjtjttjd��}|D];}|r||fn|f}|||�rJ|rDt|t�s+t	d��||dur5|St
jjj
||t�|�|d�||Sq|�|d�S)aT
    Return the first match in a dictionary of target patterns

    .. versionadded:: 2014.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' match.filter_by '{foo*: Foo!, bar*: Bar!}' minion_id=bar03

    Pillar Example:

    .. code-block:: jinja

        # Filter the data for the current minion into a variable:
        {% set roles = salt['match.filter_by']({
            'web*': ['app', 'caching'],
            'db*': ['db'],
        }, minion_id=grains['id'], default='web*') %}

        # Make the filtered data available to Pillar:
        roles: {{ roles | yaml() }}
    ��	predicatez.filter_by merge argument must be a dictionary.N)�merge_lists)�dict�inspect�
getmembers�sys�modules�__name__�
isfunctionrrrr	�utilsZ
dictupdate�update�copy�deepcopy�get)	�lookup�tgt_typer�merger4r1�
expr_funcs�key�paramsr
r
r�	filter_byKs& �
���rGc	Csjttjtjttjd��}g}|��D]\}}|D]}|r!||fn|f}|||�r/|�|�qq|p4dS)a
    Search a dictionary of target strings for matching targets

    This is the inverse of :py:func:`match.filter_by
    <salt.modules.match.filter_by>` and allows matching values instead of
    matching keys. A minion can be matched by multiple entries.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' match.search_by '{web: [node1, node2], db: [node2, node]}'

    Pillar Example:

    .. code-block:: jinja

        {% set roles = salt.match.search_by({
            'web': ['G@os_family:Debian not nodeX'],
            'db': ['L@node2,node3 and G@datacenter:west'],
            'caching': ['node3', 'node4'],
        }) %}

        # Make the filtered data available to Pillar:
        roles: {{ roles | yaml() }}
    r2N)	r5r6r7r8r9r:r;�items�append)	rArBrrD�matchesrEZtarget_list�targetrFr
r
r�	search_by�s�
��rL�ifelse)rBrrCr4c
Gs�t|�ddkrtd��t|�dkr|dSd}t|ddd��}t|�D]\}}|dur2d||<q%|d	ur:d
||<q%tt||ddd���}	|	�||di�t|	|||||d�S)
a	
    .. versionadded:: 3006.0

    Evaluate each pair of arguments up to the last one as a (matcher, value)
    tuple, returning ``value`` if matched.  If none match, returns the last
    argument.

    The ``ifelse`` function is like a multi-level if-else statement. It was
    inspired by CFEngine's ``ifelse`` function which in turn was inspired by
    Oracle's ``DECODE`` function. It must have an odd number of arguments (from
    1 to N). The last argument is the default value, like the ``else`` clause in
    standard programming languages. Every pair of arguments before the last one
    are evaluated as a pair. If the first one evaluates true then the second one
    is returned, as if you had used the first one in a compound match
    expression. Boolean values can also be used as the first item in a pair,
    as it will be translated to a match that will always match ("*") or never
    match ("SALT_IFELSE_MATCH_NOTHING") a target system.

    This is essentially another way to express the ``filter_by`` functionality
    in way that's familiar to CFEngine or Oracle users. Consider using
    ``filter_by`` unless this function fits your workflow.

    CLI Example:

    .. code-block:: bash

        salt '*' match.ifelse 'foo*' 'Foo!' 'bar*' 'Bar!' minion_id=bar03
    �rz9The ifelse function must have an odd number of arguments!�ZSALT_IFELSE_FUNCTION_DEFAULTNT�*FZSALT_IFELSE_MATCH_NOTHING���)rArBrrCr4r1)�lenrr�	enumerater5�zipr=rG)
rBrrCr4�argsZdefault_key�keys�idxrErAr
r
rrM�s,$
��)N)rNNFr1)rN)!�__doc__r>r6�loggingr8�collections.abcrZsalt.loaderr	Z
salt.defaultsrZsalt.exceptionsrZsalt.utils.decorators.jinjarZ__func_alias__�	getLoggerr:rrrr!r&r(r)r*r+rr/r0rGrLrMr
r
r
r�<module>sH

"""
"

 
�
9+�