2121log = logging .getLogger (__name__ )
2222
2323
24+ DEFAULT_UNSUPPORTED_SECURITY_TYPE_ARCHES = ["x64Gen1" ]
25+ """The default list of arches that don't support security type."""
26+
27+
2428class AzurePublishingMetadata (PublishingMetadata ):
2529 """A collection of metadata necessary for publishing a VHD Image into a product."""
2630
@@ -34,6 +38,7 @@ def __init__(
3438 generation : str = "V2" ,
3539 support_legacy : bool = False ,
3640 recommended_sizes : Optional [List [str ]] = None ,
41+ unsupported_security_type_arches : Optional [List [str ]] = None ,
3742 ** kwargs ,
3843 ) -> None :
3944 """
@@ -61,6 +66,9 @@ def __init__(
6166 The modular push causes the effect to only publish
6267 the changed plan instead of the whole offer to preview/live.
6368 Default to ``False``.
69+ unsupported_security_type_arches (list, optional):
70+ The list of arches that don't support security type.
71+ Default to ``["x64Gen1"]``.
6472 **kwargs
6573 Arguments for :class:`~cloudpub.common.PublishingMetadata`.
6674 """
@@ -72,7 +80,9 @@ def __init__(
7280 self .legacy_sku_id = kwargs .pop ("legacy_sku_id" , None )
7381 self .check_base_sas_only = kwargs .pop ("check_base_sas_only" , False )
7482 self .modular_push = kwargs .pop ("modular_push" , None ) or False
75-
83+ self .unsupported_security_type_arches = (
84+ unsupported_security_type_arches or DEFAULT_UNSUPPORTED_SECURITY_TYPE_ARCHES
85+ )
7686 if generation == "V1" or not support_legacy :
7787 self .legacy_sku_id = None
7888 else :
@@ -309,15 +319,19 @@ def _build_skus(
309319 alt_gen : str ,
310320 plan_name : str ,
311321 security_type : Optional [List [str ]] = None ,
322+ unsupported_security_type_arches : Optional [List [str ]] = None ,
312323) -> List [VMISku ]:
313324 def get_skuid (arch ):
314325 if arch == "x64" :
315326 return plan_name
316327 return f"{ plan_name } -{ arch .lower ()} "
317328
318329 def get_safe_security_type (image_type ):
319- # Arches which aren't x86Gen2 (like ARM64) doesn't work well with security type
320- if image_type != "x64Gen2" :
330+ unsupported_arches = (
331+ unsupported_security_type_arches or DEFAULT_UNSUPPORTED_SECURITY_TYPE_ARCHES
332+ )
333+ # Some arches (like x86 Gen1) doesn't support security type, so we need to skip them.
334+ if image_type in unsupported_arches :
321335 return None
322336 return security_type
323337
@@ -348,8 +362,8 @@ def get_safe_security_type(image_type):
348362
349363
350364def _get_security_type (old_skus : List [VMISku ]) -> Optional [List [str ]]:
351- # The security type may exist only for x64 Gen2, so it iterates over all gens to find it
352- # Get the security type for all gens
365+ # The security type may not be applied for certain arches, like x64 Gen1.
366+ # This function will return the proper security type for the arches that has it set.
353367 for osku in old_skus :
354368 if osku .security_type is not None :
355369 return osku .security_type
@@ -361,6 +375,7 @@ def update_skus(
361375 generation : str ,
362376 plan_name : str ,
363377 old_skus : Optional [List [VMISku ]] = None ,
378+ unsupported_security_type_arches : Optional [List [str ]] = None ,
364379) -> List [VMISku ]:
365380 """
366381 Return the expected VMISku list based on given DiskVersion.
@@ -375,13 +390,20 @@ def update_skus(
375390 old_skus (list, optional)
376391 A list of the existing SKUs to extract the security_type value
377392 when set.
393+ unsupported_security_type_arches (list, optional)
394+ The list of arches that don't support security type.
395+ Default to ``["x64Gen1"]``.
378396 Returns:
379397 The updated list with VMISkus.
380398 """
381399 if not old_skus :
382400 alt_gen = "V2" if generation == "V1" else "V1"
383401 return _build_skus (
384- disk_versions , default_gen = generation , alt_gen = alt_gen , plan_name = plan_name
402+ disk_versions ,
403+ default_gen = generation ,
404+ alt_gen = alt_gen ,
405+ plan_name = plan_name ,
406+ unsupported_security_type_arches = unsupported_security_type_arches ,
385407 )
386408
387409 # If we have SKUs for each image we don't need to update them as they're already
@@ -419,6 +441,7 @@ def update_skus(
419441 alt_gen = alt_gen ,
420442 plan_name = plan_name ,
421443 security_type = security_type ,
444+ unsupported_security_type_arches = unsupported_security_type_arches ,
422445 )
423446
424447
0 commit comments