Skip to content

Commit e2351b4

Browse files
committed
Azure: Parse all SKUs to find the security type
The PR #68 removed the loop iteration over all SKUs which were not required for detecting the default/alternate generations for `x64`, however such iteration is required to detect the `security_type`. This commit fixes it by creating a dedicated helper function `_get_security_type` for this purpose only.
1 parent 9945fc4 commit e2351b4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

cloudpub/ms_azure/utils.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ def get_skuid(arch):
307307
return sorted(res, key=attrgetter("id"))
308308

309309

310+
def _get_security_type(old_skus: List[VMISku]) -> Optional[List[str]]:
311+
# The security type may exist only for x64 Gen2, so it iterates over all gens to find it
312+
# Get the security type for all gens
313+
for osku in old_skus:
314+
if osku.security_type is not None:
315+
return osku.security_type
316+
return None
317+
318+
310319
def update_skus(
311320
disk_versions: List[DiskVersion],
312321
generation: str,
@@ -341,15 +350,12 @@ def update_skus(
341350
return old_skus
342351

343352
# Update SKUs to create the alternate gen.
344-
# The security type may exist only for Gen2, so it iterates over all gens to find it
345-
security_type = None
346-
# The alternate plan name ends with the suffix "-genX" and we can't change that once
353+
security_type = _get_security_type(old_skus)
354+
355+
# The alternate plan for x64 name ends with the suffix "-genX" and we can't change that once
347356
# the offer is live, otherwise it will raise "BadRequest" with the message:
348357
# "The property 'PlanId' is locked by a previous submission".
349358
osku = old_skus[0]
350-
# Get the security type for all gens
351-
if osku.security_type is not None:
352-
security_type = osku.security_type
353359

354360
# Default Gen2 cases
355361
if osku.image_type.endswith("Gen1") and osku.id.endswith("gen1"):

0 commit comments

Comments
 (0)