/// <summary>
 /// Creates a Virtual Machine
 /// </summary>
 /// <param name="name">name of Virtual Machine</param>
 /// <param name="resourceGroup">Name of Resource Group</param>
 /// <param name="region">Region where Virtual Machine resides</param>
 /// <param name="primaryNetwork">Primary Network</param>
 /// <param name="primaryPublicIPAddress">Primary Public IP Address</param>
 /// <param name="image">Image Type (Windows/Linux)</param>
 /// <param name="adminUserName">Administrator Name</param>
 /// <param name="adminUserPwd">Administrator Password</param>
 /// <param name="vmSize">Size of the Virtual Machine</param>
 /// <returns></returns>
 public IVirtualMachine CreateWindowsVM(
     string name,
     string resourceGroup,
     Region region,
     string primaryNetwork,
     string primaryPublicIPAddress,
     KnownWindowsVirtualMachineImage image,
     string adminUserName,
     string adminUserPwd,
     VirtualMachineSizeTypes vmSize
     )
 {
     return(azure.VirtualMachines.Define(name)
            .WithRegion(region)
            .WithExistingResourceGroup(resourceGroup)
            .WithNewPrimaryNetwork(primaryNetwork)
            .WithPrimaryPrivateIPAddressDynamic()
            .WithNewPrimaryPublicIPAddress(primaryPublicIPAddress)
            .WithPopularWindowsImage(image)
            .WithAdminUsername(adminUserName)
            .WithAdminPassword(adminUserPwd)
            .WithSize(vmSize)
            .Create());
 }
Example #2
0
        public void CreateWindowsVM(string groupName, string vmName, Region location, string azureuser, string adminPassword, KnownWindowsVirtualMachineImage
                                    mKnownWindowsVirtualMachineImage)
        {
            Console.WriteLine("Creating resource group...");
            var resourceGroup = azure.ResourceGroups.Define(groupName)
                                .WithRegion(location)
                                .Create();

            Console.WriteLine("Creating availability set...");
            var availabilitySet = azure.AvailabilitySets.Define("myAVSet")
                                  .WithRegion(location)
                                  .WithExistingResourceGroup(groupName)
                                  .WithSku(AvailabilitySetSkuTypes.Managed)
                                  .Create();

            Console.WriteLine("Creating public IP address...");
            var publicIPAddress = azure.PublicIPAddresses.Define("myPublicIP")
                                  .WithRegion(location)
                                  .WithExistingResourceGroup(groupName)
                                  .WithDynamicIP()
                                  .Create(); Console.WriteLine("Creating virtual network...");

            var network = azure.Networks.Define("myVNet")
                          .WithRegion(location)
                          .WithExistingResourceGroup(groupName)
                          .WithAddressSpace("10.0.0.0/16")
                          .WithSubnet("mySubnet", "10.0.0.0/24")
                          .Create();

            Console.WriteLine("Creating network interface...");
            var networkInterface = azure.NetworkInterfaces.Define("myNIC")
                                   .WithRegion(location)
                                   .WithExistingResourceGroup(groupName)
                                   .WithExistingPrimaryNetwork(network)
                                   .WithSubnet("mySubnet")
                                   .WithPrimaryPrivateIPAddressDynamic()
                                   .WithExistingPrimaryPublicIPAddress(publicIPAddress)
                                   .Create();

            Console.WriteLine("Creating virtual machine...");
            var vm = azure.VirtualMachines.Define(vmName);

            vm.WithRegion(location)
            .WithExistingResourceGroup(groupName)
            .WithExistingPrimaryNetworkInterface(networkInterface)
            .WithPopularWindowsImage(mKnownWindowsVirtualMachineImage)
            .WithAdminUsername(azureuser)
            .WithAdminPassword(adminPassword)
            .WithComputerName(vmName)
            .WithExistingAvailabilitySet(availabilitySet)
            .WithSize(VirtualMachineSizeTypes.StandardDS1)
            .Create();
        }
        public static ImageReference ImageReference(this KnownWindowsVirtualMachineImage image)
        {
            string referenceString = EnumNameAttribute.GetName(image);

            return(GetImageReference(referenceString, image.ToString()));
        }