⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@huiii99
Copy link
Member

@huiii99 huiii99 commented Dec 29, 2025

Related command

az vm disk attach
az vm disk detach

Description
Migrate az vm disk attach and az vm disk detach commands from hand written sdk to aaz.

Testing Guide

History Notes


This checklist is used to make sure that common guidelines for a pull request are followed.

Copilot AI review requested due to automatic review settings December 29, 2025 03:48
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Dec 29, 2025

❌AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
❌vm
❌latest
❌3.12
Type Test Case Error Message Line
Failed test_vm_custom_image self = <azure.cli.testsdk.base.ExecutionResult object at 0x7fab7ef926f0>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7fab881496d0>
command = 'vm create -g cli_test_vm_custom_image000001 -n fromimage2 --image img-from-managed --admin-username sdk-test-admin [email protected]\n" --subnet subnet1 --vnet-name vnet1 --size Standard_B2ms --public-ip-address pubip5 --nsg-rule NONE'
expect_failure = False

    def in_process_execute(self, cli_ctx, command, expect_failure=False):
        from io import StringIO
        from vcr.errors import CannotOverwriteExistingCassetteException
    
        if command.startswith('az '):
            command = command[3:]
    
        stdout_buf = StringIO()
        logging_buf = StringIO()
        try:
            # issue: stderr cannot be redirect in this form, as a result some failure information
            # is lost when command fails.
>           self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/azure-cli-testsdk/azure/cli/testsdk/base.py:303: 
                                        
env/lib/python3.12/site-packages/knack/cli.py:245: in invoke
    exit_code = self.exception_handler(ex)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/init.py:133: in exception_handler
    return handle_exception(ex)
           ^^^^^^^^^^^^^^^^^^^^
                                        

ex = InvalidTemplateError(''), args = (), kwargs = {}

    def handle_main_exception(ex, *args, **kwargs):  # pylint: disable=unused-argument
        if isinstance(ex, CannotOverwriteExistingCassetteException):
            # This exception usually caused by a no match HTTP request. This is a product error
            # that is caused by change of SDK invocation.
            raise ex
    
>       raise CliExecutionError(ex)
E       azure.cli.testsdk.exceptions.CliExecutionError: The CLI throws exception InvalidTemplateError during execution and fails the command.

src/azure-cli-testsdk/azure/cli/testsdk/patches.py:35: CliExecutionError

During handling of the above exception, another exception occurred:

self = <latest.test_vm_commands.VMCustomImageTest testMethod=test_vm_custom_image>
resource_group = 'cli_test_vm_custom_image000001'

    @AllowLargeResponse(size_kb=99999)
    @ResourceGroupPreparer(name_prefix='cli_test_vm_custom_image')
    def test_vm_custom_image(self, resource_group):
        self.kwargs.update({
            'vm1': 'vm-unmanaged-disk',
            'vm2': 'vm-managed-disk',
            'newvm1': 'fromimage1',
            'newvm2': 'fromimage2',
            'image1': 'img-from-unmanaged',
            'image2': 'img-from-managed',
            'subnet': 'subnet1',
            'vnet': 'vnet1',
            'nsg': 'nsg',
            'pubip1': 'pubip1',
            'pubip2': 'pubip2',
            'pubip3': 'pubip3',
            'pubip4': 'pubip4',
            'pubip5': 'pubip5',
            'pubip6': 'pubip6',
            'pubip7': 'pubip7',
            'ssh_key': TEST_SSH_KEY_PUB,
        })
    
        # ---------- unmanaged disk VM -> image ----------
        self.cmd('network public-ip create --name {pubip1} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vm create -g {rg} -n {vm1} --image Debian:debian-10:10:latest '
            '--use-unmanaged-disk '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip1} --nsg-rule NONE'
        )
    
        self.cmd(
            'network vnet subnet update -g {rg} --vnet-name {vnet} -n {subnet} '
            '--default-outbound-access false'
        )
    
        self.cmd(
            'vm run-command invoke -g {rg} -n {vm1} --command-id RunShellScript '
            '--scripts "echo $0 $1" --parameters hello world'
        )
        time.sleep(70)
        self.cmd('vm deallocate -g {rg} -n {vm1}')
        self.cmd('vm generalize -g {rg} -n {vm1}')
        self.cmd('image create -g {rg} -n {image1} --source {vm1}')
    
        # ---------- managed disk VM -> image ----------
        self.cmd('network public-ip create --name {pubip2} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vm create -g {rg} -n {vm2} --image Debian:debian-10:10:latest '
            '--storage-sku standard_lrs --data-disk-sizes-gb 1 1 1 1 '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip2} --nsg-rule NONE'
        )
    
        data_disks = self.cmd('vm show -g {rg} -n {vm2}').get_output_in_json()['storageProfile']['dataDisks']
        self.kwargs['disk_0_name'] = data_disks[0]['name']
        self.kwargs['disk_2_name'] = data_disks[2]['name']
    
        self.cmd('vm disk detach -n {disk_0_name} --vm-name {vm2} -g {rg}')
        self.cmd('vm disk detach -n {disk_2_name} --vm-name {vm2} -g {rg}')
        self.cmd('vm show -g {rg} -n {vm2}', checks=self.check("length(storageProfile.dataDisks)", 2))
    
        self.cmd(
            'vm run-command invoke -g {rg} -n {vm2} --command-id RunShellScript '
            '--scripts "echo $0 $1" --parameters hello world'
        )
        time.sleep(70)
        self.cmd('vm deallocate -g {rg} -n {vm2}')
        self.cmd('vm generalize -g {rg} -n {vm2}')
        self.cmd('image create -g {rg} -n {image2} --source {vm2}')
    
        # ---------- new VM from unmanaged image ----------
        self.cmd('network public-ip create --name {pubip3} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vm create -g {rg} -n {newvm1} --image {image1} '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--authentication-type password '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip3} --nsg-rule NONE'
        )
    
        self.cmd('vm show -g {rg} -n {newvm1}', checks=[
            self.check('storageProfile.imageReference.resourceGroup', '{rg}'),
            self.check('storageProfile.osDisk.createOption', 'FromImage')
        ])
    
        # ---------- VMSS from unmanaged image ----------
        self.cmd('network nsg create -g {rg} -n {nsg}')
        self.cmd('network public-ip create --name {pubip4} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vmss create -g {rg} -n vmss1 '
            '--image {image1} '
            '--vm-sku Standard_D2s_v3 '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--authentication-type password '
            '--orchestration-mode Flexible '
            '--public-ip-address {pubip4} --nsg {nsg}',
            checks=[
                self.check('vmss.virtualMachineProfile.storageProfile.imageReference.resourceGroup', '{rg}'),
                self.check('vmss.virtualMachineProfile.storageProfile.osDisk.createOption', 'FromImage')
            ]
        )
    
        # ---------- new VM from managed image (SSH only) ----------
        self.cmd('network public-ip create --name {pubip5} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
>       self.cmd(
            'vm create -g {rg} -n {newvm2} --image {image2} '
            '--admin-username sdk-test-admin '
            '--authentication-type ssh '
            '--ssh-key-value "{ssh_key}" '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip5} --nsg-rule NONE'
        )

src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:610: 
 
                                       
src/azure-cli-testsdk/azure/cli/testsdk/base.py:177: in cmd
    return execute(self.cli_ctx, command, expect_failure=expect_failure).assert_with_checks(checks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-testsdk/azure/cli/testsdk/base.py:252: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:315: in in_process_execute
    raise ex.exception
env/lib/python3.12/site-packages/knack/cli.py:233: in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:669: in execute
    raise ex
src/azure-cli-core/azure/cli/core/commands/init.py:737: in run_jobs_serially
    results.append(self.run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:729: in run_job
    return cmd_copy.exception_handler(ex)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/arm.py:112: in handle_template_based_exception
    raise_subdivision_deployment_error(ex.response.internal_response.text, ex.error.code if ex.error else None)
 
 
 
 
                                   _ 

error_message = '', error_code = 'InvalidTemplateDeployment'

    def raise_subdivision_deployment_error(error_message, error_code=None):
        from azure.cli.core.azclierror import InvalidTemplateError, DeploymentError
    
        if error_code == 'InvalidTemplateDeployment':
>           raise InvalidTemplateError(error_message)
E           azure.cli.core.azclierror.InvalidTemplateError

src/azure-cli-core/azure/cli/core/commands/arm.py:102: InvalidTemplateError
azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:501
❌3.13
Type Test Case Error Message Line
Failed test_vm_custom_image self = <azure.cli.testsdk.base.ExecutionResult object at 0x7fdd1dd7ebd0>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7fdd230dd810>
command = 'vm create -g cli_test_vm_custom_image000001 -n fromimage2 --image img-from-managed --admin-username sdk-test-admin [email protected]\n" --subnet subnet1 --vnet-name vnet1 --size Standard_B2ms --public-ip-address pubip5 --nsg-rule NONE'
expect_failure = False

    def in_process_execute(self, cli_ctx, command, expect_failure=False):
        from io import StringIO
        from vcr.errors import CannotOverwriteExistingCassetteException
    
        if command.startswith('az '):
            command = command[3:]
    
        stdout_buf = StringIO()
        logging_buf = StringIO()
        try:
            # issue: stderr cannot be redirect in this form, as a result some failure information
            # is lost when command fails.
>           self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/azure-cli-testsdk/azure/cli/testsdk/base.py:303: 
                                        
env/lib/python3.13/site-packages/knack/cli.py:245: in invoke
    exit_code = self.exception_handler(ex)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/init.py:133: in exception_handler
    return handle_exception(ex)
           ^^^^^^^^^^^^^^^^^^^^
                                        

ex = InvalidTemplateError(''), args = (), kwargs = {}

    def handle_main_exception(ex, *args, **kwargs):  # pylint: disable=unused-argument
        if isinstance(ex, CannotOverwriteExistingCassetteException):
            # This exception usually caused by a no match HTTP request. This is a product error
            # that is caused by change of SDK invocation.
            raise ex
    
>       raise CliExecutionError(ex)
E       azure.cli.testsdk.exceptions.CliExecutionError: The CLI throws exception InvalidTemplateError during execution and fails the command.

src/azure-cli-testsdk/azure/cli/testsdk/patches.py:35: CliExecutionError

During handling of the above exception, another exception occurred:

self = <latest.test_vm_commands.VMCustomImageTest testMethod=test_vm_custom_image>
resource_group = 'cli_test_vm_custom_image000001'

    @AllowLargeResponse(size_kb=99999)
    @ResourceGroupPreparer(name_prefix='cli_test_vm_custom_image')
    def test_vm_custom_image(self, resource_group):
        self.kwargs.update({
            'vm1': 'vm-unmanaged-disk',
            'vm2': 'vm-managed-disk',
            'newvm1': 'fromimage1',
            'newvm2': 'fromimage2',
            'image1': 'img-from-unmanaged',
            'image2': 'img-from-managed',
            'subnet': 'subnet1',
            'vnet': 'vnet1',
            'nsg': 'nsg',
            'pubip1': 'pubip1',
            'pubip2': 'pubip2',
            'pubip3': 'pubip3',
            'pubip4': 'pubip4',
            'pubip5': 'pubip5',
            'pubip6': 'pubip6',
            'pubip7': 'pubip7',
            'ssh_key': TEST_SSH_KEY_PUB,
        })
    
        # ---------- unmanaged disk VM -> image ----------
        self.cmd('network public-ip create --name {pubip1} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vm create -g {rg} -n {vm1} --image Debian:debian-10:10:latest '
            '--use-unmanaged-disk '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip1} --nsg-rule NONE'
        )
    
        self.cmd(
            'network vnet subnet update -g {rg} --vnet-name {vnet} -n {subnet} '
            '--default-outbound-access false'
        )
    
        self.cmd(
            'vm run-command invoke -g {rg} -n {vm1} --command-id RunShellScript '
            '--scripts "echo $0 $1" --parameters hello world'
        )
        time.sleep(70)
        self.cmd('vm deallocate -g {rg} -n {vm1}')
        self.cmd('vm generalize -g {rg} -n {vm1}')
        self.cmd('image create -g {rg} -n {image1} --source {vm1}')
    
        # ---------- managed disk VM -> image ----------
        self.cmd('network public-ip create --name {pubip2} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vm create -g {rg} -n {vm2} --image Debian:debian-10:10:latest '
            '--storage-sku standard_lrs --data-disk-sizes-gb 1 1 1 1 '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip2} --nsg-rule NONE'
        )
    
        data_disks = self.cmd('vm show -g {rg} -n {vm2}').get_output_in_json()['storageProfile']['dataDisks']
        self.kwargs['disk_0_name'] = data_disks[0]['name']
        self.kwargs['disk_2_name'] = data_disks[2]['name']
    
        self.cmd('vm disk detach -n {disk_0_name} --vm-name {vm2} -g {rg}')
        self.cmd('vm disk detach -n {disk_2_name} --vm-name {vm2} -g {rg}')
        self.cmd('vm show -g {rg} -n {vm2}', checks=self.check("length(storageProfile.dataDisks)", 2))
    
        self.cmd(
            'vm run-command invoke -g {rg} -n {vm2} --command-id RunShellScript '
            '--scripts "echo $0 $1" --parameters hello world'
        )
        time.sleep(70)
        self.cmd('vm deallocate -g {rg} -n {vm2}')
        self.cmd('vm generalize -g {rg} -n {vm2}')
        self.cmd('image create -g {rg} -n {image2} --source {vm2}')
    
        # ---------- new VM from unmanaged image ----------
        self.cmd('network public-ip create --name {pubip3} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vm create -g {rg} -n {newvm1} --image {image1} '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--authentication-type password '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip3} --nsg-rule NONE'
        )
    
        self.cmd('vm show -g {rg} -n {newvm1}', checks=[
            self.check('storageProfile.imageReference.resourceGroup', '{rg}'),
            self.check('storageProfile.osDisk.createOption', 'FromImage')
        ])
    
        # ---------- VMSS from unmanaged image ----------
        self.cmd('network nsg create -g {rg} -n {nsg}')
        self.cmd('network public-ip create --name {pubip4} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vmss create -g {rg} -n vmss1 '
            '--image {image1} '
            '--vm-sku Standard_D2s_v3 '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--authentication-type password '
            '--orchestration-mode Flexible '
            '--public-ip-address {pubip4} --nsg {nsg}',
            checks=[
                self.check('vmss.virtualMachineProfile.storageProfile.imageReference.resourceGroup', '{rg}'),
                self.check('vmss.virtualMachineProfile.storageProfile.osDisk.createOption', 'FromImage')
            ]
        )
    
        # ---------- new VM from managed image (SSH only) ----------
        self.cmd('network public-ip create --name {pubip5} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
>       self.cmd(
            'vm create -g {rg} -n {newvm2} --image {image2} '
            '--admin-username sdk-test-admin '
            '--authentication-type ssh '
            '--ssh-key-value "{ssh_key}" '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip5} --nsg-rule NONE'
        )

src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:610: 
 
                                       
src/azure-cli-testsdk/azure/cli/testsdk/base.py:177: in cmd
    return execute(self.cli_ctx, command, expect_failure=expect_failure).assert_with_checks(checks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-testsdk/azure/cli/testsdk/base.py:252: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:315: in in_process_execute
    raise ex.exception
env/lib/python3.13/site-packages/knack/cli.py:233: in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:669: in execute
    raise ex
src/azure-cli-core/azure/cli/core/commands/init.py:737: in run_jobs_serially
    results.append(self.run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:729: in run_job
    return cmd_copy.exception_handler(ex)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/arm.py:112: in handle_template_based_exception
    raise_subdivision_deployment_error(ex.response.internal_response.text, ex.error.code if ex.error else None)
 
 
 
 
                                   _ 

error_message = '', error_code = 'InvalidTemplateDeployment'

    def raise_subdivision_deployment_error(error_message, error_code=None):
        from azure.cli.core.azclierror import InvalidTemplateError, DeploymentError
    
        if error_code == 'InvalidTemplateDeployment':
>           raise InvalidTemplateError(error_message)
E           azure.cli.core.azclierror.InvalidTemplateError

src/azure-cli-core/azure/cli/core/commands/arm.py:102: InvalidTemplateError
azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:501

@azure-client-tools-bot-prd
Copy link

Hi @huiii99,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Dec 29, 2025

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@github-actions
Copy link

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@yonzhan
Copy link
Collaborator

yonzhan commented Dec 29, 2025

Thank you for your contribution! We will review the pull request and get back to you soon.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the az vm disk attach and az vm disk detach commands from hand-written SDK code to the AAZ (Azure CLI Auto-generated) framework. The migration introduces the use of AAZ operations (AttachDetachDataDisk, VMShow, VMUpdate) while maintaining backward compatibility for different disk attachment scenarios.

Key changes include:

  • Refactored attach_managed_data_disk to use AAZ operations for existing disk attachments and VMUpdate for new/copy/restore operations
  • Refactored detach_managed_data_disk to use AAZ operations with improved error handling
  • Added a new safe_get utility function for safely accessing nested dictionary keys

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
src/azure-cli/azure/cli/command_modules/vm/custom.py Refactored disk attach/detach functions to use AAZ operations; added no_wait parameter support; reorganized logic into separate code paths for different attachment types
src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py Added new safe_get utility function for safe nested dictionary access with fallback defaults

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@huiii99 huiii99 force-pushed the vm-disk-attach-detach-aaz-migration branch from e20c674 to a294602 Compare January 6, 2026 04:24
fix: resolve review issues

fix: check cli style

dev

dev
@huiii99 huiii99 force-pushed the vm-disk-attach-detach-aaz-migration branch from 8beb7bb to d566b6a Compare January 7, 2026 03:51
@huiii99 huiii99 changed the title [Compute] migrate vm disk attach/detach to aaz {Compute} migrate vm disk attach/detach to aaz Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot Compute az vm/vmss/image/disk/snapshot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants