From 5f2dceb406aa738f47ffdc7fd4960abd04ac920b Mon Sep 17 00:00:00 2001 From: william051200 Date: Thu, 22 Jan 2026 15:42:50 +0800 Subject: [PATCH 1/8] Add image deprecation status validation --- .../cli/command_modules/vm/_validators.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index c2956f33e54..48288b53304 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -657,6 +657,8 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False): source_disk_restore_point_size_gb=getattr(namespace, 'source_disk_restore_point_size_gb', None) ) + _validate_image_deprecation_status(cmd, namespace) + def _validate_vm_create_storage_account(cmd, namespace): from azure.mgmt.core.tools import parse_resource_id @@ -2684,3 +2686,33 @@ def _validate_community_gallery_legal_agreement_acceptance(cmd, namespace): if not prompt_y_n(msg, default="y"): import sys sys.exit(0) + + +def _validate_image_deprecation_status(cmd, namespace): + from .aaz.latest.vm.image import Show as _ImageShow + from ._actions import _get_latest_image_version + + if namespace.os_version.lower() == 'latest': + latest_version = _get_latest_image_version( + cmd.cli_ctx, + location=namespace.location, + publisher=namespace.os_publisher, + offer=namespace.os_offer, + sku=namespace.os_sku, + ) + else: + latest_version = namespace.os_version + + image = _ImageShow(cli_ctx=cmd.cli_ctx)(command_args={ + 'location': namespace.location, + 'publisher': namespace.os_publisher, + 'offer': namespace.os_offer, + 'sku': namespace.os_sku, + 'version': latest_version, + }) + + if not image: + return + + if image.get('imageDeprecationStatus', {}).get('imageState') == 'ScheduledForDeprecation': + logger.warning('The selected image is scheduled for deprecation.') From 41c5d510a26f551af8fe4ba9511d76385914efa8 Mon Sep 17 00:00:00 2001 From: william051200 Date: Fri, 23 Jan 2026 07:39:41 +0800 Subject: [PATCH 2/8] Update code styling and add handling --- .../cli/command_modules/vm/_validators.py | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index 48288b53304..7cf41056178 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -2690,7 +2690,9 @@ def _validate_community_gallery_legal_agreement_acceptance(cmd, namespace): def _validate_image_deprecation_status(cmd, namespace): from .aaz.latest.vm.image import Show as _ImageShow - from ._actions import _get_latest_image_version + + if not namespace.os_publisher or not namespace.os_offer or not namespace.os_sku or not namespace.os_version: + return if namespace.os_version.lower() == 'latest': latest_version = _get_latest_image_version( @@ -2703,16 +2705,20 @@ def _validate_image_deprecation_status(cmd, namespace): else: latest_version = namespace.os_version - image = _ImageShow(cli_ctx=cmd.cli_ctx)(command_args={ - 'location': namespace.location, - 'publisher': namespace.os_publisher, - 'offer': namespace.os_offer, - 'sku': namespace.os_sku, - 'version': latest_version, - }) + try: + image = _ImageShow(cli_ctx=cmd.cli_ctx)(command_args={ + 'location': namespace.location, + 'publisher': namespace.os_publisher, + 'offer': namespace.os_offer, + 'sku': namespace.os_sku, + 'version': latest_version, + }) + except Exception as err: + logger.warning('Failed to retrieve image deprecation status: %s', err) + return if not image: - return - + return + if image.get('imageDeprecationStatus', {}).get('imageState') == 'ScheduledForDeprecation': logger.warning('The selected image is scheduled for deprecation.') From c5fb8d150aea2fc233ffa6fc0d8891f30e73926b Mon Sep 17 00:00:00 2001 From: william051200 Date: Fri, 23 Jan 2026 11:36:26 +0800 Subject: [PATCH 3/8] Updated warning message --- src/azure-cli/azure/cli/command_modules/vm/_validators.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index 7cf41056178..50f92faa6a4 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -2721,4 +2721,6 @@ def _validate_image_deprecation_status(cmd, namespace): return if image.get('imageDeprecationStatus', {}).get('imageState') == 'ScheduledForDeprecation': - logger.warning('The selected image is scheduled for deprecation.') + logger.warning('Warning: This image {} is scheduled for deprecation and will be blocked for new deployments once enforcement begins.\n' + 'VM / VMSS creation is allowed temporarily, but future deployments, redeployments, or scale‑out operations may fail.\n' + 'Consider switching to a supported image now.'.format(namespace.image)) From e683234d18f70bde3e3816ccd7e66d184a333262 Mon Sep 17 00:00:00 2001 From: william051200 Date: Fri, 23 Jan 2026 12:08:24 +0800 Subject: [PATCH 4/8] Update code styling --- .../cli/command_modules/vm/_validators.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index 50f92faa6a4..5537da1cdaa 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -2700,19 +2700,19 @@ def _validate_image_deprecation_status(cmd, namespace): location=namespace.location, publisher=namespace.os_publisher, offer=namespace.os_offer, - sku=namespace.os_sku, + sku=namespace.os_sku ) else: latest_version = namespace.os_version try: image = _ImageShow(cli_ctx=cmd.cli_ctx)(command_args={ - 'location': namespace.location, - 'publisher': namespace.os_publisher, - 'offer': namespace.os_offer, - 'sku': namespace.os_sku, - 'version': latest_version, - }) + 'location': namespace.location, + 'publisher': namespace.os_publisher, + 'offer': namespace.os_offer, + 'sku': namespace.os_sku, + 'version': latest_version + }) except Exception as err: logger.warning('Failed to retrieve image deprecation status: %s', err) return @@ -2721,6 +2721,8 @@ def _validate_image_deprecation_status(cmd, namespace): return if image.get('imageDeprecationStatus', {}).get('imageState') == 'ScheduledForDeprecation': - logger.warning('Warning: This image {} is scheduled for deprecation and will be blocked for new deployments once enforcement begins.\n' - 'VM / VMSS creation is allowed temporarily, but future deployments, redeployments, or scale‑out operations may fail.\n' - 'Consider switching to a supported image now.'.format(namespace.image)) + logger.warning('Warning: This image %s is scheduled for deprecation and will be blocked for new deployments ' + 'once enforcement begins.\n' + 'VM / VMSS creation is allowed temporarily, but future deployments, redeployments, or ' + 'scale‑out operations may fail.\n' + 'Consider switching to a supported image now.', namespace.image) From 7e94c5846b806bfdd16d402b9654957c433ce3da Mon Sep 17 00:00:00 2001 From: william051200 Date: Fri, 23 Jan 2026 14:08:25 +0800 Subject: [PATCH 5/8] Add pylint handling --- src/azure-cli/azure/cli/command_modules/vm/_validators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index 5537da1cdaa..2bb27bdedda 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -2688,6 +2688,7 @@ def _validate_community_gallery_legal_agreement_acceptance(cmd, namespace): sys.exit(0) +# pylint:disable=broad-exception-caught def _validate_image_deprecation_status(cmd, namespace): from .aaz.latest.vm.image import Show as _ImageShow From 438f7c5478735863ee6ee81d5eb36ee1424560ee Mon Sep 17 00:00:00 2001 From: william051200 Date: Fri, 23 Jan 2026 14:34:48 +0800 Subject: [PATCH 6/8] Update validator --- .../cli/command_modules/vm/_validators.py | 52 ++++--------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index 2bb27bdedda..18d54e099c9 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -657,8 +657,6 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False): source_disk_restore_point_size_gb=getattr(namespace, 'source_disk_restore_point_size_gb', None) ) - _validate_image_deprecation_status(cmd, namespace) - def _validate_vm_create_storage_account(cmd, namespace): from azure.mgmt.core.tools import parse_resource_id @@ -1454,6 +1452,15 @@ def _validate_generation_version_and_trusted_launch(cmd, namespace): namespace.os_offer, namespace.os_sku) vm_image_info = client.get(namespace.location, namespace.os_publisher, namespace.os_offer, namespace.os_sku, os_version) + + if vm_image_info.image_deprecation_status.image_state == 'ScheduledForDeprecation': + logger.warning( + 'Warning: This image %s is scheduled for deprecation and will be blocked after %s.\n' + 'VM / VMSS creation is allowed temporarily, but future deployments, redeployments, or ' + 'scale‑out operations may fail after this date.\n' + 'Consider switching to a supported image now.', + namespace.image, vm_image_info.image_deprecation_status.scheduled_deprecation_time.strftime("%B %d, %Y")) + generation_version = vm_image_info.hyper_v_generation if hasattr(vm_image_info, 'hyper_v_generation') else None features = vm_image_info.features if hasattr(vm_image_info, 'features') and vm_image_info.features else [] @@ -2686,44 +2693,3 @@ def _validate_community_gallery_legal_agreement_acceptance(cmd, namespace): if not prompt_y_n(msg, default="y"): import sys sys.exit(0) - - -# pylint:disable=broad-exception-caught -def _validate_image_deprecation_status(cmd, namespace): - from .aaz.latest.vm.image import Show as _ImageShow - - if not namespace.os_publisher or not namespace.os_offer or not namespace.os_sku or not namespace.os_version: - return - - if namespace.os_version.lower() == 'latest': - latest_version = _get_latest_image_version( - cmd.cli_ctx, - location=namespace.location, - publisher=namespace.os_publisher, - offer=namespace.os_offer, - sku=namespace.os_sku - ) - else: - latest_version = namespace.os_version - - try: - image = _ImageShow(cli_ctx=cmd.cli_ctx)(command_args={ - 'location': namespace.location, - 'publisher': namespace.os_publisher, - 'offer': namespace.os_offer, - 'sku': namespace.os_sku, - 'version': latest_version - }) - except Exception as err: - logger.warning('Failed to retrieve image deprecation status: %s', err) - return - - if not image: - return - - if image.get('imageDeprecationStatus', {}).get('imageState') == 'ScheduledForDeprecation': - logger.warning('Warning: This image %s is scheduled for deprecation and will be blocked for new deployments ' - 'once enforcement begins.\n' - 'VM / VMSS creation is allowed temporarily, but future deployments, redeployments, or ' - 'scale‑out operations may fail.\n' - 'Consider switching to a supported image now.', namespace.image) From eff4cfd051ad5d24bc452f377c83569b9cd258f8 Mon Sep 17 00:00:00 2001 From: william051200 Date: Fri, 23 Jan 2026 14:36:59 +0800 Subject: [PATCH 7/8] Remove whitespace --- src/azure-cli/azure/cli/command_modules/vm/_validators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index 18d54e099c9..3f7aba074d8 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -1452,7 +1452,7 @@ def _validate_generation_version_and_trusted_launch(cmd, namespace): namespace.os_offer, namespace.os_sku) vm_image_info = client.get(namespace.location, namespace.os_publisher, namespace.os_offer, namespace.os_sku, os_version) - + if vm_image_info.image_deprecation_status.image_state == 'ScheduledForDeprecation': logger.warning( 'Warning: This image %s is scheduled for deprecation and will be blocked after %s.\n' @@ -1460,7 +1460,7 @@ def _validate_generation_version_and_trusted_launch(cmd, namespace): 'scale‑out operations may fail after this date.\n' 'Consider switching to a supported image now.', namespace.image, vm_image_info.image_deprecation_status.scheduled_deprecation_time.strftime("%B %d, %Y")) - + generation_version = vm_image_info.hyper_v_generation if hasattr(vm_image_info, 'hyper_v_generation') else None features = vm_image_info.features if hasattr(vm_image_info, 'features') and vm_image_info.features else [] From ba6a2767aa56c4d7c85e3815f74a09e430132e9a Mon Sep 17 00:00:00 2001 From: william051200 Date: Fri, 23 Jan 2026 15:07:18 +0800 Subject: [PATCH 8/8] Fix pylint issue --- src/azure-cli/azure/cli/command_modules/vm/_validators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index 3f7aba074d8..fb6530f638a 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -1458,8 +1458,8 @@ def _validate_generation_version_and_trusted_launch(cmd, namespace): 'Warning: This image %s is scheduled for deprecation and will be blocked after %s.\n' 'VM / VMSS creation is allowed temporarily, but future deployments, redeployments, or ' 'scale‑out operations may fail after this date.\n' - 'Consider switching to a supported image now.', - namespace.image, vm_image_info.image_deprecation_status.scheduled_deprecation_time.strftime("%B %d, %Y")) + 'Consider switching to a supported image now.', namespace.image, + vm_image_info.image_deprecation_status.scheduled_deprecation_time.strftime("%B %d, %Y")) generation_version = vm_image_info.hyper_v_generation if hasattr(vm_image_info, 'hyper_v_generation') else None