Package: ttp-templates
Template Text Parser TemplatesThis repository contains a collection ofTTPtemplates.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 toContribute Guidefor details.Documentation:https://dmulyalin.github.io/ttp_templates/Repository:https://github.com/dmulyalin/ttp_templatesTTP:https://ttp.readthedocs.io/InstallationFrom PyPi:pip install ttp-templatesor latest from GitHub master branch (need Git installed on the system):pip install git+https://github.com/dmulyalin/ttp_templates.gitSample usageThis example demonstrates how to parseTest Platformoutput forshow run | sec interfacecommand usingplatform/test_platform_show_run_pipe_sec_interface.txttemplate.Codefromttp_templatesimportparse_outputimportpprintdata="""interface GigabitEthernet1/3.251description Customer #32148encapsulation dot1q 251ip address 172.16.33.10 255.255.255.128shutdown!interface GigabitEthernet1/3.251description Customer #32148encapsulation dot1q 251ip address 172.16.33.10 255.255.255.128shutdown"""result=parse_output(data=data,platform="Test Platform",command="show run | sec interface")pprint.pprint(result)# prints:# [[[{'description': 'Customer #32148',#     'disabled': True,#     'dot1q': '251',#     'interface': 'GigabitEthernet1/3.251',#     'ip': '172.16.33.10',#     'mask': '255.255.255.128'},#    {'description': 'Customer #32148',#     'disabled': True,#     'dot1q': '251',#     'interface': 'GigabitEthernet1/3.251',#     'ip': '172.16.33.10',#     'mask': '255.255.255.128'}]]]Sample code to parseCisco IOSoutput in a structure compatible withietf-interfacesYANG module.Codefromttp_templatesimportget_templatefromttpimportttpimportpprintdata1="""interface GigabitEthernet1/3.251description Customer #32148encapsulation dot1q 251ip address 172.16.33.10 255.255.255.128shutdown!interface GigabitEthernet1/4description vCPEs access controlip address 172.16.33.10 255.255.255.128!"""data2="""interface GigabitEthernet1/5description Works dataip mtu 9000!interface GigabitEthernet1/7description Works data v6ipv6 address 2001::1/64ipv6 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)# prints:# [{'comment': '',#   'exception': {},#   'result': [{'ietf-interfaces:interfaces': {'interface': [{'admin-status': 'down',#                                                             'description': 'Customer '#                                                                            '#32148',#                                                             'enabled': False,#                                                             'ietf-ip:ipv4': {'address': [{'ip': '172.16.33.10',#                                                                                           'netmask': '255.255.255.128',#                                                                                           'origin': 'static'}]},#                                                             'if-index': 1,#                                                             'link-up-down-trap-enable': 'enabled',#                                                             'name': 'GigabitEthernet1/3.251',#                                                             'oper-status': 'unknown',#                                                             'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},#                                                             'type': 'iana-if-type:ethernetCsmacd'},#                                                            {'admin-status': 'up',#                                                             'description': 'vCPEs '#                                                                            'access '#                                                                            'control',#                                                             'enabled': True,#                                                             'ietf-ip:ipv4': {'address': [{'ip': '172.16.33.10',#                                                                                           'netmask': '255.255.255.128',#                                                                                           'origin': 'static'}]},#                                                             'if-index': 1,#                                                             'link-up-down-trap-enable': 'enabled',#                                                             'name': 'GigabitEthernet1/4',#                                                             'oper-status': 'unknown',#                                                             'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},#                                                             'type': 'iana-if-type:ethernetCsmacd'}]}},#              {'ietf-interfaces:interfaces': {'interface': [{'admin-status': 'up',#                                                             'description': 'Works '#                                                                            'data',#                                                             'enabled': True,#                                                             'ietf-ip:ipv4': {'mtu': 9000},#                                                             'if-index': 1,#                                                             'link-up-down-trap-enable': 'enabled',#                                                             'name': 'GigabitEthernet1/5',#                                                             'oper-status': 'unknown',#                                                             'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},#                                                             'type': 'iana-if-type:ethernetCsmacd'},#                                                            {'admin-status': 'up',#                                                             'description': 'Works '#                                                                            'data '#                                                                            'v6',#                                                             'enabled': True,#                                                             'ietf-ip:ipv6': {'address': [{'ip': '2001::1',#                                                                                           'origin': 'static',#                                                                                           'prefix-length': 64},#                                                                                          {'ip': '2001:1::1',#                                                                                           'origin': 'static',#                                                                                           'prefix-length': 64}]},#                                                             'if-index': 1,#                                                             'link-up-down-trap-enable': 'enabled',#                                                             'name': 'GigabitEthernet1/7',#                                                             'oper-status': 'unknown',#                                                             'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},#                                                             'type': 'iana-if-type:ethernetCsmacd'}]}}],#   'valid': {0: True, 1: True}}]How templates collections structuredThis repository contains three collections of templates corresponding to folder names:platformcollection - mimicsntc-templatesAPI and follows same naming ruleyangcollection - contains templates capable of producing YANG compatible structures out of text datamisccollection - miscellaneous templates for various use cases organized in foldersPlatform 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 withpipein template name. For example,
template to parse Cisco IOSshow run | section interfacecommand output
must be namedcisco_ios_show_running_config_pipe_section_interface.txtDash symbols-replaced with underscores. For example, template to parse
Huaweidisplay current-configuration interfacecommand output  must be
namedhuawei_display_current_configuration_interface.txtYANG collection templates files naming rule{{ YANG module name }}_{{ platform_name }}.txt- lower case onlyNaming rules details:All space symbols' 'replaced with underscore.Dash symbol-does notreplaced with underscore. For example, template
to produce output compatible with openconfig-lldp YANG model for Cisco IOS
must be namedopenconfig-lldp_cisco_xr.txtMisc collection templates files naming rule{{ usecase folder }}/{{ template name }}.txt- upper or lower caseNaming rules details:Nothing replaced with anything, provided template name used as is.Additional Templates ResourcesList of resources with TTP templates:TTP SrosParser -https://pypi.org/project/ttp-sros-parser/byh4ndzdatm0ldTemplate for parsing "show run" for Cisco IOS -https://github.com/tbotnz/ios-show-run-ttpbytbotnzTemplate for Cisco ASA configuration -https://gist.github.com/consentfactory/85872fc83453d1735b15aed3e47a9763byconsentfactory