它有效吗? az disk create --for-upload / az disk grant-access --access-level Write

Does it work? az disk create --for-upload / az disk grant-access --access-level Write

我正在尝试创建一个空的托管磁盘,然后我可以将其进行 blob 上传或 blob 复制。 Azure Managed Disks 的全部目的是消除管理存储帐户的痛苦,所以我特意 不想创建存储帐户

我试过:

  1. az disk create --for-upload true ...。 Azure 文档明确指出此选项用于创建将由 blob 上传填充的空磁盘映像。
  2. az disk grant-access --access-level Write 产生可写的 SAS URL.
  3. az storage blob upload ... 使用上一步中的 sas 详细信息。

详情请看这里: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"

这当然失败了,除了我的 GitHub 错误报告外,互联网上没有任何错误:

<Error><Code>ApiNotSupportedForAccount</Code><Message>This API is not supported for the account

详细说明我希望它起作用的原因:

  1. documentation for az disk create's flag --for-output 说:

    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.

  2. changelog for the Azure Storage python SDK 包含文本:

    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.

请注意,当您创建磁盘时,磁盘状态为 "ReadyToUpload",当您检索 SAS 令牌时,即使在开始 blob 操作之前,它也会自动更改为 "ActiveUpload"。

所有这些都表明我的脚本应该可以工作...然而,它没有。

我之前遇到过同样的问题。我用了很多很多方法来测试它。最后,我发现如果我们将内部部署的vhd文件上传到带有AzCopy.exe的磁盘。

azcopy copy "the url of vhd file" "the url of the disk" --blob-type PageBlob