salt.proxy.nxos module

Proxy Minion for Cisco NX-OS Switches

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 salt.utils.vt_helper

To configure the proxy minion for ssh:

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 minon for nxapi:

proxy:
  proxytype: nxos
  connection: nxapi
  host: 192.168.187.100
  username: admin
  password: admin
  transport: http
  port: 80
  verify: False
  no_save_config: True
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.
no_save_config:
If False, 'copy running-config starting-config' is issues for every
configuration command.

If True, Running config is not saved to startup config Default: False

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.

Conection 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:

nxos-switch#.*|\(y\/n\)\?.*

This should match

nxos-switch#

or

Flash complete.  Reboot this switch (y/n)? [n]

If neither prompt_name nor prompt_regex is specified the prompt will be defaulted to

.+#$

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:
Wheather 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 salt.modules.nxos execution module.

salt.proxy.nxos.grains(**kwargs)

Get grains for minion.

salt.proxy.nxos.grains_refresh(**kwargs)

Refresh the grains for the NX-OS device.

salt.proxy.nxos.init(opts=None)

Required. Initialize device connection using ssh or nxapi connection type.

salt.proxy.nxos.initialized()

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.

salt.proxy.nxos.ping()

Ping the device on the other end of the connection.

salt.proxy.nxos.proxy_config(commands, **kwargs)

Send configuration commands over SSH or NX-API

commands
List of configuration commands
no_save_config
If True, don't save configuration commands to startup configuration. If False, save configuration to startup configuration. Default: False
salt.proxy.nxos.sendline(command, method=u'cli_show_ascii')

Send arbitrary show or config commands to the NX-OS device.

command
The command to be sent.
method:

cli_show_ascii: Return raw test or unstructured output. cli_show: Return structured output. cli_conf: Send configuration commands to the device. Defaults to cli_show_ascii.

NOTES for SSH proxy minon:
method is ignored for SSH proxy minion. Only show commands are supported and data is returned unstructured. This function is preserved for backwards compatibilty.
salt.proxy.nxos.shutdown(opts)

Closes connection with the device.