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

�N�g��@s�dZddlZddlZddlZddlZddlmZdgZdZ	e�
e�ZiZ
dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zddd�ZdS)a�
Proxy Minion to manage RESTCONF Devices

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

Usage
=====

.. note::

    To be able to use this module you need to enable RESTCONF on your device
    and have https enabled.

    Cisco Configuration example:

    .. code-block:: bash

        switch# conf t
        switch(config)# restconf
        switch(config)# ip http secure-server

.. note::

    RESTCONF requires modern OS distributions.
    This plugin has been written specifically to use JSON RESTCONF endpoints

Pillar
------

The ``restconf`` proxy configuration requires the following parameters in order
to connect to the network switch:

transport: ``https`` (str)
    Specifies the type of connection transport to use. Valid values for the
    connection are ``https``, and  ``http``.
    The RESTCONF standard explicitly requires https, but http is included as an option
    as some manufacturers have ignored this requirement.

hostname: (str)
    The IP address or DNS host name of the RESTCONF device.

username: (str)
    The username for the device to authenticate the RESTCONF requests.

password: (str)
    The password for the device to authenticate the RESTCONF requests.

verify: ``True`` or ``False`` (str, optional, default:true)
    Verify the RESTCONF SSL certificate?

    When there is no certificate configuration on the device and this option is
    set as ``True`` (default), the commands will fail with the following error:
    ``SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed``.

    .. warning::
      In this case, you either need to configure a proper certificate on the
      device (*recommended*), or bypass the checks setting this argument as ``False``
      with all the security risks considered as you may be MITM'd.

Proxy Pillar Example
--------------------

.. code-block:: yaml

    proxy:
      proxytype: restconf
      host: switch1.example.com
      username: example
      password: example
      verify: false
�N)�
SaltExceptionZrestconfcCstS)zV
    This Proxy Module is widely available as there are no external dependencies.
    )�__virtualname__�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/proxy/restconf.py�__virtual__hsrcCst�d�t�|�di��}|�dd�|d<d|vr!t�d�dSd|vr,t�d	�dSd
|vr7t�d�dSd|vr?d|d<d
|vrGd|d
<|td<z1t�}|drhdtd<dtd<tj	d|ddd�WdSdtd<dtd<tj
d|ddd�WdSty�tj
d|ddd��w)zO
    Required.
    Initialize device config and test an initial connection
    z#RESTCONF proxy init(opts) called...�proxy�multiprocessingT�hostnamez1No 'hostname' key found in pillar for this proxy.F�usernamez1No 'username' key found in pillar for this proxy.�passwordz1No 'password' key found in pillar for this proxy.�verifyZ	transport�https�	conn_argsr�initializedZupzConnected to %s)�exc_infozUnable to connect to %sN)�log�debug�copy�deepcopy�get�pop�critical�restconf_device�connection_test�info�errorr)�optsr�responserrr�initts<



�rcCs4t�d�tdddd�}dt|�vrd|fSd|fS)	zB
    Runs a connection test via http/https. Returns an array.
    z*RESTCONF proxy connection_test() called...zrestconf/yang-library-version�GETN)�method�dict_payloadzyang-library-versionTF)rr�request�str)rrrrr�s

rcCst�d�t�dS)z=
    Triggers connection test.
    Returns True or False
    zRESTCONF proxy ping() called...r)rrrrrrr�ping�s

r$cCst�dd�S)z+
    Connection finished initializing?
    rF)rrrrrrr�srcCst�d|d�dS)z,
    Closes connection with the device.
    z*Shutting down the RESTCONF Proxy Minion %s�idN)rr)rrrr�shutdown�sr&rcCs�|durd}n
t|t�r|}nt�|�}tjjjdjdd|it	d��||ddt	ddt	ddt	dd	d
dgd�	}t
�d
|�|S)z(
    Trigger http request to device
    N�z{transport}://{hostname}/{path}�pathrTrr
rz=Accept: application/yang-data+json,application/yang.data+jsonz(Content-Type: application/yang-data+json)r �data�decode�statusZ
verify_sslr
rZheader_listz#proxy_restconf_request_response: %sr)�
isinstancer#�json�dumps�salt�utils�http�query�formatrrr)r(r r!r)rrrrr"�s0

��


��r")rN)�__doc__rr-�loggingZsalt.utils.httpr/Zsalt.exceptionsrZ__proxyenabled__r�	getLogger�__file__rrrrrr$rr&r"rrrr�<module>s"J
1