cisco-config-parser 2.2.4__tar.gz → 2.2.5__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.
Files changed (74) hide show
  1. cisco_config_parser-2.2.5/PKG-INFO +717 -0
  2. cisco_config_parser-2.2.5/README.md +707 -0
  3. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/__init__.py +1 -1
  4. cisco_config_parser-2.2.5/cisco_config_parser/cisco_config_parser.py +3 -0
  5. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/global_search/global_parser.py +1 -1
  6. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/global_search/global_separator.py +1 -1
  7. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/layer2_interface/l2_interface_parser.py +16 -1
  8. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/layer2_interface/l2_interface_separator.py +1 -1
  9. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/layer3_interface/l3_interface_parser.py +8 -2
  10. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/layer3_interface/l3_interface_separator.py +1 -1
  11. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/layer3_interface/l3_section_parser.py +1 -1
  12. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/old_version/old_parse.py +1 -1
  13. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/parent_child/parent_child_parser.py +1 -34
  14. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/parser/__init__.py +13 -1
  15. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/parser/parser.py +8 -6
  16. cisco_config_parser-2.2.5/cisco_config_parser/parser_regex/__init__.py +4 -0
  17. cisco_config_parser-2.2.5/cisco_config_parser/parser_regex/common_regex.py +18 -0
  18. cisco_config_parser-2.2.4/cisco_config_parser/parser_regex/regex.py → cisco_config_parser-2.2.5/cisco_config_parser/parser_regex/ios_regex.py +2 -12
  19. cisco_config_parser-2.2.5/cisco_config_parser/parser_regex/nxos_regex.py +17 -0
  20. cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/__init__.py +5 -0
  21. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/routing_protocol/ios/rtp_bgp.py +1 -1
  22. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/routing_protocol/ios/rtp_eigtp.py +4 -4
  23. cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/ios/rtp_ios_rtp_obj.py +134 -0
  24. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/routing_protocol/ios/rtp_ospf.py +3 -2
  25. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/routing_protocol/ios/rtp_static.py +3 -3
  26. cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/nxos/rtp_static.py +49 -0
  27. cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/nxos/rtp_vxlan.py +0 -0
  28. cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/utils/__init__.py +3 -0
  29. cisco_config_parser-2.2.4/cisco_config_parser/routing_protocol/utils/rtp_separator.py → cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/utils/rtp_ios_separator.py +1 -1
  30. cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/utils/rtp_nxos_separator.py +68 -0
  31. cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/xr/__init__.py +0 -0
  32. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/separator/separator.py +2 -3
  33. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/setup.py +1 -1
  34. cisco_config_parser-2.2.5/cisco_config_parser.egg-info/PKG-INFO +717 -0
  35. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser.egg-info/SOURCES.txt +10 -2
  36. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/setup.py +1 -1
  37. cisco_config_parser-2.2.4/PKG-INFO +0 -385
  38. cisco_config_parser-2.2.4/README.md +0 -375
  39. cisco_config_parser-2.2.4/cisco_config_parser/cisco_config_parser.py +0 -3
  40. cisco_config_parser-2.2.4/cisco_config_parser/parser_regex/__init__.py +0 -2
  41. cisco_config_parser-2.2.4/cisco_config_parser/routing_protocol/__init__.py +0 -5
  42. cisco_config_parser-2.2.4/cisco_config_parser.egg-info/PKG-INFO +0 -385
  43. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/global_search/__init__.py +0 -0
  44. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/global_search/global_obj.py +0 -0
  45. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/global_search/ios/__init__.py +0 -0
  46. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/global_search/nxos/__init__.py +0 -0
  47. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/global_search/xr/__init__.py +0 -0
  48. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/helper/__init__.py +0 -0
  49. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/helper/help.py +0 -0
  50. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/helper/helper.py +0 -0
  51. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/layer2_interface/__init__.py +0 -0
  52. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/layer2_interface/l2_interface_obj.py +0 -0
  53. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/layer2_interface/l2_section_parser.py +0 -0
  54. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/layer3_interface/__init__.py +0 -0
  55. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/layer3_interface/l3_interface_obj.py +0 -0
  56. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/old_version/__init__.py +0 -0
  57. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/old_version/exceptions.py +0 -0
  58. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/old_version/obj.py +0 -0
  59. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/old_version/ssh.py +0 -0
  60. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/old_version/utils.py +0 -0
  61. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/parent_child/__init__.py +0 -0
  62. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/parent_child/parent_child_obj.py +0 -0
  63. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/parent_child/parent_child_separator.py +0 -0
  64. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/routing_protocol/ios/__init__.py +0 -0
  65. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/routing_protocol/nxos/__init__.py +0 -0
  66. /cisco_config_parser-2.2.4/cisco_config_parser/routing_protocol/utils/__init__.py → /cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/nxos/rtp_bgp.py +0 -0
  67. /cisco_config_parser-2.2.4/cisco_config_parser/routing_protocol/ios/rtp_ios_rtp_obj.py → /cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/nxos/rtp_nxos_rtp_obj.py +0 -0
  68. /cisco_config_parser-2.2.4/cisco_config_parser/routing_protocol/xr/__init__.py → /cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/nxos/rtp_ospf.py +0 -0
  69. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/routing_protocol/utils/utils.py +0 -0
  70. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser/separator/__init__.py +0 -0
  71. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser.egg-info/dependency_links.txt +0 -0
  72. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/cisco_config_parser.egg-info/top_level.txt +0 -0
  73. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/pyproject.toml +0 -0
  74. {cisco_config_parser-2.2.4 → cisco_config_parser-2.2.5}/setup.cfg +0 -0
@@ -0,0 +1,717 @@
1
+ Metadata-Version: 2.1
2
+ Name: cisco_config_parser
3
+ Version: 2.2.5
4
+ Summary: This library is used for Network Automation involving Cisco Routers and Switch. It will parse Cisco IOS, IOS-XE, IOS-XR, and NXOS configuration file into objects and/or json format
5
+ Home-page: https://github.com/arezazadeh/cisco_config_parser
6
+ Author: Ahmad Rezazadeh
7
+ Author-email: ahmad@klevernet.io
8
+ License: MIT License
9
+ Description-Content-Type: text/markdown
10
+
11
+ # Cisco Configuration Parser
12
+
13
+ ## Overview
14
+ The **Cisco Configuration Parser** is a Python library designed for network automation tasks, specifically focusing on parsing configuration files from Cisco routers and switches. It supports Cisco IOS, IOS-XE, IOS-XR, and NXOS platforms. This library allows you to convert running configuration files into structured Python objects or JSON/dictionary formats for easier analysis, modification, or automation.
15
+
16
+ ## Key Features
17
+
18
+ ### <li> Platform Detection
19
+ This library is designed to be **platform agnostic**, meaning it can automatically determine the Cisco platform based on the syntax of the configuration file. In cases where the platform cannot be determined automatically, you can manually specify the platform by passing `platform="IOS/XR/NXOS"` to the parser.
20
+
21
+ ### <li> Flexible Data Handling
22
+ The parser can convert configuration data into either Python objects or JSON/dictionary formats. You can control the format by passing the `return_json=True` flag to the relevant method. This flexibility allows you to integrate with a wide range of automation workflows and tools.
23
+
24
+ ### <li> Configuration Hierarchy Recognition
25
+ Cisco configurations often feature a mix of parent-child relationships and standalone entries. This library is adept at recognizing and parsing these patterns to capture both common and critical configuration attributes. For instance:
26
+
27
+ - **Standalone Configuration Example:**
28
+ ```bash
29
+ hostname switch01.net
30
+ ```
31
+
32
+ - **Parent-Child Configuration Example:**
33
+
34
+ ```bash
35
+ Vlan 100 <<<< Parent
36
+ name DATA_VLAN <<<< Child
37
+ ```
38
+
39
+ This library tries to captures the important and common attributes of the configurations for different sections and convert them to python objects or json/dict format.
40
+
41
+ Some of those configs are as follow:
42
+
43
+ ```python
44
+ - Hostname,
45
+ - AAA,
46
+ - Interface,
47
+ - VLAN,
48
+ - Interface (Layer2 and Layer3),
49
+ - Access-list,
50
+ - Prefix-list,
51
+ - Prefix-set (IOS-XR)
52
+ - Route-map,
53
+ - Route-policy (IOS-XR),
54
+ - Static Routes,
55
+ - Dynamic Routes
56
+ - RIP
57
+ - EIGRP
58
+ - OSPF
59
+ - IS-IS
60
+ - BGP
61
+
62
+ - Line-vty
63
+ - Line-con
64
+ - Banner
65
+ ```
66
+ Above configuration sections are captured along with the most common attributes/children. and the rest of them are captured inside method `obj.children`.
67
+
68
+ ### <li> Parent/Child Regex Parsing Capabilities
69
+ In addition to above default behavior or the library, you also have the option to pass your own regex to the `ConfigParser` as either `parent_regex=r"<custom_regex>", child_regex=r"<custom_regex>"` or only `parent_regex=r"<custom_regex>"`.
70
+
71
+ **Note:** If you pass both `parent_regex` and `child_regex`, the library attempt to search for the parent and the only child that you have searched for. If you would like to get all the children, then just pass the `parent_regex` to the class. I will have some example at the bottom this document.
72
+
73
+
74
+ ## <li> Install the package
75
+ This package is available on `pypi.org` you can install the package via `pip`.
76
+
77
+ https://pypi.org/project/cisco-config-parser/
78
+
79
+ ```bash
80
+ pip install cisco-config-parser
81
+ ```
82
+
83
+
84
+ ## <li> Current Classes in this library
85
+
86
+ ```python
87
+ IOSStaticRouteConfig
88
+ IOSOSPFConfig
89
+ IOSEIGRPConfig
90
+ IOSBGPConfig
91
+ IOSBGPConfig
92
+ L3InterfaceParser
93
+ L2InterfaceParser
94
+ ParentChildParser
95
+ ```
96
+
97
+ There more Classes are being built, and will be released in the upcoming versions.
98
+
99
+ ## <li> Get Example usage:
100
+ A short documentation is embeded in the code base. you can view those example by importing `helper` and calling the class
101
+
102
+ ```python
103
+ from cisco_config_parser.helper import helper
104
+
105
+ helper = helper.IOSStaticRouteConfig()
106
+
107
+ print(helper)
108
+ ```
109
+
110
+ **Output**:
111
+ ```
112
+
113
+ Example Usage:
114
+ ====================================================================================================
115
+
116
+ with open("show_run.txt", "r") as file_output:
117
+ content = file_output.read()
118
+
119
+
120
+ obj = ConfigParser(content)
121
+
122
+ obj.get_static_routes() << Returns a list of objects
123
+ obj.get_static_routes(return_json=True) << Returns a list of dictionaries
124
+
125
+ ```
126
+ ## <li> Examples:
127
+
128
+ ## <li> Loading the Running-Config File
129
+
130
+ ```python
131
+ >>> ios_file = "/Users/fileFolder/devFolder/config.txt"
132
+ >>> with open(ios_file, "r") as f:
133
+ running_config = f.read()
134
+
135
+ >>> from cisco_config_parser import ConfigParser
136
+ >>>
137
+ >>> parser = ConfigParser(running_config)
138
+ ```
139
+
140
+
141
+ ## <li> Layer3 Interface
142
+
143
+ In layer-3 interface, the class attempts to capture all the important attributes of the interface, such as:
144
+
145
+ - IPv4 Address
146
+ - Subnet
147
+ - Subnet Mask
148
+ - Secondary IPv4 Address
149
+ - Secondary Subnet
150
+ - Secondary Subnet Mask
151
+ - HSRP or VRRP Config
152
+ - VIP
153
+
154
+ ### <li> Subnet list and their Usages
155
+
156
+ One of the great feature in this library is it captures all the subnets that are being used in your Network Device along with their usage.
157
+ Also it tells you how many of each subnet masks are being used as well. I personaly use this feature when i need to automate DHCP/IPAM documentaion cleanup.
158
+
159
+ **Example below illustriates this feature:**
160
+
161
+ ```python
162
+ >>> subnet_usage = parser.get_subnet_and_usage(include_subnet_count=True)
163
+ >>> print(json.dumps(subnet_usage, indent=4))
164
+
165
+ {
166
+ "Loopback100": "10.241.17.8/32",
167
+ "Loopback200": "10.252.248.1/32",
168
+ "Vlan200": "10.252.182.0/23",
169
+ "Vlan300": "10.244.16.160/27",
170
+ "Vlan310": "10.241.101.80/28",
171
+ "Vlan400": "10.39.10.32/27",
172
+ "Vlan700": "172.31.81.0/25",
173
+ "Vlan1100": "10.242.12.0/26",
174
+ "Vlan1125": "10.241.8.0/27",
175
+ "Vlan1126": "10.241.8.32/27",
176
+ "Vlan1127": "10.241.8.64/27",
177
+ "subnet_count": {
178
+ "/32": 2,
179
+ "/23": 1,
180
+ "/27": 5,
181
+ "/28": 1,
182
+ "/25": 1,
183
+ "/26": 1,
184
+ }
185
+ }
186
+ ```
187
+
188
+ ### <li> Layer3 Interfaces - List of Objects
189
+
190
+ ```python
191
+ >>> l3_interfaces = parser.get_l3_interfaces()
192
+ >>>for l3 in l3_interfaces:
193
+ print(l3.name)
194
+ print(l3.ip_address, l3.subnet)
195
+ print("!")
196
+
197
+ Loopback100
198
+ 10.241.17.8 10.241.17.8/32
199
+ !
200
+ Loopback200
201
+ 10.252.248.1 10.252.248.1/32
202
+ !
203
+ Loopback202
204
+ 10.245.0.199 10.245.0.199/32
205
+ ```
206
+ ### <li> Layer3 Interfaces - Json/Dict Format
207
+
208
+ ```python
209
+ >>> l3_interfaces = parser.get_l3_interfaces(return_json=True)
210
+ >>> print(json.dumps(l3_interfaces, indent=4))
211
+ [
212
+ {
213
+ "name": "Loopback100",
214
+ "description": "SWITCH01-SA01 Loopback IP",
215
+ "ip_address": "10.241.17.8",
216
+ "mask": "255.255.255.255",
217
+ "subnet": "10.241.17.8/32",
218
+ "helpers": null,
219
+ "sec_ip_address": null,
220
+ "sec_mask": null,
221
+ "sec_subnet": null,
222
+ "vrf": "mgt100",
223
+ "state": null,
224
+ "vip": null,
225
+ "children": [
226
+ "description SWITCH01-SA01 Loopback IP",
227
+ "ip vrf forwarding mgt100",
228
+ "ip address 10.241.17.8 255.255.255.255",
229
+ "ip pim sparse-mode",
230
+ "ip ospf 100 area 0"
231
+ ]
232
+ },
233
+ ]
234
+ ```
235
+
236
+ ### <li> Layer3 Interfaces - Custom Key/Value and Regex
237
+
238
+ ```python
239
+ >>> l3_interfaces = parser.get_l3_interfaces(ip_pim="ip pim.*")
240
+ >>> for i in l3_interfaces:
241
+ print(i.name)
242
+ print(i.ip_pim)
243
+ print("!")
244
+
245
+ Loopback100
246
+ ip pim sparse-mode
247
+ !
248
+ Loopback200
249
+ ip pim sparse-mode
250
+ !
251
+ ```
252
+
253
+ ## <li> Layer2 `Access` and `Trunk` Interface
254
+
255
+ ### <li> `Access Port` List of Objects
256
+
257
+ ```python
258
+ >>> access_ports = parser.get_l2_access_interfaces()
259
+ >>>
260
+ >>> for intf in access_ports:
261
+ print(intf.name)
262
+ print(intf.description)
263
+ print(intf.children)
264
+ print("!")
265
+ ...
266
+ GigabitEthernet1/1
267
+ Data Users
268
+ ['description Data Users', 'switchport access vlan 200', 'switchport mode access', 'switchport voice vlan 700', 'no logging event power-inline-status', 'ip dhcp snooping information option allow-untrusted']
269
+ !
270
+ GigabitEthernet1/2
271
+ Data Users
272
+ ['description Data Users', 'switchport access vlan 200', 'switchport mode access', 'switchport voice vlan 700', 'no logging event power-inline-status', 'ip dhcp snooping information option allow-untrusted']
273
+ !
274
+ ```
275
+
276
+ ### <li> `Access Port` the json/dict format:
277
+
278
+ ```python
279
+ >>> access_ports = parser.get_l2_access_interfaces(return_json=True)
280
+
281
+ >>> print(json.dumps(access_ports, indent=4))
282
+
283
+ [
284
+ {
285
+ "name": "GigabitEthernet1/1",
286
+ "description": "DATA Users",
287
+ "data_vlan": "200",
288
+ "voice_vlan": "700",
289
+ "state": null,
290
+ "spanning_tree": null,
291
+ "native_vlan": null,
292
+ "children": [
293
+ "description DATA Users",
294
+ "switchport access vlan 200",
295
+ "switchport mode access",
296
+ "switchport voice vlan 700",
297
+ "no logging event power-inline-status",
298
+ "ip dhcp snooping information option allow-untrusted"
299
+ ]
300
+ },
301
+ ]
302
+ ```
303
+ ### <li> `Access Port` Custom Key/method search
304
+
305
+ You can use your own custom regex with your own key, this key then become a dynamic method of the class where you can either call it or recieve it as json format.
306
+
307
+
308
+ ```python
309
+ >>> access_ports = parser.get_l2_access_interfaces(logging="no loggin.*", return_json=True)
310
+
311
+ >>> print(json.dumps(access_ports, indent=4))
312
+
313
+ [
314
+ {
315
+ "name": "GigabitEthernet1/1",
316
+ "description": "SHC-Users",
317
+ "data_vlan": "200",
318
+ "voice_vlan": "700",
319
+ "state": null,
320
+ "spanning_tree": null,
321
+ "native_vlan": null,
322
+ "children": [
323
+ "description SHC-Users",
324
+ "switchport access vlan 200",
325
+ "switchport mode access",
326
+ "switchport voice vlan 700",
327
+ "no logging event power-inline-status",
328
+ "ip dhcp snooping information option allow-untrusted"
329
+ ],
330
+ "logging": "no logging event power-inline-status" <<<<< custom Key to find logging command
331
+ },
332
+ ]
333
+ ```
334
+
335
+ ### <li> `Trunk Port` List of Objects
336
+
337
+ ```python
338
+ >>> trunk_interfaces = parser.get_l2_trunk_interfaces()
339
+
340
+ >>> for intf in trunk_interfaces:
341
+ print(intf.name)
342
+ print(intf.description)
343
+ print("!")
344
+
345
+ TenGigabitEthernet5/1
346
+ (MP)SWITCH-SD03:Twe1/0/6
347
+ !
348
+ TenGigabitEthernet5/2
349
+ Link to SWITCH-SA01 Te6/2 Decomm
350
+ !
351
+ TenGigabitEthernet6/1
352
+ (MP)SWITCH-SD04:Te1/1
353
+ !
354
+ ```
355
+
356
+ ### <li> `Trunk Port` Json/Dict format
357
+
358
+ ```python
359
+ >>> trunk_interfaces = parser.get_l2_trunk_interfaces(return_json=True)
360
+ >>> print(json.dumps(trunk_interfaces, indent=4))
361
+
362
+ [
363
+ {
364
+ "name": "TenGigabitEthernet5/1",
365
+ "description": "(MP)SWITCH-SD03:Twe1/0/6",
366
+ "allowed_vlans": null,
367
+ "dhcp_snooping": null,
368
+ "dhcp_relay": null,
369
+ "voice_vlan": null,
370
+ "state": null,
371
+ "spanning_tree": null,
372
+ "native_vlan": "256",
373
+ "children": [
374
+ "description (MP)SWITCH-SD03:Twe1/0/6",
375
+ "switchport trunk native vlan 256",
376
+ "switchport trunk allowed vlan 182,256,504,1100,3101,3201,3301,3311,3321,3331",
377
+ "switchport trunk allowed vlan add 3351,3401,3411,3911",
378
+ "switchport mode trunk",
379
+ "load-interval 30",
380
+ "udld port aggressive",
381
+ "service-policy output egress_queueing",
382
+ "ip dhcp snooping trust"
383
+ ],
384
+ "allowed_vlan": "182,256,504,1100,3101,3201,3301,3311,3321,3331"
385
+ },
386
+ ]
387
+ ```
388
+ ### <li> `Trunk Port` Custom Key/method search
389
+
390
+ ```python
391
+ >>> access_ports = parser.parser.get_l2_trunk_interfaces(load="load.*", return_json=True)
392
+
393
+ >>> print(json.dumps(access_ports, indent=4))
394
+
395
+ {
396
+ "name": "TenGigabitEthernet5/1",
397
+ "description": "(MP)SWITCH-SD03:Twe1/0/6",
398
+ "allowed_vlans": null,
399
+ "dhcp_snooping": null,
400
+ "dhcp_relay": null,
401
+ "voice_vlan": null,
402
+ "state": null,
403
+ "spanning_tree": null,
404
+ "native_vlan": "256",
405
+ "children": [
406
+ "description (MP)STNMED-LPCH-SD03:Twe1/0/6",
407
+ "switchport trunk native vlan 256",
408
+ "switchport trunk allowed vlan 182,256,504,1100,3101,3201,3301,3311,3321,3331",
409
+ "switchport trunk allowed vlan add 3351,3401,3411,3911",
410
+ "switchport mode trunk",
411
+ "load-interval 30",
412
+ "udld port aggressive",
413
+ "service-policy output egress_queueing",
414
+ "ip dhcp snooping trust"
415
+ ],
416
+ "allowed_vlan": "182,256,504,1100,3101,3201,3301,3311,3321,3331",
417
+ "load": "load-interval 30" <<<<< Custom Key and Value
418
+ },
419
+ ```
420
+
421
+
422
+ ## <li> Static Route Config
423
+
424
+ **Features**
425
+ - Parse Static Routes: Extract and parse static routing commands (ip route entries) from Cisco running configurations.
426
+ - Convert to Python Objects: Represent these routes as structured Python objects, enabling programmatic manipulation and easy integration with Python-based tools.
427
+ - Export to JSON/Dict: Convert static routing information into JSON or dictionary format, making it straightforward to use in web applications, APIs, or data storage solutions.
428
+
429
+ #### Example
430
+
431
+ **Python Object:**
432
+ ```python
433
+
434
+ >>> static = parser.get_static_config()
435
+ >>> for i in static:
436
+ print(i.subnet, i.name, i.nexthop_ip)
437
+
438
+ 0.0.0.0/0 MC-RS01 10.240.129.3
439
+ 0.0.0.0/0 NC-RS01 10.240.129.11
440
+ 10.243.98.32/28 P2P_Subnet 10.243.99.186
441
+ ```
442
+
443
+ **Json/Dict:**
444
+ ```python
445
+ static = parser.get_static_config()
446
+ [
447
+ {
448
+ "network": "0.0.0.0",
449
+ "mask": "0.0.0.0",
450
+ "nexthop_ip": "10.240.129.3",
451
+ "subnet": "0.0.0.0/0",
452
+ "vrf": "default",
453
+ "name": "MC-RS01",
454
+ "admin_distance": null
455
+ },
456
+ ]
457
+ ```
458
+
459
+
460
+ ## <li> Dynamic Route Config
461
+
462
+ ### <li> EIGRP
463
+
464
+ `eigrp_configs = parser.get_eigrp_config(return_json=True)`
465
+
466
+ ```json
467
+ [
468
+ {
469
+ "as_number": 300,
470
+ "network": [
471
+ {
472
+ "network": "10.242.96.240",
473
+ "subnet_mask": "255.255.255.252",
474
+ "wildcard_mask": "0.0.0.3"
475
+ },
476
+ {
477
+ "network": "10.242.97.244",
478
+ "subnet_mask": "255.255.255.252",
479
+ "wildcard_mask": "0.0.0.3"
480
+ },
481
+ {
482
+ "network": "10.242.98.248",
483
+ "subnet_mask": "255.255.255.252",
484
+ "wildcard_mask": "0.0.0.3"
485
+ },
486
+ {
487
+ "network": "10.242.99.252",
488
+ "subnet_mask": "255.255.255.252",
489
+ "wildcard_mask": "0.0.0.3"
490
+ }
491
+ ],
492
+ "vrf": "Global",
493
+ "wild_card_mask": null,
494
+ "subnet": null,
495
+ "has_vrf": true,
496
+ "vrf_count": 8,
497
+ "passive_interface": null,
498
+ "no_passive_interface": null,
499
+ "auto_cost": null,
500
+ "interfaces": null,
501
+ "children": [
502
+ "network 10.242.96.240 0.0.0.3",
503
+ "network 10.242.97.244 0.0.0.3",
504
+ "network 10.242.98.248 0.0.0.3",
505
+ "network 10.242.99.252 0.0.0.3",
506
+ "no passive-interface GigabitEthernet1/9",
507
+ "no passive-interface GigabitEthernet1/10",
508
+ "passive-interface default",
509
+ "no auto-summary"
510
+ ],
511
+ "vrf_children": [
512
+ {
513
+ "vrf": "mgt100",
514
+ "network": [
515
+ {
516
+ "network": "10.242.96.240",
517
+ "subnet_mask": "255.255.255.252",
518
+ "wildcard_mask": "0.0.0.3"
519
+ }
520
+ ],
521
+ "wild_card_mask": null,
522
+ "subnet": null,
523
+ "passive_interface": null,
524
+ "no_passive_interface": null,
525
+ "auto_cost": null,
526
+ "interfaces": null,
527
+ "children": [
528
+ "redistribute bgp 65240 metric 1000 100 255 1 1500 route-map MGT100_EIGRP_REDIST_BGP",
529
+ "network 10.242.96.240 0.0.0.3",
530
+ "passive-interface default",
531
+ "no passive-interface TenGigabitEthernet1/9.3131",
532
+ "distribute-list route-map route_map_inbound in",
533
+ "autonomous-system 300",
534
+ "exit-address-family"
535
+ ]
536
+ },
537
+ ]
538
+ }
539
+
540
+ ]
541
+ ```
542
+
543
+ ### <li> BGP Route Config:
544
+
545
+ **Example:**
546
+ `bgp_configs = parser.get_bgp_config(return_json=True)`
547
+
548
+ ```json
549
+ [
550
+ {
551
+ "router_id": "10.240.129.45",
552
+ "vrf_list": [
553
+ "blu300",
554
+ ],
555
+ "vrf": "Global",
556
+ "network": [
557
+ "10.245.49.132/32"
558
+ ],
559
+ "peer_group": [
560
+ {
561
+ "peer_group": {
562
+ "name": "RR",
563
+ "remote_as": "65234",
564
+ "update_source": "Loopback1",
565
+ "route_map": {
566
+ "in": "PEER_GROUP_RR_INBOUND",
567
+ "out": "PEER_GROUP_RR_OUTBOUND"
568
+ },
569
+ "neighbors": [
570
+ {
571
+ "ip": "10.252.248.251",
572
+ "description": "RR-Router-01"
573
+ },
574
+ ]
575
+ }
576
+ },
577
+ ],
578
+ "neighbors": null,
579
+ "redistribute": [
580
+ {
581
+ "vrf": "Global",
582
+ "protocol": "eigrp 100",
583
+ "route_map": ""
584
+ }
585
+ ],
586
+ "vrf_children": [
587
+ {
588
+ "vrf": "blu300",
589
+ "network": [
590
+ "10.245.17.132/32"
591
+ ],
592
+ "peer_group": null,
593
+ "neighbors": [
594
+ {
595
+ "vrf": "blu300",
596
+ "ip": "10.245.20.30",
597
+ "remote_as": "65245",
598
+ "description": "REMOTE_ROUTER-SA01_BLU300",
599
+ "update_source": "TenGigabitEthernet10/14.3301",
600
+ "route_map": {
601
+ "in": "ALLVRF_BGP_RM_INBOUND",
602
+ "out": "ALLVRF_BGP_RM_OUTBOUND"
603
+ }
604
+ }
605
+ ],
606
+ "redistribute": [
607
+ {
608
+ "vrf": "blu300",
609
+ "protocol": "eigrp 252",
610
+ "route_map": " BLU300_BGP_REDIST_EIGRP"
611
+ },
612
+ {
613
+ "vrf": "blu300",
614
+ "protocol": "static",
615
+ "route_map": " BLU300_BGP_REDIST_STATIC"
616
+ }
617
+ ],
618
+ }
619
+ ]
620
+ }
621
+ ]
622
+ ```
623
+
624
+ ### <li> OSPF Route Config
625
+
626
+ In ospf, ConfigParser attemps to capture any interfaces that are participating in OSPF as well.
627
+
628
+ **Example:**
629
+
630
+ `ospf = parser.get_ospf_config(return_json=True)`
631
+
632
+ ```json
633
+ [
634
+ {
635
+ "process_id": "240",
636
+ "router_id": "10.240.129.45",
637
+ "network": [
638
+ {
639
+ "network": "10.3.3.0",
640
+ "subnet_mask": "255.255.255.0",
641
+ "wildcard_mask": "0.0.0.255",
642
+ "area": "0"
643
+ }
644
+ ],
645
+ "wild_card_mask": null,
646
+ "subnet": null,
647
+ "vrf": null,
648
+ "passive_interface": [
649
+ {
650
+ "interface": "default"
651
+ }
652
+ ],
653
+ "no_passive_interface": [
654
+ {
655
+ "interface": "GigabitEthernet1/0"
656
+ }
657
+ ],
658
+ "auto_cost": "10000",
659
+ "interfaces": [
660
+ {
661
+ "interface": "Loopback0",
662
+ "area": "0",
663
+ "process_id": "240"
664
+ }
665
+ ]
666
+ }
667
+ ]
668
+ ```
669
+
670
+ ## <li> Custom Parsing
671
+
672
+ **Example:**
673
+ `custom_search = parser.get_parent_child(parent_regex="aaa.*", child_regex="server.*", return_json=True)`
674
+
675
+ ```json
676
+
677
+ [
678
+ {
679
+ "parent": "aaa group server tacacs+ ISE_TACACS",
680
+ "children": "server tacacs+ ISE_TACACS"
681
+ }
682
+ ]
683
+ ```
684
+
685
+
686
+
687
+ ## Future Enhancements
688
+ I am actively working on expanding the capabilities of this library. Upcoming features include:
689
+
690
+ - **Enhanced support for NXOS**: Additional parsing for NXOS-specific configurations and features.
691
+ - **Full support for IOS-XR**: Expanding coverage for IOS-XR configurations to include more advanced routing and service configurations.
692
+ - **More configuration sections**: Additional Cisco configuration types and attributes will be parsed in future releases.
693
+
694
+ Stay tuned for these updates and more in future versions of the library!
695
+
696
+
697
+
698
+ ## Contribution
699
+ Contributions are welcome! To contribute:
700
+
701
+ 1. Fork this repository.
702
+ 2. Create a feature branch.
703
+ 3. Make your changes and add tests if applicable.
704
+ 4. Submit a pull request for review.
705
+ 5. Feel free to open an issue for any bug reports or feature requests.
706
+
707
+
708
+
709
+ ## License
710
+ This project is licensed under the MIT License.
711
+
712
+ ### Key Improvements:
713
+ 1. **Title and Overview:** I emphasized the functionality of the library with clear mention of automation, parsing, and supported platforms.
714
+ 2. **Key Features:** I made the features section clearer and more structured.
715
+ 3. **Usage Example:** Added a usage example to make it easy for users to get started.
716
+ 4. **Installation:** Provided simple installation instructions using `pip`.
717
+ 5. **Contribution and License Sections:** These are standard in open-source projects and help potential contributors know how to get involved.