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/states/__pycache__/restconf.cpython-310.pyc
o

�N�g��@sXdZddlZddlZddlZddlZddlZe�e�Z	dd�Z
	ddd�Zdd	d
�ZdS)
aRESTCONF
State module for  Proxy minions

:codeauthor: Jamie (Bear) Murphy <jamiemurphyit@gmail.com>
:maturity:   new
:platform:   any

About
=====
This state module was designed to manage RESTCONF states.
This module relies on the RESTCONF proxy module to interface with the devices.
�NcCsdtvrdSdS)N�restconf.set_dataT)Fz#RESTCONF module could not be loaded)�__salt__�rr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/restconf.py�__virtual__sr�PATCHcCs�ddd�}t|�}t|�}t|�}|dkr d|d<t�d�|S|dkr/d|d<t�d�|S|dkr>d	|d<t�d
�|St|tjjj�sTd|d<t�dt|��|S|didd
�}t	d||�}t�
d�t�
|�|dszd|d<d|d<|S|}	|ddkr�i}
|dur�|}	|}|ddkr�|}i|d<t�t�
|	��}t�
dt|d�|d�t�
dt|�|�|d|kr�d|d<d|d<|Stddur�d|d<t|d|�|dd<|d|dd<d|d<|St	d|d ||�}
|
d!d"v�rd|d<t|d|�|dd<|d|dd<d#|d<|Sd|d<d$|
v�r%|
d$}nd%|
v�r/|
d%}nd}d&�|
d!||d �|d<t�
d't�
|��|S)(aQ
    Ensure a specific value exists at a given path

    name:
        (str) The name for this rule

    path:
        (str) The RESTCONF path to set / get config

    method:
        (str) rest method to use eg GET, PUT, POST, PATCH, DELETE

    config:
        (dict) The new value at the given path

    init_path: (optional)
        (str) Alternative path incase the path doesnt exist on first pass

    init_method: (optional)
        (str) Method to use on alternative path when setting config, default: PATCH

    init_config: (optional)
        (dict) The new value at the given init path.
        This is only needed if you need to supply a different style of data to an init path.

    Examples:

    .. code-block:: yaml

        do_configure_restconf_endpoint:
          restconf.config_manage:
            - name: random_name_here
            - path: restconf/data/Cisco-IOS-XE-native:native/interface/GigabitEthernet=1%2F0%2F3
            - config:
                Cisco-IOS-XE-native:GigabitEthernet:
                  description: interfaceDescription
                  name: "1/0/3"

    F�)�result�commentz CRITICAL: path must not be blankr
zpath must not be blankzCRITICAL: name is requiredzname is requiredzCRITICAL: method is requiredzmethod is requiredz,CRITICAL: config must be an OrderedDict typez?config is required, config must be a salt OrderedDict, not a %s)�namer	�changesr
zrestconf.path_checkzpath_check:r	z<RESTCONF could not find a working PATH to get initial configZ	path_used�initNZrequest_restponsez"existing path config(type: %s):
%szproposed_config(type: %s):
%sTzConfig is already set�testr�changedZrest_method_pathzConfig will be addedrZrequest_path�status)������zSuccessfully added config�dict�bodyzLfailed to add / modify config. API Statuscode: {}, API Response: {}, URI: {}zpost_content: %s)�str�log�critical�
isinstance�salt�utilsZodict�OrderedDict�typer�debug�json�loads�dumpsZ__opts__�_compare_changes�format)r�path�methodZconfigZ	init_pathZinit_methodZinit_config�retZ
path_checkZuse_conf�existingZrequest_methodZproposed_configZresp�whyrrr�
config_manages�
*


�

�
�)�� �
���



��r)�yamlcCs�tj|dd���}dd�|D�}tj|dd���}dd�|D�}|dkr8tj|ddd���}tj|ddd���}tj||d	d
d�}d�d
d�|D��}t�	d�t�	|�|S)NF)Zdefault_flow_stylecS�g|]}d|�qS�� r��.0�xrrr�
<listcomp>���z$_compare_changes.<locals>.<listcomp>cSr+r,rr.rrrr1�r2r�)�	sort_keys�indent�beforeZafter)�fromfile�tofile�
cSsg|]}|�dd��qS)r9r)�replacer.rrrr1�sz
resconf_diff:)
r*Z	safe_dump�
splitlinesrr!�difflibZunified_diff�joinrr)�old�newZoutput_styleZold_rawZnew_rawZdiffoutZ	diffcleanrrrr"�s ��

r")NrN)r*)
�__doc__r<r�loggingr*Zsalt.utils.odictr�	getLogger�__file__rrr)r"rrrr�<module>s


�