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/utils/__pycache__/napalm.cpython-310.pyc
o

�N�g�\�@s8dZddlZddlZddlZddlZddlmZddlZddl	Zddl
Zz ddlZdZze
ej�d�d�ZWneyBdZYnwWneyOdZYnwz
ddlmZdZWneyedZYnwe�e�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zddd�Zddd�Z dd�Z!dd�Z"ddd�Z#dS) a�
Utils for the NAPALM modules and proxy.

.. seealso::

    - :mod:`NAPALM grains: select network devices based on their characteristics <salt.grains.napalm>`
    - :mod:`NET module: network basic features <salt.modules.napalm_network>`
    - :mod:`NTP operational and configuration management module <salt.modules.napalm_ntp>`
    - :mod:`BGP operational and configuration management module <salt.modules.napalm_bgp>`
    - :mod:`Routes details <salt.modules.napalm_route>`
    - :mod:`SNMP configuration module <salt.modules.napalm_snmp>`
    - :mod:`Users configuration management <salt.modules.napalm_users>`

.. versionadded:: 2017.7.0
�N��wrapsT�.F)�ConnectionClosedExceptioncCs"tjj��o|�di��d�dkS)z!
    Is this a NAPALM proxy?
    �proxyZ	proxytype�napalm)�salt�utils�platform�is_proxy�get��opts�r�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/napalm.pyr:s�rcCs|�di��dd�S)z#
    Is always alive required?
    r�always_aliveT)rr
rrr�is_always_aliveDsrcCst|�r	t|�pt|�S)z,
    Should this proxy be always alive?
    )rr�	is_minionr
rrr�not_always_aliveKsrcCstjj��o
d|vS)z+
    Is this a NAPALM straight minion?
    r)rr	r
rr
rrrrRsrcCs6trtdkrt|�st|�r|Sdd|�d|�d�fS)z"
    Returns the __virtual__.
    �F�"z" (zC) cannot be loaded: NAPALM is not installed: ``pip install napalm``)�
HAS_NAPALM�NAPALM_MAJORrr)rZvirtualname�filenamerrr�virtualYs
�rc
OsBd}d}|�di�}|�dd�}|�dd�}|rCt�d�t�d�t�|d	�|d	jd'i|��t�d
�t�|d	�t|�}�z=z4|�dd�sPtd��i}	|	�|�|	��D]
\}
}|durh|�|
�q[t|�d
�|�|i|��}d}Wn�t�yj}z�|�dd�}
t	�
�}t|t�r�dj
||�d�d�}n�|�r
t�r
t|t��r
d|d<dj
|
d�}t�|�t�|�t�d|
�t|ddd�t�d|
�t|ddd�t�d|
�t�d|�t||g|�Ri|��WYd}~W|�r
t|��r|�dd��r|d
��SSSSdj
|�dd�|�di��d��r+d j
|�di��d�d!�nd"|�d#d"�||d$�}t�|�t�|�id||d%�WYd}~W|�rct|��rd|�dd��re|d
��SSSSd}~wwW|�r�t|��r�|�dd��r�|d
��n|�r�t|��r�|�dd��r�|d
��wwww||d"d&�S)(a�
    Calls arbitrary methods from the network driver instance.
    Please check the readthedocs_ page for the updated list of getters.

    .. _readthedocs: http://napalm.readthedocs.org/en/latest/support/index.html#getters-support-matrix

    method
        Specifies the name of the method to be called.

    *args
        Arguments.

    **kwargs
        More arguments.

    :return: A dictionary with three keys:

        * result (True/False): if the operation succeeded
        * out (object): returns the object as-is from the call
        * comment (string): provides more details in case the call failed
        * traceback (string): complete traceback in case of exception.         Please submit an issue including this traceback         on the `correct driver repo`_ and make sure to read the FAQ_

    .. _`correct driver repo`: https://github.com/napalm-automation/napalm/issues/new
    .. FAQ_: https://github.com/napalm-automation/napalm#faq

    Example:

    .. code-block:: python

        salt.utils.napalm.call(
            napalm_object,
            'cli',
            [
                'show version',
                'show chassis fan'
            ]
        )
    FN�__opts__�__retryT�force_reconnectzForced reconnection initiatedz'The current opts (under the proxy key):rzUpdated to:�UPz
not connected�DRIVER�HOSTNAME�[unspecified hostname]z;{method} is not implemented for the NAPALM {driver} driver!�DRIVER_NAME)�method�driverz0Disconnected from {device}. Trying to reconnect.)�devicezClearing the connection with %s�close�rz!Re-opening the connection with %s�openzConnection re-opened with %szRe-executing %sZCLOSEzGCannot execute "{method}" on {device}{port} as {user}. Reason: {error}!�
OPTIONAL_ARGS�port�:{port}�r*��USERNAME)r%r*�userr#�error)�out�result�comment�	traceback)r1r2r3r)r�pop�log�debug�update�
get_device�	Exception�items�getattrr4�
format_exc�
isinstance�NotImplementedError�format�HAS_CONN_CLOSED_EXC_CLASSrr0�callrr&)�
napalm_devicer#�args�kwargsr2r1rZretryrZkwargs_copyZkargZwargr0�hostnameZerr_tbr3rrrrBgs�)




��

������

$)��
��
��

����P���rBcCsZi}t|�r|�di�n|�di�}|�d�s|�d�r$|�dd�|d<|s+t�d�|�d�p>|�d�p>|�d�p>|�d	�|d
<|�d�pJ|�d�|d
<|�d�pV|�d�|d<|�d�pi|�d�pi|�d�pid|d<|�dd�|d<|�di�|d<|�dd�|d<|�d�|d<d|d <d!|dvr�d|dd!<|dr�d"|dvr�d#|dd"<|S)$zh
    Returns the options of the napalm device.
    :pram: opts
    :return: the network device opts
    rr�multiprocessingFzHIncorrect minion config. Please specify at least the napalm driver name!�hostrF�fqdn�ipr �usernamer/r.r$�osr"�passwd�password�passr-�PASSWORD�timeout�<�TIMEOUT�
optional_argsr)rTZALWAYS_ALIVEZprovider�PROVIDERrZconfig_lockZ	keepalive�)rrr6r0)r�salt_obj�network_deviceZdevice_dictrrr�get_device_optssH �
���
����rYc
Csht�d�t||d�}tj}|�d�r;z
t�|�d��}Wnty:}ztj	d|�d�dd�WYd}~nd}~ww|�
|�d��}z)||�d	d
�|�dd
�|�dd
�|d
|dd�|d<|�d���d|d<W|Stjjj
y�}z8dj|�d	d�|�di��d�r�dj|�di��d�d�nd
|�dd
�d�}t�	|�t�	d|�tjj�
|��d}~ww)z�
    Initialise the connection with the network device through NAPALM.
    :param: opts
    :return: the network device object
    zSetting up NAPALM connection�rWrUzUnable to import %sT)�exc_infoNr"r r-r.rPrSr))rQrTrrz1Cannot connect to {hostname}{port} as {username}.r!r*r+r,)rFr*rKzPlease check error: %s)r6r7rYr�baser�	importlib�
import_module�ImportErrorr0Zget_network_driverr(�
exceptions�ConnectionExceptionr@)rrWrXZprovider_libZierrZ_driver_r0Zbase_err_msgrrrr95sN

���



�
�
��
�
��r9cst���fdd��}|S)ae
    This decorator is used to make the execution module functions
    available outside a proxy minion, or when running inside a proxy
    minion. If we are running in a proxy, retrieve the connection details
    from the __proxy__ injected variable.  If we are not, then
    use the connection information from the opts.
    :param func:
    :return:
    c
s4�j}|�d�}t�|�d��}|�di��dd�}|�dd�}|rIt�d�t�d	�t�|d�|djd!i|��t�d
�t�|d�t|�rb|rb|rYt|�|d<�n|d�|d<�nt|�r�|s�d
|vstd
|vr�|d
s�zt|�|d<Wn�t	j
jjy�}zt�
|�djt|j�d�WYd}~Sd}~ww|d
|d<n�t�d�|�d�}|ddi�}	|ddi�}
t�d�t�|	�tjjjd!i|��}|	�|�t�d�t�|	�|	�d�p�|	�d�p�|	�d�p�|	�d�}|�r&|
�r&t|
t��r&||
v�r&|
|}
t�d|�t�|
�|	�|
�t�d|�t�|	�t�|�}|	|d<d
|v�s>d
|v�rm|d
�smz
t||d�|d<Wn*t	j
jj�yl}zt�
|�djt|j�d�WYd}~Sd}~ww|d
|d<t|��r~||dd<�|i|��}|�r�t�d�|d}t|ddd �}|S)"NZ	__proxy__rrrTrFz!Usage of reconnect force detectedzOpts before mergingzOpts after mergingrCznapalm.get_deviceZinherit_napalm_devicez {base_msg}. See log for details.)Zbase_msgz$Not running in a NAPALM Proxy MinionZ__salt__z
config.getr�napalm_inventoryz&NAPALM opts found in the Minion configz(Merging the found opts with the CLI argsrHrFrIrJz!Found %s in the NAPALM inventory:zIMerging the config for %s with the details found in the napalm inventory:rZz3That was a forced reconnect, gracefully clearing upr&r'r)�__globals__r�copy�deepcopyr6r7r8rr9rr\r`rar0r@�str�msgrr	rD�clean_kwargsr>�dictrrB)rDrEZwrapped_global_namespacerrrrZnceZ	_salt_objZnapalm_optsrbrhrHZinventory_opts�retr%�closing��funcrr�func_wrapperps�



�
���
�
	






������


�



��
����

z'proxy_napalm_wrap.<locals>.func_wrapperr)rmrnrrlr�proxy_napalm_wrapes
rocCs|iddd�}|S)z6
    Return the default dict of the state output.
    Fr-)�name�changesr2r3r)rprjrrr�default_retsrrcCsBi}|d|d<d|vr|d|d<d|vr|d|d<d|vr(|r(|d|d<|r4d|vr4|d|d<|�d�rFdj|d|dd�|d<|�d�rXdj|d|dd	�|d<|�d�rqd
j|dtjj|dd|d�d
�|d<|�dd�sy|S|�dd�s�|r�d|d<|S|�d|d�|d�d��|S|�did��|S)z�
    Return the final state output.
    ret
        The initial state output structure.
    loaded
        The loaded dictionary.
    r3�diffZ	commit_id�compliance_reportZ
loaded_configz+{comment_base}

Configuration diff:

{diff})�comment_basersz,{comment_base}

Loaded config:

{loaded_cfg})ruZ
loaded_cfgz0{comment_base}

Compliance report:

{compliance}�nestedr
)ruZ
compliancer2FZalready_configuredTNzConfiguration changed!
{})r2rqr3)r2rq)rr@r�outputZ
string_formatr8)rjZloaded�testr7rtrrqrrr�
loaded_retsR	

�

�

�
���ry)N)FN)$�__doc__rdr]�loggingr4�	functoolsrZsalt.outputrZsalt.utils.argsZsalt.utils.platformrr�int�__version__�splitr�AttributeErrorr_Znapalm.base.exceptionsrrA�	getLogger�__file__r6rrrrrrBrYr9rorrryrrrr�<module>sR����



20