cisco-config-parser 2.2.5__tar.gz → 2.2.6__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 (70) hide show
  1. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/PKG-INFO +5 -1
  2. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/README.md +4 -0
  3. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/__init__.py +1 -1
  4. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/layer2_interface/l2_interface_parser.py +1 -1
  5. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/layer3_interface/l3_interface_parser.py +1 -2
  6. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/layer3_interface/l3_interface_separator.py +1 -1
  7. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/parser/parser.py +0 -4
  8. cisco_config_parser-2.2.6/cisco_config_parser/parser_regex/nxos_regex.py +23 -0
  9. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/nxos/rtp_nxos_rtp_obj.py +4 -8
  10. cisco_config_parser-2.2.6/cisco_config_parser/routing_protocol/nxos/rtp_static.py +91 -0
  11. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/utils/utils.py +13 -2
  12. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser.egg-info/PKG-INFO +6 -2
  13. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/setup.py +1 -1
  14. cisco_config_parser-2.2.5/cisco_config_parser/parser_regex/nxos_regex.py +0 -17
  15. cisco_config_parser-2.2.5/cisco_config_parser/routing_protocol/nxos/rtp_static.py +0 -49
  16. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/cisco_config_parser.py +0 -0
  17. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/global_search/__init__.py +0 -0
  18. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/global_search/global_obj.py +0 -0
  19. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/global_search/global_parser.py +0 -0
  20. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/global_search/global_separator.py +0 -0
  21. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/global_search/ios/__init__.py +0 -0
  22. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/global_search/nxos/__init__.py +0 -0
  23. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/global_search/xr/__init__.py +0 -0
  24. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/helper/__init__.py +0 -0
  25. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/helper/help.py +0 -0
  26. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/helper/helper.py +0 -0
  27. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/layer2_interface/__init__.py +0 -0
  28. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/layer2_interface/l2_interface_obj.py +0 -0
  29. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/layer2_interface/l2_interface_separator.py +0 -0
  30. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/layer2_interface/l2_section_parser.py +0 -0
  31. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/layer3_interface/__init__.py +0 -0
  32. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/layer3_interface/l3_interface_obj.py +0 -0
  33. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/layer3_interface/l3_section_parser.py +0 -0
  34. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/old_version/__init__.py +0 -0
  35. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/old_version/exceptions.py +0 -0
  36. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/old_version/obj.py +0 -0
  37. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/old_version/old_parse.py +0 -0
  38. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/old_version/ssh.py +0 -0
  39. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/old_version/utils.py +0 -0
  40. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/parent_child/__init__.py +0 -0
  41. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/parent_child/parent_child_obj.py +0 -0
  42. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/parent_child/parent_child_parser.py +0 -0
  43. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/parent_child/parent_child_separator.py +0 -0
  44. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/parser/__init__.py +0 -0
  45. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/parser_regex/__init__.py +0 -0
  46. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/parser_regex/common_regex.py +0 -0
  47. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/parser_regex/ios_regex.py +0 -0
  48. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/__init__.py +0 -0
  49. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/ios/__init__.py +0 -0
  50. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/ios/rtp_bgp.py +0 -0
  51. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/ios/rtp_eigtp.py +0 -0
  52. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/ios/rtp_ios_rtp_obj.py +0 -0
  53. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/ios/rtp_ospf.py +0 -0
  54. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/ios/rtp_static.py +0 -0
  55. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/nxos/__init__.py +0 -0
  56. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/nxos/rtp_bgp.py +0 -0
  57. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/nxos/rtp_ospf.py +0 -0
  58. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/nxos/rtp_vxlan.py +0 -0
  59. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/utils/__init__.py +0 -0
  60. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/utils/rtp_ios_separator.py +0 -0
  61. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/utils/rtp_nxos_separator.py +0 -0
  62. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/routing_protocol/xr/__init__.py +0 -0
  63. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/separator/__init__.py +0 -0
  64. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/separator/separator.py +0 -0
  65. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser/setup.py +0 -0
  66. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser.egg-info/SOURCES.txt +0 -0
  67. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser.egg-info/dependency_links.txt +0 -0
  68. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/cisco_config_parser.egg-info/top_level.txt +0 -0
  69. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/pyproject.toml +0 -0
  70. {cisco_config_parser-2.2.5 → cisco_config_parser-2.2.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cisco_config_parser
3
- Version: 2.2.5
3
+ Version: 2.2.6
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
@@ -58,6 +58,10 @@ Some of those configs are as follow:
58
58
  - OSPF
59
59
  - IS-IS
60
60
  - BGP
61
+ - VXLAN Related Configs (NXOS)
62
+ - BGP EVPN MP-BGP
63
+ - NVE Config
64
+ - Anycast Gateway Config
61
65
 
62
66
  - Line-vty
63
67
  - Line-con
@@ -48,6 +48,10 @@ Some of those configs are as follow:
48
48
  - OSPF
49
49
  - IS-IS
50
50
  - BGP
51
+ - VXLAN Related Configs (NXOS)
52
+ - BGP EVPN MP-BGP
53
+ - NVE Config
54
+ - Anycast Gateway Config
51
55
 
52
56
  - Line-vty
53
57
  - Line-con
@@ -14,4 +14,4 @@ __license__ = "MIT"
14
14
  __description__ = "A simple library to parse Cisco configuration files"
15
15
 
16
16
 
17
- __all__ = _ALL_
17
+ __all__ = _ALL_
@@ -147,7 +147,7 @@ class L2InterfaceParser:
147
147
  l2_trunk_intf_cls.description = description_regex.group(1)
148
148
 
149
149
  if allowed_vlan_regex:
150
- l2_trunk_intf_cls.allowed_vlan = allowed_vlan_regex.group(1)
150
+ l2_trunk_intf_cls.allowed_vlans = allowed_vlan_regex.group(1)
151
151
 
152
152
  if native_vlan_regex:
153
153
  l2_trunk_intf_cls.native_vlan = native_vlan_regex.group(1)
@@ -36,6 +36,7 @@ class L3InterfaceParser:
36
36
 
37
37
  l3_intf = L3InterfaceSeparator(self.content)
38
38
  l3_interfaces = l3_intf.find_all_l3_interfaces()
39
+
39
40
  l3_intf_objects = []
40
41
 
41
42
  for l3_interface in l3_interfaces:
@@ -89,7 +90,6 @@ class L3InterfaceParser:
89
90
  if description_regex:
90
91
  l3_intf_cls.description = description_regex.group(1).strip()
91
92
 
92
-
93
93
  # if there are custom kwargs, search for the custom regex in the l3_interface section
94
94
  # if the regex is found, parse the line and store the value in the l3_intf_cls object
95
95
  if kwargs:
@@ -104,7 +104,6 @@ class L3InterfaceParser:
104
104
  }
105
105
  l3_intf_cls = _L3SectionParser._parse_custom_regex(**custom_regex_kwargs)
106
106
 
107
-
108
107
  # append the l3_intf_cls object to the l3_intf_objects list
109
108
  l3_intf_objects.append(l3_intf_cls)
110
109
 
@@ -12,7 +12,7 @@ class L3InterfaceSeparator(Separator):
12
12
  def _is_l3_interface_section(self, section):
13
13
  interface_regex = re.search(r"^interface", section, flags=re.MULTILINE)
14
14
  if interface_regex:
15
- l3_interface_regex = re.search(r"ip address", section, flags=re.MULTILINE)
15
+ l3_interface_regex = re.search(r"(ip address)|(ipv4 address)", section, flags=re.MULTILINE)
16
16
  if l3_interface_regex:
17
17
  return True
18
18
  return False
@@ -2,10 +2,6 @@ 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.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
5
  from cisco_config_parser.routing_protocol import *
10
6
 
11
7
  from cisco_config_parser.parser_regex.ios_regex import *
@@ -0,0 +1,23 @@
1
+ import re
2
+
3
+
4
+ RTP_NXOS_REGEX = re.compile(r"^router\s(\S+)", flags=re.MULTILINE)
5
+
6
+
7
+ # NXOS STATIC ROUTE
8
+
9
+
10
+ RTP_NXOS_VRF_CONTEXT_REGEX = re.compile(r"^vrf\scontext\s(\S+)", flags=re.MULTILINE)
11
+ RTP_NXOS_VRF_STATIC_ROUTE_REGEX = re.compile(r" ip route .*", flags=re.MULTILINE)
12
+ RTP_NXOS_GLOBAL_STATIC_ROUTE_REGEX = re.compile(r"^ip route .*", flags=re.MULTILINE)
13
+ RTP_NXOS_STATIC_ROUTE_REGEX = re.compile(r"ip route .*", flags=re.MULTILINE)
14
+
15
+ # Global
16
+ RTP_NXOS_STATIC_REGEX = re.compile(r"ip route (\S+) (\S+)$", flags=re.MULTILINE)
17
+ RTP_NXOS_STATIC_AD_REGEX = re.compile(r"ip route (\S+) (\S+) (\d+)", flags=re.MULTILINE)
18
+ RTP_NXOS_STATIC_NAME_REGEX = re.compile(r"ip route (\S+) (\S+) name (.*)$", flags=re.MULTILINE)
19
+ RTP_NXOS_STATIC_NAME_AD_REGEX = re.compile(r"ip route (\S+) (\S+) name (.*) (\d+)$", flags=re.MULTILINE)
20
+
21
+
22
+
23
+
@@ -6,15 +6,11 @@ from dataclasses import dataclass
6
6
 
7
7
  @dataclass
8
8
  class StaticRoute:
9
- network: str = None
10
- mask: str = None
11
- nexthop_ip: str = None
12
- subnet: str = None
13
- vrf: str = None
14
- name: str = None
15
- admin_distance: str = None
16
-
9
+ networks: list = None
17
10
 
11
+ def __post_init__(self):
12
+ if self.networks is None:
13
+ self.networks = []
18
14
 
19
15
 
20
16
  @dataclass
@@ -0,0 +1,91 @@
1
+ from .rtp_nxos_rtp_obj import StaticRoute
2
+ from cisco_config_parser.parser_regex import *
3
+ from dataclasses import dataclass
4
+ from cisco_config_parser.routing_protocol.utils import *
5
+ from cisco_config_parser.routing_protocol.utils.rtp_nxos_separator import NXOSRoutingProtocolSeparator
6
+
7
+ @dataclass
8
+ class NXOSStaticRouteConfig:
9
+ content: str = None
10
+
11
+
12
+ def _rewrite_static_route_section(self, section):
13
+ """
14
+ Rewrite static route section
15
+ :param section: section of the config file
16
+ :return: str
17
+ """
18
+ cleaned_section = [line.strip() for line in section.split("\n") if line.strip()]
19
+ return "\n".join(cleaned_section)
20
+
21
+
22
+ def _process_static_route_alone(self, section):
23
+ """
24
+ Process static route alone
25
+ :param section: section of the config file
26
+ :return: dict
27
+ """
28
+ cleaned_section = self._rewrite_static_route_section(section)
29
+ result = RTP_NXOS_STATIC_REGEX.findall(cleaned_section)
30
+ print(result)
31
+
32
+
33
+
34
+ def _process_static_route(self, section, obj):
35
+ """
36
+ Description:
37
+ the global static routes come to this function one line at a time
38
+ """
39
+ static_alone = RTP_NXOS_STATIC_REGEX.findall(section)
40
+ static_with_name = RTP_NXOS_STATIC_NAME_REGEX.findall(section)
41
+ static_with_ad = RTP_NXOS_STATIC_AD_REGEX.findall(section)
42
+ static_with_name_ad = RTP_NXOS_STATIC_NAME_AD_REGEX.findall(section)
43
+ print(static_alone)
44
+ print(static_with_name)
45
+ print(static_with_ad)
46
+ print(static_with_name_ad)
47
+
48
+ pass
49
+
50
+
51
+
52
+ def _fetch_static_route_config(self, return_json=False):
53
+ """
54
+ Fetch static route configuration
55
+ :param return_json: return the output in json format
56
+ :return: str or dict
57
+ """
58
+
59
+ static_route_obj_list = []
60
+ static_route_sections = NXOSRoutingProtocolSeparator(self.content).find_static_route_section()
61
+
62
+ global_routes = []
63
+ for section in static_route_sections:
64
+ static_route_obj = StaticRoute()
65
+
66
+ # Process Global Static Route
67
+ if RTP_NXOS_GLOBAL_STATIC_ROUTE_REGEX.findall(section):
68
+
69
+ # some global static route might have vrf in them,
70
+ # so we will ignore them while processing global static route
71
+ # and process them in vrf context
72
+ if "vrf" not in section:
73
+ global_routes.append(section)
74
+
75
+ global_results = self._process_static_route(
76
+ "\n".join(global_routes), static_route_obj
77
+ )
78
+
79
+
80
+ # # Process VRF Static Route
81
+ # elif RTP_NXOS_VRF_CONTEXT_REGEX.search(section):
82
+ # static_route_obj = self._process_static_route(section, static_route_obj)
83
+ # static_route_obj.vrf = RTP_NXOS_VRF_CONTEXT_REGEX.search(section).group(1)
84
+ # static_route_obj_list.append(static_route_obj)
85
+
86
+ if return_json:
87
+ return [obj.__dict__.copy() for obj in static_route_obj_list]
88
+
89
+ return static_route_obj_list
90
+
91
+
@@ -1,14 +1,25 @@
1
1
  import ipaddress
2
2
 
3
3
 
4
- def get_subnet(network, mask):
4
+ def get_subnet(network=None, mask=None):
5
5
  """
6
6
  Get the subnet from the network and mask
7
7
  :param network: str
8
8
  :param mask: str
9
9
  :return: str
10
10
  """
11
- return str(ipaddress.ip_network((network, mask), strict=False))
11
+ return str(ipaddress.ip_network((network, mask), strict=False)) if mask else str(ipaddress.ip_network(network))
12
+
13
+
14
+ def get_mask_from_cidr(subnet):
15
+ """
16
+ Get the mask from the CIDR
17
+ Args:
18
+ subnet: str
19
+ Returns:
20
+ str
21
+ """
22
+ return str(ipaddress.IPv4Network(subnet).netmask)
12
23
 
13
24
 
14
25
  def convert_wildcard_to_mask(wildcard_mask):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
- Name: cisco-config-parser
3
- Version: 2.2.5
2
+ Name: cisco_config_parser
3
+ Version: 2.2.6
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
@@ -58,6 +58,10 @@ Some of those configs are as follow:
58
58
  - OSPF
59
59
  - IS-IS
60
60
  - BGP
61
+ - VXLAN Related Configs (NXOS)
62
+ - BGP EVPN MP-BGP
63
+ - NVE Config
64
+ - Anycast Gateway Config
61
65
 
62
66
  - Line-vty
63
67
  - Line-con
@@ -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.5'
6
+ VERSION = '2.2.6'
7
7
  PACKAGE_NAME = 'cisco_config_parser'
8
8
  AUTHOR = 'Ahmad Rezazadeh'
9
9
  AUTHOR_EMAIL = 'ahmad@klevernet.io'
@@ -1,17 +0,0 @@
1
- import re
2
-
3
-
4
- RTP_NXOS_REGEX = re.compile(r"^router\s(\S+)", flags=re.MULTILINE)
5
-
6
-
7
- # NXOS STATIC ROUTE
8
-
9
-
10
- RTP_NXOS_VRF_CONTEXT_REGEX = re.compile(r"^vrf\scontext\s(\S+)", flags=re.MULTILINE)
11
- RTP_NXOS_VRF_STATIC_ROUTE_REGEX = re.compile(r"\s+ip\sroute\s.*", flags=re.MULTILINE)
12
- RTP_NXOS_GLOBAL_STATIC_ROUTE_REGEX = re.compile(r"^ip\sroute\s.*", flags=re.MULTILINE)
13
- RTP_NXOS_STATIC_ROUTE_REGEX = re.compile(r"ip\sroute\s.*", flags=re.MULTILINE)
14
- RTP_NXOS_STATIC_W_NAME_REGEX = re.compile(r"ip route\s(\S+)\s(\S+)\sname\s(.*)$", flags=re.MULTILINE)
15
- RTP_NXOS_STATIC_W_NAME_AD_REGEX = re.compile(r"ip route\s(\S+)\s(\S+)\sname\s(.*)\s(\d+)$", flags=re.MULTILINE)
16
- RTP_NXOS_STATIC_WO_NAME_REGEX = re.compile(r"ip route\s(\S+)\s(\S+)$", flags=re.MULTILINE)
17
-
@@ -1,49 +0,0 @@
1
- from .rtp_nxos_rtp_obj import StaticRoute
2
- from cisco_config_parser.parser_regex import *
3
- from dataclasses import dataclass
4
- from cisco_config_parser.routing_protocol.utils.rtp_nxos_separator import NXOSRoutingProtocolSeparator
5
-
6
- @dataclass
7
- class NXOSStaticRouteConfig:
8
- content: str = None
9
-
10
-
11
- def _process_global_static_route(self, section, obj):
12
- """
13
- Process global static route
14
- :param section: section of the config file
15
- :param obj: object to store the data
16
- :return: None
17
- """
18
- static_route_with_name = RTP_NXOS_STATIC_W_NAME_REGEX.search(section)
19
- static_route_with_name_and_ad = RTP_NXOS_STATIC_W_NAME_AD_REGEX.search(section)
20
- static_route = RTP_NXOS_STATIC_WO_NAME_REGEX.search(section)
21
- print(section)
22
- if static_route_with_name:
23
- obj.network = static_route_with_name.group(1)
24
- obj.mask = static_route_with_name.group(2)
25
- obj.name = static_route_with_name.group(3)
26
- if static_route:
27
- print("no name")
28
- print(static_route.groups())
29
- obj.network = static_route.group(1)
30
- obj.mask = static_route.group(2)
31
-
32
-
33
-
34
-
35
- def _fetch_static_route_config(self, return_json=False):
36
- """
37
- Fetch static route configuration
38
- :param return_json: return the output in json format
39
- :return: str or dict
40
- """
41
-
42
- static_route_obj_list = []
43
- static_route_sections = NXOSRoutingProtocolSeparator(self.content).find_static_route_section()
44
- for section in static_route_sections:
45
- static_route_obj = StaticRoute()
46
- if RTP_NXOS_GLOBAL_STATIC_ROUTE_REGEX.search(section):
47
- static_route_obj = self._process_global_static_route(section, static_route_obj)
48
-
49
-