In this lesson, we will cover:
- An overview of Netmiko parsing.
- How to use TTP templates within Netmiko.
- How to build a custom TTP parser.
The scripts and code for this lesson can be found within the Netmiko repo under the directory: examples/003_parsing/ttp
.
Netmiko Parsing
Netmiko provides the ability to parse the data returned from the device into a Python data structure. Having our data in a Python-based structure rather than a single block of text allows us to interact with the data programmatically. Below visualizes this further:
Nemiko provides support for the following open source parsing libraries. Below is a table showing Netmikos implementation of each. It shows whether you can supply your own template and if a template library for the parser is available.
Parser | Custom Templates | Template Library |
TTP (Template Text Parser) | Yes | No |
TextFSM | Yes | Yes |
Genie | No | Yes |
TTP Overview
TTP (Template Text Parser) is a fairly new tool. A TTP template (shown below) is defined, this is then applied to your data, and your structured data is rendered. TTP is straightforward to use; one of the main reasons for this is that it abstracts away much of the regex required when creating parsing templates.
interface {{ interface }}
ip address {{ ip }}/{{ mask }}
description {{ description }}
ip vrf {{ vrf }}