cisco-config-parser 2.2.2__tar.gz → 2.2.4__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 (62) hide show
  1. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/PKG-INFO +1 -1
  2. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/helper/help.py +10 -1
  3. cisco_config_parser-2.2.4/cisco_config_parser/parent_child/parent_child_parser.py +94 -0
  4. cisco_config_parser-2.2.4/cisco_config_parser/routing_protocol/nxos/__init__.py +0 -0
  5. cisco_config_parser-2.2.4/cisco_config_parser/routing_protocol/utils/__init__.py +0 -0
  6. cisco_config_parser-2.2.4/cisco_config_parser/routing_protocol/xr/__init__.py +0 -0
  7. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser.egg-info/PKG-INFO +1 -1
  8. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser.egg-info/SOURCES.txt +3 -1
  9. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/setup.py +1 -1
  10. cisco_config_parser-2.2.2/cisco_config_parser/parent_child/parent_child_parser.py +0 -45
  11. cisco_config_parser-2.2.2/cisco_config_parser/testing.py +0 -80
  12. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/README.md +0 -0
  13. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/__init__.py +0 -0
  14. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/cisco_config_parser.py +0 -0
  15. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/global_search/__init__.py +0 -0
  16. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/global_search/global_obj.py +0 -0
  17. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/global_search/global_parser.py +0 -0
  18. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/global_search/global_separator.py +0 -0
  19. {cisco_config_parser-2.2.2/cisco_config_parser/helper → cisco_config_parser-2.2.4/cisco_config_parser/global_search/ios}/__init__.py +0 -0
  20. {cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol → cisco_config_parser-2.2.4/cisco_config_parser/global_search}/nxos/__init__.py +0 -0
  21. {cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/utils → cisco_config_parser-2.2.4/cisco_config_parser/global_search/xr}/__init__.py +0 -0
  22. {cisco_config_parser-2.2.2/cisco_config_parser/routing_protocol/xr → cisco_config_parser-2.2.4/cisco_config_parser/helper}/__init__.py +0 -0
  23. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/helper/helper.py +0 -0
  24. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/layer2_interface/__init__.py +0 -0
  25. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/layer2_interface/l2_interface_obj.py +0 -0
  26. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/layer2_interface/l2_interface_parser.py +0 -0
  27. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/layer2_interface/l2_interface_separator.py +0 -0
  28. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/layer2_interface/l2_section_parser.py +0 -0
  29. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/layer3_interface/__init__.py +0 -0
  30. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/layer3_interface/l3_interface_obj.py +0 -0
  31. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/layer3_interface/l3_interface_parser.py +0 -0
  32. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/layer3_interface/l3_interface_separator.py +0 -0
  33. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/layer3_interface/l3_section_parser.py +0 -0
  34. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/old_version/__init__.py +0 -0
  35. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/old_version/exceptions.py +0 -0
  36. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/old_version/obj.py +0 -0
  37. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/old_version/old_parse.py +0 -0
  38. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/old_version/ssh.py +0 -0
  39. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/old_version/utils.py +0 -0
  40. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/parent_child/__init__.py +0 -0
  41. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/parent_child/parent_child_obj.py +0 -0
  42. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/parent_child/parent_child_separator.py +0 -0
  43. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/parser/__init__.py +0 -0
  44. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/parser/parser.py +0 -0
  45. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/parser_regex/__init__.py +0 -0
  46. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/parser_regex/regex.py +0 -0
  47. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/routing_protocol/__init__.py +0 -0
  48. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/routing_protocol/ios/__init__.py +0 -0
  49. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/routing_protocol/ios/rtp_bgp.py +0 -0
  50. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/routing_protocol/ios/rtp_eigtp.py +0 -0
  51. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/routing_protocol/ios/rtp_ios_rtp_obj.py +0 -0
  52. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/routing_protocol/ios/rtp_ospf.py +0 -0
  53. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/routing_protocol/ios/rtp_static.py +0 -0
  54. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/routing_protocol/utils/rtp_separator.py +0 -0
  55. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/routing_protocol/utils/utils.py +0 -0
  56. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/separator/__init__.py +0 -0
  57. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/separator/separator.py +0 -0
  58. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser/setup.py +0 -0
  59. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser.egg-info/dependency_links.txt +0 -0
  60. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/cisco_config_parser.egg-info/top_level.txt +0 -0
  61. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/pyproject.toml +0 -0
  62. {cisco_config_parser-2.2.2 → cisco_config_parser-2.2.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cisco_config_parser
3
- Version: 2.2.2
3
+ Version: 2.2.4
4
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
@@ -105,7 +105,16 @@ with open("show_run.txt", "r") as file_output:
105
105
 
106
106
  obj = ConfigParser(content)
107
107
 
108
- parent_child = obj.get_parent_child(custom_regex="(^snmp.*)|(^aaa.*)")
108
+ # This will only return the parent and its child based on the custom regex
109
+ parent_child = obj.get_parent_child(parent_regex="^aaa.*", child_regex="^server.*")
110
+
111
+ >> output:
112
+ aaa group server tacacs+ TACACS_GROUP
113
+ server-private 1.1.1.1 key 7 1234567890
114
+
115
+
116
+ # This will only return the parent and its child based on the custom regex
117
+ parent_child = obj.get_parent_child(parent_regex="(^snmp.*)|(^aaa.*)")
109
118
 
110
119
  for i in parent_child:
111
120
  print(i.parent)
@@ -0,0 +1,94 @@
1
+ import re
2
+ from .parent_child_obj import ParentChild
3
+ from cisco_config_parser.parser_regex.regex import SPLIT_ON_LINE
4
+ from .parent_child_separator import ParentChildSeparator
5
+ from dataclasses import dataclass
6
+
7
+
8
+
9
+ @dataclass
10
+ class ParentChildParser:
11
+ """
12
+ Parent Child Parser class
13
+ :param content: str
14
+ :return: list of ParentChild objects
15
+ """
16
+ content: str = None
17
+
18
+ def _fetch_parent_child_old(self, **kwargs):
19
+ """
20
+ Fetch the parent child from the config file
21
+ return: list of ParentChild objects
22
+ """
23
+ custom_regex = kwargs.get("custom_regex", None)
24
+ return_json = kwargs.get("return_json", False)
25
+ if not custom_regex:
26
+ raise ValueError("custom_regex is required")
27
+
28
+ custom_regex = re.compile(custom_regex, flags=re.MULTILINE)
29
+ parent_child = ParentChildSeparator(self.content)
30
+ sections = parent_child._get_separated_sections()
31
+
32
+ parent_child_obj_list = []
33
+
34
+ for section in sections:
35
+ parent_child_obj = ParentChild()
36
+ regex_result = re.match(custom_regex, section.strip())
37
+ if regex_result:
38
+ if section.strip().startswith(regex_result.group()):
39
+ child_regex = SPLIT_ON_LINE.split(section.strip())
40
+ parent_child_obj.parent = child_regex[0]
41
+ child_regex.pop(0)
42
+ parent_child_obj.children = [line.strip() for line in child_regex if line] if child_regex else ""
43
+ parent_child_obj_list.append(parent_child_obj)
44
+
45
+ if return_json:
46
+ return [obj.__dict__ for obj in parent_child_obj_list]
47
+
48
+ return parent_child_obj_list
49
+
50
+
51
+ def _fetch_parent_child(self, **kwargs):
52
+ """
53
+ Fetch the parent child from the config file
54
+ :param parent_regex: str Default is None (required)
55
+ :param child_regex: str Default is None (optional)
56
+ :param return_json: bool Default is False (optional)
57
+ return: list of ParentChild objects
58
+ """
59
+ parent_regex = kwargs.get("parent_regex", None)
60
+ child_regex = kwargs.get("child_regex", None)
61
+ return_json = kwargs.get("return_json", False)
62
+
63
+ if not parent_regex:
64
+ raise ValueError("parent_regex is required")
65
+
66
+ PARENT_REGEX = re.compile(parent_regex, flags=re.MULTILINE)
67
+ parent_child = ParentChildSeparator(self.content)
68
+ sections = parent_child._get_separated_sections()
69
+
70
+ parent_child_obj_list = []
71
+
72
+ for section in sections:
73
+ parent_child_obj = ParentChild()
74
+ parent_regex_result = PARENT_REGEX.search(section.strip())
75
+ if parent_regex_result:
76
+ if section.strip().startswith(parent_regex_result.group()):
77
+ if child_regex:
78
+ CHILD_REGEX = re.compile(child_regex, flags=re.MULTILINE)
79
+ child_regex_result = CHILD_REGEX.search(section.strip())
80
+ if child_regex_result:
81
+ parent_child_obj.parent = parent_regex_result.group()
82
+ parent_child_obj.children = child_regex_result.group()
83
+ parent_child_obj_list.append(parent_child_obj)
84
+ else:
85
+ children_regex = SPLIT_ON_LINE.split(section.strip())
86
+ children_regex.pop(0)
87
+ parent_child_obj.parent = parent_regex_result.group()
88
+ parent_child_obj.children = [line.strip() for line in children_regex if line] if children_regex else ""
89
+ parent_child_obj_list.append(parent_child_obj)
90
+
91
+ if return_json:
92
+ return [obj.__dict__ for obj in parent_child_obj_list]
93
+
94
+ return parent_child_obj_list
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cisco-config-parser
3
- Version: 2.2.2
3
+ Version: 2.2.4
4
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
@@ -4,7 +4,6 @@ setup.py
4
4
  cisco_config_parser/__init__.py
5
5
  cisco_config_parser/cisco_config_parser.py
6
6
  cisco_config_parser/setup.py
7
- cisco_config_parser/testing.py
8
7
  cisco_config_parser.egg-info/PKG-INFO
9
8
  cisco_config_parser.egg-info/SOURCES.txt
10
9
  cisco_config_parser.egg-info/dependency_links.txt
@@ -13,6 +12,9 @@ cisco_config_parser/global_search/__init__.py
13
12
  cisco_config_parser/global_search/global_obj.py
14
13
  cisco_config_parser/global_search/global_parser.py
15
14
  cisco_config_parser/global_search/global_separator.py
15
+ cisco_config_parser/global_search/ios/__init__.py
16
+ cisco_config_parser/global_search/nxos/__init__.py
17
+ cisco_config_parser/global_search/xr/__init__.py
16
18
  cisco_config_parser/helper/__init__.py
17
19
  cisco_config_parser/helper/help.py
18
20
  cisco_config_parser/helper/helper.py
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
3
3
 
4
4
  HERE = pathlib.Path(__file__).parent
5
5
 
6
- VERSION = '2.2.2'
6
+ VERSION = '2.2.4'
7
7
  PACKAGE_NAME = 'cisco_config_parser'
8
8
  AUTHOR = 'Ahmad Rezazadeh'
9
9
  AUTHOR_EMAIL = 'ahmad@klevernet.io'
@@ -1,45 +0,0 @@
1
- import re
2
- from .parent_child_obj import ParentChild
3
- from cisco_config_parser.parser_regex.regex import SPLIT_ON_LINE
4
- from .parent_child_separator import ParentChildSeparator
5
- from dataclasses import dataclass
6
-
7
-
8
-
9
- @dataclass
10
- class ParentChildParser:
11
- """
12
- Parent Child Parser class
13
- :param content: str
14
- :return: list of ParentChild objects
15
- """
16
- content: str = None
17
-
18
- def _fetch_parent_child(self, **kwargs):
19
- """
20
- Fetch the parent child from the config file
21
- return: list of ParentChild objects
22
- """
23
- custom_regex = kwargs.get("custom_regex", None)
24
- if not custom_regex:
25
- raise ValueError("custom_regex is required")
26
-
27
- custom_regex = re.compile(custom_regex, flags=re.MULTILINE)
28
- parent_child = ParentChildSeparator(self.content)
29
- sections = parent_child._get_separated_sections()
30
-
31
- parent_child_obj_list = []
32
-
33
- for section in sections:
34
- parent_child_obj = ParentChild()
35
- regex_result = re.match(custom_regex, section.strip())
36
- if regex_result:
37
- if section.strip().startswith(regex_result.group()):
38
- child_regex = SPLIT_ON_LINE.split(section.strip())
39
- parent_child_obj.parent = child_regex[0]
40
- child_regex.pop(0)
41
- parent_child_obj.children = [line.strip() for line in child_regex if line] if child_regex else ""
42
- parent_child_obj_list.append(parent_child_obj)
43
-
44
- return parent_child_obj_list
45
-
@@ -1,80 +0,0 @@
1
- import re
2
-
3
- cfg_section = """
4
- router bgp 65240
5
- bgp router-id 10.240.129.45
6
- bgp log-neighbor-changes
7
- timers bgp 3 10
8
- neighbor SHC_RR peer-group
9
- neighbor LPCH_PEERS peer-group
10
- neighbor SHC_RR remote-as 65240
11
- neighbor SHC_RR update-source Loopback1
12
- neighbor SHC_RR timers 7 21
13
- neighbor 10.252.248.251 peer-group SHC_RR
14
- neighbor 10.252.248.251 description STNNC-420-RR-1
15
- neighbor 10.252.248.252 peer-group SHC_RR
16
- neighbor 10.252.248.252 description STNMC-FOR-RR-2
17
- neighbor 10.252.248.253 peer-group SHC_RR
18
- neighbor 10.252.248.253 description STNMC-FOR-RR-3
19
-
20
- address-family ipv4
21
- bgp nexthop trigger delay 4
22
- bgp scan-time 5
23
- neighbor SHC_RR send-community both
24
- network 10.245.49.132 mask 255.255.255.255
25
- neighbor 10.252.248.251 activate
26
- neighbor 10.252.248.252 activate
27
- neighbor 10.252.248.253 activate
28
- exit-address-family
29
- """
30
-
31
- # Compile regex patterns
32
- peer_group_regex = re.compile(r"neighbor (\S+) peer-group")
33
- remote_as_regex = re.compile(r"neighbor (\S+) remote-as (\d+)")
34
- update_source_regex = re.compile(r"neighbor (\S+) update-source (\S+)")
35
- neighbor_ip_regex = re.compile(r"neighbor (\d+\.\d+\.\d+\.\d+) peer-group (\S+)")
36
- neighbor_desc_regex = re.compile(r"neighbor (\d+\.\d+\.\d+\.\d+) description (.+)")
37
-
38
- # Parsing peer groups
39
- peer_groups = peer_group_regex.findall(cfg_section)
40
- peer_group_details = []
41
-
42
- for pg in peer_groups:
43
- details = {
44
- "peer_group": {
45
- "name": pg,
46
- "remote_as": "",
47
- "update_source": "",
48
- "route-map": {"in": "", "out": ""},
49
- "neighbors": []
50
- }
51
- }
52
- # Remote AS
53
- ras = remote_as_regex.search(cfg_section)
54
- if ras and ras.group(1) == pg:
55
- details["peer_group"]["remote_as"] = ras.group(2)
56
-
57
- # Update Source
58
- ups = update_source_regex.search(cfg_section)
59
- if ups and ups.group(1) == pg:
60
- details["peer_group"]["update_source"] = ups.group(2)
61
-
62
- # Neighbors
63
- for nip in neighbor_ip_regex.finditer(cfg_section):
64
- if nip.group(2) == pg:
65
- neighbor_info = {
66
- "ip": nip.group(1),
67
- "description": ""
68
- }
69
- # Description
70
- ndesc = neighbor_desc_regex.search(cfg_section)
71
- if ndesc and ndesc.group(1) == nip.group(1):
72
- neighbor_info["description"] = ndesc.group(2)
73
- details["peer_group"]["neighbors"].append(neighbor_info)
74
-
75
- peer_group_details.append(details)
76
-
77
- # Output the structured data
78
- import json
79
-
80
- print(json.dumps(peer_group_details, indent=2))