@@ -51,6 +51,9 @@ def __init__(
5151 legacy_sku_id (str, optional):
5252 Only required when ``support_legacy == True``. The SKU ID for Gen1.
5353 Defaults to ``{sku_id}-gen1``
54+ check_base_sas_only (bool, optional):
55+ Indicates to skip checking SAS parameters when set as ``True``.
56+ Default to ``False``
5457 **kwargs
5558 Arguments for :class:`~cloudpub.common.PublishingMetadata`.
5659 """
@@ -60,6 +63,7 @@ def __init__(
6063 self .support_legacy = support_legacy
6164 self .recommended_sizes = recommended_sizes or []
6265 self .legacy_sku_id = kwargs .pop ("legacy_sku_id" , None )
66+ self .check_base_sas_only = kwargs .pop ("check_base_sas_only" , False )
6367
6468 if generation == "V1" or not support_legacy :
6569 self .legacy_sku_id = None
@@ -113,7 +117,7 @@ def get_image_type_mapping(architecture: str, generation: str) -> str:
113117 return gen_map .get (generation , "" )
114118
115119
116- def is_sas_eq (sas1 : str , sas2 : str ) -> bool :
120+ def is_sas_eq (sas1 : str , sas2 : str , base_only = False ) -> bool :
117121 """
118122 Compare 2 SAS URI and determine where they're equivalent.
119123
@@ -127,10 +131,12 @@ def is_sas_eq(sas1: str, sas2: str) -> bool:
127131 This comparison is necessary as each time a SAS URI is generated it returns a different value.
128132
129133 Args:
130- sas1:
134+ sas1 (str) :
131135 The left SAS to compare the equivalency
132- sas2:
136+ sas2 (str) :
133137 The right SAS to compare the equivalency
138+ base_only (bool):
139+ When True it will only compare the base SAS and not its arguments. Defaults to False.
134140
135141 Returns:
136142 True when both SAS URIs are equivalent, False otherwise.
@@ -147,25 +153,26 @@ def is_sas_eq(sas1: str, sas2: str) -> bool:
147153 log .debug ("Got different base SAS: %s - Expected: %s" % (base_sas1 , base_sas2 ))
148154 return False
149155
150- # Parameters lengh differs
151- if len (params_sas1 ) != len (params_sas2 ):
152- log .debug (
153- "Got different lengh of SAS parameters: len(%s) - Expected len(%s)"
154- % (params_sas1 , params_sas2 )
155- )
156- return False
157-
158- # Parameters values differs
159- for k , v in params_sas1 .items ():
160- if v != params_sas2 .get (k , None ):
161- log .debug ("The SAS parameter %s doesn't match %s." % (v , params_sas2 .get (k , None )))
156+ if not base_only :
157+ # Parameters lengh differs
158+ if len (params_sas1 ) != len (params_sas2 ):
159+ log .debug (
160+ "Got different lengh of SAS parameters: len(%s) - Expected len(%s)"
161+ % (params_sas1 , params_sas2 )
162+ )
162163 return False
163164
165+ # Parameters values differs
166+ for k , v in params_sas1 .items ():
167+ if v != params_sas2 .get (k , None ):
168+ log .debug ("The SAS parameter %s doesn't match %s." % (v , params_sas2 .get (k , None )))
169+ return False
170+
164171 # Equivalent SAS
165172 return True
166173
167174
168- def is_sas_present (tech_config : VMIPlanTechConfig , sas_uri : str ) -> bool :
175+ def is_sas_present (tech_config : VMIPlanTechConfig , sas_uri : str , base_only : bool = False ) -> bool :
169176 """
170177 Check whether the given SAS URI is already present in the disk_version.
171178
@@ -174,12 +181,14 @@ def is_sas_present(tech_config: VMIPlanTechConfig, sas_uri: str) -> bool:
174181 The plan's technical configuraion to seek the SAS_URI.
175182 sas_uri (str)
176183 The SAS URI to check whether it's present or not in disk version.
184+ base_only (bool):
185+ When True it will only compare the base SAS and not its arguments. Defaults to False.
177186 Returns:
178187 bool: True when the SAS is present in the plan, False otherwise.
179188 """
180189 for disk_version in tech_config .disk_versions :
181190 for img in disk_version .vm_images :
182- if is_sas_eq (img .source .os_disk .uri , sas_uri ):
191+ if is_sas_eq (img .source .os_disk .uri , sas_uri , base_only ):
183192 return True
184193 return False
185194
0 commit comments