Template Text Parser Templates
This repository contains a collection of TTP templates.
If you solved a problem using TTP and feel that your work can be useful to other people, feel
free to raise an issue or submit pull request to include your template(s) in this repository.
Refer to Contribute Guide for details.
Documentation: https://dmulyalin.github.io/ttp_templates/
Repository: https://github.com/dmulyalin/ttp_templates
TTP: https://ttp.readthedocs.io/
Installation
From PyPi:
pip install ttp-templates
or latest from GitHub master branch (need Git installed on the system):
pip install git+https://github.com/dmulyalin/ttp_templates.git
Sample usage
This example demonstrates how to parse Test Platform
output for show run | sec interface
command using platform/test_platform_show_run_pipe_sec_interface.txt
template.
Code
from ttp_templates import parse_output
import pprint
data = """
interface GigabitEthernet1/3.251
description Customer #32148
encapsulation dot1q 251
ip address 172.16.33.10 255.255.255.128
shutdown
!
interface GigabitEthernet1/3.251
description Customer #32148
encapsulation dot1q 251
ip address 172.16.33.10 255.255.255.128
shutdown
"""
result = parse_output(
data=data,
platform="Test Platform",
command="show run | sec interface"
)
pprint.pprint(result)
Sample code to parse Cisco IOS
output in a structure compatible with ietf-interfaces
YANG module.
Code
from ttp_templates import get_template
from ttp import ttp
import pprint
data1 = """
interface GigabitEthernet1/3.251
description Customer #32148
encapsulation dot1q 251
ip address 172.16.33.10 255.255.255.128
shutdown
!
interface GigabitEthernet1/4
description vCPEs access control
ip address 172.16.33.10 255.255.255.128
!
"""
data2 = """
interface GigabitEthernet1/5
description Works data
ip mtu 9000
!
interface GigabitEthernet1/7
description Works data v6
ipv6 address 2001::1/64
ipv6 address 2001:1::1/64
"""
template = get_template(yang="ietf-interfaces", platform="cisco_ios")
parser = ttp(template=template)
parser.add_input(data1)
parser.add_input(data2)
parser.parse()
res = parser.result()
pprint.pprint(res)
How templates collections structured
This repository contains three collections of templates corresponding to folder names:
platform
collection - mimics ntc-templates API and follows same naming ruleyang
collection - contains templates capable of producing YANG compatible structures out of text datamisc
collection - miscellaneous templates for various use cases organized in folders
Platform collection templates files naming rule
{{ vendor_os }}_{{ command_with_underscores }}.txt
- lower case only.
Naming rules details:
- All space symbols
' '
replaced with underscores. - Pipe symbol
|
replaced with pipe
in template name. For example,
template to parse Cisco IOS show run | section interface
command output
must be named cisco_ios_show_running_config_pipe_section_interface.txt
- Dash symbols
-
replaced with underscores. For example, template to parse
Huawei display current-configuration interface
command output must be
named huawei_display_current_configuration_interface.txt
YANG collection templates files naming rule
{{ YANG module name }}_{{ platform_name }}.txt
- lower case only
Naming rules details:
- All space symbols
' '
replaced with underscore. - Dash symbol
-
does not replaced with underscore. For example, template
to produce output compatible with openconfig-lldp YANG model for Cisco IOS
must be named openconfig-lldp_cisco_xr.txt
Misc collection templates files naming rule
{{ usecase folder }}/{{ template name }}.txt
- upper or lower case
Naming rules details:
- Nothing replaced with anything, provided template name used as is.
Additional Templates Resources
List of resources with TTP templates: