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

�N�g7�@s�dZddlZddlZddlZddlZddlZddlmm	Z	ddl
ZddlZddlZddl
ZdZe�e�Zdd�Zdd�Zdd	d
�Zdd
d�Zdd�Zddd�ZdS)z2
Module to work with salt formula defaults files

�N�defaultscCstj�t�S)z8
    Create a file client and add it to the context
    )�saltZ
fileclientZget_file_clientZ__opts__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/defaults.py�
_mk_clientsrc	Csg}dD]}tjj�|d|�}|�|�qt��
}|�|�}Wd�n1s*wY|D][}|s6q1|�dd�d}|dkrHtjjj	}n|dkrRtjj
j}nt�
d	|�q1tj�|�r�t�
d
|�tjj�|��}	||	�}
t�
d|
�Wd�n1s�wY|
p�iSq1dS)z�
    Generates a list of salt://<formula>/defaults.(json|yaml) files
    and fetches them from the Salt master.

    Returns first defaults file as python dict.
    )�yaml�jsonz
/defaults.N�.����rrz!Failed to determine loader for %rzReading defaults from %rzRead defaults %r)r�utils�url�create�appendrZcache_files�rsplitrZ	safe_loadr�load�log�debug�os�path�exists�filesZfopen)Zformula�paths�extZ
source_url�clientZdefaults_filesZfile_�suffix�loaderZfhrrrrr�_loads4	����r�cCsFd|vr
|�dd�\}}n|d}}t|�}|r!tjj�|||�S|S)a
    defaults.get is used much like pillar.get except that it will read
    a default value for a pillar from defaults.json or defaults.yaml
    files that are stored in the root of a salt formula.

    CLI Example:

    .. code-block:: bash

        salt '*' defaults.get core:users:root

    The defaults is computed from pillar key. The first entry is considered as
    the formula namespace.

    For example, querying ``core:users:root`` will try to load
    ``salt://core/defaults.yaml`` and ``salt://core/defaults.json``.
    �:r
N)�splitrrr�dataZtraverse_dict_and_list)�key�default�	namespacerrrr�getFs
r%FTcCsT|dur|rin|}|dur|r|rtd��i}|r|}nt�|�}tj|||d�S)a$
    defaults.merge
        Allows deep merging of dicts in formulas.

    merge_lists : False
        If True, it will also merge lists instead of replace their items.

    in_place : True
        If True, it will merge into dest dict,
        if not it will make a new copy from that dict and return it.

    convert_none : True
        If True, it will convert src and dest to empty dicts if they are None.
        If True and dest is None but in_place is True, raises TypeError.
        If False it will make a new copy from that dict and return it.

        .. versionadded:: 3005

    CLI Example:

    .. code-block:: bash

        salt '*' defaults.merge '{a: b}' '{d: e}'

    It is more typical to use this in a templating language in formulas,
    instead of directly on the command-line.
    Nz*Can't perform in-place merge into NoneType)�merge_lists)�	TypeError�copy�deepcopy�
dictupdate�update)�dest�srcr&�in_place�convert_noneZmergedrrr�mergeis
r0cCs
t�|�S)a2
    defaults.deepcopy
        Allows deep copy of objects in formulas.

        By default, Python does not copy objects,
        it creates bindings between a target and an object.

    It is more typical to use this in a templating language in formulas,
    instead of directly on the command-line.
    )r(r))�sourcerrrr)�s
r)c	Cs�|r
|dur
td��|}n|dur|rin|}t|�}|dur#|r#in|}|��D]\}}t|�}t||||d�}|||<q)|S)aB
    defaults.update
        Allows setting defaults for group of data set e.g. group for nodes.

        This function is a combination of defaults.merge
        and defaults.deepcopy to avoid redundant in jinja.

        Example:

        .. code-block:: yaml

            group01:
              defaults:
                enabled: True
                extra:
                  - test
                  - stage
              nodes:
                host01:
                  index: foo
                  upstream: bar
                host02:
                  index: foo2
                  upstream: bar2

        .. code-block:: jinja

            {% do salt['defaults.update'](group01.nodes, group01.defaults) %}

        Each node will look like the following:

        .. code-block:: yaml

            host01:
              enabled: True
              index: foo
              upstream: bar
              extra:
                - test
                - stage

    merge_lists : True
        If True, it will also merge lists instead of replace their items.

    in_place : True
        If True, it will merge into dest dict.
        if not it will make a new copy from that dict and return it.

    convert_none : True
        If True, it will convert src and dest to empty dicts if they are None.
        If True and dest is None but in_place is True, raises TypeError.
        If False it will make a new copy from that dict and return it.

        .. versionadded:: 3005

    It is more typical to use this in a templating language in formulas,
    instead of directly on the command-line.
    Nz+Can't perform in-place update into NoneType)r&r/)r'r)�itemsr0)	r,rr&r.r/ZnodesZ	node_nameZ	node_varsZ
defaults_varsrrrr+�s<�
r+)r)FTT)TTT)�__doc__r(�loggingrZsalt.fileclientrZsalt.utils.dataZsalt.utils.dictupdaterr*Zsalt.utils.filesZsalt.utils.jsonZsalt.utils.urlZsalt.utils.yamlZ__virtualname__�	getLogger�__name__rrrr%r0r)r+rrrr�<module>s&

(
#+