File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/proxy/__pycache__/nxos.cpython-310.pyc
o
�N�g�= � @ s: d Z ddlZddlZddlZddlZddlZddlmZm Z ddl
mZ ddlm
Z
ddlmZ e�e�ZdgZdZdi iZd ad
d� Zd6dd
�Zdd� Zdd� Zdd� Zdd� Zdd� Zd7dd�Zd6dd�Zd6dd�Z dd � Z!d!d"� Z"d#d$� Z#d6d%d&�Z$d6d'd(�Z%d)d*� Z&d+d,� Z'd-d.� Z(d/d0� Z)d1d2� Z*d8d4d5�Z+dS )9a
Proxy Minion for Cisco NX-OS Switches
.. versionadded:: 2016.11.0
The Cisco NX-OS Proxy Minion is supported on NX-OS devices for the following connection types:
1) Connection Type SSH
2) Connection Type NX-API (If Supported By The Device and Image Version).
:maturity: new
:platform: nxos
SSH uses the built in SSHConnection module in :mod:`salt.utils.vt_helper <salt.utils.vt_helper>`
To configure the proxy minion for ssh:
.. code-block:: yaml
proxy:
proxytype: nxos
connection: ssh
host: 192.168.187.100
username: admin
password: admin
prompt_name: nxos-switch
ssh_args: '-o PubkeyAuthentication=no'
key_accept: True
To configure the proxy minion for nxapi:
.. code-block:: yaml
proxy:
proxytype: nxos
connection: nxapi
host: 192.168.187.100
username: admin
password: admin
transport: http
port: 80
verify: False
save_config: False
proxytype:
(REQUIRED) Use this proxy minion `nxos`
connection:
(REQUIRED) connection transport type.
Choices: `ssh, nxapi`
Default: `ssh`
host:
(REQUIRED) login ip address or dns hostname.
username:
(REQUIRED) login username.
password:
(REQUIRED) login password.
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.
Connection SSH Args:
prompt_name:
(REQUIRED when `connection` is `ssh`)
(REQUIRED, this or `prompt_regex` below, but not both)
The name in the prompt on the switch. Recommended to use your
device's hostname.
prompt_regex:
(REQUIRED when `connection` is `ssh`)
(REQUIRED, this or `prompt_name` above, but not both)
A regular expression that matches the prompt on the switch
and any other possible prompt at which you need the proxy minion
to continue sending input. This feature was specifically developed
for situations where the switch may ask for confirmation. `prompt_name`
above would not match these, and so the session would timeout.
Example:
.. code-block:: yaml
nxos-switch#.*|\(y\/n\)\?.*
This should match
.. code-block:: shell
nxos-switch#
or
.. code-block:: shell
Flash complete. Reboot this switch (y/n)? [n]
If neither `prompt_name` nor `prompt_regex` is specified the prompt will be
defaulted to
.. code-block:: shell
.+#$
which should match any number of characters followed by a `#` at the end
of the line. This may be far too liberal for most installations.
ssh_args:
Extra optional arguments used for connecting to switch.
key_accept:
Whether or not to accept the host key of the switch on initial login.
Default: `False`
Connection NXAPI Args:
transport:
(REQUIRED) when `connection` is `nxapi`.
Choices: `http, https`
Default: `https`
port:
(REQUIRED) when `connection` is `nxapi`.
Default: `80`
verify:
(REQUIRED) when `connection` is `nxapi`.
Either a boolean, in which case it controls whether we verify the NX-API
TLS certificate, or a string, in which case it must be a path to a CA bundle
to use.
Default: `True`
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 (_ssl.c:581)``.
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.
Check https://www.cisco.com/c/en/us/td/docs/switches/datacenter/nexus3000/sw/programmability/6_x/b_Cisco_Nexus_3000_Series_NX-OS_Programmability_Guide/b_Cisco_Nexus_3000_Series_NX-OS_Programmability_Guide_chapter_01.html
to see how to properly configure the certificate.
The functions from the proxy minion can be run from the salt commandline using
the :mod:`salt.modules.nxos<salt.modules.nxos>` execution module.
.. note:
If `multiprocessing: True` is set for the proxy minion config, each forked
worker will open up a new connection to the Cisco NX OS Switch. If you
only want one consistent connection used for everything, use
`multiprocessing: False`
� N)�CommandExecutionError�NxosCliError)�clean_kwargs)�TerminalException)�
SSHConnection�nxos�grains_cache�sshc C s t �d� tS )z6
Only return if all the modules are available
z"nxos proxy __virtual__() called...)�log�info�__virtualname__� r
r
�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/proxy/nxos.py�__virtual__� s
r c C sh t �d��d�durt �d��d�atdkrt�d� t| �S tdkr,t�d� t| �S t�dt� d S )
zX
Required.
Initialize device connection using ssh or nxapi connection type.
�proxy�
connectionNr z+NXOS PROXY: Initialize ssh proxy connection�nxapiz-NXOS PROXY: Initialize nxapi proxy connectionzUnknown Connection Type: %sF)�__opts__�get�
CONNECTIONr
r � _init_ssh�_init_nxapi�error)�optsr
r
r �init� s
r c C � t dkrt� S t dkrt� S dS )z�
Since grains are loaded in many different places and some of those
places occur before the proxy can be initialized, return whether the
init() function has been called.
r r N)r �_initialized_ssh�_initialized_nxapir
r
r
r �initialized� s
�r c C r )z{
Helper function for nxos execution module functions that need to
ping the nxos device using the proxy minion.
r r N)r � _ping_ssh�_ping_nxapir
r
r
r �ping� �
�r! c C sX t d s&td�} tdkr| d } tjj�| �}t�d|� t d � |d � dt d iS )z{
Helper function for nxos execution module functions that need to
retrieve nxos grains using the proxy minion.
r zshow versionr r zSystem Info: %sr )
�DEVICE_DETAILS�sendliner �salt�utilsr Zsystem_infor
�debug�update)�data�retr
r
r �grains� s r+ c C s i t d<