diff --git a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/__init__.py b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/__init__.py
index 9079d870e3d..72b1df4b559 100644
--- a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/__init__.py
+++ b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/__init__.py
@@ -20,6 +20,8 @@
from ._list_skus import *
from ._patch import *
from ._perform_maintenance import *
+from ._reimage import *
+from ._reimageall import *
from ._show import *
from ._simulate_eviction import *
from ._start import *
diff --git a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/_reimage.py b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/_reimage.py
new file mode 100644
index 00000000000..8cafcd3d233
--- /dev/null
+++ b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/_reimage.py
@@ -0,0 +1,222 @@
+# --------------------------------------------------------------------------------------------
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License. See License.txt in the project root for license information.
+#
+# Code generated by aaz-dev-tools
+# --------------------------------------------------------------------------------------------
+
+# pylint: skip-file
+# flake8: noqa
+
+from azure.cli.core.aaz import *
+
+
+class Reimage(AAZCommand):
+ """Reimages (upgrade the operating system) one or more virtual machines in a VM scale set which don't have a ephemeral OS disk, for virtual machines who have a ephemeral OS disk the virtual machine is reset to initial state.
+ """
+
+ _aaz_info = {
+ "version": "2024-11-01",
+ "resources": [
+ ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachinescalesets/{}/reimage", "2024-11-01"],
+ ]
+ }
+
+ AZ_SUPPORT_NO_WAIT = True
+
+ def _handler(self, command_args):
+ super()._handler(command_args)
+ return self.build_lro_poller(self._execute_operations, None)
+
+ _args_schema = None
+
+ @classmethod
+ def _build_arguments_schema(cls, *args, **kwargs):
+ if cls._args_schema is not None:
+ return cls._args_schema
+ cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
+
+ # define Arg Group ""
+
+ _args_schema = cls._args_schema
+ _args_schema.resource_group = AAZResourceGroupNameArg(
+ required=True,
+ )
+ _args_schema.vm_scale_set_name = AAZStrArg(
+ options=["--vm-scale-set-name"],
+ help="The name of the VM scale set.",
+ required=True,
+ id_part="name",
+ )
+
+ # define Arg Group "VmScaleSetReimageInput"
+
+ _args_schema = cls._args_schema
+ _args_schema.exact_version = AAZStrArg(
+ options=["--exact-version"],
+ arg_group="VmScaleSetReimageInput",
+ help="Specifies in decimal number, the version the OS disk should be reimaged to. If exact version is not provided, the OS disk is reimaged to the existing version of OS Disk.",
+ )
+ _args_schema.force_update_os_disk_for_ephemeral = AAZBoolArg(
+ options=["--force-update-os-disk-for-ephemeral"],
+ arg_group="VmScaleSetReimageInput",
+ help="Parameter to force update ephemeral OS disk for a virtual machine scale set VM",
+ )
+ _args_schema.instance_ids = AAZListArg(
+ options=["--instance-ids"],
+ arg_group="VmScaleSetReimageInput",
+ help="The virtual machine scale set instance ids. Omitting the virtual machine scale set instance ids will result in the operation being performed on all virtual machines in the virtual machine scale set.",
+ )
+ _args_schema.os_profile = AAZObjectArg(
+ options=["--os-profile"],
+ arg_group="VmScaleSetReimageInput",
+ help="Specifies information required for reimaging the non-ephemeral OS disk.",
+ )
+ _args_schema.temp_disk = AAZBoolArg(
+ options=["--temp-disk"],
+ arg_group="VmScaleSetReimageInput",
+ help="Specifies whether to reimage temp disk. Default value: false. Note: This temp disk reimage parameter is only supported for VM/VMSS with Ephemeral OS disk.",
+ )
+
+ instance_ids = cls._args_schema.instance_ids
+ instance_ids.Element = AAZStrArg()
+
+ os_profile = cls._args_schema.os_profile
+ os_profile.admin_password = AAZPasswordArg(
+ options=["admin-password"],
+ help="Specifies the password of the administrator account.
**Minimum-length (Windows):** 8 characters
**Minimum-length (Linux):** 6 characters
**Max-length (Windows):** 123 characters
**Max-length (Linux):** 72 characters
**Complexity requirements:** 3 out of 4 conditions below need to be fulfilled
Has lower characters
Has upper characters
Has a digit
Has a special character (Regex match [\\W_])
**Disallowed values:** \"abc@123\", \"P@$$w0rd\", \"P@ssw0rd\", \"P@ssword123\", \"Pa$$word\", \"pass@word1\", \"Password!\", \"Password1\", \"Password22\", \"iloveyou!\"
For resetting the password, see [How to reset the Remote Desktop service or its login password in a Windows VM](https://docs.microsoft.com/troubleshoot/azure/virtual-machines/reset-rdp)
For resetting root password, see [Manage users, SSH, and check or repair disks on Azure Linux VMs using the VMAccess Extension](https://docs.microsoft.com/troubleshoot/azure/virtual-machines/troubleshoot-ssh-connection)",
+ blank=AAZPromptPasswordInput(
+ msg="Password:",
+ ),
+ )
+ os_profile.custom_data = AAZStrArg(
+ options=["custom-data"],
+ help="Specifies a base-64 encoded string of custom data. The base-64 encoded string is decoded to a binary array that is saved as a file on the Virtual Machine. The maximum length of the binary array is 65535 bytes. **Note: Do not pass any secrets or passwords in customData property.** This property cannot be updated after the VM is created. The property customData is passed to the VM to be saved as a file, for more information see [Custom Data on Azure VMs](https://azure.microsoft.com/blog/custom-data-and-cloud-init-on-windows-azure/). If using cloud-init for your Linux VM, see [Using cloud-init to customize a Linux VM during creation](https://docs.microsoft.com/azure/virtual-machines/linux/using-cloud-init).",
+ )
+ return cls._args_schema
+
+ def _execute_operations(self):
+ self.pre_operations()
+ yield self.VirtualMachineScaleSetsReimage(ctx=self.ctx)()
+ self.post_operations()
+
+ @register_callback
+ def pre_operations(self):
+ pass
+
+ @register_callback
+ def post_operations(self):
+ pass
+
+ class VirtualMachineScaleSetsReimage(AAZHttpOperation):
+ CLIENT_TYPE = "MgmtClient"
+
+ def __call__(self, *args, **kwargs):
+ request = self.make_request()
+ session = self.client.send_request(request=request, stream=False, **kwargs)
+ if session.http_response.status_code in [202]:
+ return self.client.build_lro_polling(
+ self.ctx.args.no_wait,
+ session,
+ self.on_200,
+ self.on_error,
+ lro_options={"final-state-via": "location"},
+ path_format_arguments=self.url_parameters,
+ )
+ if session.http_response.status_code in [200]:
+ return self.client.build_lro_polling(
+ self.ctx.args.no_wait,
+ session,
+ self.on_200,
+ self.on_error,
+ lro_options={"final-state-via": "location"},
+ path_format_arguments=self.url_parameters,
+ )
+
+ return self.on_error(session.http_response)
+
+ @property
+ def url(self):
+ return self.client.format_url(
+ "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/reimage",
+ **self.url_parameters
+ )
+
+ @property
+ def method(self):
+ return "POST"
+
+ @property
+ def error_format(self):
+ return "ODataV4Format"
+
+ @property
+ def url_parameters(self):
+ parameters = {
+ **self.serialize_url_param(
+ "resourceGroupName", self.ctx.args.resource_group,
+ required=True,
+ ),
+ **self.serialize_url_param(
+ "subscriptionId", self.ctx.subscription_id,
+ required=True,
+ ),
+ **self.serialize_url_param(
+ "vmScaleSetName", self.ctx.args.vm_scale_set_name,
+ required=True,
+ ),
+ }
+ return parameters
+
+ @property
+ def query_parameters(self):
+ parameters = {
+ **self.serialize_query_param(
+ "api-version", "2024-11-01",
+ required=True,
+ ),
+ }
+ return parameters
+
+ @property
+ def header_parameters(self):
+ parameters = {
+ **self.serialize_header_param(
+ "Content-Type", "application/json",
+ ),
+ }
+ return parameters
+
+ @property
+ def content(self):
+ _content_value, _builder = self.new_content_builder(
+ self.ctx.args,
+ typ=AAZObjectType,
+ typ_kwargs={"flags": {"client_flatten": True}}
+ )
+ _builder.set_prop("exactVersion", AAZStrType, ".exact_version")
+ _builder.set_prop("forceUpdateOSDiskForEphemeral", AAZBoolType, ".force_update_os_disk_for_ephemeral")
+ _builder.set_prop("instanceIds", AAZListType, ".instance_ids")
+ _builder.set_prop("osProfile", AAZObjectType, ".os_profile")
+ _builder.set_prop("tempDisk", AAZBoolType, ".temp_disk")
+
+ instance_ids = _builder.get(".instanceIds")
+ if instance_ids is not None:
+ instance_ids.set_elements(AAZStrType, ".")
+
+ os_profile = _builder.get(".osProfile")
+ if os_profile is not None:
+ os_profile.set_prop("adminPassword", AAZStrType, ".admin_password", typ_kwargs={"flags": {"secret": True}})
+ os_profile.set_prop("customData", AAZStrType, ".custom_data")
+
+ return self.serialize_content(_content_value)
+
+ def on_200(self, session):
+ pass
+
+
+class _ReimageHelper:
+ """Helper class for Reimage"""
+
+
+__all__ = ["Reimage"]
diff --git a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/_reimageall.py b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/_reimageall.py
new file mode 100644
index 00000000000..be316cb7ae5
--- /dev/null
+++ b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/_reimageall.py
@@ -0,0 +1,180 @@
+# --------------------------------------------------------------------------------------------
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License. See License.txt in the project root for license information.
+#
+# Code generated by aaz-dev-tools
+# --------------------------------------------------------------------------------------------
+
+# pylint: skip-file
+# flake8: noqa
+
+from azure.cli.core.aaz import *
+
+
+class Reimageall(AAZCommand):
+ """Reimages all the disks ( including data disks ) in the virtual machines in a VM scale set. This operation is only supported for managed disks.
+ """
+
+ _aaz_info = {
+ "version": "2024-11-01",
+ "resources": [
+ ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachinescalesets/{}/reimageall", "2024-11-01"],
+ ]
+ }
+
+ AZ_SUPPORT_NO_WAIT = True
+
+ def _handler(self, command_args):
+ super()._handler(command_args)
+ return self.build_lro_poller(self._execute_operations, None)
+
+ _args_schema = None
+
+ @classmethod
+ def _build_arguments_schema(cls, *args, **kwargs):
+ if cls._args_schema is not None:
+ return cls._args_schema
+ cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
+
+ # define Arg Group ""
+
+ _args_schema = cls._args_schema
+ _args_schema.resource_group = AAZResourceGroupNameArg(
+ required=True,
+ )
+ _args_schema.vm_scale_set_name = AAZStrArg(
+ options=["--vm-scale-set-name"],
+ help="The name of the VM scale set.",
+ required=True,
+ id_part="name",
+ )
+
+ # define Arg Group "VmInstanceIDs"
+
+ _args_schema = cls._args_schema
+ _args_schema.instance_ids = AAZListArg(
+ options=["--instance-ids"],
+ arg_group="VmInstanceIDs",
+ help="The virtual machine scale set instance ids. Omitting the virtual machine scale set instance ids will result in the operation being performed on all virtual machines in the virtual machine scale set.",
+ )
+
+ instance_ids = cls._args_schema.instance_ids
+ instance_ids.Element = AAZStrArg()
+ return cls._args_schema
+
+ def _execute_operations(self):
+ self.pre_operations()
+ yield self.VirtualMachineScaleSetsReimageAll(ctx=self.ctx)()
+ self.post_operations()
+
+ @register_callback
+ def pre_operations(self):
+ pass
+
+ @register_callback
+ def post_operations(self):
+ pass
+
+ class VirtualMachineScaleSetsReimageAll(AAZHttpOperation):
+ CLIENT_TYPE = "MgmtClient"
+
+ def __call__(self, *args, **kwargs):
+ request = self.make_request()
+ session = self.client.send_request(request=request, stream=False, **kwargs)
+ if session.http_response.status_code in [202]:
+ return self.client.build_lro_polling(
+ self.ctx.args.no_wait,
+ session,
+ self.on_200,
+ self.on_error,
+ lro_options={"final-state-via": "location"},
+ path_format_arguments=self.url_parameters,
+ )
+ if session.http_response.status_code in [200]:
+ return self.client.build_lro_polling(
+ self.ctx.args.no_wait,
+ session,
+ self.on_200,
+ self.on_error,
+ lro_options={"final-state-via": "location"},
+ path_format_arguments=self.url_parameters,
+ )
+
+ return self.on_error(session.http_response)
+
+ @property
+ def url(self):
+ return self.client.format_url(
+ "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/reimageall",
+ **self.url_parameters
+ )
+
+ @property
+ def method(self):
+ return "POST"
+
+ @property
+ def error_format(self):
+ return "ODataV4Format"
+
+ @property
+ def url_parameters(self):
+ parameters = {
+ **self.serialize_url_param(
+ "resourceGroupName", self.ctx.args.resource_group,
+ required=True,
+ ),
+ **self.serialize_url_param(
+ "subscriptionId", self.ctx.subscription_id,
+ required=True,
+ ),
+ **self.serialize_url_param(
+ "vmScaleSetName", self.ctx.args.vm_scale_set_name,
+ required=True,
+ ),
+ }
+ return parameters
+
+ @property
+ def query_parameters(self):
+ parameters = {
+ **self.serialize_query_param(
+ "api-version", "2024-11-01",
+ required=True,
+ ),
+ }
+ return parameters
+
+ @property
+ def header_parameters(self):
+ parameters = {
+ **self.serialize_header_param(
+ "Content-Type", "application/json",
+ ),
+ }
+ return parameters
+
+ @property
+ def content(self):
+ _content_value, _builder = self.new_content_builder(
+ self.ctx.args,
+ typ=AAZObjectType,
+ typ_kwargs={"flags": {"client_flatten": True}}
+ )
+ _builder.set_prop("instanceIds", AAZListType, ".instance_ids")
+
+ instance_ids = _builder.get(".instanceIds")
+ if instance_ids is not None:
+ instance_ids.set_elements(AAZStrType, ".")
+
+ return self.serialize_content(_content_value)
+
+ def on_200(self, session):
+ pass
+
+
+class _ReimageallHelper:
+ """Helper class for Reimageall"""
+
+
+__all__ = ["Reimageall"]
diff --git a/src/azure-cli/azure/cli/command_modules/vm/commands.py b/src/azure-cli/azure/cli/command_modules/vm/commands.py
index 2bcde721d8e..43021ff13e4 100644
--- a/src/azure-cli/azure/cli/command_modules/vm/commands.py
+++ b/src/azure-cli/azure/cli/command_modules/vm/commands.py
@@ -404,6 +404,7 @@ def load_command_table(self, _):
g.custom_show_command('identity show', 'show_vmss_identity')
g.custom_command('deallocate', 'deallocate_vmss', supports_no_wait=True)
+ g.custom_command('reimage', 'reimage_vmss', supports_no_wait=True)
with self.command_group('vmss', compute_vmss_sdk, operation_group='virtual_machine_scale_sets') as g:
g.custom_command('application set', 'set_vmss_applications', validator=process_set_applications_namespace, min_api='2021-07-01')
@@ -413,7 +414,6 @@ def load_command_table(self, _):
g.custom_command('list-instance-connection-info', 'list_vmss_instance_connection_info')
g.custom_command('list-instance-public-ips', 'list_vmss_instance_public_ips')
g.custom_command('list-instances', 'get_instances_list')
- g.custom_command('reimage', 'reimage_vmss', supports_no_wait=True, min_api='2017-03-30')
g.custom_command('restart', 'restart_vmss', supports_no_wait=True)
g.custom_command('scale', 'scale_vmss', supports_no_wait=True)
g.custom_show_command('show', 'get_vmss', table_transformer=get_vmss_table_output_transformer(self, False))
diff --git a/src/azure-cli/azure/cli/command_modules/vm/custom.py b/src/azure-cli/azure/cli/command_modules/vm/custom.py
index 8109aee1139..0210b886048 100644
--- a/src/azure-cli/azure/cli/command_modules/vm/custom.py
+++ b/src/azure-cli/azure/cli/command_modules/vm/custom.py
@@ -4488,20 +4488,24 @@ def list_vmss_instance_public_ips(cmd, resource_group_name, vm_scale_set_name):
def reimage_vmss(cmd, resource_group_name, vm_scale_set_name, instance_ids=None,
force_update_os_disk_for_ephemeral=None, no_wait=False):
- client = _compute_client_factory(cmd.cli_ctx)
+ from .aaz.latest.vmss import Reimageall as VmssReimageAll, Reimage as VmssReimage
if instance_ids:
- VirtualMachineScaleSetVMInstanceIDs = cmd.get_models('VirtualMachineScaleSetVMInstanceIDs')
- instance_ids = VirtualMachineScaleSetVMInstanceIDs(instance_ids=instance_ids)
- return sdk_no_wait(no_wait, client.virtual_machine_scale_sets.begin_reimage_all, resource_group_name,
- vm_scale_set_name, instance_ids)
+ command_args = {
+ 'resource_group': resource_group_name,
+ 'vm_scale_set_name': vm_scale_set_name,
+ 'instance_ids': instance_ids,
+ 'no_wait': no_wait
+ }
+ return VmssReimageAll(cli_ctx=cmd.cli_ctx)(command_args=command_args)
+
+ command_args = {
+ 'resource_group': resource_group_name,
+ 'vm_scale_set_name': vm_scale_set_name,
+ 'no_wait': no_wait
+ }
if force_update_os_disk_for_ephemeral is not None:
- VirtualMachineScaleSetReimageParameters = cmd.get_models('VirtualMachineScaleSetReimageParameters')
- vm_scale_set_reimage_input = VirtualMachineScaleSetReimageParameters(
- force_update_os_disk_for_ephemeral=force_update_os_disk_for_ephemeral)
- return sdk_no_wait(no_wait, client.virtual_machine_scale_sets.begin_reimage,
- resource_group_name, vm_scale_set_name, vm_scale_set_reimage_input)
- return sdk_no_wait(no_wait, client.virtual_machine_scale_sets.begin_reimage,
- resource_group_name, vm_scale_set_name)
+ command_args['force_update_os_disk_for_ephemeral'] = force_update_os_disk_for_ephemeral
+ return VmssReimage(cli_ctx=cmd.cli_ctx)(command_args=command_args)
def restart_vmss(cmd, resource_group_name, vm_scale_set_name, instance_ids=None, no_wait=False):