【问题标题】:Can I do the same thing as Azure Powershell with Azure CLI? (Upload VHD)我可以使用 Azure CLI 执行与 Azure Powershell 相同的操作吗? (上传 VHD)
【发布时间】:2019-06-10 22:00:07
【问题描述】:

所以我有一个大小为 90mb 的原始 vhd 文件。

使用 Azure Powershell 模块 Add-AzureRMVhd 上传 vhd 会导致上传的 vhd 大小为 2gb。

Add-AzureRmVhd -LocalFilePath $sourceVHD -Destination $destinationVHD -ResourceGroupName $resourceGroupName -NumberOfUploaderThreads 5

使用 azure cli 上传 vhd 会导致上传的 vhd 大小为 90mb。

az storage blob upload --account-name tstorage --container-name tcontainer --file /home/azure/images/test.vhd --name test.vhd --type page

我可以使用 2gb vhd 创建图像,但不能使用 90mb。

有没有办法用AZ cli执行powershell模块的功能?

【问题讨论】:

  • 我可以知道你为什么坚持使用 azure cli 吗?

标签: azure powershell sdk command-line-interface azure-cli


【解决方案1】:

我尝试了下面的命令,它对我有用,请尝试按照这个操作,看看它是否适合你使用 Azure CLI

#!/bin/bash

# Create a resource group
az group create -n myResourceGroup -l westus

# Create the storage account to upload the vhd
az storage account create -g myResourceGroup -n mystorageaccount -l westus --sku PREMIUM_LRS

# Get a storage key for the storage account
STORAGE_KEY=$(az storage account keys list -g myResourceGroup -n mystorageaccount --query "[?keyName=='key1'] | [0].value" -o tsv)

# Create the container for the vhd
az storage container create -n vhds --account-name mystorageaccount --account-key ${STORAGE_KEY}

# Upload the vhd to a blob
az storage blob upload -c vhds -f ~/sample.vhd -n sample.vhd --account-name mystorageaccount --account-key ${STORAGE_KEY}

# Create the vm from the vhd
az vm create -g myResourceGroup -n myVM --image "https://myStorageAccount.blob.core.windows.net/vhds/sample.vhd" \
        --os-type linux --admin-username deploy --generate-ssh-keys

# Update the deploy user with your ssh key
az vm user update --resource-group myResourceGroup -n custom-vm -u deploy --ssh-key-value "$(< ~/.ssh/id_rsa.pub)"

# Get public IP address for the VM
IP_ADDRESS=$(az vm list-ip-addresses -g az-cli-vhd -n custom-vm \
    --query "[0].virtualMachine.network.publicIpAddresses[0].ipAddress" -o tsv)

echo "You can now connect using 'ssh deploy@${IP_ADDRESS}'"

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    • 2016-10-08
    • 2016-10-15
    • 1970-01-01
    相关资源
    最近更新 更多