Command Output Parsers¶
CiscoAutomationFramework provides integrated parsers for various command outputs. These parsers allow you to pass in the output from the network device and be able to iterate over output and/or extract data from the output in a programatic way versus needing to build your own parsers
Show Interface Status Parser¶
Pass in the raw output from “show interface status” command to this parser and you will be able to iterate over the table and interact with the entries individually
-
class
CiscoAutomationFramework.Parsers.InterfaceStatusParser.
InterfaceStatusOutputParser
(raw_table)¶ Provide the output directly from the device after issuing the command ‘show interface status’ to this object to parse it
-
interfaces
¶ Parses the raw output from the command and provides a list of all entries from the table
Returns: LineParser Return type: list[LineParser]
-
-
class
CiscoAutomationFramework.Parsers.InterfaceStatusParser.
LineParser
(raw_line)¶ -
description
¶ Description set on interface
Returns: Confiured Description Return type: str
-
duplex
¶ Interface duplex settings ex. auto, a-full a-half
Returns: Duplex Setting Return type: str
-
name
¶ Name of the interface ex. Gi1/0/1
Returns: Interface Name abbriviated Return type: str
-
not_present
¶ Returns True/False if the text “not present” in the lowercase line
Returns: True/False Return type: bool
-
speed
¶ Interface Operating Speed ex. auto, a-100, a-1000
Returns: Interface Speed Return type: str
-
status
¶ Status of interface ex. connected, notconnected, disabled, err-disable, etc
Returns: interface status Return type: str
-
type
¶ Interface Type ex. 10/100/1000BaseTX, Not Present
Returns: Interface Type Return type: str
-
vlan
¶ Vlan configuration of interface ex. 1, 100, trunk, routed
Returns: vlan configuration Return type: str
-
IP Device Tracking Parser¶
Pass in the raw output from “show ip device tracking all” and this parser allows you to iterate over the contents of the table one at a time.
-
class
CiscoAutomationFramework.Parsers.IpDeviceTrackingParser.
DeviceTrackingOutputParser
(output_from_device)¶ -
entries
¶ Extracts the entires from the table and returns them as a list
Returns: List of table entries as EntryParser instances Return type: list[EntryParser]
-
-
class
CiscoAutomationFramework.Parsers.IpDeviceTrackingParser.
EntryParser
(entry_data)¶ -
interface
¶ Extracts interface of the ip device tracking entry
Returns: Switch Interface Return type: str
-
ip_address
¶ IP address of the IP device tracking entry
Returns: IP address Return type: str
-
is_apipa
¶ True/False if the IP address in the entry is an APIPA address.
Returns: True/False Return type: bool
-
mac_address
¶ MAC address of the ip device tracking entry
Returns: MAC Address Return type: str
-
probe_timeout
¶ Extracts probe timeout of the ip device tracking entry
Returns: Probe Timeout Return type: str
-
source
¶ Extracts source of the ip device tracking entry
Returns: Source Return type: str
-
state
¶ Extracts state of the ip device tracking entry
Returns: State Return type: str
-
vlan
¶ Extracts vlan of the ip device tracking entry
Returns: Vlan Return type: str
-
MAC Address Table Parser¶
Pass in the raw output from “show mac address-table” and this parser allows you to iterate over the contents of the table one at a time and also analyze the table in other ways.:
from CiscoAutomationFramework import connect_ssh
from CiscoAutomationFramework.Parsers.MacAddressTableParser import MacAddressTableParser
with connect_ssh('ip', 'username', 'password') as ssh:
mac_table = MacAddressTableParser(ssh.mac_address_table)
for entry in mac_table:
print(f'{entry.interface} - {entry.vlan} - {entry.mac_address}')
-
class
CiscoAutomationFramework.Parsers.MacAddressTableParser.
MacAddressTableParser
(raw_table)¶ -
is_nexus
¶ Checks the raw table for specific key words to determine if it is a Nexus platform or not returning True if it is False if it is not
Returns: True/False Return type: bool
-
table_entries
¶ Parses the mac address table and returns a list of the entries
Returns: List of entries from the MAC address table Return type: list[MacEntryParser]
-
-
class
CiscoAutomationFramework.Parsers.MacAddressTableParser.
MacEntryParser
(raw_entry)¶ -
interface
¶ Interface on device that the MAC address is on ex. Gi1/0/8
Returns: Interface on Device Return type: str
-
is_nexus
¶ Searches the entire mac address table, checking if any of a set of keywords are in it
-
mac_address
¶ MAC address from the row
Returns: MAC Address Return type: str
-
type
¶ Address type from the row ex. dynamic, static
Returns: Address Type Return type: str
-
vlan
¶ Vlan from the row
Returns: Vlan Return type: str
-
Power Inline Parser¶
Pass the raw output from ‘show power inline’ to this parser and you will be able to iterate over the entries in the power inline table:
from CiscoAutomationFramework import connect_ssh
from CiscoAutomationFramework.Parsers.PowerInlineParser import PowerInlineParser
with connect_ssh('ip', 'username', 'password') as ssh:
parser = PowerInlineParser(ssh.send_command_get_output('show power inline'))
for entry in parser:
print(f'{entry.name} - {entry.watts} - {entry.detected_device}')
-
class
CiscoAutomationFramework.Parsers.PowerInlineParser.
PowerInlineParser
(sh_power_inline)¶ -
interfaces
¶ Returns list of interfaces in the power inline table to extract the values from the entry
Returns: List of entries in the power inline table Return type: list[PowerInlineInterface]
-
-
class
CiscoAutomationFramework.Parsers.PowerInlineParser.
PowerInlineInterface
(interface_data)¶ -
admin
¶ Admin column of the entry ex. auto
Returns: Admin column Return type: str
-
detected_device
¶ Detected device type of connected device
Returns: Detected device Return type: str
-
max_watts
¶ Max watts capable of being drawn on port
Returns: Max watts supported Return type: float
-
name
¶ Interface name ex. Gi1/0/5
Returns: Interface Name Return type: str
-
oper
¶ Oper column of the entry, off/on weather it is providing power or not
Returns: Operation status Return type: str
-
poe_class
¶ POE class of connected device ex. 0, 1, 2, 3, n/a
Returns: POE Class Return type: str
-
watts
¶ Watts currently being drawn on port by connected device
Returns: Watts currently drawn Return type: float
-