【问题标题】:Upload VHD to Azure using the Azure SDK使用 Azure SDK 将 VHD 上传到 Azure
【发布时间】:2017-04-07 14:22:17
【问题描述】:

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

【问题讨论】:

    标签: azure azure-storage azure-sdk azure-sdk-python


    【解决方案1】:

    根据您的描述,我们可以在您的 Linux 环境中安装 Azure CLI 1.0CLI 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
    

    【讨论】:

      【解决方案2】:

      根据您的描述,我认为您想在本地 Linux 上将 VHD 上传到 Azure,就像在 Windows 上通过 powershell 一样。因此,正如官方 tutorial 通过 Azure CLI 对 Linux 所说的那样,这就是你想要的。但是,这是使用 Azure 服务管理 (ASM) 模式创建 VHD 并将其上传到 Azure 的一种旧方法。现在,Azure 资源管理 (ARM) 取代了 ASM API。如果要使用 ARM API 创建 VHD,可以参考 REST API Create a virtual machine image 或 Python SDK for Managed Disks

      如果你只是需要从本地上传一个VHD到Azure Storage,你只需要参考官方教程How to use Azure Blob storage from Python就可以了。

      希望对你有帮助。

      【讨论】:

      • 好像没有相当于“vm image create”CLI命令的Python-SDK吧?我最初是在查看 SDK 方法,但 SDK 中似乎不存在此调用。
      • @GeorgeTs 事实上,我在 Python SDK 中找不到任何与“vm image create”等效的方法,即使在旧 SDK 中也是如此。
      猜你喜欢
      • 2017-10-10
      • 2016-10-15
      • 1970-01-01
      • 2016-04-05
      • 2021-04-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      相关资源
      最近更新 更多