question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow Azure CLI to attach multiple disks to a VM at once

See original GitHub issue

Describe the bug

When attaching multiple disks to an Azure VM at once using the --ids parameter on az vm disk attach only one disk gets attached and the command fails with upstream REST API errors.

To Reproduce

In bash:

disks_to_attach=$(az disk list --resource-group "someazureresourcegroup" --query "[? contains(name,'someazurehostname')].id" -o tsv)
az vm disk attach --vm-name "someazurehostname" --caching "None" --sku Premium_LRS --ids $disks_to_attach

Expected behavior

The multiple disks specified in --ids will be attached on sequential LUNs starting with the next available and filling any available LUNs in order.

Environment summary

Azure CLI installed on CentOS 7 via yum install azure-cli

Additional context

This is similar to issue #15583 but provides a more specific request rather than asking a question.

The az CLI will allow this to happen, but the upstream REST calls into Azure end up conflicting with one another.

For example, this command starts just fine:

disks_to_attach=$(az disk list --resource-group "someazureresourcegroup" --query "[? contains(name,'someazurehostname')].id" -o tsv)
az vm disk attach --vm-name "someazurehostname" --caching "None" --sku Premium_LRS --ids $disks_to_attach

This ends up failing when multiple disks are involved with the following errors:

Azure Error: Conflict Message: The request failed due to conflict with a concurrent request.

And:

Azure Error: PropertyChangeNotAllowed Message: Changing property 'dataDisk.managedDisk.id' is not allowed.

This works just fine as a workaround in bash:

disks_to_attach=$(az disk list --resource-group "someazureresourcegroup" --query "[? contains(name,'someazurehostname')].id" -o tsv)
for disk in $disks_to_attach; do
  echo Attaching $disk
  az vm disk attach --vm-name "someazurehostname" --caching "None" --sku Premium_LRS --ids $disk
done

Running the az CLI with --debug shows that the CLI loops over the list of IDs and submits a separate REST PUT for each one. The conflict arises since the prior disk attachment hasn’t yet finished when the second and succeeding REST calls arrive.

The “PropertyChangeNotAllowed” appears to be a result of the CLI attempting to assign each disk to LUN 0 (or the single next available LUN) rather than incrementing it each time for a new disk ID.

The REST API appears to support reconfiguring a VM with multiple disk changes at once, but the CLI as written does not.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
sbondscommented, Feb 23, 2022

Yes, the provided solution documents a workaround but doesn’t solve the underlying issue. It’s not any different than running in a loop.

However, it’s much harder to take the list of IDs and build a single REST call for them.

3reactions
fabnordcommented, Feb 23, 2022

I know this issue has been closed, but I don’t think the proposed change of concurrency is a solution rather than a workaround. Essentially az config set core.disable_concurrent_ids=True will result in Azure CLI sequentially attaching the disks and not attaching them in one single operation. Can we change the behaviour of Azure CLI to add all disks with one API call?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add a data disk to Linux VM using the Azure CLI
If you add multiple disks, and aren't sure which disk it is based on size alone, you can go to the VM page...
Read more >
az vm disk - Microsoft Learn
Attach a managed persistent disk to a VM. This allows for the preservation of data, even if the VM is reprovisioned due to...
Read more >
Enable shared disk - Azure Virtual Machines - Microsoft Learn
Configure an Azure managed disk with shared disks so that you can share it across multiple VMs.
Read more >
Attach a data disk to a Linux VM - Azure Virtual Machines
Attach an existing disk · On the Disks pane, under Data disks, select Attach existing disks. · Click the drop-down menu for Disk...
Read more >
Attach a managed data disk to a Windows VM - Azure
Add a data disk · Sign in to the Azure portal. · Search for and select Virtual machines. · Select a virtual machine...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found