I'm trying to create an empty Managed Disk that I can then blob upload, or blob copy to. The entire purpose of Azure Managed Disks is abstracting away the pain of managing storage accounts, so I specifically do not want to create a storage account.
I've tried doing:
az disk create --for-upload true ...
. The Azure docs clearly indicate this option is for creating an empty disk image that will be populated by a blob upload.az disk grant-access --access-level Write
which yields a write-capable SAS URL.az storage blob upload ...
using the sas details from the previous step.See here for more details: https://github.com/Azure/azure-cli/issues/10192
g=group1 # targetr resource group
n=nixosDisk1 # disk name
s=50 # disk size in GB
timeout=$(( 60*60 )) # sas url timeout
./az.sh disk create \
--resource-group $g \
--name $n \
--size-gb $s \
--for-upload true
sasurl="$(\
./az.sh disk grant-access \
--access-level Write \
--resource-group $g \
--name $n \
--duration-in-seconds $timeout \
| jq -r '.accessSas')"
# decompose the URL into parts:
strg="md-impexp-jbvwf1mxwlr1"
cntr="mn02nwdj3lzl"
blob="abcd"
sastoken="sv=2017-04-17&sr=b&si=295e4a79-c2ac-4064-96c7-f6cb408ea89d&sig=zeTB%2FFGm3FEqkRg6XqsNLfF8ohgRHfGa6XSe2TDwU%2Fc%3D"
f="/tmp/azure-cli/disk.vhd"
./az.sh storage blob upload \
--account-name "${strg}" \
--container-name "${cntr}" \
--name "$blob" \
--sas-token "$sastoken" \
--file "$f"
This of course fails with an error that isn't anywhere on the Internet except my GitHub bug report:
<Error><Code>ApiNotSupportedForAccount</Code><Message>This API is not supported for the account
To elaborate on why I expect this to work:
The documentation for az disk create
's flag --for-output
says:
Create the disk for uploading blobs later on through storage commands.
Run "az disk grant-access --access-level Write" to retrieve the disk's SAS token.
The changelog for the Azure Storage python SDK includes the texts:
New version of Managed Disks
Use GrantAccess API with AccessLevel.Write to a get a write SAS to the disk. This is a new access level and it can only be used when uploading to a new disk. Customers can then use storage API to upload the bits for the disk.
There are new DiskStates (DiskState.ReadyToUpload and DiskState.ActiveUpload) that are associated with the upload process.
Note that when you create the disk, the disk status is "ReadyToUpload" and when you retrieve the SAS token, it automatically changes to "ActiveUpload", even before starting a blob operation.
All of this indicates that my script should work... and yet, it doesn't.
I meet the same issue before some time. I used many many ways to test it. At last, I found if we upload the on-premise vhd file to the disk with AzCopy.exe.
azcopy copy "the url of vhd file" "the url of the disk" --blob-type PageBlob