Skip to content
Open
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions netutils/os_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,28 @@ def compare_version_strict(current_version: str, comparison: str, target_version
return _compare_version(current_version, comparison, target_version, "strict")


def _hpe_arubaos_cx_version_metadata(version: str) -> t.Dict[str, t.Any]:
"""Parse Aruba AOS-CX versions.

Examples:
>>> _hpe_arubaos_cx_version_metadata("FL.10.13.1161")
{'release': 'FL', 'major': '10', 'minor': '13', 'patch': '1161'}

>>> _hpe_arubaos_cx_version_metadata("GL.10.13.1090")
{'release': 'GL', 'major': '10', 'minor': '13', 'patch': '1090'}
"""
regex = re.compile(
r"^(?P<release>[A-Z]{2})\.(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)$"
)

parsed_version = regex.match(version)

if parsed_version:
return parsed_version.groupdict()

return {"Error": "Unable to evaluate the version number entered."}


def _juniper_junos_version_metadata(version: str) -> t.Dict[str, t.Any]:
"""Parses JunOS Version into usable bits matching JunOS Standards.

Expand Down Expand Up @@ -286,6 +308,9 @@ def _basic_version_metadata(version: str) -> t.Dict[str, t.Any]:
"juniper": {
"junos": _juniper_junos_version_metadata,
},
"hpe": {
"arubaos-cx": _hpe_arubaos_cx_version_metadata,
},
}


Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_os_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from netutils import os_version
from netutils.constants import UPGRADE_PATHS
from netutils.os_version import version_metadata

LOOSE_VERSION = [
{"sent": {"current_version": "10.1", "comparison": ">=", "target_version": "10.2"}, "received": False},
Expand Down Expand Up @@ -33,6 +34,35 @@
]

PLATFORM_VERSION_METADATA = [
# ArubaOS-CX uses a custom version format
{
"sent": {
"vendor": "hpe",
"platform": "arubaos-cx",
"version": "FL.10.13.1161",
},
"received": {
"major": "10",
"minor": "13",
"patch": "1161",
"release": "FL",
"vendor_metadata": True,
},
},
{
"sent": {
"vendor": "hpe",
"platform": "arubaos-cx",
"version": "GL.10.13.1090",
},
"received": {
"major": "10",
"minor": "13",
"patch": "1090",
"release": "GL",
"vendor_metadata": True,
},
},
# Cisco and Arista use the generic parsing
{
"sent": {"vendor": "cisco", "platform": "ios", "version": "15.7(2.0z)M"},
Expand Down