0
votes

I am trying to create a (windows) VM from a deployment template file. in Starting it usually took 7 to 8 minutes to get the deployment done successfully and getting vm in 'Started' state. but with the passage of time its taking long (20-30) minutes or more to get the deployment done and getting the vm provisioned. here is the part of template that is being used to create a vm from custom vhd (vhd is 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"
}}}}]

before running the above template i am creating a public ip address resource using azure compute management libraries for .net and a network interface card resource using azure network management libraries for .net.Names of these resources are refered in the template above using proper variables. Since i am using async tasks so both of these resources are created before above template is run. i am deploying the template using azure resource management sdk for .net

1
How you been trying to do the same deployment in Azure portal and/or using Azure PowerShell? - juvchan
no i have not used powershell for the deployment though. I need to do it using .net sdk for ARM. What is the way to do it through azure portal? - Muhammad Murad Haider

1 Answers

0
votes

i think this work for you

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"
                    })
            });

this use async method so you do not need to wait.