|
1 | 1 | """Functions for working with OS Versions.""" |
2 | | -import re |
3 | 2 | import typing as t |
4 | 3 | from distutils.version import LooseVersion # pylint: disable=deprecated-module |
5 | 4 |
|
@@ -48,90 +47,3 @@ def get_upgrade_path( |
48 | 47 | upgrade_path.append(target_version) |
49 | 48 |
|
50 | 49 | return upgrade_path |
51 | | - |
52 | | - |
53 | | -def juniper_junos_version_parser(version: str) -> t.Dict[str, t.Any]: |
54 | | - """Parses JunOS Version into usable bits matching JunOS Standards. |
55 | | -
|
56 | | - Args: |
57 | | - version |
58 | | -
|
59 | | - Returns: |
60 | | - A dictionary containing parsed version information |
61 | | -
|
62 | | - Examples: |
63 | | - >>> parsed_version = juniper_junos_version_parser("12.3R4") |
64 | | - """ |
65 | | - # Use regex to group the main, minor, type and build into useable pieces |
66 | | - # re_main_minor_type_build = re.search(r"^(\d+)\.(\d+)([xXrRsS])?(\d+)?", split_version[0]) |
67 | | - re_main_minor_type_build: re.Pattern[str] = re.compile( |
68 | | - r""" |
69 | | - ^ |
70 | | - (?P<main>\d+) # main train |
71 | | - \. # dot separator |
72 | | - (?P<minor>\d+) # minor version |
73 | | - (?P<type>[xXrRsS])? # version type (optional) |
74 | | - (?P<build>\d+)? # build (optional) |
75 | | - """, |
76 | | - re.VERBOSE, |
77 | | - ) |
78 | | - re_service_build_respin: re.Pattern[str] = re.compile( |
79 | | - r""" |
80 | | - (?P<service>[sSdD])? # service (optional) |
81 | | - (?P<service_build>\d+)? # service build (optional) |
82 | | - \.? |
83 | | - (?P<service_respin>\d+)? # service respin (optional) |
84 | | - """, |
85 | | - re.VERBOSE, |
86 | | - ) |
87 | | - # Set empty params for service pieces and complete them if a second indice exists from the version split |
88 | | - # Define isservice, isfrs, isspecial, ismaintenance |
89 | | - parsed_version: t.Dict[str, t.Any] = { |
90 | | - "isservice": False, |
91 | | - "ismaintenance": False, |
92 | | - "isfrs": False, |
93 | | - "isspecial": False, |
94 | | - "service": None, |
95 | | - "service_build": None, |
96 | | - "service_respin": None, |
97 | | - } |
98 | | - |
99 | | - # Juniper junos marks the division between main, minor, type and build from the service build and respin with a - |
100 | | - version_core_part, *version_service_part = re.split("-|:", version) |
101 | | - |
102 | | - # Parse out junos into sections that can be used for logic |
103 | | - parsed_version.update(re_main_minor_type_build.search(version_core_part).groupdict()) # type:ignore |
104 | | - |
105 | | - if version_service_part: |
106 | | - parsed_version.update(re_service_build_respin.search(version_service_part[0]).groupdict()) # type:ignore |
107 | | - if parsed_version.get("service", "").lower() == "s": |
108 | | - parsed_version["isservice"] = True |
109 | | - # Juniper looks at the D in special releases like it's the R in normal releases; Use it as the frs identifier |
110 | | - elif parsed_version.get("service").lower() == "d" and ( # type:ignore |
111 | | - parsed_version.get("service_build") is None or int(parsed_version.get("service_build", 1)) <= 1 |
112 | | - ): |
113 | | - parsed_version["isfrs"] = True |
114 | | - |
115 | | - if parsed_version.get("type") is None: |
116 | | - return parsed_version |
117 | | - |
118 | | - if parsed_version["type"].lower() == "x": |
119 | | - parsed_version["isspecial"] = True |
120 | | - elif parsed_version["type"].lower() == "s": |
121 | | - parsed_version["isservice"] = True |
122 | | - |
123 | | - if parsed_version["type"].lower() == "r" and ( |
124 | | - parsed_version.get("build") is None or int(parsed_version.get("build")) <= 1 # type:ignore |
125 | | - ): |
126 | | - parsed_version["isfrs"] = True |
127 | | - elif parsed_version["type"].lower() == "r": |
128 | | - parsed_version["ismaintenance"] = True |
129 | | - |
130 | | - return parsed_version |
131 | | - |
132 | | - |
133 | | -os_version_parsers = { |
134 | | - "juniper": { |
135 | | - "junos": juniper_junos_version_parser, |
136 | | - } |
137 | | -} |
0 commit comments