pyntc.devices.asa_device
¶
Module for using a Cisco ASA device over SSH.
pyntc.devices.asa_device.ASADevice
¶
Bases: BaseDevice
Cisco ASA Device Implementation.
boot_options
property
¶
Determine boot image.
Returns:
| Type | Description |
|---|---|
dict
|
Key: 'sys' Value: Current boot image. |
connected_interface
property
¶
Interface that is assigned an IP Address of self.ip_address.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name of the interfaces associated to |
Example
dev = ASADevice("10.1.1.1", **connection_args) dev.connected_interface 'management'
facts
property
¶
Implement this once facts re-factor is done.
hostname
property
¶
Get hostname of device.
Returns:
| Type | Description |
|---|---|
str
|
Hostname of device. |
interfaces
property
¶
Get list of interfaces on device.
Returns:
| Type | Description |
|---|---|
list
|
List of interfaces on device. |
ip_address
property
¶
IP Address used to establish the connection to the device.
Returns:
| Type | Description |
|---|---|
Union[IPv4Address, IPv6Address]
|
IPv4Address/IPv6Address: The IP address used by the paramiko connection. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When a valid IP Address is unable to be derived from |
Example
dev = ASADevice("10.1.1.1", connection_args) dev.ip_address IPv4Address('10.1.1.1') dev = ASADevice("asa_host", connection_args) dev.ip_address IPv6Address('fe80::2a0:c9ff:fe03:102')
ip_protocol
property
¶
IP Protocol of the IP Addressed used by the underlying paramiko connection.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
"ipv4" for IPv4 Addresses and "ipv6" for IPv6 Addresses. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Example
dev = ASADevice("10.1.1.1", connection_args) dev.ip_protocol 'ipv4' dev = ASADevice("asa_host", connection_args) dev.ip_protocol 'ipv6'
ipv4_addresses
property
¶
IPv4 addresses of the device's interfaces.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, List[IPv4Address]]
|
The ipv4 addresses mapped to their interfaces. |
Example
dev = ASADevice(**connection_args) dev.ipv4_addresses
ipv6_addresses
property
¶
IPv6 addresses of the device's interfaces.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, List[IPv6Address]]
|
The ipv6 addresses mapped to their interfaces. |
Example
dev = ASADevice(**connection_args) dev.ipv6_addresses
model
property
¶
Get the device model.
Returns:
| Type | Description |
|---|---|
str
|
Device model. |
os_version
property
¶
Get os version on device.
Returns:
| Type | Description |
|---|---|
str
|
OS version on device. |
peer_device
property
¶
Create instance of ASADevice for peer device.
Returns:
| Type | Description |
|---|---|
ASADevice
|
class |
peer_ip_address
property
¶
IP Address associated with self.ip_address on the peer device.
Returns:
| Type | Description |
|---|---|
Union[IPv4Address, IPv6Address]
|
IPv4Address/IPv6Address: The IP address used by the paramiko connection. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When a valid IP Address is unable to be derived from |
Example
dev = ASADevice("10.1.1.1", connection_args) dev.peer_ip_address IPv4Address('10.1.1.2') dev = ASADevice("asa_host", connection_args) dev.peer_ip_address IPv6Address('fe80::2a0:c9ff:fe03:103')
peer_ipv4_addresses
property
¶
IPv4 addresses of the peer device's interfaces.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, List[IPv4Address]]
|
The ipv4 addresses mapped to their interfaces. |
Example
dev = ASADevice(**connection_args) dev.peer_ipv4_addresses
peer_ipv6_addresses
property
¶
IPv6 addresses of the peer device's interfaces.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, List[IPv6Address]]
|
The ipv6 addresses mapped to their interfaces. |
Example
dev = ASADevice(**connection_args) dev.peer_ipv6_addresses
peer_redundancy_state
property
¶
Determine the current redundancy state of the peer processor.
In the case of multi-context configurations, a peer will be considered active if it is the active device for any context. Otherwise, the most common state will be returned.
Returns:
| Type | Description |
|---|---|
str
|
The redundancy state of the peer processor. |
None
|
When the processor does not support redundancy. |
Example
device = ASADevice(**connection_args) device.peer_redundancy_state 'standby ready'
redundancy_mode
property
¶
Operating redundancy mode of the device.
Returns:
| Type | Description |
|---|---|
str
|
The redundancy mode the device is operating in. If the command is not supported, then "n/a" is returned. |
Example
device = ASADevice(**connection_args) device.redundancy_mode 'on'
redundancy_state
property
¶
Determine the current redundancy state of the processor.
In the case of multi-context configurations, a device will be considered active if it is the active device for any context. Otherwise, the most common state will be returned.
Returns:
| Type | Description |
|---|---|
str
|
The redundancy state of the processor. |
None
|
When the processor does not support redundancy. |
Example
device = ASADevice(**connection_args) device.redundancy_state 'active'
running_config
property
¶
Get current running config on device.
Returns:
| Type | Description |
|---|---|
str
|
Running configuration on device. |
serial_number
property
¶
Get serial number of device.
Returns:
| Type | Description |
|---|---|
str
|
Serial number of device. |
startup_config
property
¶
Show startup config.
:return: Output of command 'show startup-config'.
uptime
property
¶
Get uptime from device.
Returns:
| Type | Description |
|---|---|
int
|
Uptime in seconds. |
uptime_string
property
¶
Get uptime in format dd:hh:mm.
Returns:
| Type | Description |
|---|---|
str
|
Uptime of device. |
vlans
property
¶
Get vlan ids from device.
Returns:
| Type | Description |
|---|---|
list
|
List of vlans |
__init__(host, username, password, secret='', port=None, **kwargs)
¶
Pyntc Device constructor for Cisco ASA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
The address of the network device. |
required |
username
|
str
|
The username to authenticate to the device. |
required |
password
|
str
|
The password to authenticate to the device. |
required |
secret
|
str
|
The password to escalate privilege on the device. Defaults to 22. |
''
|
port
|
int
|
Port used to establish connection. Defaults to 22. |
None
|
kwargs
|
dict
|
Additional keyword arguments to pass to the Netmiko connection handler. |
{}
|
backup_running_config(filename)
¶
Backups running config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of backup file. |
required |
check_file_exists(filename, **kwargs)
¶
Check whether a file exists on the device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The name of the file to check for on the device. |
required |
**kwargs
|
Any
|
Optional keyword arguments. |
{}
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
file_system |
str
|
The file system to check. Defaults to |
Returns:
| Type | Description |
|---|---|
bool
|
True if the file exists, False otherwise. |
checkpoint(checkpoint_file)
¶
Create a checkpoint file of the current config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_file
|
str
|
Saves a checkpoint file with the name provided to the function. |
required |
close()
¶
Disconnect from device.
config(command)
¶
Send configuration commands to a device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
(str, list)
|
String with single command, or list with multiple commands. |
required |
Raises:
| Type | Description |
|---|---|
CommandListError
|
Message stating which command failed and the response from the device. |
enable()
¶
Ensure device is in enable mode.
Returns:
| Type | Description |
|---|---|
None
|
Device prompt is set to enable mode. |
enable_scp()
¶
Enable SCP on device by configuring "ssh scopy enable".
The command is ran on the active device; if the device is currently standby, then a new connection is created to the active device. The configuration is saved after to sync to peer.
Raises:
| Type | Description |
|---|---|
FileTransferError
|
When unable to configure scopy on the active device. |
Example
device = ASADevice(**connection_args) device.show("show run ssh | i scopy") '' device.enable_scp() device.show("show run ssh | i scopy") 'ssh scopy enable'
file_copy(src, dest=None, file_system=None, peer=False)
¶
Copy src file to device.
The src file can be copied to both the device and its peer by
setting peer to True. If transferring to the peer device, the
transfer will use the address associated with the peer_interface
from "show failover" output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
The path to the file to be copied to the device. |
required |
dest
|
str
|
The name to use for storing the file on the device.
Default is to use the name of the |
None
|
file_system
|
str
|
The directory to store the file on the device.
Default will use |
None
|
peer
|
bool
|
Whether to transfer the |
False
|
Raises:
| Type | Description |
|---|---|
FileTransferError
|
When the |
NotEnoughFreeSpaceError
|
When |
Example
dev = ASADevice(**connection_args) dev.file_copy("path/to/asa-image.bin", peer=True)
file_copy_remote_exists(src, dest=None, file_system=None)
¶
Copy src file to device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
The path to the file to be copied to the device. |
required |
dest
|
str
|
The name to use for storing the file on the device.
Defaults to use the name of the |
None
|
file_system
|
str
|
The directory name to store files on the device. Defaults to discover the default directory of the device. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the file exists on the device and the md5 hashes match. Otherwise, false. |
Example:
status = file_copy_remote_exists("path/to/asa-image.bin") print(status) True
get_remote_checksum(filename, hashing_algorithm='md5', **kwargs)
¶
Get the checksum of a file on the device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The name of the file on the device. |
required |
hashing_algorithm
|
str
|
The hashing algorithm to use. Valid choices are |
'md5'
|
**kwargs
|
Any
|
Optional keyword arguments. |
{}
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
file_system |
str
|
The file system where the file resides. Defaults to |
Returns:
| Type | Description |
|---|---|
str
|
The checksum of the file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unsupported hashing algorithm is provided. |
CommandError
|
If the checksum cannot be parsed from the device output. |
install_os(image_name, reboot=True, **vendor_specifics)
¶
Install OS on device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_name
|
str
|
Name of the image to be installed. |
required |
reboot
|
bool
|
Whether to reboot the device after setting the boot options. Defaults to true. |
True
|
vendor_specifics
|
dict
|
Vendor specific arguments to pass to the install process. |
{}
|
Raises:
| Type | Description |
|---|---|
OSInstallError
|
Message stating the end device could not boot into the new image. |
Returns:
| Type | Description |
|---|---|
bool
|
True if new image is installed correctly. False if device is already running image_name. |
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. |
Example
device = ASADevice(**connection_args) device.is_active() True
open()
¶
Attempt to find device prompt. If not found, create Connecthandler object to 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 the reboot method. |
{}
|
Raises:
| Type | Description |
|---|---|
RebootTimeoutError
|
When the device is still unreachable after the timeout period. |
Example
device = ASADevice(**connection_args) device.reboot()
reboot_standby(acceptable_states=None, timeout=None)
¶
Reload the standby device from the active device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
acceptable_states
|
iter
|
List of acceptable redundancy states for the peer device after reboot.
Default will use the current value of |
None
|
timeout
|
int
|
The maximum time to wait for the device to boot back into an |
None
|
Raises:
| Type | Description |
|---|---|
RebootTimeoutError
|
When |
Example
dev = ASADevice(**connection_args) dev.peer_redundancy_state 'standby ready' dev.reboot_standby() RebootTimeoutError... dev.peer_redundancy_state 'cold standby' dev.reboot_standby(acceptbale_states=["standby ready", "cold standby"]) dev.peer_redundancy_state 'cold standby'
remote_file_copy(src=None, dest=None, **kwargs)
¶
Copy a file from a remote server to the device.
Pulls the file specified by src from a remote server using the protocol in
src.download_url (FTP, TFTP, SCP, HTTP, or HTTPS) and saves it to the device
filesystem. The file is verified after transfer using the checksum in src.
SFTP is not supported on Cisco ASA devices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
FileCopyModel
|
Specification of the source file including URL, checksum, and credentials. |
None
|
dest
|
str
|
Filename to use on the device. Defaults to |
None
|
**kwargs
|
Any
|
Optional keyword arguments. |
{}
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
file_system |
str
|
Destination file system on the device (e.g. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
FileTransferError
|
If the transfer fails or the file cannot be verified afterwards. |
NotEnoughFreeSpaceError
|
If |
rollback(rollback_to)
¶
Rollback the device configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rollback_to
|
str
|
Name of checkpoint file to rollback to |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Function not implemented yet. |
save(filename='startup-config')
¶
Save changes to startup config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of startup configuration file. Defaults to "startup-config". |
'startup-config'
|
Returns:
| Type | Description |
|---|---|
bool
|
True if configuration saved succesfully. |
set_boot_options(image_name, **vendor_specifics)
¶
Set new image as boot option on device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_name
|
str
|
AName of image. |
required |
vendor_specifics
|
dict
|
Vendor specific arguments to pass to the set_boot_options process. |
{}
|
Raises:
| Type | Description |
|---|---|
NTCFileNotFoundError
|
File not found on device. |
CommandError
|
Unable to issue command on device. |
show(command, expect_string=None)
¶
Send command to device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
Command to be ran on device. |
required |
expect_string
|
str
|
Expected response from running command on device. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Output from running command on device. |
verify_file(checksum, filename, hashing_algorithm='md5', **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'
|
**kwargs
|
Any
|
Optional keyword arguments passed through to |
{}
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
file_system |
str
|
The file system where the file resides. Defaults to |
Returns:
| Type | Description |
|---|---|
bool
|
True if the file exists and the checksum matches, False otherwise. |