@@ -319,24 +319,32 @@ def _parse_image_argument(cmd, namespace):
319319 raise CLIError (err )
320320
321321
322- def _get_image_plan_info_if_exists (cmd , namespace ):
323- try :
324- from .aaz .latest .vm .image import Show as VmImageShow
325- if namespace .os_version .lower () == 'latest' :
326- image_version = _get_latest_image_version_by_aaz (cmd .cli_ctx , namespace .location , namespace .os_publisher ,
327- namespace .os_offer , namespace .os_sku )
328- else :
329- image_version = namespace .os_version
322+ # pylint: disable=protected-access
323+ def _show_vm_image (cmd , namespace ):
324+ if hasattr (namespace , '_vm_image_info_cache' ):
325+ return namespace ._vm_image_info_cache
326+
327+ from .aaz .latest .vm .image import Show as VMImageShow
328+ image_version = namespace .os_version
329+ if namespace .os_version .lower () == 'latest' :
330+ image_version = _get_latest_image_version_by_aaz (cmd .cli_ctx , namespace .location , namespace .os_publisher ,
331+ namespace .os_offer , namespace .os_sku )
332+
333+ command_args = {
334+ 'location' : namespace .location ,
335+ 'offer' : namespace .os_offer ,
336+ 'publisher' : namespace .os_publisher ,
337+ 'sku' : namespace .os_sku ,
338+ 'version' : image_version ,
339+ }
340+
341+ namespace ._vm_image_info_cache = VMImageShow (cli_ctx = cmd .cli_ctx )(command_args = command_args )
342+ return namespace ._vm_image_info_cache
330343
331- command_args = {
332- 'location' : namespace .location ,
333- 'offer' : namespace .os_offer ,
334- 'publisher' : namespace .os_publisher ,
335- 'sku' : namespace .os_sku ,
336- 'version' : image_version ,
337- }
338- image = VmImageShow (cli_ctx = cmd .cli_ctx )(command_args = command_args )
339344
345+ def _get_image_plan_info_if_exists (cmd , namespace ):
346+ try :
347+ image = _show_vm_image (cmd , namespace )
340348 return image .get ('plan' )
341349 except ResourceNotFoundError as ex :
342350 logger .warning ("Querying the image of '%s' failed for an error '%s'. Configuring plan settings "
@@ -643,7 +651,10 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False):
643651 'when "--security-type" is "ConfidentialVM" and "--enable-vtpm" is True' )
644652
645653 if not namespace .os_type :
646- namespace .os_type = 'windows' if 'windows' in namespace .os_offer .lower () else 'linux'
654+ image = _show_vm_image (cmd , namespace )
655+
656+ os_system = image .get ('osDiskImage' , {}).get ('operatingSystem' , '' )
657+ namespace .os_type = os_system .lower ()
647658
648659 if getattr (namespace , 'source_snapshots_or_disks' , None ) and \
649660 getattr (namespace , 'source_snapshots_or_disks_size_gb' , None ):
@@ -1499,20 +1510,7 @@ def _validate_generation_version_and_trusted_launch(cmd, namespace):
14991510 return
15001511
15011512 if image_type == 'urn' :
1502- from .aaz .latest .vm .image import Show as VmImageShow
1503- os_version = namespace .os_version
1504- if os_version .lower () == 'latest' :
1505- os_version = _get_latest_image_version_by_aaz (cmd .cli_ctx , namespace .location , namespace .os_publisher ,
1506- namespace .os_offer , namespace .os_sku )
1507-
1508- command_args = {
1509- 'location' : namespace .location ,
1510- 'offer' : namespace .os_offer ,
1511- 'publisher' : namespace .os_publisher ,
1512- 'sku' : namespace .os_sku ,
1513- 'version' : os_version
1514- }
1515- vm_image_info = VmImageShow (cli_ctx = cmd .cli_ctx )(command_args = command_args )
1513+ vm_image_info = _show_vm_image (cmd , namespace )
15161514
15171515 if vm_image_info .get ('imageDeprecationStatus' , {}).get ('imageState' ) == 'ScheduledForDeprecation' :
15181516 from datetime import datetime
0 commit comments