-
Notifications
You must be signed in to change notification settings - Fork 2
/
showRouterTunnel-table.py
47 lines (42 loc) · 1.12 KB
/
showRouterTunnel-table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from pprint import pprint
from ttp import ttp
import json
import time
with open("showRouterTunnel-table.txt") as f:
data_to_parse = f.read()
ttp_template = """
<group name="Show_Router_Tunnel-table">
{{Prefix|PREFIX}} {{Protocol}} {{Encap_Type}} {{Tunnel_id}} {{Preference}} {{Next_hop|IP}} {{Metric}}
</group>
"""
parser = ttp(data=data_to_parse, template=ttp_template)
parser.parse()
# print result in JSON format
results = parser.result(format='json')[0]
print(results)
'''
[
{
"Show_Router_Ospf_Neighbor": [
{
"Area_ID": "0.0.0.0",
"Interface-Name": "toSR7-3",
"Neighbor_State": "Full",
"Pri": "1",
"RetxQ": "0",
"Rtr_Id": "10.10.10.3",
"TTL": "33"
},
{
"Area_ID": "1.1.1.1",
"Interface-Name": "toSR7-4",
"Neighbor_State": "Full",
"Pri": "10",
"RetxQ": "0",
"Rtr_Id": "10.10.12.3",
"TTL": "34"
}
]
}
]
'''