Skip to content

Commit

Permalink
Updating the os_version module to include a jinja friendly function f…
Browse files Browse the repository at this point in the history
…or os_version_parsing. Updated docs.
  • Loading branch information
Brandon Minnix authored and Brandon Minnix committed Apr 26, 2024
1 parent e089fc7 commit a20dbdb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/user/include_jinja_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
| compare_version_strict | netutils.os_version.compare_version_strict |
| get_upgrade_path | netutils.os_version.get_upgrade_path |
| juniper_junos_version_parser | netutils.os_version.juniper_junos_version_parser |
| vendorize_version | netutils.os_version.vendorize_version |
| compare_cisco_type5 | netutils.password.compare_cisco_type5 |
| compare_cisco_type7 | netutils.password.compare_cisco_type7 |
| compare_cisco_type9 | netutils.password.compare_cisco_type9 |
Expand Down
1 change: 1 addition & 0 deletions docs/user/lib_mapper/nist.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| NIST | | NORMALIZED |
| ---------- | -- | ------ |
| adaptive_security_appliance_software || cisco_asa |
| eos || arista_eos |
| ios || cisco_ios |
| ios_xe || cisco_xe |
Expand Down
1 change: 1 addition & 0 deletions docs/user/lib_mapper/nist_reverse.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
| NORMALIZED | | NIST |
| ---------- | -- | ------ |
| arista_eos || eos |
| cisco_asa || adaptive_security_appliance_software |
| cisco_ios || ios |
| cisco_nxos || nx-os |
| cisco_xe || ios_xe |
Expand Down
9 changes: 5 additions & 4 deletions netutils/os_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,14 @@ def juniper_junos_version_parser(version: str) -> t.Dict[str, t.Any]:
return parsed_version


CUSTOM_VERSION_PARSERS = {
os_version_parsers = {
"juniper": {
"junos": juniper_junos_version_parser,
}
}

def vendorize_version(vendor: str, os_type: str, version: str) -> dict:

def vendorize_version(vendor: str, os_type: str, version: str) -> t.Dict[str, t.Any]:
"""If a custom version parser is avaialable, use it.
Args:
Expand All @@ -232,14 +233,14 @@ def vendorize_version(vendor: str, os_type: str, version: str) -> dict:
dict: Dict of broken down version into vendor standards.
Example:
>>> from os_version import vendorize_version
>>> from netutils.os_version import vendorize_version
>>> vendorize_version("Cisco", "IOS", "15.5")
{'vendor': 'Cisco', 'os_type': 'IOS', 'version': '15.5', 'vendorized': False}
>>> vendorize_version("juniper", "junos", "12.4R")
{'isservice': False, 'ismaintenance': False, 'isfrs': True, 'isspecial': False, 'service': None, 'service_build': None, 'service_respin': None, 'main': '12', 'minor': '4', 'type': 'R', 'build': None, 'vendorized': True}
"""
try:
parsed_version = CUSTOM_VERSION_PARSERS[vendor][os_type](version)
parsed_version = os_version_parsers[vendor][os_type](version)
parsed_version.update({"vendorized": True})
except KeyError:
parsed_version = {"vendor": vendor, "os_type": os_type, "version": version, "vendorized": False}
Expand Down
2 changes: 1 addition & 1 deletion netutils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"get_ips_sorted": "ip.get_ips_sorted",
"os_platform_object_builder": "platform_mapper.os_platform_object_builder",
"juniper_junos_version_parser": "os_version.juniper_junos_version_parser",
"vendorize_version": "os.version.vendorize_version",
"vendorize_version": "os_version.vendorize_version",
}


Expand Down

0 comments on commit a20dbdb

Please sign in to comment.