File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/nxos.cpython-310.pyc
o
�N�gKb � @ s� d Z ddlZddlZddlZddlZddlmZ ddlZ ddl
Z ddlmZm
Z
mZ ddlmZ ddlmZ ddlmZ dZe�e�Zd i iZd
ZdZdd
� Zdd� ZdKdd�Zdd� Zdd� Z dd� Z!dd� Z"dd� Z#dd� Z$dd � Z%dLd"d#�Z&dMd%d&�Z'd'd(� Z(d)d*� Z)d+d,� Z*d-d.� Z+ / 0dNd1d2�Z,d3d4� Z-d5d6� Z.d7d8� Z/dKd9d:�Z0d;d<� Z1 =dOd>d?�Z2d@dA� Z3dBdC� Z4dDdE� Z5dFdG� Z6dPdIdJ�Z7dS )Qa#
Execution module for Cisco NX OS Switches.
.. versionadded:: 2016.11.0
This module supports execution using a Proxy Minion or Native Minion:
1) Proxy Minion: Connect over SSH or NX-API HTTP(S).
See :mod:`salt.proxy.nxos <salt.proxy.nxos>` for proxy minion setup details.
2) Native Minion: Connect over NX-API Unix Domain Socket (UDS).
Install the minion inside the GuestShell running on the NX-OS device.
:maturity: new
:platform: nxos
.. note::
To use this module over remote NX-API the feature must be enabled on the
NX-OS device by executing ``feature nxapi`` in configuration mode.
This is not required for NX-API over UDS.
Configuration example:
.. code-block:: bash
switch# conf t
switch(config)# feature nxapi
To check that NX-API is properly enabled, execute ``show nxapi``.
Output example:
.. code-block:: bash
switch# show nxapi
nxapi enabled
HTTPS Listen on port 443
Native minion configuration options:
.. code-block:: yaml
nxos:
cookie: 'username'
save_config: False
cookie
Use the option to override the default cookie 'admin:local' when
connecting over UDS and use 'username:local' instead. This is needed when
running the salt-minion in the GuestShell using a non-admin user.
This option is ignored for SSH and NX-API Proxy minions.
save_config:
If True, 'copy running-config starting-config' is issues for every
configuration command.
If False, Running config is not saved to startup config
Default: True
The recommended approach is to use the `save_running_config` function
instead of this option to improve performance. The default behavior
controlled by this option is preserved for backwards compatibility.
The APIs defined in this execution module can also be executed using
salt-call from the GuestShell environment as follows.
.. code-block:: bash
salt-call --local nxos.sendline 'show lldp neighbors' raw_text
.. note::
The functions in this module should be executed like so:
salt '*' nxos.<function>
salt '*' nxos.get_user username=admin
For backwards compatibility, the following syntax will be supported
until the 3001 release.
salt '*' nxos.cmd <function>
salt '*' nxos.cmd get_user username=admin
� N)�error)�CommandExecutionError� NxosError�SaltInvocationError)�clean_kwargs)�gen_hash)�
warn_until�nxos�grains_cachez"copy running-config startup-configa`
Unable to send command to the NX-OS device.
Please verify the following and re-try:
- 'feature ssh' must be enabled for SSH proxy minions.
- 'feature nxapi' must be enabled for NX-API proxy minions.
- Settings in the proxy minion configuration file must match device settings.
- NX-OS device is reachable from the Salt Master.
c C s t S )N)�__virtualname__� r r �E/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/nxos.py�__virtual__t s r c K s( t jj�� rtd � S td di | ��S )zr
Ping the device on the other end of the connection.
.. code-block: bash
salt '*' nxos.ping
z nxos.pingNr )�salt�utils�platform�is_proxy� __proxy__� __utils__��kwargsr r r
�pingx s
r Fc K s� ddddd�}t | fi |��}|sdS d|v rdS t�d |��d
�}|du r;t�d|��� \}}} t|||| d�}
n|}
|
|krCd
S dS )a�
Verify user password.
username
Username on which to perform password check
password
Password to check
encrypted
Whether or not the password is encrypted
Default: False
.. code-block: bash
salt '*' nxos.check_password username=admin password=admin
salt '*' nxos.check_password username=admin \
password='$5$2fWwO2vK$s7.Hr3YltMNHuhywQQ3nfOd.gAPHgs3SOBYYdGT3E.A' \
encrypted=True
�md5�blowfish�sha256�sha512)�1Z2a�5�6N�!Fz(\$[0-6](?:\$[^$ ]+)+)r z^\$([0-6])\$([^$]+)\$(.*)$��
crypt_salt�password� algorithmT)�get_user�re�search�group�groupsr )�usernamer"