TTP#
quickstart.py
from ttp import ttp
data_to_parse = """
interface Loopback0
description Router-id-loopback
ip address 192.168.0.113/24
!
interface Vlan778
description CPE_Acces_Vlan
ip address 2002::fd37/124
ip vrf CPE1
!
"""
ttp_template = """
interface {{ interface }}
ip address {{ ip }}/{{ mask }}
description {{ description }}
ip vrf {{ vrf }}
"""
# create parser object and parse data using template:
parser = ttp(data=data_to_parse, template=ttp_template)
parser.parse()
# print result in JSON format
results = parser.result(format='json')[0]
print(results)
# or in csv format
csv_results = parser.result(format='csv')[0]
print(csv_results)
template#
cisco_xr_show_running_config_interface.txt
<doc>
Template to produce list of dictionaries with interface
configuration details using Cisco IOS-XR "show run interface"
command output.
</doc>
<group>
interface {{ interface | _start_ }}
interface {{ interface | _start_ }} l2transport
description {{ description | re(".*") }}
mtu {{ mtu }}
service-policy input {{ qos_policy_in }}
service-policy output {{ qos_policy_out }}
ipv4 address {{ ipv4 }} {{ mask_v4 }}
ipv6 address {{ ipv6 }}/{{ mask_v6 }}
encapsulation dot1q {{ dot1q }}
vrf {{ vrf }}
bundle id {{ lag_id }} mode {{ ignore }}
shutdown {{ disabled | set(True) }}
! {{ _end_ }}
</group>