In this lesson, we will cover:
- What is Genie Parse?
- What parsers are supported?
- How to perform Genie parsing via the command line.
- How to perform Genie parsing using Python.
The scripts and code for this lesson can be found within the pyATS repo under the directory: 003_genie/parse/
.
What is Genie Parse?
Genie parse
provides the ability to parse a given command into structured output. By having the output in a structured format, we can work with the data in a programmatic way, such as looping over the data or extracting certain elements.
For example, if we were to collect the show int ip br
output, we would get an output much similar to this.
leaf1-ios#show ip int br
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 10.1.1.2 YES NVRAM up up
GigabitEthernet0/1 10.2.1.2 YES NVRAM up up
GigabitEthernet0/2 unassigned YES NVRAM down down
...
This isn’t ideal! How would we pull out a given value from this block of text? Regex? Ouch! Instead, we can parse this through Genie parse
to get structured output like so:
...
{'interface': {'GigabitEthernet0/0': {'interface_is_ok': 'YES',
'ip_address': '10.1.1.2',
'method': 'NVRAM',
'protocol': 'up',
'status': 'up'},
'GigabitEthernet0/1': {'interface_is_ok': 'YES',
'ip_address': '10.2.1.2',
'method': 'NVRAM',
'protocol': 'up',
'status': 'up'},
...
With our data structured, we can now use programmatic methods for working with the data, such as performing key-value lookups, like so:
interface_output['interface']['Eth1/1']['ip_address']
===
"10.1.1.1"
Supported Parsers
Genie supports various NOS’s (Network Operating Systems), as shown below. Furthermore, numerous parsers (on average, 10 to 40) are added in each pyATS release cycle.
- IOS
- IOSXE
- IOSXR
- NXOS
- ASA - Cisco Adaptive Security Appliance Software
- LINUX - Linux operating system
- JUNOS - Juniper Junos
- SROS - Nokia SROS
- BIGIP - F5 BIG-IP
- VIPTELA - Viptela operating system
- APIC - Cisco API
- DNAC - Cisco DNAC Centre
- IRONWARE
A full list of commands which are supported can be found below:
https://pubhub.devnetcloud.com/media/genie-feature-browser/docs/#/parsers
The page is interactive so that you can enter in command, and the supported NOS will be presented:
Alternatively, you can filter by network operating system as shown below: