使用 Azure SDK 将 VHD 上传到 Azure

Upload VHD to Azure using the Azure SDK

有没有办法使用 Azure SDK 将 VHD 上传到 Azure?我知道通过 Powershell (https://docs.microsoft.com/en-us/azure/virtual-machines/windows/classic/createupload-vhd) 上传它的过程相同,但我想使用 SDK 来实现,以便可以使用 Linux 环境来执行。

根据您的描述,我们可以在您的 Linux 环境中安装 Azure CLI 1.0 or CLI 2.0

关于如何使用CLI 2.0从Linux环境上传VHD,请参考这个link

az group create --name myResourceGroup --location westus
az storage account create --resource-group myResourceGroup --location westus --name mystorageaccount --kind Storage --sku Standard_LRS
az storage account keys list --resource-group myResourceGroup --account-name mystorageaccount
az storage container create --account-name mystorageaccount --account-key key1 --name mydisks
az storage blob upload --account-name mystorageaccount --account-key key1 --container-name mydisks --type page --file /path/to/disk/mydisk.vhd --name myDisk.vhd

关于如何使用CLI 1.0从您的Linux环境上传VHD,请参考link

azure config mode arm
azure group create myResourceGroup --location "WestUS"
azure storage account create mystorageaccount --resource-group myResourceGroup --location "WestUS" --kind Storage --sku-name PLRS
azure storage account keys list mystorageaccount --resource-group myResourceGroup
azure storage container create --account-name mystorageaccount --account-key key1 --container myimages
azure storage blob upload --blobtype page --account-name mystorageaccount --account-key key1 --container myimages /path/to/disk/mydisk.vhd

根据您的描述,我认为您想在本地 Linux 上将 VHD 上传到 Azure,就像在 Windows 上通过 powershell 一样。所以作为官方 tutorial said for Linux via Azure CLI, it's you wanna. However, it's an old way to create and upload a VHD to Azure using Azure Service Management (ASM) Mode. Now, Azure Resource Management (ARM) had instead of ASM APIs. If you want to create a VHD using ARM API, you can refer to the REST API Create a virtual machine image or Python SDK for Managed Disks.

如果只需要从本地上传VHD到Azure Storage,参考官方教程How to use Azure Blob storage from Python即可

希望对您有所帮助。