ttp_templates 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ttp_templates-0.4.0/LICENSE +21 -0
- ttp_templates-0.4.0/PKG-INFO +261 -0
- ttp_templates-0.4.0/README.md +226 -0
- ttp_templates-0.4.0/pyproject.toml +70 -0
- ttp_templates-0.4.0/ttp_templates/__init__.py +3 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ip_data/a10.txt +33 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ip_data/arista_eos.txt +38 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ip_data/cisco_ios.txt +43 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ip_data/cisco_nxos.txt +49 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ip_data/cisco_xr.txt +42 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ip_data/fortinet.txt +43 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ip_data/huawei.txt +43 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ip_data/juniper_junos.txt +70 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ip_data/readme.md +53 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_isis_data/cisco_xr.txt +13 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_isis_data/juniper_junos.txt +12 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_isis_data/readme.md +14 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_l2_data/cisco_ios.txt +84 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_l2_data/cisco_nxos.txt +102 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_l2_data/cisco_xr.txt +130 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_l2_data/huawei.txt +90 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_l2_data/juniper_junos.txt +82 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_l2_data/readme.md +87 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ospf_data/cisco_ios.txt +18 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ospf_data/cisco_xr.txt +19 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ospf_data/huawei.txt +14 -0
- ttp_templates-0.4.0/ttp_templates/misc/N2G/cli_ospf_data/readme.md +14 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netbox/parse_arista_eos_config.txt +294 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netbox/parse_cisco_nxos_config.txt +227 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netbox/parse_cisco_xr_config.txt +544 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netbox/parse_juniper_junos_config.txt +414 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netbox/parse_opengear_config.txt +145 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netmiko/cisco.ios.arp.txt +48 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netmiko/cisco.ios.cfg.bgp.txt +28 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netmiko/cisco.ios.cfg.interface.txt +9 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netmiko/cisco.ios.cfg.ip.txt +108 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netmiko/cisco.ios.cfg.nat.static.txt +30 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netmiko/cisco.iosxr.arp.txt +48 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netmiko/cisco.iosxr.cfg.interface.txt +9 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netmiko/cisco.iosxr.cfg.ip.txt +280 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netmiko/huawei.vrp.cfg.interface.txt +9 -0
- ttp_templates-0.4.0/ttp_templates/misc/Netmiko/huawei.vrp.cfg.ip.txt +99 -0
- ttp_templates-0.4.0/ttp_templates/misc/ttp_templates_tests/cisco_ios_interfaces_cfg_per_ip.txt +95 -0
- ttp_templates-0.4.0/ttp_templates/misc/ttp_templates_tests/netmiko_cisco_ios_interfaces.txt +19 -0
- ttp_templates-0.4.0/ttp_templates/platform/arista_eos_show_hostname.txt +8 -0
- ttp_templates-0.4.0/ttp_templates/platform/arista_eos_show_inventory_pipe_json.txt +72 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_ios_show_ip_arp.txt +66 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_ios_show_ip_ospf_database_external.txt +55 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_ios_show_ip_ospf_database_router.txt +92 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_ios_show_ip_ospf_database_summary.txt +53 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_ios_show_isdn_status.txt +19 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_ios_show_running_config_pipe_include_source_static.txt +119 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_ios_show_running_config_pipe_section_interface.txt +25 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_ios_show_running_configuration_pipe_section_bgp.txt +237 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_nxos_show_inventory_pipe_json_pretty.txt +55 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_xr_show_arp_vrf_all.txt +7 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_xr_show_inventory.txt +30 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_xr_show_isis_database_verbose.txt +75 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_xr_show_ospf_database_external.txt +55 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_xr_show_ospf_database_router.txt +92 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_xr_show_ospf_database_summary.txt +60 -0
- ttp_templates-0.4.0/ttp_templates/platform/cisco_xr_show_running_config_interface.txt +21 -0
- ttp_templates-0.4.0/ttp_templates/platform/huawei_display_current_configuration_interface.txt +19 -0
- ttp_templates-0.4.0/ttp_templates/platform/huawei_display_ospf_lsdb_router.txt +71 -0
- ttp_templates-0.4.0/ttp_templates/platform/juniper_junos_show_chassis_hardware_pipe_json.txt +74 -0
- ttp_templates-0.4.0/ttp_templates/platform/juniper_junos_show_isis_database_verbose_pipe_no_more.txt +114 -0
- ttp_templates-0.4.0/ttp_templates/platform/test_platform_show_run_pipe_sec_interface.txt +11 -0
- ttp_templates-0.4.0/ttp_templates/ttp_templates.py +250 -0
- ttp_templates-0.4.0/ttp_templates/ttp_vars.py +171 -0
- ttp_templates-0.4.0/ttp_templates/yang/ietf-interfaces_cisco_ios.txt +259 -0
- ttp_templates-0.4.0/ttp_templates/yang/openconfig-lldp_cisco_ios.txt +182 -0
- ttp_templates-0.4.0/ttp_templates/yang/openconfig-lldp_cisco_nxos.txt +173 -0
- ttp_templates-0.4.0/ttp_templates/yang/openconfig-lldp_cisco_xr.txt +176 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Denis Mulyalin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ttp_templates
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Template Text Parser Templates collections
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: Parsing,TTP,regex
|
|
8
|
+
Author: Denis Mulyalin
|
|
9
|
+
Author-email: d.mulyalin@gmail.com
|
|
10
|
+
Maintainer: Denis Mulyalin
|
|
11
|
+
Maintainer-email: d.mulyalin@gmail.com
|
|
12
|
+
Requires-Python: >=3.10,<4.0
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Utilities
|
|
22
|
+
Provides-Extra: docs
|
|
23
|
+
Requires-Dist: mkdocs ; extra == "docs"
|
|
24
|
+
Requires-Dist: mkdocs-material ; extra == "docs"
|
|
25
|
+
Requires-Dist: mkdocs-material-extensions ; extra == "docs"
|
|
26
|
+
Requires-Dist: mkdocstrings[python] ; extra == "docs"
|
|
27
|
+
Requires-Dist: pygments ; extra == "docs"
|
|
28
|
+
Requires-Dist: pymdown-extensions ; extra == "docs"
|
|
29
|
+
Requires-Dist: ttp (>=0.6.0)
|
|
30
|
+
Project-URL: Documentation, https://dmulyalin.github.io/ttp_templates/
|
|
31
|
+
Project-URL: Homepage, https://github.com/dmulyalin/ttp_templates
|
|
32
|
+
Project-URL: Repository, https://github.com/dmulyalin/ttp_templates
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
[](https://pepy.tech/project/ttp_templates)
|
|
36
|
+
[](https://pypi.python.org/pypi/ttp_templates/)
|
|
37
|
+
|
|
38
|
+
# Template Text Parser Templates
|
|
39
|
+
|
|
40
|
+
This repository contains a collection of [TTP](https://github.com/dmulyalin/ttp) templates.
|
|
41
|
+
|
|
42
|
+
If you solved a problem using TTP and feel that your work can be useful to other people, feel
|
|
43
|
+
free to raise an issue or submit pull request to include your template(s) in this repository.
|
|
44
|
+
Refer to [Contribute Guide](https://dmulyalin.github.io/ttp_templates/contribute/) for details.
|
|
45
|
+
|
|
46
|
+
Documentation: [https://dmulyalin.github.io/ttp_templates/](https://dmulyalin.github.io/ttp_templates/)
|
|
47
|
+
|
|
48
|
+
Repository: [https://github.com/dmulyalin/ttp_templates](https://github.com/dmulyalin/ttp_templates)
|
|
49
|
+
|
|
50
|
+
TTP: [https://ttp.readthedocs.io/](https://ttp.readthedocs.io/)
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
From PyPi:
|
|
55
|
+
|
|
56
|
+
`pip install ttp-templates`
|
|
57
|
+
|
|
58
|
+
or latest from GitHub master branch (need Git installed on the system):
|
|
59
|
+
|
|
60
|
+
`pip install git+https://github.com/dmulyalin/ttp_templates.git`
|
|
61
|
+
|
|
62
|
+
## Sample usage
|
|
63
|
+
|
|
64
|
+
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.
|
|
65
|
+
<details><summary>Code</summary>
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from ttp_templates import parse_output
|
|
69
|
+
import pprint
|
|
70
|
+
|
|
71
|
+
data = """
|
|
72
|
+
interface GigabitEthernet1/3.251
|
|
73
|
+
description Customer #32148
|
|
74
|
+
encapsulation dot1q 251
|
|
75
|
+
ip address 172.16.33.10 255.255.255.128
|
|
76
|
+
shutdown
|
|
77
|
+
!
|
|
78
|
+
interface GigabitEthernet1/3.251
|
|
79
|
+
description Customer #32148
|
|
80
|
+
encapsulation dot1q 251
|
|
81
|
+
ip address 172.16.33.10 255.255.255.128
|
|
82
|
+
shutdown
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
result = parse_output(
|
|
86
|
+
data=data,
|
|
87
|
+
platform="Test Platform",
|
|
88
|
+
command="show run | sec interface"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
pprint.pprint(result)
|
|
92
|
+
|
|
93
|
+
# prints:
|
|
94
|
+
# [[[{'description': 'Customer #32148',
|
|
95
|
+
# 'disabled': True,
|
|
96
|
+
# 'dot1q': '251',
|
|
97
|
+
# 'interface': 'GigabitEthernet1/3.251',
|
|
98
|
+
# 'ip': '172.16.33.10',
|
|
99
|
+
# 'mask': '255.255.255.128'},
|
|
100
|
+
# {'description': 'Customer #32148',
|
|
101
|
+
# 'disabled': True,
|
|
102
|
+
# 'dot1q': '251',
|
|
103
|
+
# 'interface': 'GigabitEthernet1/3.251',
|
|
104
|
+
# 'ip': '172.16.33.10',
|
|
105
|
+
# 'mask': '255.255.255.128'}]]]
|
|
106
|
+
```
|
|
107
|
+
</details>
|
|
108
|
+
|
|
109
|
+
Sample code to parse `Cisco IOS` output in a structure compatible with `ietf-interfaces` YANG module.
|
|
110
|
+
<details><summary>Code</summary>
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from ttp_templates import get_template
|
|
114
|
+
from ttp import ttp
|
|
115
|
+
import pprint
|
|
116
|
+
|
|
117
|
+
data1 = """
|
|
118
|
+
interface GigabitEthernet1/3.251
|
|
119
|
+
description Customer #32148
|
|
120
|
+
encapsulation dot1q 251
|
|
121
|
+
ip address 172.16.33.10 255.255.255.128
|
|
122
|
+
shutdown
|
|
123
|
+
!
|
|
124
|
+
interface GigabitEthernet1/4
|
|
125
|
+
description vCPEs access control
|
|
126
|
+
ip address 172.16.33.10 255.255.255.128
|
|
127
|
+
!
|
|
128
|
+
"""
|
|
129
|
+
data2 = """
|
|
130
|
+
interface GigabitEthernet1/5
|
|
131
|
+
description Works data
|
|
132
|
+
ip mtu 9000
|
|
133
|
+
!
|
|
134
|
+
interface GigabitEthernet1/7
|
|
135
|
+
description Works data v6
|
|
136
|
+
ipv6 address 2001::1/64
|
|
137
|
+
ipv6 address 2001:1::1/64
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
template = get_template(yang="ietf-interfaces", platform="cisco_ios")
|
|
141
|
+
parser = ttp(template=template)
|
|
142
|
+
|
|
143
|
+
parser.add_input(data1)
|
|
144
|
+
parser.add_input(data2)
|
|
145
|
+
|
|
146
|
+
parser.parse()
|
|
147
|
+
res = parser.result()
|
|
148
|
+
pprint.pprint(res)
|
|
149
|
+
|
|
150
|
+
# prints:
|
|
151
|
+
# [{'comment': '',
|
|
152
|
+
# 'exception': {},
|
|
153
|
+
# 'result': [{'ietf-interfaces:interfaces': {'interface': [{'admin-status': 'down',
|
|
154
|
+
# 'description': 'Customer '
|
|
155
|
+
# '#32148',
|
|
156
|
+
# 'enabled': False,
|
|
157
|
+
# 'ietf-ip:ipv4': {'address': [{'ip': '172.16.33.10',
|
|
158
|
+
# 'netmask': '255.255.255.128',
|
|
159
|
+
# 'origin': 'static'}]},
|
|
160
|
+
# 'if-index': 1,
|
|
161
|
+
# 'link-up-down-trap-enable': 'enabled',
|
|
162
|
+
# 'name': 'GigabitEthernet1/3.251',
|
|
163
|
+
# 'oper-status': 'unknown',
|
|
164
|
+
# 'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},
|
|
165
|
+
# 'type': 'iana-if-type:ethernetCsmacd'},
|
|
166
|
+
# {'admin-status': 'up',
|
|
167
|
+
# 'description': 'vCPEs '
|
|
168
|
+
# 'access '
|
|
169
|
+
# 'control',
|
|
170
|
+
# 'enabled': True,
|
|
171
|
+
# 'ietf-ip:ipv4': {'address': [{'ip': '172.16.33.10',
|
|
172
|
+
# 'netmask': '255.255.255.128',
|
|
173
|
+
# 'origin': 'static'}]},
|
|
174
|
+
# 'if-index': 1,
|
|
175
|
+
# 'link-up-down-trap-enable': 'enabled',
|
|
176
|
+
# 'name': 'GigabitEthernet1/4',
|
|
177
|
+
# 'oper-status': 'unknown',
|
|
178
|
+
# 'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},
|
|
179
|
+
# 'type': 'iana-if-type:ethernetCsmacd'}]}},
|
|
180
|
+
# {'ietf-interfaces:interfaces': {'interface': [{'admin-status': 'up',
|
|
181
|
+
# 'description': 'Works '
|
|
182
|
+
# 'data',
|
|
183
|
+
# 'enabled': True,
|
|
184
|
+
# 'ietf-ip:ipv4': {'mtu': 9000},
|
|
185
|
+
# 'if-index': 1,
|
|
186
|
+
# 'link-up-down-trap-enable': 'enabled',
|
|
187
|
+
# 'name': 'GigabitEthernet1/5',
|
|
188
|
+
# 'oper-status': 'unknown',
|
|
189
|
+
# 'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},
|
|
190
|
+
# 'type': 'iana-if-type:ethernetCsmacd'},
|
|
191
|
+
# {'admin-status': 'up',
|
|
192
|
+
# 'description': 'Works '
|
|
193
|
+
# 'data '
|
|
194
|
+
# 'v6',
|
|
195
|
+
# 'enabled': True,
|
|
196
|
+
# 'ietf-ip:ipv6': {'address': [{'ip': '2001::1',
|
|
197
|
+
# 'origin': 'static',
|
|
198
|
+
# 'prefix-length': 64},
|
|
199
|
+
# {'ip': '2001:1::1',
|
|
200
|
+
# 'origin': 'static',
|
|
201
|
+
# 'prefix-length': 64}]},
|
|
202
|
+
# 'if-index': 1,
|
|
203
|
+
# 'link-up-down-trap-enable': 'enabled',
|
|
204
|
+
# 'name': 'GigabitEthernet1/7',
|
|
205
|
+
# 'oper-status': 'unknown',
|
|
206
|
+
# 'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},
|
|
207
|
+
# 'type': 'iana-if-type:ethernetCsmacd'}]}}],
|
|
208
|
+
# 'valid': {0: True, 1: True}}]
|
|
209
|
+
```
|
|
210
|
+
</details>
|
|
211
|
+
|
|
212
|
+
## How templates collections structured
|
|
213
|
+
|
|
214
|
+
This repository contains three collections of templates corresponding to folder names:
|
|
215
|
+
|
|
216
|
+
* `platform` collection - mimics [ntc-templates](https://github.com/networktocode/ntc-templates) API and follows same naming rule
|
|
217
|
+
* `yang` collection - contains templates capable of producing YANG compatible structures out of text data
|
|
218
|
+
* `misc` collection - miscellaneous templates for various use cases organized in folders
|
|
219
|
+
|
|
220
|
+
### Platform collection templates files naming rule
|
|
221
|
+
|
|
222
|
+
`{{ vendor_os }}_{{ command_with_underscores }}.txt` - lower case only.
|
|
223
|
+
|
|
224
|
+
Naming rules details:
|
|
225
|
+
|
|
226
|
+
* All space symbols `' '` replaced with underscores.
|
|
227
|
+
* Pipe symbol `|` replaced with `pipe` in template name. For example,
|
|
228
|
+
template to parse Cisco IOS `show run | section interface` command output
|
|
229
|
+
must be named `cisco_ios_show_running_config_pipe_section_interface.txt`
|
|
230
|
+
* Dash symbols `-` replaced with underscores. For example, template to parse
|
|
231
|
+
Huawei `display current-configuration interface` command output must be
|
|
232
|
+
named `huawei_display_current_configuration_interface.txt`
|
|
233
|
+
|
|
234
|
+
### YANG collection templates files naming rule
|
|
235
|
+
|
|
236
|
+
`{{ YANG module name }}_{{ platform_name }}.txt` - lower case only
|
|
237
|
+
|
|
238
|
+
Naming rules details:
|
|
239
|
+
|
|
240
|
+
* All space symbols `' '` replaced with underscore.
|
|
241
|
+
* Dash symbol `-` **does not** replaced with underscore. For example, template
|
|
242
|
+
to produce output compatible with openconfig-lldp YANG model for Cisco IOS
|
|
243
|
+
must be named `openconfig-lldp_cisco_xr.txt`
|
|
244
|
+
|
|
245
|
+
### Misc collection templates files naming rule
|
|
246
|
+
|
|
247
|
+
`{{ usecase folder }}/{{ template name }}.txt` - upper or lower case
|
|
248
|
+
|
|
249
|
+
Naming rules details:
|
|
250
|
+
|
|
251
|
+
* Nothing replaced with anything, provided template name used as is.
|
|
252
|
+
|
|
253
|
+
## Additional Templates Resources
|
|
254
|
+
|
|
255
|
+
List of resources with TTP templates:
|
|
256
|
+
|
|
257
|
+
- TTP SrosParser - https://pypi.org/project/ttp-sros-parser/ by [h4ndzdatm0ld](https://github.com/h4ndzdatm0ld)
|
|
258
|
+
- Template for parsing "show run" for Cisco IOS - https://github.com/tbotnz/ios-show-run-ttp by [tbotnz](https://github.com/tbotnz)
|
|
259
|
+
- Template for Cisco ASA configuration - https://github.com/consentfactory/ttp-cisco-asa-template by [consentfactory](https://gist.github.com/consentfactory)
|
|
260
|
+
- (gist for historical purposes) https://gist.github.com/consentfactory/85872fc83453d1735b15aed3e47a9763
|
|
261
|
+
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
[](https://pepy.tech/project/ttp_templates)
|
|
2
|
+
[](https://pypi.python.org/pypi/ttp_templates/)
|
|
3
|
+
|
|
4
|
+
# Template Text Parser Templates
|
|
5
|
+
|
|
6
|
+
This repository contains a collection of [TTP](https://github.com/dmulyalin/ttp) templates.
|
|
7
|
+
|
|
8
|
+
If you solved a problem using TTP and feel that your work can be useful to other people, feel
|
|
9
|
+
free to raise an issue or submit pull request to include your template(s) in this repository.
|
|
10
|
+
Refer to [Contribute Guide](https://dmulyalin.github.io/ttp_templates/contribute/) for details.
|
|
11
|
+
|
|
12
|
+
Documentation: [https://dmulyalin.github.io/ttp_templates/](https://dmulyalin.github.io/ttp_templates/)
|
|
13
|
+
|
|
14
|
+
Repository: [https://github.com/dmulyalin/ttp_templates](https://github.com/dmulyalin/ttp_templates)
|
|
15
|
+
|
|
16
|
+
TTP: [https://ttp.readthedocs.io/](https://ttp.readthedocs.io/)
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
From PyPi:
|
|
21
|
+
|
|
22
|
+
`pip install ttp-templates`
|
|
23
|
+
|
|
24
|
+
or latest from GitHub master branch (need Git installed on the system):
|
|
25
|
+
|
|
26
|
+
`pip install git+https://github.com/dmulyalin/ttp_templates.git`
|
|
27
|
+
|
|
28
|
+
## Sample usage
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
<details><summary>Code</summary>
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from ttp_templates import parse_output
|
|
35
|
+
import pprint
|
|
36
|
+
|
|
37
|
+
data = """
|
|
38
|
+
interface GigabitEthernet1/3.251
|
|
39
|
+
description Customer #32148
|
|
40
|
+
encapsulation dot1q 251
|
|
41
|
+
ip address 172.16.33.10 255.255.255.128
|
|
42
|
+
shutdown
|
|
43
|
+
!
|
|
44
|
+
interface GigabitEthernet1/3.251
|
|
45
|
+
description Customer #32148
|
|
46
|
+
encapsulation dot1q 251
|
|
47
|
+
ip address 172.16.33.10 255.255.255.128
|
|
48
|
+
shutdown
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
result = parse_output(
|
|
52
|
+
data=data,
|
|
53
|
+
platform="Test Platform",
|
|
54
|
+
command="show run | sec interface"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
pprint.pprint(result)
|
|
58
|
+
|
|
59
|
+
# prints:
|
|
60
|
+
# [[[{'description': 'Customer #32148',
|
|
61
|
+
# 'disabled': True,
|
|
62
|
+
# 'dot1q': '251',
|
|
63
|
+
# 'interface': 'GigabitEthernet1/3.251',
|
|
64
|
+
# 'ip': '172.16.33.10',
|
|
65
|
+
# 'mask': '255.255.255.128'},
|
|
66
|
+
# {'description': 'Customer #32148',
|
|
67
|
+
# 'disabled': True,
|
|
68
|
+
# 'dot1q': '251',
|
|
69
|
+
# 'interface': 'GigabitEthernet1/3.251',
|
|
70
|
+
# 'ip': '172.16.33.10',
|
|
71
|
+
# 'mask': '255.255.255.128'}]]]
|
|
72
|
+
```
|
|
73
|
+
</details>
|
|
74
|
+
|
|
75
|
+
Sample code to parse `Cisco IOS` output in a structure compatible with `ietf-interfaces` YANG module.
|
|
76
|
+
<details><summary>Code</summary>
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from ttp_templates import get_template
|
|
80
|
+
from ttp import ttp
|
|
81
|
+
import pprint
|
|
82
|
+
|
|
83
|
+
data1 = """
|
|
84
|
+
interface GigabitEthernet1/3.251
|
|
85
|
+
description Customer #32148
|
|
86
|
+
encapsulation dot1q 251
|
|
87
|
+
ip address 172.16.33.10 255.255.255.128
|
|
88
|
+
shutdown
|
|
89
|
+
!
|
|
90
|
+
interface GigabitEthernet1/4
|
|
91
|
+
description vCPEs access control
|
|
92
|
+
ip address 172.16.33.10 255.255.255.128
|
|
93
|
+
!
|
|
94
|
+
"""
|
|
95
|
+
data2 = """
|
|
96
|
+
interface GigabitEthernet1/5
|
|
97
|
+
description Works data
|
|
98
|
+
ip mtu 9000
|
|
99
|
+
!
|
|
100
|
+
interface GigabitEthernet1/7
|
|
101
|
+
description Works data v6
|
|
102
|
+
ipv6 address 2001::1/64
|
|
103
|
+
ipv6 address 2001:1::1/64
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
template = get_template(yang="ietf-interfaces", platform="cisco_ios")
|
|
107
|
+
parser = ttp(template=template)
|
|
108
|
+
|
|
109
|
+
parser.add_input(data1)
|
|
110
|
+
parser.add_input(data2)
|
|
111
|
+
|
|
112
|
+
parser.parse()
|
|
113
|
+
res = parser.result()
|
|
114
|
+
pprint.pprint(res)
|
|
115
|
+
|
|
116
|
+
# prints:
|
|
117
|
+
# [{'comment': '',
|
|
118
|
+
# 'exception': {},
|
|
119
|
+
# 'result': [{'ietf-interfaces:interfaces': {'interface': [{'admin-status': 'down',
|
|
120
|
+
# 'description': 'Customer '
|
|
121
|
+
# '#32148',
|
|
122
|
+
# 'enabled': False,
|
|
123
|
+
# 'ietf-ip:ipv4': {'address': [{'ip': '172.16.33.10',
|
|
124
|
+
# 'netmask': '255.255.255.128',
|
|
125
|
+
# 'origin': 'static'}]},
|
|
126
|
+
# 'if-index': 1,
|
|
127
|
+
# 'link-up-down-trap-enable': 'enabled',
|
|
128
|
+
# 'name': 'GigabitEthernet1/3.251',
|
|
129
|
+
# 'oper-status': 'unknown',
|
|
130
|
+
# 'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},
|
|
131
|
+
# 'type': 'iana-if-type:ethernetCsmacd'},
|
|
132
|
+
# {'admin-status': 'up',
|
|
133
|
+
# 'description': 'vCPEs '
|
|
134
|
+
# 'access '
|
|
135
|
+
# 'control',
|
|
136
|
+
# 'enabled': True,
|
|
137
|
+
# 'ietf-ip:ipv4': {'address': [{'ip': '172.16.33.10',
|
|
138
|
+
# 'netmask': '255.255.255.128',
|
|
139
|
+
# 'origin': 'static'}]},
|
|
140
|
+
# 'if-index': 1,
|
|
141
|
+
# 'link-up-down-trap-enable': 'enabled',
|
|
142
|
+
# 'name': 'GigabitEthernet1/4',
|
|
143
|
+
# 'oper-status': 'unknown',
|
|
144
|
+
# 'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},
|
|
145
|
+
# 'type': 'iana-if-type:ethernetCsmacd'}]}},
|
|
146
|
+
# {'ietf-interfaces:interfaces': {'interface': [{'admin-status': 'up',
|
|
147
|
+
# 'description': 'Works '
|
|
148
|
+
# 'data',
|
|
149
|
+
# 'enabled': True,
|
|
150
|
+
# 'ietf-ip:ipv4': {'mtu': 9000},
|
|
151
|
+
# 'if-index': 1,
|
|
152
|
+
# 'link-up-down-trap-enable': 'enabled',
|
|
153
|
+
# 'name': 'GigabitEthernet1/5',
|
|
154
|
+
# 'oper-status': 'unknown',
|
|
155
|
+
# 'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},
|
|
156
|
+
# 'type': 'iana-if-type:ethernetCsmacd'},
|
|
157
|
+
# {'admin-status': 'up',
|
|
158
|
+
# 'description': 'Works '
|
|
159
|
+
# 'data '
|
|
160
|
+
# 'v6',
|
|
161
|
+
# 'enabled': True,
|
|
162
|
+
# 'ietf-ip:ipv6': {'address': [{'ip': '2001::1',
|
|
163
|
+
# 'origin': 'static',
|
|
164
|
+
# 'prefix-length': 64},
|
|
165
|
+
# {'ip': '2001:1::1',
|
|
166
|
+
# 'origin': 'static',
|
|
167
|
+
# 'prefix-length': 64}]},
|
|
168
|
+
# 'if-index': 1,
|
|
169
|
+
# 'link-up-down-trap-enable': 'enabled',
|
|
170
|
+
# 'name': 'GigabitEthernet1/7',
|
|
171
|
+
# 'oper-status': 'unknown',
|
|
172
|
+
# 'statistics': {'discontinuity-time': '1970-01-01T00:00:00+00:00'},
|
|
173
|
+
# 'type': 'iana-if-type:ethernetCsmacd'}]}}],
|
|
174
|
+
# 'valid': {0: True, 1: True}}]
|
|
175
|
+
```
|
|
176
|
+
</details>
|
|
177
|
+
|
|
178
|
+
## How templates collections structured
|
|
179
|
+
|
|
180
|
+
This repository contains three collections of templates corresponding to folder names:
|
|
181
|
+
|
|
182
|
+
* `platform` collection - mimics [ntc-templates](https://github.com/networktocode/ntc-templates) API and follows same naming rule
|
|
183
|
+
* `yang` collection - contains templates capable of producing YANG compatible structures out of text data
|
|
184
|
+
* `misc` collection - miscellaneous templates for various use cases organized in folders
|
|
185
|
+
|
|
186
|
+
### Platform collection templates files naming rule
|
|
187
|
+
|
|
188
|
+
`{{ vendor_os }}_{{ command_with_underscores }}.txt` - lower case only.
|
|
189
|
+
|
|
190
|
+
Naming rules details:
|
|
191
|
+
|
|
192
|
+
* All space symbols `' '` replaced with underscores.
|
|
193
|
+
* Pipe symbol `|` replaced with `pipe` in template name. For example,
|
|
194
|
+
template to parse Cisco IOS `show run | section interface` command output
|
|
195
|
+
must be named `cisco_ios_show_running_config_pipe_section_interface.txt`
|
|
196
|
+
* Dash symbols `-` replaced with underscores. For example, template to parse
|
|
197
|
+
Huawei `display current-configuration interface` command output must be
|
|
198
|
+
named `huawei_display_current_configuration_interface.txt`
|
|
199
|
+
|
|
200
|
+
### YANG collection templates files naming rule
|
|
201
|
+
|
|
202
|
+
`{{ YANG module name }}_{{ platform_name }}.txt` - lower case only
|
|
203
|
+
|
|
204
|
+
Naming rules details:
|
|
205
|
+
|
|
206
|
+
* All space symbols `' '` replaced with underscore.
|
|
207
|
+
* Dash symbol `-` **does not** replaced with underscore. For example, template
|
|
208
|
+
to produce output compatible with openconfig-lldp YANG model for Cisco IOS
|
|
209
|
+
must be named `openconfig-lldp_cisco_xr.txt`
|
|
210
|
+
|
|
211
|
+
### Misc collection templates files naming rule
|
|
212
|
+
|
|
213
|
+
`{{ usecase folder }}/{{ template name }}.txt` - upper or lower case
|
|
214
|
+
|
|
215
|
+
Naming rules details:
|
|
216
|
+
|
|
217
|
+
* Nothing replaced with anything, provided template name used as is.
|
|
218
|
+
|
|
219
|
+
## Additional Templates Resources
|
|
220
|
+
|
|
221
|
+
List of resources with TTP templates:
|
|
222
|
+
|
|
223
|
+
- TTP SrosParser - https://pypi.org/project/ttp-sros-parser/ by [h4ndzdatm0ld](https://github.com/h4ndzdatm0ld)
|
|
224
|
+
- Template for parsing "show run" for Cisco IOS - https://github.com/tbotnz/ios-show-run-ttp by [tbotnz](https://github.com/tbotnz)
|
|
225
|
+
- Template for Cisco ASA configuration - https://github.com/consentfactory/ttp-cisco-asa-template by [consentfactory](https://gist.github.com/consentfactory)
|
|
226
|
+
- (gist for historical purposes) https://gist.github.com/consentfactory/85872fc83453d1735b15aed3e47a9763
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "ttp_templates"
|
|
3
|
+
version = "0.4.0"
|
|
4
|
+
description = "Template Text Parser Templates collections"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
include = [
|
|
7
|
+
"platform/*.txt",
|
|
8
|
+
"yang/*.txt",
|
|
9
|
+
"misc/*/*.txt",
|
|
10
|
+
]
|
|
11
|
+
authors = ["Denis Mulyalin <d.mulyalin@gmail.com>"]
|
|
12
|
+
maintainers = ["Denis Mulyalin <d.mulyalin@gmail.com>"]
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
homepage = "https://github.com/dmulyalin/ttp_templates"
|
|
15
|
+
repository = "https://github.com/dmulyalin/ttp_templates"
|
|
16
|
+
documentation = "https://dmulyalin.github.io/ttp_templates/"
|
|
17
|
+
keywords = ["Parsing", "TTP", "regex"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Topic :: Utilities",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Programming Language :: Python :: 3.14",
|
|
25
|
+
"License :: OSI Approved :: MIT License",
|
|
26
|
+
"Operating System :: POSIX :: Linux",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[tool.poetry.dependencies]
|
|
30
|
+
python = "^3.10"
|
|
31
|
+
ttp = { version = ">=0.6.0" }
|
|
32
|
+
|
|
33
|
+
# docs dependencies for extras definition
|
|
34
|
+
mkdocs = { version = "*", optional = true }
|
|
35
|
+
mkdocs-material = { version = "*", optional = true }
|
|
36
|
+
mkdocs-material-extensions = { version = "*", optional = true }
|
|
37
|
+
mkdocstrings = { version = "*", optional = true, extras = ["python"] }
|
|
38
|
+
pygments = { version = "*", optional = true }
|
|
39
|
+
pymdown-extensions = { version = "*", optional = true }
|
|
40
|
+
|
|
41
|
+
[tool.poetry.group.dev.dependencies]
|
|
42
|
+
bandit = { version = "*" }
|
|
43
|
+
black = { version = "*" }
|
|
44
|
+
flake8 = { version = "*" }
|
|
45
|
+
pre-commit = { version = "*" }
|
|
46
|
+
pyenchant = { version = "*" }
|
|
47
|
+
pylint = { version = "*" }
|
|
48
|
+
pytest = { version = "*" }
|
|
49
|
+
cerberus = { version = "*" }
|
|
50
|
+
jinja2 = { version = "*" }
|
|
51
|
+
pyyaml = { version = "*" }
|
|
52
|
+
deepdiff = { version = "*" }
|
|
53
|
+
openpyxl = { version = "*" }
|
|
54
|
+
tabulate = { version = "*" }
|
|
55
|
+
yangson = { version = "*" }
|
|
56
|
+
netmiko = { version = "*" }
|
|
57
|
+
|
|
58
|
+
[build-system]
|
|
59
|
+
requires = ["poetry-core>=1.0.0"]
|
|
60
|
+
build-backend = "poetry.core.masonry.api"
|
|
61
|
+
|
|
62
|
+
[tool.poetry.extras]
|
|
63
|
+
docs = [
|
|
64
|
+
"mkdocs",
|
|
65
|
+
"mkdocs-material",
|
|
66
|
+
"mkdocs-material-extensions",
|
|
67
|
+
"mkdocstrings",
|
|
68
|
+
"pygments",
|
|
69
|
+
"pymdown-extensions",
|
|
70
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<template name="a10" results="per_template">
|
|
2
|
+
|
|
3
|
+
<doc>
|
|
4
|
+
Template to parse A10 devices interfaces configuration and IP ARP cache.
|
|
5
|
+
</doc>
|
|
6
|
+
|
|
7
|
+
<input load="python">
|
|
8
|
+
commands = [
|
|
9
|
+
"show running-config",
|
|
10
|
+
"show arp all",
|
|
11
|
+
]
|
|
12
|
+
kwargs = {"strip_prompt": False}
|
|
13
|
+
method = "send_command"
|
|
14
|
+
platform = ["a10"]
|
|
15
|
+
</input>
|
|
16
|
+
|
|
17
|
+
<vars>local_hostname="gethostname"</vars>
|
|
18
|
+
|
|
19
|
+
<!-- Interfaces configuration group -->
|
|
20
|
+
<group name="{{ local_hostname }}.interfaces.{{ interface }}">
|
|
21
|
+
interface {{ interface | PHRASE | resuball("IfsNormalize") }}
|
|
22
|
+
description {{ port_description | re(".+") }}
|
|
23
|
+
<group name="ip_addresses*" chain="add_network()" method="table">
|
|
24
|
+
ip address {{ ip | IP }} {{ netmask }}
|
|
25
|
+
</group>
|
|
26
|
+
</group>
|
|
27
|
+
|
|
28
|
+
<!-- ARP cache group -->
|
|
29
|
+
<group name="{{ local_hostname }}.interfaces.{{ interface }}.arp*" method="table">
|
|
30
|
+
{{ ip | IP }} {{ mac | MAC | mac_eui }} Dynamic {{ age }} {{ interface | PHRASE | resuball("IfsNormalize") }} {{ vlan }}
|
|
31
|
+
</group>
|
|
32
|
+
|
|
33
|
+
</template>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<template name="arista_eos" results="per_template">
|
|
2
|
+
|
|
3
|
+
<doc>
|
|
4
|
+
Template to parse Arista EOS interfaces configuration and ARP cache.
|
|
5
|
+
</doc>
|
|
6
|
+
|
|
7
|
+
<input load="python">
|
|
8
|
+
commands = [
|
|
9
|
+
"show running-config",
|
|
10
|
+
"show ip arp vrf all",
|
|
11
|
+
]
|
|
12
|
+
method = "send_command"
|
|
13
|
+
platform = ["arista_eos"]
|
|
14
|
+
</input>
|
|
15
|
+
|
|
16
|
+
<!-- Extract Device Hostname -->
|
|
17
|
+
<group name="nill" void="">
|
|
18
|
+
hostname {{ local_hostname | record("local_hostname") }}
|
|
19
|
+
</group>
|
|
20
|
+
|
|
21
|
+
<!-- Interfaces configuration group -->
|
|
22
|
+
<group name="{{ local_hostname }}.interfaces.{{ interface }}">
|
|
23
|
+
interface {{ interface | resuball("IfsNormalize") }}
|
|
24
|
+
description {{ port_description | re(".+") }}
|
|
25
|
+
vrf {{ vrf }}
|
|
26
|
+
<group name="ip_addresses*" chain="add_network()" method="table">
|
|
27
|
+
ip address {{ ip | IP }}/{{ netmask }}
|
|
28
|
+
ip address {{ ip | IP }}/{{ netmask }} secondary
|
|
29
|
+
</group>
|
|
30
|
+
! {{ _end_ }}
|
|
31
|
+
</group>
|
|
32
|
+
|
|
33
|
+
<!-- ARP cache group -->
|
|
34
|
+
<group name="{{ local_hostname }}.interfaces.{{ interface }}.arp*" method="table">
|
|
35
|
+
{{ ip | IP }} {{ age }} {{ mac | MAC | mac_eui }} {{ interface | resuball("IfsNormalize") }}
|
|
36
|
+
</group>
|
|
37
|
+
|
|
38
|
+
</template>
|