cisco-config-parser 2.1__tar.gz → 2.2.1__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.
- cisco_config_parser-2.1/README.md → cisco_config_parser-2.2.1/PKG-INFO +102 -11
- cisco_config_parser-2.1/PKG-INFO → cisco_config_parser-2.2.1/README.md +92 -21
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/global_search/global_parser.py +3 -1
- cisco_config_parser-2.1/cisco_config_parser/testing.py → cisco_config_parser-2.2.1/cisco_config_parser/helper/__init__.py +0 -0
- cisco_config_parser-2.2.1/cisco_config_parser/helper/help.py +122 -0
- cisco_config_parser-2.2.1/cisco_config_parser/helper/helper.py +26 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/layer3_interface/l3_interface_obj.py +2 -1
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/layer3_interface/l3_interface_parser.py +27 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/layer3_interface/l3_section_parser.py +25 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/parser/__init__.py +36 -2
- cisco_config_parser-2.2.1/cisco_config_parser/parser/parser.py +201 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/parser_regex/regex.py +46 -1
- cisco_config_parser-2.2.1/cisco_config_parser/routing_protocol/__init__.py +4 -0
- cisco_config_parser-2.2.1/cisco_config_parser/routing_protocol/rtp_dynamic_obj.py +0 -0
- cisco_config_parser-2.2.1/cisco_config_parser/routing_protocol/rtp_dynamic_parser.py +0 -0
- cisco_config_parser-2.2.1/cisco_config_parser/routing_protocol/rtp_ios_obj.py +68 -0
- cisco_config_parser-2.2.1/cisco_config_parser/routing_protocol/rtp_ios_parser.py +448 -0
- cisco_config_parser-2.2.1/cisco_config_parser/routing_protocol/rtp_separator.py +130 -0
- cisco_config_parser-2.2.1/cisco_config_parser/testing.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser.egg-info/PKG-INFO +94 -13
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser.egg-info/SOURCES.txt +9 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/setup.py +2 -2
- cisco_config_parser-2.1/cisco_config_parser/parser/parser.py +0 -101
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/__init__.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/cisco_config_parser.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/global_search/__init__.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/global_search/global_obj.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/global_search/global_separator.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/layer2_interface/__init__.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/layer2_interface/l2_interface_obj.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/layer2_interface/l2_interface_parser.py +1 -1
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/layer2_interface/l2_interface_separator.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/layer2_interface/l2_section_parser.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/layer3_interface/__init__.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/layer3_interface/l3_interface_separator.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/old_version/__init__.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/old_version/exceptions.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/old_version/obj.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/old_version/old_parse.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/old_version/ssh.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/old_version/utils.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/parent_child/__init__.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/parent_child/parent_child_obj.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/parent_child/parent_child_parser.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/parent_child/parent_child_separator.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/parser_regex/__init__.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/separator/__init__.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/separator/separator.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/setup.py +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser.egg-info/dependency_links.txt +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser.egg-info/top_level.txt +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/pyproject.toml +0 -0
- {cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/setup.cfg +0 -0
|
@@ -1,8 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cisco_config_parser
|
|
3
|
+
Version: 2.2.1
|
|
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
|
+
|
|
1
11
|
# Cisco Configuration Parser
|
|
2
|
-
## This Package Will Parse Cisco IOS, IOS-XE, IOS-XR, and NXOS Configuration File.
|
|
3
12
|
|
|
13
|
+
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
|
|
14
|
+
|
|
15
|
+
## New Version 2.0
|
|
16
|
+
|
|
17
|
+
## Install the package
|
|
18
|
+
|
|
19
|
+
https://pypi.org/project/cisco-config-parser/
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install cisco-config-parser
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Classes in this library
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
IOSRouteParser
|
|
30
|
+
L3InterfaceParser
|
|
31
|
+
L2InterfaceParser
|
|
32
|
+
ParentChildParser
|
|
33
|
+
```
|
|
34
|
+
there more Classes are being built, and will be released in the upcoming versions.
|
|
35
|
+
|
|
36
|
+
## Get Example usage:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from cisco_config_parser.helper import helper
|
|
40
|
+
|
|
41
|
+
helper = helper.IOSRouteParser()
|
|
42
|
+
|
|
43
|
+
print(helper)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Output**:
|
|
47
|
+
```
|
|
4
48
|
|
|
5
|
-
|
|
49
|
+
Example Usage:
|
|
50
|
+
====================================================================================================
|
|
51
|
+
|
|
52
|
+
with open("show_run.txt", "r") as file_output:
|
|
53
|
+
content = file_output.read()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
obj = ConfigParser(content)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
##
|
|
61
|
+
###
|
|
62
|
+
#### Static Routes Example:
|
|
63
|
+
###
|
|
64
|
+
##
|
|
65
|
+
#
|
|
66
|
+
obj.get_static_routes()
|
|
67
|
+
obj.get_static_routes(return_json=True)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
#
|
|
71
|
+
##
|
|
72
|
+
###
|
|
73
|
+
#### OSPF Example:
|
|
74
|
+
###
|
|
75
|
+
##
|
|
76
|
+
#
|
|
77
|
+
ospf = obj.get_ospf_config(return_json=True)
|
|
78
|
+
ospf = obj.get_ospf_config()
|
|
79
|
+
for i in ospf:
|
|
80
|
+
print(i.children)
|
|
81
|
+
print(i.network)
|
|
82
|
+
print(i.no_passive_interface)
|
|
83
|
+
|
|
84
|
+
#
|
|
85
|
+
##
|
|
86
|
+
###
|
|
87
|
+
#### EIGRP Example:
|
|
88
|
+
###
|
|
89
|
+
##
|
|
90
|
+
#
|
|
91
|
+
eigrp = obj.get_eigrp_config(return_json=True)
|
|
92
|
+
eigrp = obj.get_eigrp_config()
|
|
93
|
+
for i in eigrp:
|
|
94
|
+
print(i.children)
|
|
95
|
+
print(i.network)
|
|
96
|
+
print(i.vrf_children) << returns a list of EIGRPVrfChildren objects
|
|
97
|
+
vrf_children = i.vrf_children
|
|
98
|
+
for vrf in vrf_children:
|
|
99
|
+
print(vrf.network)
|
|
100
|
+
print(vrf.children)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
```
|
|
6
104
|
|
|
7
105
|
### 1. Layer3 Interfaces:
|
|
8
106
|
- added interface details - returns dict of all layer3 interfaces
|
|
@@ -10,6 +108,7 @@
|
|
|
10
108
|
- platform agnostic
|
|
11
109
|
- able to set custom regex and create dynamic method
|
|
12
110
|
|
|
111
|
+
|
|
13
112
|
* Example:
|
|
14
113
|
|
|
15
114
|
```python
|
|
@@ -43,7 +142,7 @@ None
|
|
|
43
142
|
<hr>
|
|
44
143
|
<hr>
|
|
45
144
|
|
|
46
|
-
|
|
145
|
+
## Old Version < 2.0
|
|
47
146
|
|
|
48
147
|
There are two ways to parse the config, 1, SSH which is not recommended, and 2, feeding the running-config file
|
|
49
148
|
|
|
@@ -76,14 +175,6 @@ pass the kwargs then it will login to your device and does the `show running-con
|
|
|
76
175
|
|
|
77
176
|
**if you select `json=True` then the object will return the result in json format. else, it would return as list of objects.**
|
|
78
177
|
|
|
79
|
-
## Install the package
|
|
80
|
-
|
|
81
|
-
https://pypi.org/project/cisco-config-parser/
|
|
82
|
-
|
|
83
|
-
```ruby
|
|
84
|
-
pip install cisco-config-parser
|
|
85
|
-
```
|
|
86
|
-
|
|
87
178
|
|
|
88
179
|
## Regex Search Strings:
|
|
89
180
|
|
|
@@ -1,18 +1,96 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: cisco_config_parser
|
|
3
|
-
Version: 2.1
|
|
4
|
-
Summary: This Package Will Parse Cisco IOS, IOS-XE, IOS-XR and NXOS Configuration File.
|
|
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
1
|
# Cisco Configuration Parser
|
|
12
|
-
## This Package Will Parse Cisco IOS, IOS-XE, IOS-XR, and NXOS Configuration File.
|
|
13
2
|
|
|
3
|
+
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
|
|
4
|
+
|
|
5
|
+
## New Version 2.0
|
|
6
|
+
|
|
7
|
+
## Install the package
|
|
8
|
+
|
|
9
|
+
https://pypi.org/project/cisco-config-parser/
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install cisco-config-parser
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Classes in this library
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
IOSRouteParser
|
|
20
|
+
L3InterfaceParser
|
|
21
|
+
L2InterfaceParser
|
|
22
|
+
ParentChildParser
|
|
23
|
+
```
|
|
24
|
+
there more Classes are being built, and will be released in the upcoming versions.
|
|
25
|
+
|
|
26
|
+
## Get Example usage:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from cisco_config_parser.helper import helper
|
|
30
|
+
|
|
31
|
+
helper = helper.IOSRouteParser()
|
|
32
|
+
|
|
33
|
+
print(helper)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Output**:
|
|
37
|
+
```
|
|
14
38
|
|
|
15
|
-
|
|
39
|
+
Example Usage:
|
|
40
|
+
====================================================================================================
|
|
41
|
+
|
|
42
|
+
with open("show_run.txt", "r") as file_output:
|
|
43
|
+
content = file_output.read()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
obj = ConfigParser(content)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
#
|
|
50
|
+
##
|
|
51
|
+
###
|
|
52
|
+
#### Static Routes Example:
|
|
53
|
+
###
|
|
54
|
+
##
|
|
55
|
+
#
|
|
56
|
+
obj.get_static_routes()
|
|
57
|
+
obj.get_static_routes(return_json=True)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
#
|
|
61
|
+
##
|
|
62
|
+
###
|
|
63
|
+
#### OSPF Example:
|
|
64
|
+
###
|
|
65
|
+
##
|
|
66
|
+
#
|
|
67
|
+
ospf = obj.get_ospf_config(return_json=True)
|
|
68
|
+
ospf = obj.get_ospf_config()
|
|
69
|
+
for i in ospf:
|
|
70
|
+
print(i.children)
|
|
71
|
+
print(i.network)
|
|
72
|
+
print(i.no_passive_interface)
|
|
73
|
+
|
|
74
|
+
#
|
|
75
|
+
##
|
|
76
|
+
###
|
|
77
|
+
#### EIGRP Example:
|
|
78
|
+
###
|
|
79
|
+
##
|
|
80
|
+
#
|
|
81
|
+
eigrp = obj.get_eigrp_config(return_json=True)
|
|
82
|
+
eigrp = obj.get_eigrp_config()
|
|
83
|
+
for i in eigrp:
|
|
84
|
+
print(i.children)
|
|
85
|
+
print(i.network)
|
|
86
|
+
print(i.vrf_children) << returns a list of EIGRPVrfChildren objects
|
|
87
|
+
vrf_children = i.vrf_children
|
|
88
|
+
for vrf in vrf_children:
|
|
89
|
+
print(vrf.network)
|
|
90
|
+
print(vrf.children)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
```
|
|
16
94
|
|
|
17
95
|
### 1. Layer3 Interfaces:
|
|
18
96
|
- added interface details - returns dict of all layer3 interfaces
|
|
@@ -20,6 +98,7 @@ Description-Content-Type: text/markdown
|
|
|
20
98
|
- platform agnostic
|
|
21
99
|
- able to set custom regex and create dynamic method
|
|
22
100
|
|
|
101
|
+
|
|
23
102
|
* Example:
|
|
24
103
|
|
|
25
104
|
```python
|
|
@@ -53,7 +132,7 @@ None
|
|
|
53
132
|
<hr>
|
|
54
133
|
<hr>
|
|
55
134
|
|
|
56
|
-
|
|
135
|
+
## Old Version < 2.0
|
|
57
136
|
|
|
58
137
|
There are two ways to parse the config, 1, SSH which is not recommended, and 2, feeding the running-config file
|
|
59
138
|
|
|
@@ -86,14 +165,6 @@ pass the kwargs then it will login to your device and does the `show running-con
|
|
|
86
165
|
|
|
87
166
|
**if you select `json=True` then the object will return the result in json format. else, it would return as list of objects.**
|
|
88
167
|
|
|
89
|
-
## Install the package
|
|
90
|
-
|
|
91
|
-
https://pypi.org/project/cisco-config-parser/
|
|
92
|
-
|
|
93
|
-
```ruby
|
|
94
|
-
pip install cisco-config-parser
|
|
95
|
-
```
|
|
96
|
-
|
|
97
168
|
|
|
98
169
|
## Regex Search Strings:
|
|
99
170
|
|
|
File without changes
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
RTP_IOS_HELP = """
|
|
4
|
+
|
|
5
|
+
Example Usage:
|
|
6
|
+
====================================================================================================
|
|
7
|
+
|
|
8
|
+
with open("show_run.txt", "r") as file_output:
|
|
9
|
+
content = file_output.read()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
obj = ConfigParser(content)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
#
|
|
16
|
+
##
|
|
17
|
+
###
|
|
18
|
+
#### Static Routes Example:
|
|
19
|
+
###
|
|
20
|
+
##
|
|
21
|
+
#
|
|
22
|
+
obj.get_static_routes()
|
|
23
|
+
obj.get_static_routes(return_json=True)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
##
|
|
28
|
+
###
|
|
29
|
+
#### OSPF Example:
|
|
30
|
+
###
|
|
31
|
+
##
|
|
32
|
+
#
|
|
33
|
+
ospf = obj.get_ospf_config(return_json=True)
|
|
34
|
+
ospf = obj.get_ospf_config()
|
|
35
|
+
for i in ospf:
|
|
36
|
+
print(i.children)
|
|
37
|
+
print(i.network)
|
|
38
|
+
print(i.no_passive_interface)
|
|
39
|
+
|
|
40
|
+
#
|
|
41
|
+
##
|
|
42
|
+
###
|
|
43
|
+
#### EIGRP Example:
|
|
44
|
+
###
|
|
45
|
+
##
|
|
46
|
+
#
|
|
47
|
+
eigrp = obj.get_eigrp_config(return_json=True)
|
|
48
|
+
eigrp = obj.get_eigrp_config()
|
|
49
|
+
for i in eigrp:
|
|
50
|
+
print(i.children)
|
|
51
|
+
print(i.network)
|
|
52
|
+
print(i.vrf_children) << returns a list of EIGRPVrfChildren objects
|
|
53
|
+
vrf_children = i.vrf_children
|
|
54
|
+
for vrf in vrf_children:
|
|
55
|
+
print(vrf.network)
|
|
56
|
+
print(vrf.children)
|
|
57
|
+
"""
|
|
58
|
+
PARENT_CHILD_HELP = """
|
|
59
|
+
Example Usage:
|
|
60
|
+
====================================================================================================
|
|
61
|
+
|
|
62
|
+
with open("show_run.txt", "r") as file_output:
|
|
63
|
+
content = file_output.read()
|
|
64
|
+
|
|
65
|
+
obj = ConfigParser(content)
|
|
66
|
+
|
|
67
|
+
parent_child = obj.get_parent_child(custom_regex="(^snmp.*)|(^aaa.*)")
|
|
68
|
+
|
|
69
|
+
for i in parent_child:
|
|
70
|
+
print(i.parent)
|
|
71
|
+
print(i.children)
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
LAYER3_INTERFACE_HELP = """
|
|
75
|
+
Example Usage:
|
|
76
|
+
====================================================================================================
|
|
77
|
+
with open("show_run.txt", "r") as file_output:
|
|
78
|
+
content = file_output.read()
|
|
79
|
+
|
|
80
|
+
obj = ConfigParser(content)
|
|
81
|
+
|
|
82
|
+
# returns dictionary of layer3 interfaces
|
|
83
|
+
l3_intfs = obj.get_l3_interface_details()
|
|
84
|
+
|
|
85
|
+
l3_intfs = obj.get_l3_interface()
|
|
86
|
+
|
|
87
|
+
for intf in l3_intfs:
|
|
88
|
+
print(intf.name)
|
|
89
|
+
print(intf.ip_address)
|
|
90
|
+
print(intf.children)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# you can also search for specific entry under layer3 interface with custom regex
|
|
94
|
+
l3_intfs = obj.get_l3_interface(ip_pim="(ip\spim\s.*)", load_interval="(load\sinterval.*)")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
for intf in l3_intfs:
|
|
98
|
+
print(intf.name)
|
|
99
|
+
print(intf.ip_address)
|
|
100
|
+
print(intf.ip_pim) <<< dynamically creates an attribute based on the custom regex
|
|
101
|
+
print(intf.load_interval) <<< dynamically creates an attribute based on the custom regex
|
|
102
|
+
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
LAYER2_INTERFACE_HELP = """
|
|
106
|
+
Example Usage:
|
|
107
|
+
====================================================================================================
|
|
108
|
+
with open("show_run.txt", "r") as file_output:
|
|
109
|
+
content = file_output.read()
|
|
110
|
+
|
|
111
|
+
obj = ConfigParser(content)
|
|
112
|
+
|
|
113
|
+
# returns dictionary of layer2 interfaces
|
|
114
|
+
l2_intfs = obj.get_l2_interface_details()
|
|
115
|
+
|
|
116
|
+
l2_intfs = obj.get_l2_interface()
|
|
117
|
+
|
|
118
|
+
for intf in l2_intfs:
|
|
119
|
+
print(intf.name)
|
|
120
|
+
print(intf.children)
|
|
121
|
+
|
|
122
|
+
"""
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from .help import *
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class IOSRouteParser:
|
|
5
|
+
def __repr__(self):
|
|
6
|
+
return RTP_IOS_HELP
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ParentChild:
|
|
11
|
+
def __repr__(self):
|
|
12
|
+
return PARENT_CHILD_HELP
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class L3Interface:
|
|
16
|
+
def __repr__(self):
|
|
17
|
+
return LAYER3_INTERFACE_HELP
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class L2Interface:
|
|
21
|
+
def __repr__(self):
|
|
22
|
+
return LAYER2_INTERFACE_HELP
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
1
3
|
from .l3_interface_separator import L3InterfaceSeparator
|
|
2
4
|
from .l3_interface_obj import L3Interface
|
|
3
5
|
from .l3_section_parser import _L3SectionParser
|
|
4
6
|
from cisco_config_parser.parser_regex.regex import *
|
|
5
7
|
from dataclasses import dataclass
|
|
8
|
+
import re, ipaddress
|
|
9
|
+
|
|
10
|
+
|
|
6
11
|
|
|
7
12
|
|
|
8
13
|
|
|
@@ -65,6 +70,7 @@ class L3InterfaceParser:
|
|
|
65
70
|
if ip_address_regex:
|
|
66
71
|
l3_intf_cls = _L3SectionParser._parse_ip_address_line(**ip_address_kwargs)
|
|
67
72
|
|
|
73
|
+
|
|
68
74
|
if sec_ip_address_regex:
|
|
69
75
|
# set the primary flag to False to indicate that the ip address is a secondary ip address
|
|
70
76
|
ip_address_kwargs["primary"] = False
|
|
@@ -102,5 +108,26 @@ class L3InterfaceParser:
|
|
|
102
108
|
return l3_intf_objects
|
|
103
109
|
|
|
104
110
|
|
|
111
|
+
def _fetch_subnet_and_usage(self, include_subnet_count=False):
|
|
112
|
+
"""
|
|
113
|
+
Fetch the subnet usage from the config file
|
|
114
|
+
return: dictionary of subnet usage
|
|
115
|
+
"""
|
|
105
116
|
|
|
117
|
+
subnet_usage = {}
|
|
118
|
+
subnet_count = {}
|
|
119
|
+
l3_interfaces = self._fetch_l3_interfaces()
|
|
120
|
+
for i in l3_interfaces:
|
|
121
|
+
if i.subnet:
|
|
122
|
+
cidr = str(ipaddress.IPv4Network(i.subnet, strict=False).prefixlen)
|
|
123
|
+
subnet_usage[i.name] = i.subnet
|
|
124
|
+
if subnet_count.get(f"/{cidr}"):
|
|
125
|
+
subnet_count[f"/{cidr}"] += 1
|
|
126
|
+
else:
|
|
127
|
+
subnet_count[f"/{cidr}"] = 1
|
|
128
|
+
|
|
129
|
+
if include_subnet_count:
|
|
130
|
+
subnet_usage["subnet_count"] = subnet_count
|
|
131
|
+
|
|
132
|
+
return subnet_usage
|
|
106
133
|
|
|
@@ -5,6 +5,8 @@ import ipaddress
|
|
|
5
5
|
|
|
6
6
|
class _L3SectionParser:
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
|
|
8
10
|
@classmethod
|
|
9
11
|
def _parse_ip_address_line(cls, **kwargs):
|
|
10
12
|
"""
|
|
@@ -16,11 +18,34 @@ class _L3SectionParser:
|
|
|
16
18
|
mask using the ipaddress module
|
|
17
19
|
return: l3_interface_obj
|
|
18
20
|
"""
|
|
21
|
+
|
|
22
|
+
def process_ip_address_with_cidr(ip_address_with_cidr, obj):
|
|
23
|
+
"""
|
|
24
|
+
Process the ip address with cidr
|
|
25
|
+
:param ip_address_with_cidr: str
|
|
26
|
+
:param obj: L3Interface object
|
|
27
|
+
:return:
|
|
28
|
+
"""
|
|
29
|
+
ip_address_config = ip_address_with_cidr.split("/")
|
|
30
|
+
ip_addr = ip_address_config[0].strip()
|
|
31
|
+
cidr = ip_address_config[1].strip()
|
|
32
|
+
subnet_ = ipaddress.IPv4Network(f"{ip_addr}/{cidr}", strict=False)
|
|
33
|
+
obj.ip_address = ip_addr.strip()
|
|
34
|
+
obj.mask = str(subnet_.netmask)
|
|
35
|
+
obj.subnet = str(subnet_).strip()
|
|
36
|
+
return obj
|
|
37
|
+
|
|
19
38
|
ip_address_line_regex = kwargs.get("ip_address_line_regex")
|
|
20
39
|
l3_interface_obj = kwargs.get("l3_interface_obj")
|
|
21
40
|
primary = kwargs.get("primary", True)
|
|
22
41
|
|
|
23
42
|
ip_address_regex = [ip_group for ip_group in ip_address_line_regex.groups() if ip_group]
|
|
43
|
+
|
|
44
|
+
# Check if the ip address has a CIDR - 10.1.1.1/24
|
|
45
|
+
if "/" in ip_address_regex[0]:
|
|
46
|
+
l3_interface_obj = process_ip_address_with_cidr(ip_address_regex[0], l3_interface_obj)
|
|
47
|
+
return l3_interface_obj
|
|
48
|
+
|
|
24
49
|
ip_address_section = ip_address_regex[0].split()
|
|
25
50
|
ip_address = ip_address_section[0].strip()
|
|
26
51
|
mask = ip_address_section[1].strip()
|
{cisco_config_parser-2.1 → cisco_config_parser-2.2.1}/cisco_config_parser/parser/__init__.py
RENAMED
|
@@ -4,8 +4,33 @@ from .parser import Parser
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class ConfigParser(Parser):
|
|
7
|
-
def __init__(self, _content):
|
|
8
|
-
super().__init__(_content)
|
|
7
|
+
def __init__(self, _content, platform=None):
|
|
8
|
+
super().__init__(_content, platform=platform)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_static_config(self, return_json=False):
|
|
12
|
+
"""
|
|
13
|
+
Get the static routes from the config file
|
|
14
|
+
:return: list of static route objects
|
|
15
|
+
"""
|
|
16
|
+
return self._get_static_config(return_json=return_json)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_ospf_config(self, return_json=False):
|
|
20
|
+
"""
|
|
21
|
+
Get the ospf configuration from the config file
|
|
22
|
+
:return: list of ospf objects or json
|
|
23
|
+
"""
|
|
24
|
+
return self._get_ospf_config(return_json=return_json)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def get_eigrp_config(self, return_json=False):
|
|
28
|
+
"""
|
|
29
|
+
Get the eigrp configuration from the config file
|
|
30
|
+
:return: list of eigrp objects or json
|
|
31
|
+
"""
|
|
32
|
+
return self._get_eigrp_config(return_json=return_json)
|
|
33
|
+
|
|
9
34
|
|
|
10
35
|
def get_vlan_info(self):
|
|
11
36
|
"""
|
|
@@ -28,6 +53,15 @@ class ConfigParser(Parser):
|
|
|
28
53
|
"""
|
|
29
54
|
return self._get_parent_child(**kwargs)
|
|
30
55
|
|
|
56
|
+
|
|
57
|
+
def get_subnet_and_usage(self, include_subnet_count=False):
|
|
58
|
+
"""
|
|
59
|
+
Fetch the subnet usage from the config file
|
|
60
|
+
return: dictionary of subnet usage
|
|
61
|
+
"""
|
|
62
|
+
return self._get_subnet_and_usage(include_subnet_count=include_subnet_count)
|
|
63
|
+
|
|
64
|
+
|
|
31
65
|
def get_l3_interfaces(self, **kwargs):
|
|
32
66
|
"""
|
|
33
67
|
Get L3 interfaces from the config file
|