【问题标题】:Creating OS disk from VHD stored in another storage account从存储在另一个存储帐户中的 VHD 创建 OS 磁盘
【发布时间】:2019-08-06 07:12:13
【问题描述】:

拥有一个现有的 PowerShell 脚本,该脚本使用存储在存储帐户中的预先创建的 VHD 创建 VM(为了提高速度,跨区域存储帐户复制)。

在 PS 中我们可以使用以下内容:

New-AzureRmDisk -DiskName $osDiskName -Disk `
(New-AzureRmDiskConfig -AccountType Premium_LRS  `
        -Location $location -CreateOption Import `
        -StorageAccountId $storageAccountId `
        -SourceUri $osVHDUri) `
    -ResourceGroupName $resourceGroupName
$osDisk = Get-AzureRMDisk -DiskName $osDiskName -ResourceGroupName $resourceGroupName

$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -ManagedDiskId $osDisk.Id -CreateOption Attach -Windows -StorageAccountType Premium_LRS

其中 $storageAccountId 类似于:

/subscriptions/{0}/resourceGroups/my-snapshot/providers/Microsoft.Storage/storageAccounts/mysnapshots -f $sourceSnapshotSubscriptionId

在 .net Azure SDK 中,我没有看到复制它的方法?当我尝试创建时,它说找不到,但我的 PS 工作正常。

【问题讨论】:

    标签: azure-sdk-.net azure-sdk


    【解决方案1】:

    如果您想使用现有磁盘而不是市场映像,请使用以下代码:

    var managedDisk = azure.Disks.Define("myosdisk")
        .WithRegion(location)
        .WithExistingResourceGroup(groupName)
        .WithWindowsFromVhd("https://mystorage.blob.core.windows.net/vhds/myosdisk.vhd")
        .WithSizeInGB(128)
        .WithSku(DiskSkuTypes.PremiumLRS)
        .Create();
    
    azure.VirtualMachines.Define("myVM")
        .WithRegion(location)
        .WithExistingResourceGroup(groupName)
        .WithExistingPrimaryNetworkInterface(networkInterface)
        .WithSpecializedOSDisk(managedDisk, OperatingSystemTypes.Windows)
        .WithExistingAvailabilitySet(availabilitySet)
        .WithSize(VirtualMachineSizeTypes.StandardDS1)
        .Create();
    

    查看此link 以获取更多参考。希望对您有所帮助。

    【讨论】:

    • 挑战在于 VHD Uri 引用了不同的存储帐户位置。 PowerShell 允许您传入 storageaccountid,但 .net SDK 对此没有参考。
    猜你喜欢
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-01
    • 2021-08-25
    相关资源
    最近更新 更多