### Install TTP from source Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Installation.rst Install TTP by downloading the source code from GitHub, unzipping it, navigating to the folder, and running the setup script. ```bash python setup.py install ``` ```bash python -m pip install . ``` -------------------------------- ### Install TTP with all optional dependencies Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Installation.rst Install TTP along with all optional dependencies using the 'full' extras. ```bash pip install ttp[full] ``` -------------------------------- ### Example using _start_ indicator Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Match Variables/Indicators.rst This example shows how the '_start_' indicator can be used to explicitly mark the beginning of a group, matching lines that serve as delimiters. ```jinja ------------------------- {{ _start_ }} Device ID: {{ peer_hostname }} Entry address(es): IP address: {{ peer_ip }} ``` -------------------------------- ### Example with multiple _start_ indicators Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Match Variables/Indicators.rst This example demonstrates using '_start_' with different patterns to indicate the beginning of the same group, allowing for flexible matching of interface types. ```jinja interface Tunnel{{ if_id }} interface GigabitEthernet{{ if_id | _start_ }} description {{ description }} ``` -------------------------------- ### Install TTP with Dev Dependencies Source: https://github.com/dmulyalin/ttp/blob/master/CLAUDE.md Installs the TTP library along with development dependencies using Poetry. This is useful for contributing to the project. ```bash python -m pip install poetry python -m poetry install ``` -------------------------------- ### Install TTP with All Optional Dependencies Source: https://github.com/dmulyalin/ttp/blob/master/CLAUDE.md Installs the TTP library with all optional dependencies enabled using Poetry. This ensures all features and plugins are available. ```bash python -m poetry install -E full ``` -------------------------------- ### Install TTP using pip Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Installation.rst Use this command to install the TTP library with pip. ```bash pip install ttp ``` -------------------------------- ### CSV Output Example Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Writing templates/index.rst Example of structured data parsed and formatted as CSV. ```csv description,interface,ip,mask,vrf Router-id-loopback,Loopback0,192.168.0.113,24, CPE_Acces_Vlan,Vlan778,2002::fd37,124,CPE1 ``` -------------------------------- ### Dynamic Path with Path Formatters Example Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Forming Results Structure/Dynamic path with path formatters.rst This example shows how to use a dynamic path with a path formatter to capture interface names and their details. The `interfaces*.{{ interface }}` pattern dynamically creates keys based on interface names. ```text interface Port-Chanel11 description Storage ! interface Loopback0 description RID ip address 10.0.0.3/24 ! interface Vlan777 description Management ip address 192.168.0.1/24 vrf MGMT ``` ```jinja interface {{ interface }} description {{ description }} ip address {{ ip }}/{{ mask }} vrf {{ vrf }} ``` ```json [ { "interfaces": [ { "Loopback0": { "description": "RID", "ip": "10.0.0.3", "mask": "24" }, "Port-Chanel11": { "description": "Storage" }, "Vlan777": { "description": "Management", "ip": "192.168.0.1", "mask": "24", "vrf": "MGMT" } } ] } ] ``` -------------------------------- ### Tabulate Formatter Example Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Outputs/Formatters.rst This example utilizes the tabulate formatter to render parsed data into a plain-text table using the 'fancy_grid' format. Ensure the 'tabulate' Python module is installed. ```xml router bgp 65100 neighbor 10.145.1.9 description vic-mel-core1 ! neighbor 192.168.101.1 description qld-bri-core1 router bgp {{ bgp_as }} neighbor {{ peer }} description {{ description }} ``` -------------------------------- ### TTP Template with Doc Tag Example Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Doc Tag/Doc Tag.rst This example demonstrates how to use the tag to provide information about a TTP template and its usage, including how to invoke it with Netmiko. ```xml TTP template to parse Cisco IOS "show ip arp" output. Template can be invoked using Netmiko run_ttp method like this: import pprint from netmiko import ConnectHandler net_connect = ConnectHandler( device_type="cisco_ios", host="1.2.3.4", username="admin", password="admin", ) res = net_connect.run_ttp("ttp://misc/netmiko/cisco.ios.arp.txt", res_kwargs={"structure": "flat_list"}) pprint.pprint(res) commands = [ "show ip arp" ] {{ protocol }} {{ ip | IP }} {{ age | replace("-", "-1") }} {{ mac | mac_eui }} {{ type | let("interface", "Unknown") }} {{ protocol }} {{ ip | IP }} {{ age | replace("-", "-1") }} {{ mac | mac_eui }} {{ type }} {{ interface | resuball("short_interface_names") }} ``` -------------------------------- ### Install ttp_templates Package Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/TTP Templates Collection.rst Install the ttp_templates package using pip. This is the first step to using external TTP templates. ```bash pip install ttp_templates ``` -------------------------------- ### YANG Module Directory Content Example Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Outputs/Functions.rst Illustrates the structure of a YANG modules directory, including example YANG files for network interface and IP type definitions. ```text ./yang_modules/ |__/iana-if-type@2017-01-19.yang |__/ietf-inet-types@2013-07-15.yang |__/ietf-interfaces@2018-02-20.yang |__/ietf-ip@2018-02-22.yang |__/ietf-yang-types@2013-07-15.yang ``` -------------------------------- ### Table Formatter Example Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Outputs/Formatters.rst This example demonstrates the table formatter to structure parsed data into a table with specified headers and a key for dictionary keys. ```xml interface Loopback0 ip address 192.168.0.113/24 ! interface Vlan778 ip address 2002::fd37/124 ! interface {{ interface }} ip address {{ ip }}/{{ mask }} ``` -------------------------------- ### JSON Output Example Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Writing templates/index.rst Example of structured data parsed into JSON format. ```json [ [ { "description": "Router-id-loopback", "interface": "Loopback0", "ip": "192.168.0.113", "mask": "24" }, { "description": "CPE_Acces_Vlan", "interface": "Vlan778", "ip": "2002::fd37", "mask": "124", "vrf": "CPE1" } ] ] ``` -------------------------------- ### Install TTP from GitHub master branch Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Installation.rst Install the latest source code directly from the GitHub master branch using pip. ```bash python -m pip install git+https://github.com/dmulyalin/ttp ``` -------------------------------- ### File Returner Example with Dynamic Filename Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Outputs/Returners.rst Saves group results to a file, using the device hostname in the filename. Ensure the output directory exists. ```text switch-sw1# show run interfaces interface Port-Chanel2 vlan 100 interface Loopback1 vlan 200 switch-sw2# show run interfaces interface Port-Chanel11 vlan 10 interface Loopback0 vlan 20 host_name = "gethostname" interface {{ interface }} vlan {{ vlan | to_int }} returner="file" url="./Output/" filename="{host_name}_interfaces.txt" ``` -------------------------------- ### TTP CLI tool usage examples Source: https://context7.com/dmulyalin/ttp/llms.txt Command-line examples for using TTP to parse data files with templates. Options include specifying input/output files, output formats (JSON, YAML), multi-process mode, and logging levels. ```bash # Parse a data file with a template, output JSON to terminal ttp --data "path/to/device_output.txt" --template "path/to/template.txt" --outputter json # Parse all .txt files in a directory, output YAML ttp --data "path/to/logs/" --template "path/to/template.txt" --outputter yaml # Use multi-process mode with timing info ttp --data "path/to/data/" --template "path/to/template.txt" --outputter json --multi --Timing # Output results as flat list, specify log level ttp --data "data.txt" --template "template.txt" -o json --structure flat_list --logging DEBUG ``` -------------------------------- ### Jinja2 Output Formatter Example Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Outputs/Formatters.rst Demonstrates how to use the Jinja2 formatter to structure output data. This is useful for generating configuration files or reports in a templated format. ```jinja2 interface {{ interface }} ip address {{ ip }}/{{ mask }} # ``` ```jinja2 {% for input_result in _data_ %} {% for item in input_result %} if_cfg id {{ item['interface'] }} ip address {{ item['ip'] }} subnet mask {{ item['mask'] }} # {% endfor %} {% endfor %} ``` -------------------------------- ### Data for YANG Validation (Example 1) Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Outputs/Functions.rst Provides sample network interface configuration data for YANG validation. Includes configurations with valid and invalid IP addresses. ```text data1 = """ interface GigabitEthernet1/3.251 description Customer #32148 encapsulation dot1q 251 ip address 172.16.10 255.255.255.128 shutdown ! interface GigabitEthernet1/4 description vCPEs access control ip address 172.16.33.10 255.255.255.128 ! 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 ! """ data2 = """ interface GigabitEthernet1/3.254 description Customer #5618 encapsulation dot1q 251 ip address 172.16.33.11 255.255.255.128 shutdown ! """ ``` -------------------------------- ### NTP Configuration Validation with Cerberus Source: https://github.com/dmulyalin/ttp/blob/master/docs/source/Outputs/Functions.rst Validates NTP configuration using the Cerberus library. This example shows how to define a schema for NTP peers and apply it to parsed results when the template results attribute is set to 'per_template'. Ensure Cerberus is installed. ```xml