Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map 'aruba_os' to the existing 'aoscx' parser #588

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/dev/include_parser_list.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
| ---------- | ------ |
| arista_eos | netutils.config.parser.EOSConfigParser |
| aruba_aoscx | netutils.config.parser.ArubaConfigParser |
| aruba_os | netutils.config.parser.ArubaOSConfigParser |
| bigip_f5 | netutils.config.parser.F5ConfigParser |
| cisco_aireos | netutils.config.parser.AIREOSConfigParser |
| cisco_asa | netutils.config.parser.ASAConfigParser |
1 change: 1 addition & 0 deletions docs/user/lib_mapper/netutilsparser.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
| ---------- | -- | ------ |
| arista_eos | → | arista_eos |
| aruba_aoscx | → | aruba_aoscx |
| aruba_os | → | aruba_os |
| bigip_f5 | → | bigip_f5 |
| cisco_aireos | → | cisco_aireos |
| cisco_asa | → | cisco_asa |
1 change: 1 addition & 0 deletions docs/user/lib_mapper/netutilsparser_reverse.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
| ---------- | -- | ------ |
| arista_eos | → | arista_eos |
| aruba_aoscx | → | aruba_aoscx |
| aruba_os | → | aruba_os |
| bigip_f5 | → | bigip_f5 |
| cisco_aireos | → | cisco_aireos |
| cisco_asa | → | cisco_asa |
1 change: 1 addition & 0 deletions netutils/config/compliance.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
parser_map: t.Dict[str, t.Type[parser.BaseConfigParser]] = {
"arista_eos": parser.EOSConfigParser,
"aruba_aoscx": parser.ArubaConfigParser,
Copy link

@bradh11 bradh11 Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to rename this parser class to ArubaCXConfigParser. In Aruba, there is the legacy AOS (think Procurve and older model switches/gateways) as well as AOS-CX (newer switches and gateways. If we keep the name generic as it is today, this could add to confusion since the name Aruba on it's own does not make distinction between the two OS's.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, I am not sure the repurcussions of changing the parser class name. I think since we have the mapping table it might be a non-issue, but I will let others comment.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"aruba_aoscx": parser.ArubaConfigParser,
"aruba_aoscx": parser.ArubaCXConfigParser,

and this...

class ArubaCXConfigParser(BaseSpaceConfigParser):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but also am not sure about the repercussions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itdependsnetworks agrees this specific update would be a 'breaking change', IMHO this shouldn't be done as part of this PR. The other changes requested have been pushed.

"aruba_os": parser.ArubaOSConfigParser,
"bigip_f5": parser.F5ConfigParser,
"cisco_aireos": parser.AIREOSConfigParser,
"cisco_asa": parser.ASAConfigParser,
82 changes: 82 additions & 0 deletions netutils/config/parser.py
Original file line number Diff line number Diff line change
@@ -1287,6 +1287,88 @@ def config_lines_only(self) -> str:
return self._config


class ArubaOSConfigParser(BaseSpaceConfigParser):
"""Aruba OS (AOS) implementation fo ConfigParser Class."""

banner_end = "!"
comment_chars = ["!"]

def _build_banner(self, config_line: str) -> t.Optional[str]:
"""Handle banner config lines.

Args:
config_line: The start of the banner config.

Returns:
The next configuration line in the configuration text or None when banner end is the end of the config text.

Raises:
ValueError: When the parser is unable to identify the End of the Banner.
"""
self._update_config_lines(config_line)
self._current_parents += (config_line,)
banner_config = []
for line in self.generator_config:
if not self.is_banner_end(line):
banner_config.append(line)
else:
banner_config.append(line)
line = "\n".join(banner_config)
self._update_config_lines(line)
self._current_parents = self._current_parents[:-1]
try:
return next(self.generator_config)
except StopIteration:
return None
raise ValueError("Unable to parse banner end.")

def _parse_out_comments(self, config: str) -> str:
"""Remove comments while retaining the banner end.

Args:
config (str): full config as a string.

Returns:
The non-comment lines from ``config``.
"""
# Aruba OS uses "!" as both comments and the banner delimiter.
# Even if another delimiter is used while creating the banner, show run changes the delimiter to use "!".
# We need to remove comments while retaining the banner delimiter.

config_lines = []
banner_started = False
banner_ended = False
for line in config.splitlines():
if self.is_banner_start(line):
banner_started = True
banner_ended = False
if line and banner_started and not banner_ended:
config_lines.append(line.rstrip())
if line.lstrip().startswith(self.banner_end):
banner_ended = True
banner_started = False
else:
if line and not self.is_comment(line):
config_lines.append(line.rstrip())
full_config = "\n".join(config_lines)
return full_config

@property
def config_lines_only(self) -> str:
"""Remove spaces and unwanted lines from config lines.

Returns:
The non-space and non-comment lines from ``config``.
"""
if self._config is None:
config_lines = []
for line in self.config.splitlines():
if line and not line.isspace():
config_lines.append(line.rstrip())
self._config = self._parse_out_comments("\n".join(config_lines))
return self._config


class IOSXRConfigParser(CiscoConfigParser):
"""IOS-XR config parser."""

2 changes: 2 additions & 0 deletions netutils/lib_mapper.py
Original file line number Diff line number Diff line change
@@ -388,6 +388,7 @@
NETUTILSPARSER_LIB_MAPPER: t.Dict[str, str] = {
"arista_eos": "arista_eos",
"aruba_aoscx": "aruba_aoscx",
"aruba_os": "aruba_os",
"bigip_f5": "bigip_f5",
"cisco_aireos": "cisco_aireos",
"cisco_asa": "cisco_asa",
@@ -553,6 +554,7 @@
NETUTILSPARSER_LIB_MAPPER_REVERSE: t.Dict[str, str] = {
"arista_eos": "arista_eos",
"aruba_aoscx": "aruba_aoscx",
"aruba_os": "aruba_os",
"bigip_f5": "bigip_f5",
"cisco_aireos": "cisco_aireos",
"cisco_asa": "cisco_asa",
1,473 changes: 1,473 additions & 0 deletions tests/unit/mock/config/parser/base/aruba_os/os_full_received.py

Large diffs are not rendered by default.

1,523 changes: 1,523 additions & 0 deletions tests/unit/mock/config/parser/base/aruba_os/os_full_sent.txt

Large diffs are not rendered by default.