File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/defaults.cpython-310.pyc
Back
o ;j7 � @ s� d Z ddlZddlZddlZddlZddlZddlm m Z ddl ZddlZddlZddl ZdZe�e�Zdd� Zdd� Zdd d �Zdd d�Zdd� Zddd�ZdS )z2 Module to work with salt formula defaults files � N�defaultsc C s t j�t�S )z8 Create a file client and add it to the context )�saltZ fileclientZget_file_clientZ__opts__� r r �I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/defaults.py� _mk_client s r c C s g }dD ]}t jj�| d | �}|�|� qt� � }|�|�}W d � n1 s*w Y |D ][}|s6q1|�dd�d }|dkrHt jjj }n|dkrRt jj j}nt� d |� q1tj�|�r�t� d |� t jj�|��} || �} t� d| � W d � n1 s�w Y | p�i S q1dS )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�.� ���r r z!Failed to determine loader for %rzReading defaults from %rzRead defaults %r)r �utils�url�create�appendr Zcache_files�rsplitr Z safe_loadr �load�log�debug�os�path�exists�filesZfopen)Zformula�paths�extZ source_url�clientZdefaults_filesZfile_�suffix�loaderZfhrr r r r �_load s4 ����r � c C sF d| v r | � 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)�splitr r r �dataZtraverse_dict_and_list)�key�default� namespacer r r r �getF s r% FTc C sT |du r|ri n|}| du r|r|rt d��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&