Allow Azure CLI to attach multiple disks to a VM at once
See original GitHub issueDescribe 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:
- Created 3 years ago
- Comments:19 (7 by maintainers)
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.
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?