creating vm from image

Dharshan M 0 Reputation points

i'm trying to create a new vm from a captured image which was creating using c sharp i created now i'm trying to create a new vm from that image using this below code but i'm getting this error/message

"Microsoft.Rest.Azure.CloudException: 'Long running operation failed with status 'Failed'. Additional Info:'OS Provisioning for VM 'Test-3' did not finish in the allotted time. However, the VM guest agent was detected running. This suggests the guest OS has not been properly prepared to be used as a VM image (with CreateOption=FromImage). To resolve this issue, either use the VHD as is with CreateOption=Attach or prepare it properly for use as an image:

will anybody help on this ......


 public void DOCreateVMFromImage()
            string captureimage = "new_Image";
            string vmName = "Test-3";
            string resourceGrp = "NEW-Test-Grp1";
            string resource = "New_test_grp2"; 
            string adminUsername = "Student1";
            string adminPassword = "student1Excel";
            var location = Region.USEast;
            var vNetName = "VNET-Fluent";
            var vNetAddress = "";
            var subnetName = "Subnet-Fluent";
            var subnetAddress = "";
            var nicName = "NIC-CVM";
            var publicIPName = "TestpublicIp";
            var nsgName = "NSG-Fluent";

            var credentials = SdkContext.AzureCredentialsFactory

            var azure = Azure.Authenticate(credentials).WithDefaultSubscription();

            // Get the captured image
            var capturedImage = azure.VirtualMachineCustomImages.GetByResourceGroup(resourceGrp, captureimage);
            if (capturedImage != null)
               var resourceGroup = azure.ResourceGroups.Define(resource)

                Console.WriteLine($"Creating virtual network {vNetName} ...");
                var network = azure.Networks.Define(vNetName)
                    .WithSubnet(subnetName, subnetAddress)

                Console.WriteLine($"Creating public IP {publicIPName} ...");
                var publicIP = azure.PublicIPAddresses.Define(publicIPName)
                //You need a network security group for controlling the access to the VM
                Console.WriteLine($"Creating Network Security Group {nsgName} ...");
                var nsg = azure.NetworkSecurityGroups.Define(nsgName)
                //You need a security rule for allowing the
                Console.WriteLine($"Creating a Security Rule for allowing the remote");

                Console.WriteLine($"Creating network interface {nicName} ...");
                var nic = azure.NetworkInterfaces.Define(nicName)

                Console.WriteLine($"Creating a new VM using {captureimage}...");

                var newVM = azure.VirtualMachines.Define(vmName)
                ///CheckVMStatus(azure, newVM.Id);
               ///ShutDownVM(azure, newVM.Id);

                Console.WriteLine("Successfully created a new VM: {0}!", vmName);
                Console.WriteLine("Press any key to exit...");
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,605 questions
0 comments No comments
{count} votes