首页 文章

Azure资源管理器VM需要很长时间才能进行配置

提问于
浏览
0

我正在尝试从部署模板文件创建(Windows)VM . 在启动它通常需要7到8分钟才能成功完成部署并使vm处于“已启动”状态 . 但随着时间的推移,需要花费很长时间(20-30分钟)才能完成部署并获得配置的vm . 这是用于从custom vhd创建vm的模板的一部分(vhd是syspreped):

"resources": [
{
"apiVersion": "2015-06-15",
 "type": "Microsoft.Compute/virtualMachines", 
 "name": "[variables('vmName1')]",
 "location": "[variables('location')]",
 "properties": {
 "hardwareProfile": {
 "vmSize": "[variables('vmSize')]"
},
 "networkProfile": {
 "networkInterfaces": [
 {
 "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName1'))]"
 }
 ]
 },
 "osProfile": {
 "computerName": "[variables('vmName1')]",
 "adminUsername": "[variables('adminUsername')]",
 "adminPassword": "[variables('adminPassword')]"
 },
 "storageProfile": {
 "osDisk": {
 "ostype": "windows",
 "name": "windows201606221843019334",
"vhd": {
       "uri": "https://armstorageaccount.blob.core.windows.net/storage-31/vm2016062218430193341.vhd"
       },
"image": {
      "uri": "https://armstorageaccount.blob.core.windows.net/resource-vhd/VM-ARM-os-2016-06-08-37FFE535.vhd"
         },
"caching": "readwrite",
"createOption": "FromImage"
}}}}]

在运行上述模板之前,我正在使用.net的天蓝色计算管理库创建公共IP地址资源,使用天网网络管理库为这些资源创建一个网络接口卡资源 . 这些资源的名称在上面的模板中使用适当的变量引用 . 由于我使用的是异步任务,因此在运行上述模板之前会创建这两个资源 . 我正在使用azure资源管理sdk为.net部署模板

1 回答

  • 0

    我认为这对你有用

    var computeClient = new Microsoft.Azure.Management.Compute.ComputeManagementClient(credentials) { SubscriptionId = subscriptionId };
     var vm = await computeClient.VirtualMachines.BeginCreateOrUpdate(resourceGroup, vmName,
                new VirtualMachine
                {
                    Location = location,
                    HardwareProfile = new HardwareProfile(vmSize),
                    OsProfile = new OSProfile(vmName, vmAdminUsername, vmAdminPassword),
                    StorageProfile = new StorageProfile(
                        new ImageReference
                        {
                            Publisher = vmImagePublisher,
                            Offer = vmImageOffer,
                            Sku = vmImageSku,
                            Version = vmImageVersion
                        },
                        new OSDisk
                        {
                            Name = vmOSDiskName,
                            Vhd = new VirtualHardDisk(@"http://" + storageAccountName + ".blob.core.windows.net/vhds/{vmOSDiskName}.vhd"),
                            Caching = "ReadWrite",
                            CreateOption = "FromImage"
                        },
                        new List<DataDisk>()
                        {
    
                        }
                        ),
                    NetworkProfile = new NetworkProfile(
                        new[] { new NetworkInterfaceReference { Id = nicId } }),
                    DiagnosticsProfile = new DiagnosticsProfile(
                        new BootDiagnostics
                        {
                            Enabled = true,
                            StorageUri = @"http://" + storageAccountName + ".blob.core.windows.net"
                        })
                });
    

    这使用异步方法,所以你不需要等待 .

相关问题