Skip to content

pyntc.devices.base_device

The module contains the base class that all device classes must inherit from.

pyntc.devices.base_device.BaseDevice

Base Device ABC.

boot_options property

Get current boot variables.

like system image and kickstart image.

Returns:

Type Description
dict

A dictionary, e.g. {'kick': router_kick.img, 'sys': 'router_sys.img'}

fqdn property

Get FQDN of the device.

Raises:

Type Description
NotImplementedError

returns not implemented if not included in facts.

hostname property

Host name string property, part of device facts.

Raises:

Type Description
NotImplementedError

returns not implemented if not included in facts.

install_mode property

Indicate whether the device is operating in install mode.

Drivers override this to derive the value from the device's current boot configuration. Used by install_os to choose between install-mode and legacy upgrade procedures.

Returns:

Type Description
bool

True when the device boots from an install-mode bundle (e.g., packages.conf on IOS-XE), False otherwise.

interfaces property

Interfaces list of strings property, part of device facts.

Raises:

Type Description
NotImplementedError

returns not implemented if not included in facts.

model property

Model string property, part of device facts.

Raises:

Type Description
NotImplementedError

returns not implemented if not included in facts.

os_version property

Operating System string property, part of device facts.

Raises:

Type Description
NotImplementedError

returns not implemented if not included in facts.

running_config property

Return the running configuration of the device.

serial_number property

Get serial number of the device.

Raises:

Type Description
NotImplementedError

returns not implemented if not included in facts.

startup_config property

Return the startup configuration of the device.

uptime property

Uptime integer property, part of device facts.

Raises:

Type Description
NotImplementedError

returns not implemented if not included in facts.

uptime_string property

Uptime string string property, part of device facts.

Raises:

Type Description
NotImplementedError

returns not implemented if not included in facts.

vlans property

Vlans lost of strings property, part of device facts.

Raises:

Type Description
NotImplementedError

returns not implemented if not included in facts.

__init__(host, username, password, device_type=None, **kwargs)

PyNTC base device implementation.

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
device_type str

Denotes which device type. Defaults to None.

None
kwargs dict

Additional keyword arguments that may be used by subclasses.

{}

backup_running_config(filename)

Save a local copy of the running config.

Parameters:

Name Type Description Default
filename str

The local file path on which to save the running config.

required

check_file_exists(filename, **kwargs)

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
kwargs dict

Additional keyword arguments that may be used by subclasses.

{}

Other Parameters:

Name Type Description
file_system str

Supported only for IOS and NXOS. The file system for the remote file. If no file_system is provided, then the get_file_system method is used to determine the correct file system to use.

Returns:

Type Description
bool

True if the remote file exists, False if it doesn't.

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 as on the remote device.

required

close()

Close the connection to the device.

compare_file_checksum(checksum, filename, hashing_algorithm='md5', **kwargs)

Compare the checksum of a local file with a remote file.

Parameters:

Name Type Description Default
checksum str

The checksum of the file.

required
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 dict

Additional keyword arguments that may be used by subclasses.

{}

Other Parameters:

Name Type Description
file_system str

Supported only for IOS and NXOS. The file system for the remote file. If no file_system is provided, then the get_file_system method is used to determine the correct file system to use.

Returns:

Type Description
bool

True if the checksums match, False otherwise.

config(command)

Send a configuration command.

Parameters:

Name Type Description Default
command str

The command to send to the device.

required

Raises:

Type Description
CommandError

If there is a problem with the supplied command.

facts()

DEPRECATED - Use individual properties to get facts.

feature(feature_name)

Return a feature class based on the feature_name for the appropriate subclassed device type.

file_copy(src, dest=None, **kwargs)

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 to be saved on remote flash. If none is supplied, the implementing class should use the basename of the source path.

None
kwargs dict

Additional keyword arguments that may be used by subclasses.

{}

Other Parameters:

Name Type Description
file_system str

Supported only for IOS and NXOS. The file system for the remote file. If no file_system is provided, then the get_file_system method is used to determine the correct file system to use.

file_copy_remote_exists(src, dest=None, **kwargs)

Check if a remote file exists.

A remote file exists if it has the same name as supplied dest, and the same md5 hash as the source.

Parameters:

Name Type Description Default
src str

Path to local file to check.

required
dest str

The destination file path to be saved on remote the remote device. If none is supplied, the implementing class should use the basename of the source path.

None
kwargs dict

Additional keyword arguments that may be used by subclasses.

{}

Other Parameters:

Name Type Description
file_system str

Supported only for IOS and NXOS. The file system for the remote file. If no file_system is provided, then the get_file_system method is used to determine the correct file system to use.

Returns:

Type Description
bool

True if the remote file exists, False if it doesn't.

get_boot_options()

Get current boot variables like system image and kickstart image.

Returns:

Type Description
dict

A dictionary, e.g. {'kick': router_kick.img, 'sys': 'router_sys.img'}

get_local_checksum(filepath, hashing_algorithm='md5', add_newline=False) staticmethod

Get the checksum of a local file using a specified algorithm.

Parameters:

Name Type Description Default
filepath str

The path to the local file.

required
hashing_algorithm str

The hashing algorithm to use (e.g., "md5", "sha256").

'md5'
add_newline bool

Whether to append a newline before final hashing (Some devices may require this).

False

Returns:

Type Description
str

The hex digest of the file.

get_remote_checksum(filename, hashing_algorithm='md5', **kwargs)

Get the checksum of a remote file.

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 dict

Additional keyword arguments that may be used by subclasses.

{}

Other Parameters:

Name Type Description
file_system str

Supported only for IOS and NXOS. The file system for the remote file. If no file_system is provided, then the get_file_system method is used to determine the correct file system to use.

Returns:

Type Description
str

The checksum of the remote file.

install_os(image_name, reboot=True, **vendor_specifics)

Install the OS from specified image_name.

Parameters:

Name Type Description Default
image_name str

The name of the image on the device to install.

required
reboot bool

Whether to reboot the device after setting the boot options. Defaults to true.

True

Other Parameters:

Name Type Description
kickstart str

Option for NXOSDevice for devices that require a kickstart image.

volume str

Option for F5Device to set the target boot volume.

file_system str

Option for ASADevice, EOSDevice, IOSDevice, and NXOSDevice to set where the OS files are stored. The default will use the _get_file_system method.

timeout int

Option for IOSDevice and NXOSDevice to set the wait time for device installation to complete.

vendor_specifics kwargs

Additional keyword arguments that may be used by subclasses.

Returns:

Type Description
bool

True if system has been installed during function's call, False if OS has not been installed

Raises:

Type Description
OSInstallError

When device finishes installation process, but the running image does not match image_name.

CommandError

When sending a command to the device fails, or when the config status after sending a command does not yield expected results.

CommandListError

When sending commands to the device fails.

NotEnoughFreeSpaceError

When the device does not have enough free space for install.

NTCFileNotFoundError

When the image_name is not found in the devices file_system.

FileSystemNotFoundError

When the file_system is left to default, and the file_system cannot be identified.

RebootTimeoutError

When device is rebooted and is unreachable longer than timeout period.

open()

Open a connection to the device.

reboot(wait_for_reload=False)

Reload a device.

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

Raises:

Type Description
RebootTimeoutError

When the device is still unreachable after the timeout period.

Raises:

Type Description
NotImplementedError

description

refresh()

Refresh caches on device instance.

refresh_facts()

Refresh cached facts.

remote_file_copy(src=None, dest=None, **kwargs)

Copy a file to a remote device.

Parameters:

Name Type Description Default
src FileCopyModel

The source file model.

None
dest str

The destination file path on the remote device.

None
kwargs dict

Additional keyword arguments that may be used by subclasses.

{}

Other Parameters:

Name Type Description
file_system str

Supported only for IOS and NXOS. The file system for the remote file. If no file_system is provided, then the get_file_system method is used to determine the correct file system to use.

rollback(checkpoint_file)

Rollback to a checkpoint file.

Parameters:

Name Type Description Default
checkpoint_file str

The filename of the checkpoint file to load into the running configuration.

required

save(filename=None)

Save a device's running configuration.

Parameters:

Name Type Description Default
filename str

The filename on the remote device. If none is supplied, the implementing class should save to the "startup configuration".

None

set_boot_options(image_name, **vendor_specifics)

Set boot variables like system image and kickstart image.

Parameters:

Name Type Description Default
image_name str

The main system image file name.

required

Other Parameters:

Name Type Description
kickstart str

Option for NXOSDevice for devices that require a kickstart image.

volume str

Option for F5Device to set which volume should have image installed.

file_system str

Option for ASADevice and IOSDevice to set which directory to use when setting the boot path. The default will use the directory returned by the _get_file_system() method.

vendor_specifics kwargs

Additional keyword arguments that may be used by subclasses.

Raises:

Type Description
ValueError

When the boot options returned by the boot_options method does not match the image_name after the config command(s) have been sent to the device.

show(command, raw_text=False)

Send a non-configuration command.

Parameters:

Name Type Description Default
command str

The command to send to the device.

required

Other Parameters:

Name Type Description
raw_text bool

Whether to return raw text or structured data.

Returns:

Type Description
NotImplementedError

The output of the show command, which could be raw text or structured data.

verify_file(checksum, filename, hashing_algorithm='md5', **kwargs)

Verify a file on the remote device by confirming the file exists and validate the checksum.

Parameters:

Name Type Description Default
checksum str

The checksum of the file.

required
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 dict

Additional keyword arguments that may be used by subclasses.

{}

Other Parameters:

Name Type Description
file_system str

Supported only for IOS and NXOS. The file system for the remote file. If no file_system is provided, then the get_file_system method is used to determine the correct file system to use.

Returns:

Type Description
bool

True if the file is verified successfully, False otherwise.

pyntc.devices.base_device.RebootTimerError

Bases: NTCError

Reboot timer error class to notify user reboot timer is not supported.

__init__(device_type)

Error to notify user reboot timer is not supported.

Parameters:

Name Type Description Default
device_type str

Ex: cisco_nxos_nxapi, cisco_ios_ssh

required

pyntc.devices.base_device.RollbackError

Bases: NTCError

Rollback error.

pyntc.devices.base_device.SetBootImageError

Bases: NTCError

Set boot image error.

pyntc.devices.base_device.fix_docs(cls)

Create docstring at runtime.

Returns:

Type Description
class

Returns the class passed in.