cisco-config-parser 2.2__tar.gz → 2.2.2__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 (63) hide show
  1. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/PKG-INFO +23 -63
  2. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/README.md +21 -61
  3. cisco_config_parser-2.2.2/cisco_config_parser/helper/help.py +164 -0
  4. cisco_config_parser-2.2.2/cisco_config_parser/helper/helper.py +38 -0
  5. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/parser/__init__.py +9 -0
  6. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/parser/parser.py +34 -10
  7. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/parser_regex/regex.py +25 -2
  8. cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/__init__.py +5 -0
  9. cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/ios/__init__.py +6 -0
  10. cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/ios/rtp_bgp.py +294 -0
  11. cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/ios/rtp_eigtp.py +149 -0
  12. cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/ios/rtp_ios_rtp_obj.py +127 -0
  13. cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/ios/rtp_ospf.py +194 -0
  14. cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/ios/rtp_static.py +107 -0
  15. {cisco_config_parser-2.2/cisco_config_parser/routing_protocol → cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/utils}/rtp_separator.py +13 -0
  16. cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/utils/utils.py +22 -0
  17. cisco_config_parser-2.2/cisco_config_parser/testing.py → cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/xr/__init__.py +0 -0
  18. cisco_config_parser-2.2.2/cisco_config_parser/testing.py +80 -0
  19. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser.egg-info/PKG-INFO +23 -63
  20. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser.egg-info/SOURCES.txt +11 -5
  21. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/setup.py +2 -2
  22. cisco_config_parser-2.2/cisco_config_parser/helper/help.py +0 -73
  23. cisco_config_parser-2.2/cisco_config_parser/helper/helper.py +0 -23
  24. cisco_config_parser-2.2/cisco_config_parser/routing_protocol/__init__.py +0 -4
  25. cisco_config_parser-2.2/cisco_config_parser/routing_protocol/rtp_ios_obj.py +0 -68
  26. cisco_config_parser-2.2/cisco_config_parser/routing_protocol/rtp_ios_parser.py +0 -448
  27. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/__init__.py +0 -0
  28. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/cisco_config_parser.py +0 -0
  29. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/global_search/__init__.py +0 -0
  30. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/global_search/global_obj.py +0 -0
  31. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/global_search/global_parser.py +0 -0
  32. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/global_search/global_separator.py +0 -0
  33. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/helper/__init__.py +0 -0
  34. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/layer2_interface/__init__.py +0 -0
  35. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/layer2_interface/l2_interface_obj.py +0 -0
  36. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/layer2_interface/l2_interface_parser.py +0 -0
  37. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/layer2_interface/l2_interface_separator.py +0 -0
  38. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/layer2_interface/l2_section_parser.py +0 -0
  39. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/layer3_interface/__init__.py +0 -0
  40. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/layer3_interface/l3_interface_obj.py +0 -0
  41. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/layer3_interface/l3_interface_parser.py +0 -0
  42. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/layer3_interface/l3_interface_separator.py +0 -0
  43. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/layer3_interface/l3_section_parser.py +0 -0
  44. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/old_version/__init__.py +0 -0
  45. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/old_version/exceptions.py +0 -0
  46. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/old_version/obj.py +0 -0
  47. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/old_version/old_parse.py +0 -0
  48. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/old_version/ssh.py +0 -0
  49. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/old_version/utils.py +0 -0
  50. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/parent_child/__init__.py +0 -0
  51. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/parent_child/parent_child_obj.py +0 -0
  52. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/parent_child/parent_child_parser.py +0 -0
  53. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/parent_child/parent_child_separator.py +0 -0
  54. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/parser_regex/__init__.py +0 -0
  55. /cisco_config_parser-2.2/cisco_config_parser/routing_protocol/rtp_dynamic_obj.py → /cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/nxos/__init__.py +0 -0
  56. /cisco_config_parser-2.2/cisco_config_parser/routing_protocol/rtp_dynamic_parser.py → /cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/utils/__init__.py +0 -0
  57. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/separator/__init__.py +0 -0
  58. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/separator/separator.py +0 -0
  59. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser/setup.py +0 -0
  60. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser.egg-info/dependency_links.txt +0 -0
  61. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/cisco_config_parser.egg-info/top_level.txt +0 -0
  62. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/pyproject.toml +0 -0
  63. {cisco_config_parser-2.2 → cisco_config_parser-2.2.2}/setup.cfg +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cisco_config_parser
3
- Version: 2.2
4
- Summary: This Package Will Parse Cisco IOS, IOS-XE, IOS-XR and NXOS Configuration File.
3
+ Version: 2.2.2
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
5
  Home-page: https://github.com/arezazadeh/cisco_config_parser
6
6
  Author: Ahmad Rezazadeh
7
7
  Author-email: ahmad@klevernet.io
@@ -9,15 +9,28 @@ License: MIT License
9
9
  Description-Content-Type: text/markdown
10
10
 
11
11
  # Cisco Configuration Parser
12
- ## This Package Will Parse Cisco IOS, IOS-XE, IOS-XR, and NXOS Configuration File.
13
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
+ ```
14
24
 
15
- # New Version 2.0
16
25
 
17
26
  ## Classes in this library
18
27
 
19
28
  ```python
20
- IOSRouteParser
29
+ IOSStaticRouteConfig
30
+ IOSOSPFConfig
31
+ IOSEIGRPConfig
32
+ IOSBGPConfig
33
+ IOSBGPConfig
21
34
  L3InterfaceParser
22
35
  L2InterfaceParser
23
36
  ParentChildParser
@@ -29,7 +42,7 @@ there more Classes are being built, and will be released in the upcoming version
29
42
  ```python
30
43
  from cisco_config_parser.helper import helper
31
44
 
32
- helper = helper.IOSRouteParser()
45
+ helper = helper.IOSStaticRouteConfig()
33
46
 
34
47
  print(helper)
35
48
  ```
@@ -46,56 +59,11 @@ with open("show_run.txt", "r") as file_output:
46
59
 
47
60
  obj = ConfigParser(content)
48
61
 
49
-
50
- #
51
- ##
52
- ###
53
- #### Static Routes Example:
54
- ###
55
- ##
56
- #
57
- obj.get_static_routes()
58
- obj.get_static_routes(return_json=True)
59
-
60
-
61
- #
62
- ##
63
- ###
64
- #### OSPF Example:
65
- ###
66
- ##
67
- #
68
- ospf = obj.get_ospf_config(return_json=True)
69
- ospf = obj.get_ospf_config()
70
- for i in ospf:
71
- print(i.children)
72
- print(i.network)
73
- print(i.no_passive_interface)
74
-
75
- #
76
- ##
77
- ###
78
- #### EIGRP Example:
79
- ###
80
- ##
81
- #
82
- eigrp = obj.get_eigrp_config(return_json=True)
83
- eigrp = obj.get_eigrp_config()
84
- for i in eigrp:
85
- print(i.children)
86
- print(i.network)
87
- print(i.vrf_children) << returns a list of EIGRPVrfChildren objects
88
- vrf_children = i.vrf_children
89
- for vrf in vrf_children:
90
- print(vrf.network)
91
- print(vrf.children)
92
-
62
+ obj.get_static_routes() << Returns a list of objects
63
+ obj.get_static_routes(return_json=True) << Returns a list of dictionaries
93
64
 
94
65
  ```
95
66
 
96
-
97
-
98
-
99
67
  ### 1. Layer3 Interfaces:
100
68
  - added interface details - returns dict of all layer3 interfaces
101
69
  - methods are unified
@@ -103,7 +71,7 @@ for i in eigrp:
103
71
  - able to set custom regex and create dynamic method
104
72
 
105
73
 
106
- * Example:
74
+ * L3Interface Example:
107
75
 
108
76
  ```python
109
77
  from cisco_config_parser import ConfigParser
@@ -136,7 +104,7 @@ None
136
104
  <hr>
137
105
  <hr>
138
106
 
139
- # Old Version < 2.0
107
+ ## Old Version < 2.0
140
108
 
141
109
  There are two ways to parse the config, 1, SSH which is not recommended, and 2, feeding the running-config file
142
110
 
@@ -169,14 +137,6 @@ pass the kwargs then it will login to your device and does the `show running-con
169
137
 
170
138
  **if you select `json=True` then the object will return the result in json format. else, it would return as list of objects.**
171
139
 
172
- ## Install the package
173
-
174
- https://pypi.org/project/cisco-config-parser/
175
-
176
- ```ruby
177
- pip install cisco-config-parser
178
- ```
179
-
180
140
 
181
141
  ## Regex Search Strings:
182
142
 
@@ -1,13 +1,26 @@
1
1
  # Cisco Configuration Parser
2
- ## This Package Will Parse Cisco IOS, IOS-XE, IOS-XR, and NXOS Configuration File.
3
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
+ ```
4
14
 
5
- # New Version 2.0
6
15
 
7
16
  ## Classes in this library
8
17
 
9
18
  ```python
10
- IOSRouteParser
19
+ IOSStaticRouteConfig
20
+ IOSOSPFConfig
21
+ IOSEIGRPConfig
22
+ IOSBGPConfig
23
+ IOSBGPConfig
11
24
  L3InterfaceParser
12
25
  L2InterfaceParser
13
26
  ParentChildParser
@@ -19,7 +32,7 @@ there more Classes are being built, and will be released in the upcoming version
19
32
  ```python
20
33
  from cisco_config_parser.helper import helper
21
34
 
22
- helper = helper.IOSRouteParser()
35
+ helper = helper.IOSStaticRouteConfig()
23
36
 
24
37
  print(helper)
25
38
  ```
@@ -36,56 +49,11 @@ with open("show_run.txt", "r") as file_output:
36
49
 
37
50
  obj = ConfigParser(content)
38
51
 
39
-
40
- #
41
- ##
42
- ###
43
- #### Static Routes Example:
44
- ###
45
- ##
46
- #
47
- obj.get_static_routes()
48
- obj.get_static_routes(return_json=True)
49
-
50
-
51
- #
52
- ##
53
- ###
54
- #### OSPF Example:
55
- ###
56
- ##
57
- #
58
- ospf = obj.get_ospf_config(return_json=True)
59
- ospf = obj.get_ospf_config()
60
- for i in ospf:
61
- print(i.children)
62
- print(i.network)
63
- print(i.no_passive_interface)
64
-
65
- #
66
- ##
67
- ###
68
- #### EIGRP Example:
69
- ###
70
- ##
71
- #
72
- eigrp = obj.get_eigrp_config(return_json=True)
73
- eigrp = obj.get_eigrp_config()
74
- for i in eigrp:
75
- print(i.children)
76
- print(i.network)
77
- print(i.vrf_children) << returns a list of EIGRPVrfChildren objects
78
- vrf_children = i.vrf_children
79
- for vrf in vrf_children:
80
- print(vrf.network)
81
- print(vrf.children)
82
-
52
+ obj.get_static_routes() << Returns a list of objects
53
+ obj.get_static_routes(return_json=True) << Returns a list of dictionaries
83
54
 
84
55
  ```
85
56
 
86
-
87
-
88
-
89
57
  ### 1. Layer3 Interfaces:
90
58
  - added interface details - returns dict of all layer3 interfaces
91
59
  - methods are unified
@@ -93,7 +61,7 @@ for i in eigrp:
93
61
  - able to set custom regex and create dynamic method
94
62
 
95
63
 
96
- * Example:
64
+ * L3Interface Example:
97
65
 
98
66
  ```python
99
67
  from cisco_config_parser import ConfigParser
@@ -126,7 +94,7 @@ None
126
94
  <hr>
127
95
  <hr>
128
96
 
129
- # Old Version < 2.0
97
+ ## Old Version < 2.0
130
98
 
131
99
  There are two ways to parse the config, 1, SSH which is not recommended, and 2, feeding the running-config file
132
100
 
@@ -159,14 +127,6 @@ pass the kwargs then it will login to your device and does the `show running-con
159
127
 
160
128
  **if you select `json=True` then the object will return the result in json format. else, it would return as list of objects.**
161
129
 
162
- ## Install the package
163
-
164
- https://pypi.org/project/cisco-config-parser/
165
-
166
- ```ruby
167
- pip install cisco-config-parser
168
- ```
169
-
170
130
 
171
131
  ## Regex Search Strings:
172
132
 
@@ -0,0 +1,164 @@
1
+
2
+
3
+ RTP_IOS_STATIC_HELP = """
4
+
5
+ Example Usage For Static Routes:
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
+ # Return it as a json object
15
+ obj.get_static_routes(return_json=True)
16
+
17
+ # or as a list of StaticRoute objects
18
+ obj.get_static_routes()
19
+ """
20
+
21
+
22
+ RTP_IOS_OSPF_HELP = """
23
+
24
+ Example Usage For OSPF Routes:
25
+ ====================================================================================================
26
+
27
+ with open("show_run.txt", "r") as file_output:
28
+ content = file_output.read()
29
+
30
+
31
+ obj = ConfigParser(content)
32
+
33
+ # Return it as a json object
34
+ ospf = obj.get_ospf_config(return_json=True)
35
+
36
+ # or as a list of OSPFConfig objects
37
+ ospf = obj.get_ospf_config()
38
+ for i in ospf:
39
+ print(i.children)
40
+ print(i.network)
41
+ print(i.no_passive_interface)
42
+
43
+ """
44
+ RTP_IOS_EIGRP_HELP = """
45
+
46
+ Example Usage For EIGRP Routes:
47
+ ====================================================================================================
48
+
49
+ with open("show_run.txt", "r") as file_output:
50
+ content = file_output.read()
51
+
52
+
53
+ obj = ConfigParser(content)
54
+
55
+ # Return it as a json object
56
+ eigrp = obj.get_eigrp_config(return_json=True)
57
+
58
+ # or as a list of EIGRPConfig objects
59
+ eigrp = obj.get_eigrp_config()
60
+ for i in eigrp:
61
+ print(i.children)
62
+ print(i.network)
63
+ print(i.vrf_children) << returns a list of EIGRPVrfChildren objects
64
+ vrf_children = i.vrf_children
65
+ for vrf in vrf_children:
66
+ print(vrf.network)
67
+ print(vrf.children)
68
+ """
69
+
70
+
71
+ RTP_IOS_BGP_HELP = """
72
+
73
+ Example Usage For BGP Routes:
74
+ ====================================================================================================
75
+
76
+ with open("show_run.txt", "r") as file_output:
77
+ content = file_output.read()
78
+
79
+
80
+ obj = ConfigParser(content)
81
+
82
+ # Return it as a json object
83
+ bgp = obj.get_bgp_config(return_json=True)
84
+
85
+
86
+ # or as a list of BGPConfig objects
87
+ bgp = obj.get_bgp_config()
88
+ for i in bgp:
89
+ print(i.children)
90
+ print(i.network)
91
+ print(i.vrf_children) << returns a list of BGPVrfChildren objects
92
+ vrf_children = i.vrf_children
93
+ for vrf in vrf_children:
94
+ print(vrf.network)
95
+ print(vrf.children)
96
+ """
97
+
98
+ PARENT_CHILD_HELP = """
99
+
100
+ Example Usage For Parent Child:
101
+ ====================================================================================================
102
+
103
+ with open("show_run.txt", "r") as file_output:
104
+ content = file_output.read()
105
+
106
+ obj = ConfigParser(content)
107
+
108
+ parent_child = obj.get_parent_child(custom_regex="(^snmp.*)|(^aaa.*)")
109
+
110
+ for i in parent_child:
111
+ print(i.parent)
112
+ print(i.children)
113
+
114
+ """
115
+ LAYER3_INTERFACE_HELP = """
116
+
117
+ Example Usage For Layer3 Interfaces:
118
+ ====================================================================================================
119
+ with open("show_run.txt", "r") as file_output:
120
+ content = file_output.read()
121
+
122
+ obj = ConfigParser(content)
123
+
124
+ # returns dictionary of layer3 interfaces
125
+ l3_intfs = obj.get_l3_interface_details()
126
+
127
+ l3_intfs = obj.get_l3_interface()
128
+
129
+ for intf in l3_intfs:
130
+ print(intf.name)
131
+ print(intf.ip_address)
132
+ print(intf.children)
133
+
134
+
135
+ # you can also search for specific entry under layer3 interface with custom regex
136
+ l3_intfs = obj.get_l3_interface(ip_pim="(ip\spim\s.*)", load_interval="(load\sinterval.*)")
137
+
138
+
139
+ for intf in l3_intfs:
140
+ print(intf.name)
141
+ print(intf.ip_address)
142
+ print(intf.ip_pim) <<< dynamically creates an attribute based on the custom regex
143
+ print(intf.load_interval) <<< dynamically creates an attribute based on the custom regex
144
+
145
+ """
146
+ LAYER2_INTERFACE_HELP = """
147
+
148
+ Example Usage For Layer2 Interfaces:
149
+ ====================================================================================================
150
+ with open("show_run.txt", "r") as file_output:
151
+ content = file_output.read()
152
+
153
+ obj = ConfigParser(content)
154
+
155
+ # returns dictionary of layer2 interfaces
156
+ l2_intfs = obj.get_l2_interface_details()
157
+
158
+ l2_intfs = obj.get_l2_interface()
159
+
160
+ for intf in l2_intfs:
161
+ print(intf.name)
162
+ print(intf.children)
163
+
164
+ """
@@ -0,0 +1,38 @@
1
+ from .help import *
2
+
3
+
4
+ class IOSStaticRouteConfig:
5
+ def __repr__(self):
6
+ return RTP_IOS_STATIC_HELP
7
+
8
+ class IOSOSPFConfig:
9
+ def __repr__(self):
10
+ return RTP_IOS_OSPF_HELP
11
+
12
+
13
+ class IOSEIGRPConfig:
14
+ def __repr__(self):
15
+ return RTP_IOS_EIGRP_HELP
16
+
17
+ class IOSBGPConfig:
18
+ def __repr__(self):
19
+ return RTP_IOS_BGP_HELP
20
+
21
+
22
+ class ParentChild:
23
+ def __repr__(self):
24
+ return PARENT_CHILD_HELP
25
+
26
+
27
+ class L3Interface:
28
+ def __repr__(self):
29
+ return LAYER3_INTERFACE_HELP
30
+
31
+
32
+ class L2Interface:
33
+ def __repr__(self):
34
+ return LAYER2_INTERFACE_HELP
35
+
36
+
37
+
38
+
@@ -32,6 +32,15 @@ class ConfigParser(Parser):
32
32
  return self._get_eigrp_config(return_json=return_json)
33
33
 
34
34
 
35
+ def get_bgp_config(self, return_json=False):
36
+ """
37
+ Get the eigrp configuration from the config file
38
+ :return: list of eigrp objects or json
39
+ """
40
+ return self._get_bgp_config(return_json=return_json)
41
+
42
+
43
+
35
44
  def get_vlan_info(self):
36
45
  """
37
46
  Get the vlan information from the config file
@@ -2,7 +2,12 @@ from cisco_config_parser.layer3_interface import L3InterfaceParser
2
2
  from cisco_config_parser.layer2_interface import L2InterfaceParser
3
3
  from cisco_config_parser.parent_child import ParentChildParser
4
4
  from cisco_config_parser.global_search import GlobalParser
5
- from cisco_config_parser.routing_protocol.rtp_ios_parser import IOSRouteParser
5
+ from cisco_config_parser.routing_protocol.ios.rtp_ospf import IOSOSPFConfig
6
+ from cisco_config_parser.routing_protocol.ios.rtp_eigtp import IOSEIGRPConfig
7
+ from cisco_config_parser.routing_protocol.ios.rtp_static import IOSStaticRouteConfig
8
+ from cisco_config_parser.routing_protocol.ios.rtp_bgp import IOSBGPConfig
9
+
10
+
6
11
  from cisco_config_parser.parser_regex.regex import *
7
12
 
8
13
 
@@ -14,11 +19,10 @@ class Parser:
14
19
  self._l2_parser_obj = L2InterfaceParser(self._content)
15
20
  self._parent_child_parser_obj = ParentChildParser(self._content)
16
21
  self._global_parser_obj = GlobalParser(self._content)
17
- self._routing_protocol_parser_obj = IOSRouteParser(self._content)
18
22
 
19
23
 
20
24
 
21
- def determine_platform(self):
25
+ def determine_platform(self, TARGET_CLASS):
22
26
  """
23
27
  Determine the platform of the device
24
28
  IOS, NXOS, IOSXR
@@ -29,7 +33,7 @@ class Parser:
29
33
  """
30
34
 
31
35
  if IOS_PLATFORM_REGEX_1.search(self._content):
32
- return IOSRouteParser
36
+ return TARGET_CLASS
33
37
 
34
38
  elif NXOS_PLATFORM_REGEX_1.search(self._content) or NXOS_PLATFORM_REGEX_2.search(self._content):
35
39
  return "NXOS"
@@ -57,12 +61,12 @@ class Parser:
57
61
  if user provides the platform, then use the platform to fetch the static routes
58
62
  """
59
63
  if "ios" in self._platform.lower():
60
- return self._routing_protocol_parser_obj._fetch_static_route_config(return_json=return_json)
64
+ return IOSStaticRouteConfig(self._content)._fetch_static_route_config(return_json=return_json)
61
65
 
62
66
  """
63
67
  if platform is not provided, then use internal logic to determine the platform
64
68
  """
65
- relevant_object = self.determine_platform()
69
+ relevant_object = self.determine_platform(IOSStaticRouteConfig)
66
70
  return relevant_object(self._content)._fetch_static_route_config(return_json=return_json)
67
71
 
68
72
 
@@ -76,12 +80,12 @@ class Parser:
76
80
  if user provides the platform, then use the platform to fetch the static routes
77
81
  """
78
82
  if "ios" in self._platform.lower():
79
- return self._routing_protocol_parser_obj._fetch_ospf_config(return_json=return_json)
83
+ return IOSOSPFConfig(self._content)._fetch_ospf_config(return_json=return_json)
80
84
 
81
85
  """
82
86
  if platform is not provided, then use internal logic to determine the platform
83
87
  """
84
- relevant_object = self.determine_platform()
88
+ relevant_object = self.determine_platform(IOSOSPFConfig)
85
89
  return relevant_object(self._content)._fetch_ospf_config(return_json=return_json)
86
90
 
87
91
 
@@ -96,15 +100,35 @@ class Parser:
96
100
  if user provides the platform, then use the platform to fetch the static routes
97
101
  """
98
102
  if "ios" in self._platform.lower():
99
- return self._routing_protocol_parser_obj._fetch_eigrp_config(return_json=return_json)
103
+ return IOSEIGRPConfig(self._content)._fetch_eigrp_config(return_json=return_json)
100
104
 
101
105
  """
102
106
  if platform is not provided, then use internal logic to determine the platform
103
107
  """
104
- relevant_object = self.determine_platform()
108
+ relevant_object = self.determine_platform(IOSEIGRPConfig)
105
109
  return relevant_object(self._content)._fetch_eigrp_config(return_json=return_json)
106
110
 
107
111
 
112
+ def _get_bgp_config(self, return_json=False):
113
+ """
114
+ Get the static routes from the config file
115
+ :return: list of static route objects
116
+ """
117
+ if self._platform:
118
+ """
119
+ if user provides the platform, then use the platform to fetch the static routes
120
+ """
121
+ if "ios" in self._platform.lower():
122
+ return IOSBGPConfig(self._content)._fetch_bgp_config(return_json=return_json)
123
+
124
+ """
125
+ if platform is not provided, then use internal logic to determine the platform
126
+ """
127
+ relevant_object = self.determine_platform(IOSBGPConfig)
128
+ return relevant_object(self._content)._fetch_bgp_config(return_json=return_json)
129
+
130
+
131
+
108
132
 
109
133
  def _get_vlan_info(self):
110
134
  """
@@ -61,8 +61,6 @@ VLAN_REGEX = re.compile(r"^vlan\s([0-9]+)", flags=re.MULTILINE)
61
61
 
62
62
  # Routing Protocol
63
63
  RTP_REGEX = re.compile(r"^router\s(.*)", flags=re.MULTILINE)
64
-
65
- RTP_BGP_REGEX = re.compile(r"^router bgp", flags=re.MULTILINE)
66
64
  RTP_ISIS_REGEX = re.compile(r"^router isis", flags=re.MULTILINE)
67
65
  RTP_RIP_REGEX = re.compile(r"^router rip", flags=re.MULTILINE)
68
66
 
@@ -99,6 +97,31 @@ RTP_EIGRP_REGEX = re.compile(r"^router eigrp", flags=re.MULTILINE)
99
97
  RTP_IOS_EIGRP_VRF_REGEX = re.compile(r"\s+address-family\sipv4\svrf\s(\S+)", flags=re.MULTILINE)
100
98
  RTP_IOS_EIGRP_NETWORK_REGEX = re.compile(r"\s+network\s(\d+\.\d+\.\d+\.\d+)\s(\d+\.\d+\.\d+\.\d+)", flags=re.MULTILINE)
101
99
 
100
+ # IOS ROUTING PROTOCOL - BGP
101
+ RTP_BGP_REGEX = re.compile(r"^router bgp", flags=re.MULTILINE)
102
+ RTP_BGP_ROUTER_ID_REGEX = re.compile(r"\s+bgp\srouter-id\s(\d+\.\d+\.\d+\.\d+)", flags=re.MULTILINE)
103
+ RTP_IOS_BGP_VRF_REGEX = re.compile(r"\s+address-family\sipv4\svrf\s(\S+)", flags=re.MULTILINE)
104
+ RTP_IOS_BGP_NETWORK_REGEX = re.compile(r"\s+network\s(\d+\.\d+\.\d+\.\d+)\smask\s(\d+\.\d+\.\d+\.\d+)", flags=re.MULTILINE)
105
+ RTP_IOS_BGP_NEIGHBOR_IP_REGEX = re.compile(r"\s+neighbor\s(\d+\.\d+\.\d+\.\d+)\s(.*)", flags=re.MULTILINE)
106
+ RTP_IOS_BGP_NEIGHBOR_REMOTE_AS_REGEX = re.compile(r"\s+neighbor\s(\d+\.\d+\.\d+\.\d+)\sremote-as\s(\d+)", flags=re.MULTILINE)
107
+ RTP_IOS_BGP_NEIGHBOR_DESCR_REGEX = re.compile(r"\s+neighbor\s(\d+\.\d+\.\d+\.\d+)\sdescription\s(.*)", flags=re.MULTILINE)
108
+ RTP_IOS_BGP_NEIGHBOR_UPDATE_SRC_REGEX = re.compile(r"\s+neighbor\s(\d+\.\d+\.\d+\.\d+)\supdate-source\s(.*)", flags=re.MULTILINE)
109
+ RTP_IOS_BGP_NEIGHBOR_RM_INBOUND_REGEX = re.compile(r"\s+neighbor\s(\d+\.\d+\.\d+\.\d+)\sroute-map\s(.*)\sin", flags=re.MULTILINE)
110
+ RTP_IOS_BGP_NEIGHBOR_RM_OUTBOUND_REGEX = re.compile(r"\s+neighbor\s(\d+\.\d+\.\d+\.\d+)\sroute-map\s(.*)\sout", flags=re.MULTILINE)
111
+
112
+ RTP_IOS_BGP_PEER_GROUP_REGEX = re.compile(r"\s+neighbor\s(\S+)\speer-group$", flags=re.MULTILINE)
113
+ RTP_IOS_BGP_PG_REMOTE_AS_REGEX = re.compile(r"\s+neighbor\s(.*)\sremote-as\s(\S+)", flags=re.MULTILINE)
114
+ RTP_IOS_BGP_PG_UPDATE_SRC_REGEX = re.compile(r"\s+neighbor\s(.*)\supdate-source\s(\S+)", flags=re.MULTILINE)
115
+ RTP_IOS_BGP_PG_RM_IN_REGEX = re.compile(r"\s+neighbor\s(.*)\sroute-map\s(\S+)\sin", flags=re.MULTILINE)
116
+ RTP_IOS_BGP_PG_RM_OUT_REGEX = re.compile(r"\s+neighbor\s(.*)\sroute-map\s(\S+)\sout", flags=re.MULTILINE)
117
+ RTP_IOS_BGP_PG_NEIGHBOR_REGEX = re.compile(r"\s+neighbor\s(\d+\.\d+\.\d+\.\d+)\speer-group(.*)", flags=re.MULTILINE)
118
+ RTP_IOS_BGP_PG_NEIGHBOR_DESCR_REGEX = re.compile(r"\s+neighbor\s(\d+\.\d+\.\d+\.\d+)\sdescription(.*)", flags=re.MULTILINE)
119
+ RTP_IOS_BGP_GLOBAL_IPV4_REGEX = re.compile(r"\s+address-family\sipv4$", flags=re.MULTILINE)
120
+
121
+ RTP_IOS_BGP_REDISTRIBUTE_REGEX = re.compile(r"\s+(redistribute\s.*)", flags=re.MULTILINE)
122
+ RTP_IOS_BGP_REDISTRIBUTE_W_RM_REGEX = re.compile(r"redistribute\s(\S+\s\S+|\S+)\s+route-map(.*)", flags=re.MULTILINE)
123
+ RTP_IOS_BGP_REDISTRIBUTE_WO_RM_REGEX = re.compile(r"redistribute\s(\S+\s\S+|\S+)$", flags=re.MULTILINE)
124
+
102
125
 
103
126
 
104
127
  def find_vrf_section(vrf, item):
@@ -0,0 +1,5 @@
1
+ from cisco_config_parser.routing_protocol.utils.rtp_separator import IOSRoutingProtocolSeparator
2
+ from .utils import *
3
+ from .ios import *
4
+ from .nxos import *
5
+ from .xr import *
@@ -0,0 +1,6 @@
1
+
2
+ from .rtp_bgp import *
3
+ from .rtp_eigtp import *
4
+ from .rtp_ospf import *
5
+ from .rtp_static import *
6
+ from .rtp_ios_rtp_obj import *