Skip to content

Commit aacc82a

Browse files
authored
feat(panos_software): support Skip Software Version Upgrade (#638)
Skipping 3 major/minor releases is allowed for both upgrade and downgrade paths for PAN-OS devices supporting Skip Software Version Upgrade feature starting from 10.1 onwards. Downgrade path is limited to min. 10.1.x release when downgrading from Skip Software Version Upgrade supported PAN-OS devices.
1 parent 4730663 commit aacc82a

1 file changed

Lines changed: 57 additions & 2 deletions

File tree

plugins/modules/panos_software.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ def needs_download(device, version):
149149

150150

151151
def is_valid_sequence(current, target):
152+
# PAN-OS version sequence for Skip Software Version Upgrade supported from 10.1
153+
# It is recommended to skip at most 2 major/minor release from 10.1 and 3 major/minor release from 11.0
154+
version_sequence = [
155+
PanOSVersion("10.1"),
156+
PanOSVersion("10.2"),
157+
PanOSVersion("11.0"),
158+
PanOSVersion("11.1"),
159+
PanOSVersion("11.2"),
160+
PanOSVersion("12.1"),
161+
]
162+
152163
# Patch version change (major and minor versions match)
153164
if (current.major == target.major) and (current.minor == target.minor):
154165
return True
@@ -169,8 +180,52 @@ def is_valid_sequence(current, target):
169180
elif current.major - 1 == target.major:
170181
return True
171182

172-
else:
173-
return False
183+
# Skip Software Version Upgrade version logic for >= 10.1
184+
elif current >= PanOSVersion("10.1.0"):
185+
try:
186+
current_index = -1
187+
target_index = -1
188+
189+
# Find the indices of current and target versions in the sequence
190+
for i, version in enumerate(version_sequence):
191+
if current.major == version.major and current.minor == version.minor:
192+
current_index = i
193+
if target.major == version.major and target.minor == version.minor:
194+
target_index = i
195+
196+
# fail if either version is not in our sequence
197+
if current_index == -1 or target_index == -1:
198+
return False
199+
200+
# Calculate version distance based on the sequence
201+
version_distance = target_index - current_index
202+
abs_version_distance = abs(version_distance)
203+
204+
# Downgrade path
205+
if version_distance < 0:
206+
if target < PanOSVersion("10.1.0"):
207+
# downgrades supported to min 10.1 for Skip Software Version
208+
return False
209+
210+
# For all versions >= 10.1, allow skipping at most 3 versions in downgrade
211+
# (11.2 -> 10.1) or (12.1 -> 10.2)
212+
return (
213+
abs_version_distance <= 4
214+
) # Distance of 4 means skipping 3 versions
215+
216+
# Upgrade path
217+
else:
218+
# For all versions >= 10.1, allow skipping at most 3 versions in upgrade
219+
# (10.1 -> 11.2) or (10.2 -> 12.1)
220+
return (
221+
abs_version_distance <= 4
222+
) # Distance of 4 means skipping 3 versions
223+
224+
except (ValueError, TypeError): # If there's any issue with version comparisons
225+
return False
226+
227+
# if nothing matched so far
228+
return False
174229

175230

176231
def main():

0 commit comments

Comments
 (0)