pyntc.devices.nxos_device
¶
Module for using an NXOS device over NX-API.
pyntc.devices.nxos_device.NXOSDevice
¶
Bases: BaseDevice
Cisco NXOS Device Implementation.
active_redundancy_states
property
¶
Get list of states that indicate the device is active.
Returns:
| Type | Description |
|---|---|
list
|
List of active redundancy states. |
boot_options
property
¶
Get current boot variables.
Returns:
| Type | Description |
|---|---|
dict
|
e.g . {"kick": "router_kick.img", "sys": "router_sys.img"} |
connected
property
writable
¶
Get connection status of the device.
Returns:
| Type | Description |
|---|---|
bool
|
True if the device is connected, else False. |
fqdn
property
¶
Get fully qualified domain name.
Returns:
| Type | Description |
|---|---|
str
|
Fully qualified domain name. |
hostname
property
¶
Get hostname of the device.
Returns:
| Type | Description |
|---|---|
str
|
Hostname of the device. |
interfaces
property
¶
Get list of interfaces.
Returns:
| Type | Description |
|---|---|
list
|
List of interfaces. |
model
property
¶
Get device model.
Returns:
| Type | Description |
|---|---|
str
|
Model of device. |
os_version
property
¶
Get device version.
Returns:
| Type | Description |
|---|---|
str
|
Device version. |
redundancy_state
property
¶
Get redundancy state of the device.
Returns:
| Type | Description |
|---|---|
str
|
Redundancy state of the device (e.g., "active", "standby", "init"). |
running_config
property
¶
Get running configuration of device.
Returns:
| Type | Description |
|---|---|
str
|
Running configuration of device. |
serial_number
property
¶
Get device serial number.
Returns:
| Type | Description |
|---|---|
str
|
Device serial number. |
startup_config
property
¶
Get startup configuration.
Returns:
| Type | Description |
|---|---|
str
|
Startup configuration. |
uptime
property
¶
Get uptime of the device in seconds.
Returns:
| Type | Description |
|---|---|
int
|
Uptime of the device in seconds. |
uptime_string
property
¶
Get uptime in format dd:hh:mm.
Returns:
| Type | Description |
|---|---|
str
|
Uptime of device. |
vlans
property
¶
Get list of vlans.
Returns:
| Type | Description |
|---|---|
list
|
List of vlans on the device. |
__init__(host, username, password, transport='http', timeout=30, port=None, verify=True, **kwargs)
¶
PyNTC Device implementation for Cisco IOS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
The address of the network device. |
required |
username
|
str
|
The username to authenticate with the device. |
required |
password
|
str
|
The password to authenticate with the device. |
required |
transport
|
str
|
Transport protocol to connect to device. Defaults to "http". |
'http'
|
timeout
|
int
|
Timeout in seconds. Defaults to 30. |
30
|
port
|
int
|
Port used to connect to device. Defaults to None. |
None
|
verify
|
bool
|
SSL verification. |
True
|
kwargs
|
dict
|
Left for compatibility with other tools, for instance nautobot-inventory may pass additional kwargs. |
{}
|
backup_running_config(filename)
¶
Backup running configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of backup file. |
required |
check_file_exists(filename, file_system=None)
¶
Check if a remote file exists by filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The name of the file to check for on the remote device. |
required |
file_system
|
str
|
Supported only for Arista. The file system for the
remote file. If no file_system is provided, then the |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the remote file exists, False if it doesn't. |
Raises:
| Type | Description |
|---|---|
CommandError
|
If there is an error in executing the command to check if the file exists. |
checkpoint(filename)
¶
Save a checkpoint of the running configuration to the device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The filename to save the checkpoint on the remote device. |
required |
close()
¶
Disconnect from device.
config(command)
¶
Send configuration command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
(str, list)
|
command to be sent to the device. |
required |
Raises:
| Type | Description |
|---|---|
CommandError
|
Error if command is not succesfully ran on device. |
file_copy(src, dest=None, file_system='bootflash:')
¶
Send a local file to the device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Path to the local file to send. |
required |
dest
|
str
|
The destination file path. Defaults to basename of source path. |
None
|
file_system
|
str
|
[The file system for the remote file. Defaults to "bootflash:". |
'bootflash:'
|
Raises:
| Type | Description |
|---|---|
FileTransferError
|
Error if transfer of file cannot be verified. |
file_copy_remote_exists(src, dest=None, file_system='bootflash:')
¶
Check if a remote file exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Path to the local file to send. |
required |
dest
|
str
|
The destination file path to be saved on remote device. Defaults to basename of source path. |
None
|
file_system
|
str
|
The file system for the remote file. Defaults to "bootflash:". |
'bootflash:'
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the remote file exists. Otherwise, false. |
get_remote_checksum(filename, hashing_algorithm='md5', **kwargs)
¶
Get the checksum of a remote file on Cisco NXOS device using netmiko SSH.
Uses NXOS's 'show file' command via SSH to compute file checksums.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The name of the file to check for on the remote device. |
required |
hashing_algorithm
|
str
|
The hashing algorithm to use (default: "md5"). |
'md5'
|
**kwargs
|
Any
|
Passible parameters such as file_system. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The checksum of the remote file. |
Raises:
| Type | Description |
|---|---|
CommandError
|
If the verify command fails (but not if file doesn't exist). |
install_os(image_name, reboot=True, **vendor_specifics)
¶
Upgrade device with provided image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_name
|
str
|
Name of the image file to upgrade the device to. |
required |
reboot
|
bool
|
Whether to reboot the device after setting the boot options. Defaults to true. |
True
|
vendor_specifics
|
dict
|
Vendor specific options. |
{}
|
Raises:
| Type | Description |
|---|---|
OSInstallError
|
Error if boot option is not set to new image. |
Returns:
| Type | Description |
|---|---|
bool
|
True if new image is boot option on device. Otherwise, false. |
is_active()
¶
Determine if the current processor is the active processor.
Returns:
| Type | Description |
|---|---|
bool
|
True if the processor is active or does not support HA, else False. |
open()
¶
Open a connection to the network device.
reboot(wait_for_reload=False, **kwargs)
¶
Reload the controller or controller pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wait_for_reload
|
bool
|
Whether or not reboot method should also run _wait_for_device_reboot(). Defaults to False. |
False
|
kwargs
|
dict
|
Additional arguments to pass to reboot method. |
{}
|
Raises:
| Type | Description |
|---|---|
RebootTimerError
|
When the device is still unreachable after the timeout period. |
Example
device = NXOSDevice(**connection_args) device.reboot()
refresh()
¶
Refresh caches on device instance.
remote_file_copy(src, dest=None, file_system=None, **kwargs)
¶
Copy a file from remote source to device. Skips if file already exists and is verified on remote device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
FileCopyModel
|
The source file model with transfer parameters. |
required |
dest
|
str
|
Destination filename (defaults to src.file_name). |
None
|
file_system
|
str
|
Device filesystem (auto-detected if not provided). |
None
|
**kwargs
|
Any
|
Passible parameters such as file_system. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If src is not a FileCopyModel. |
FileTransferError
|
If transfer or verification fails. |
FileSystemNotFoundError
|
If filesystem cannot be determined. |
rollback(filename)
¶
Rollback configuration to specified file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of the file to rollback to. |
required |
Raises:
| Type | Description |
|---|---|
RollbackError
|
Error if rollback command is unsuccesfull. |
save(filename='startup-config')
¶
Save a device's running configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Filename to save running configuration to. Defaults to "startup-config". |
'startup-config'
|
Returns:
| Type | Description |
|---|---|
bool
|
True if configuration is saved. |
set_boot_options(image_name, kickstart=None, reboot=True, **vendor_specifics)
¶
Set boot variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_name
|
str
|
Main system image file. |
required |
kickstart
|
str
|
Kickstart filename. Defaults to None. |
None
|
reboot
|
bool
|
Whether to reboot the device after setting the boot options. Defaults to true. |
True
|
vendor_specifics
|
dict
|
Vendor specific options. |
{}
|
Raises:
| Type | Description |
|---|---|
NTCFileNotFoundError
|
Error if either image_name or kickstart image not found on device. |
set_timeout(timeout)
¶
Set timeout value on device connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
int
|
Timeout value. |
required |
show(command, raw_text=False)
¶
Send a non-configuration command using netmiko.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
(str, list)
|
The command (or list of commands) to send to the device. |
required |
raw_text
|
bool
|
When True return raw text; when False parse with TextFSM into a list of dicts. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
CommandError
|
A single command failed on the device. |
CommandListError
|
A command within a list failed on the device. |
Returns:
| Type | Description |
|---|---|
str | list
|
Raw text or TextFSM-parsed result; a list when |
show_netmiko(command, raw_text=False, read_timeout=None)
¶
Send a non-configuration command using netmiko.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The command to send to the device. |
required |
raw_text
|
bool
|
Whether to return raw text or structured data. Defaults to False. |
False
|
read_timeout
|
int
|
Timeout to pass to Netmiko read_timeout. Defaults to the Netmiko timeout if not set. |
None
|
Raises:
| Type | Description |
|---|---|
CommandError
|
Error message stating which command failed. |
Returns:
| Type | Description |
|---|---|
str | list
|
Raw text or TextFSM-parsed result; a list when |
verify_file(checksum, filename, hashing_algorithm='md5', file_system=None, **kwargs)
¶
Verify a file on the device by comparing checksums.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checksum
|
str
|
The expected checksum of the file. |
required |
filename
|
str
|
The name of the file on the device. |
required |
hashing_algorithm
|
str
|
The hashing algorithm to use (default: "md5"). |
'md5'
|
file_system
|
str
|
The file system where the file is located. |
None
|
**kwargs
|
Any
|
Passible parameters such as file_system. |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the file is verified successfully, False otherwise. |