Cisco_IOS_Cli

This class provides low-level connection to Cisco networking devices running Cisco IOS and IOS XE. In order for this connection to work, SSH or Telnet must be enabled on the target device. After creating connection object and connecting to the device using either Python’s Context Manager or by calling _connect() method, you can start retrieving structured data by calling get_ functions. To see other supported get_ functions, please check out the documentation page of the parent object CliBaseConnection.

Example usage:

>>> from nuaal.connections.cli import Cisco_IOS_Cli
>>> # For further easier manipulation, create provider dictionary
>>> provider = {
    "username": "admin",    # Username for authentication
    "password": "cisco",    # Password for authentication
    "enable": True,         # Whether or not enable Privileged EXEC Mode
    "secret": "cisco",      # Enable secret for entering Privileged EXEC Mode
    "store_outputs": True,  # Enables saving Plaintext output of commands
    "method": "ssh"         # Optional, defaults to "ssh"
}
>>>
>>> # Create variable for storing data
>>> data = None
>>> # Establish connection using Context Manager
>>> with Cisco_IOS_Cli(ip="192.168.1.1", **provider) as ios_device:
>>>     # Run selected commands
>>>     ios_device.get_interfaces()
>>>     ios_device.get_vlans()
>>>     ios_device.get_trunks()
>>>     ios_device.get_version()
>>>     ios_device.get_inventory()
>>>     # Store data to variable
>>>     data = ios_device.data
>>> # Do other fancy stuff with data
>>> print(data)

Defined get_* functions return output in JSON format (except for get_config()). You can also send your own commands, such as:

>>> with Cisco_IOS_Cli(ip="192.168.1.1", **provider) as ios_device:
>>>     ios_device._send_command(command="show version")

And you will receive Plaintext output of selected command.

class Cisco_IOS_Cli(ip=None, username=None, password=None, parser=None, secret=None, method='ssh', enable=False, store_outputs=False, DEBUG=False, verbosity=3, netmiko_params={})

Bases: nuaal.connections.cli.CliBase.CliBaseConnection

Object for interaction with network devices running Cisco IOS (or IOS XE) software via CLI interface.

Parameters:
  • ip – (str) IP address or FQDN of the device you’re trying to connect to
  • username – (str) Username used for login to device
  • password – (str) Password used for login to device
  • parser – (ParserModule) Instance of ParserModule class which will be used for parsing of text outputs.

By default, new instance of ParserModule is created. :param secret: (str) Enable secret for accessing Privileged EXEC Mode :param method: (str) Primary method of connection, ‘ssh’ or ‘telnet’. (Default is ‘ssh’) :param enable: (bool) Whether or not enable Privileged EXEC Mode on device :param store_outputs: (bool) Whether or not store text outputs of sent commands :param DEBUG: (bool) Enable debugging logging

get_auth_sessions()
Returns:
get_auth_sessions_intf(interface: str)

Function for retrieving 802.1X Auth Session on an interface

Parameters:interface (str) – Name of the interface to retrieve auth session from
Returns:
get_config()

Function for retrieving current configuration of the device.

Return str:Device configuration
get_interfaces_status()
get_mac_address_table(vlan=None, interface=None)

Returns content of device MAC address table in JSON format. In Cisco terms, this represents the command show mac address-table.

Parameters:vlan (int) – Number of VLAN to get MAC addresses from
Returns:List of dictionaries.
get_neighbors(output_filter=None, strip_domain=False)

Function to get neighbors of the device with possibility to filter neighbors

Parameters:
  • output_filter – (Filter) Instance of Filter class, used to filter neighbors, such as only “Switch” or “Router”
  • strip_domain – (bool) Whether or not to strip domain names and leave only device hostname
Returns:

List of dictionaries

get_portchannels()

This function returns JSON representation of all logical bind interfaces (etherchannels, portchannels). In Cisco terms, this represents the show etherchannel summary command.

Returns:List of dictionaries.
get_trunks(expand_vlan_groups=False)

Custom parsing function for output of “show interfaces trunk”

Parameters:expand_vlan_groups – (bool) Whether or not to expand VLAN ranges, for example ‘100-102’ -> [100, 101, 102]
Returns:List of dictionaries