示例#1
0
        public void NewAzureVMWithResizeDiskTest()
        {
            imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false, 50);
            string    newVMImageName = Utilities.GetUniqueShortName("vmimage");
            const int newDiskSize    = 100;

            try
            {
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, _vmName, _serviceName, imageName, username, password, locationName);
                Console.WriteLine("Service Name: {0} is created.  VM: {1} is created.", _serviceName, _vmName);

                string diskLabel1 = "disk1";
                int    diskSize1  = 30;
                int    lunSlot1   = 0;

                string diskLabel2 = "disk2";
                int    diskSize2  = 50;
                int    lunSlot2   = 2;

                AddAzureDataDiskConfig dataDiskInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize1, diskLabel1, lunSlot1);
                AddAzureDataDiskConfig dataDiskInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize2, diskLabel2, lunSlot2);

                vmPowershellCmdlets.AddDataDisk(_vmName, _serviceName, new[] { dataDiskInfo1, dataDiskInfo2 });

                vmPowershellCmdlets.SaveAzureVMImage(_serviceName, _vmName, newVMImageName, "Specialized");

                var newImage = vmPowershellCmdlets.GetAzureVMImageReturningVMImages(newVMImageName).FirstOrDefault();

                foreach (var disk in newImage.DataDiskConfigurations)
                {
                    Utilities.PrintContextAndItsBase(disk);
                }

                string disk1 = newImage.DataDiskConfigurations[0].Name;
                string disk2 = newImage.DataDiskConfigurations[1].Name;

                vmPowershellCmdlets.RemoveAzureService(_serviceName);

                // Add-AzureProvisioningConfig with NoSSHEndpoint
                var vm = vmPowershellCmdlets.NewAzureVMConfig(new AzureVMConfigInfo(_vmName, InstanceSize.Small.ToString(), newVMImageName));
                vm = vmPowershellCmdlets.SetAzureDataDisk(new SetAzureDataDiskResizeConfig(disk1, newDiskSize, vm));
                vm = vmPowershellCmdlets.SetAzureDataDisk(new SetAzureDataDiskResizeConfig(disk2, newDiskSize, vm));
                vm = vmPowershellCmdlets.SetAzureOSDisk(null, vm, newDiskSize);

                // New-AzureVM
                vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }, locationName);
                Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName);

                // Validate disk sizes
                var returnedVM = vmPowershellCmdlets.GetAzureVM(_vmName, _serviceName);
                foreach (var disk in returnedVM.VM.DataVirtualHardDisks)
                {
                    Utilities.PrintContextAndItsBase(disk);
                }
                Assert.AreEqual(newDiskSize, returnedVM.VM.DataVirtualHardDisks[0].LogicalDiskSizeInGB);
                Assert.AreEqual(newDiskSize, returnedVM.VM.DataVirtualHardDisks[1].LogicalDiskSizeInGB);

                pass = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException);
                }
                throw;
            }
            finally
            {
                vmPowershellCmdlets.RemoveAzureService(_serviceName);
                vmPowershellCmdlets.RemoveAzureVMImage(newVMImageName, true);
            }
        }