From 768f091de01cd4e80dd1adcc08954d7c72b9d423 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Mar 2015 18:05:59 -0800 Subject: [PATCH 1/2] Add 'ResizedSizeInGB' parameter to Update-AzureDisk --- .../FunctionalTestCommonVhd.cs | 42 +++++++++++-- .../UpdateAzureDiskCmdletInfo.cs | 12 +++- .../ServiceManagementCmdletTestHelper.cs | 7 ++- .../IaaS/DiskRepository/UpdateAzureDisk.cs | 59 +++++++++++++++---- 4 files changed, 99 insertions(+), 21 deletions(-) diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTestCommonVhd.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTestCommonVhd.cs index b8376f416340..6dd92abc80f0 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTestCommonVhd.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTestCommonVhd.cs @@ -33,8 +33,6 @@ public class FunctionalTestCommonVhd : ServiceManagementTest [ClassInitialize] public static void ClassInit(TestContext context) { - //SetTestSettings(); - if (defaultAzureSubscription.Equals(null)) { Assert.Inconclusive("No Subscription is selected!"); @@ -103,19 +101,42 @@ public void AzureDiskTest() found = true; Console.WriteLine("{0} is found", disk.DiskName); } - } Assert.IsTrue(found, "Error: Disk is not added"); + // Update only label string newLabel = "NewLabel"; vmPowershellCmdlets.UpdateAzureDisk(vhdName, newLabel); - DiskContext disk2 = vmPowershellCmdlets.GetAzureDisk(vhdName)[0]; + DiskContext virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0]; - Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", disk2.DiskName, disk2.Label, disk2.DiskSizeInGB); - Assert.AreEqual(newLabel, disk2.Label); + Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB); + Assert.AreEqual(newLabel, virtualDisk.Label); Console.WriteLine("Disk Label is successfully updated"); + // Update only size + int newSize = 100; + vmPowershellCmdlets.UpdateAzureDisk(vhdName, null, newSize); + + virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0]; + + Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB); + Assert.AreEqual(newLabel, virtualDisk.Label); + Assert.AreEqual(newSize, virtualDisk.DiskSizeInGB); + Console.WriteLine("Disk size is successfully updated"); + + // Update both label and size + newLabel = "NewLabel2"; + newSize = 200; + vmPowershellCmdlets.UpdateAzureDisk(vhdName, newLabel, newSize); + + virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0]; + + Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB); + Assert.AreEqual(newLabel, virtualDisk.Label); + Assert.AreEqual(newSize, virtualDisk.DiskSizeInGB); + Console.WriteLine("Both disk label and size are successfully updated"); + vmPowershellCmdlets.RemoveAzureDisk(vhdName, false); Assert.IsTrue(Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDisk, vhdName), "The disk was not removed"); pass = true; @@ -129,6 +150,15 @@ public void AzureDiskTest() Console.WriteLine("Please upload {0} file to \\vhdtest\\ blob directory before running this test", vhdName); } + try + { + vmPowershellCmdlets.RemoveAzureDisk(vhdName, false); + } + catch (Exception cleanupError) + { + Console.WriteLine("Error during cleaning up the disk.. Continue..:{0}", cleanupError); + } + Assert.Fail("Exception occurs: {0}", e.ToString()); } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/UpdateAzureDiskCmdletInfo.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/UpdateAzureDiskCmdletInfo.cs index 9a508e308f11..b866b9723919 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/UpdateAzureDiskCmdletInfo.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/UpdateAzureDiskCmdletInfo.cs @@ -18,12 +18,20 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests { public class UpdateAzureDiskCmdletInfo : CmdletsInfo { - public UpdateAzureDiskCmdletInfo(string diskName, string label) + public UpdateAzureDiskCmdletInfo(string diskName, string label, int? resizedSize) { cmdletName = Utilities.UpdateAzureDiskCmdletName; this.cmdletParams.Add(new CmdletParam("DiskName", diskName)); - this.cmdletParams.Add(new CmdletParam("Label", label)); + + if (label != null) + { + this.cmdletParams.Add(new CmdletParam("Label", label)); + } + if (resizedSize != null) + { + this.cmdletParams.Add(new CmdletParam("ResizedSizeInGB", resizedSize)); + } } } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs index b30103fa4517..8eb6b23b8923 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs @@ -535,7 +535,12 @@ public ManagementOperationContext RemoveAzureDisk(string diskName, bool deleteVh // Update-AzureDisk public SM.DiskContext UpdateAzureDisk(string diskName, string label) { - return RunPSCmdletAndReturnFirst(new UpdateAzureDiskCmdletInfo(diskName, label)); + return RunPSCmdletAndReturnFirst(new UpdateAzureDiskCmdletInfo(diskName, label, null)); + } + + public ManagementOperationContext UpdateAzureDisk(string diskName, string label, int? resizedSize) + { + return RunPSCmdletAndReturnFirst(new UpdateAzureDiskCmdletInfo(diskName, label, resizedSize)); } #endregion diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/DiskRepository/UpdateAzureDisk.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/DiskRepository/UpdateAzureDisk.cs index d6858b714571..ca6475f32a85 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/DiskRepository/UpdateAzureDisk.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/DiskRepository/UpdateAzureDisk.cs @@ -24,28 +24,63 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS [Cmdlet(VerbsData.Update, "AzureDisk"), OutputType(typeof(DiskContext))] public class UpdateAzureDiskCommand : ServiceManagementBaseCmdlet { - [Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the disk in the disk library.")] + public const string ResizeParameterSetName = "Resize"; + public const string NoResizeParameterSetName = "NoResize"; + + [Parameter(Position = 0, ParameterSetName = ResizeParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the disk in the disk library.")] + [Parameter(Position = 0, ParameterSetName = NoResizeParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the disk in the disk library.")] [ValidateNotNullOrEmpty] public string DiskName { get; set; } - [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Label of the disk.")] + [Parameter(Position = 1, ParameterSetName = ResizeParameterSetName, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Label of the disk.")] + [Parameter(Position = 1, ParameterSetName = NoResizeParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Label of the disk.")] [ValidateNotNullOrEmpty] public string Label { get; set; } + [Parameter(Position = 2, ParameterSetName = ResizeParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Label of the disk.")] + [ValidateNotNullOrEmpty] + public int ResizedSizeInGB { get; set; } + internal void ExecuteCommand() { ServiceManagementProfile.Initialize(); - var parameters = new VirtualMachineDiskUpdateParameters + + VirtualMachineDiskUpdateParameters parameters; + + if (this.ParameterSetName == NoResizeParameterSetName) { - Name = this.DiskName, - Label = this.Label - }; - - this.ExecuteClientActionNewSM( - null, - this.CommandRuntime.ToString(), - () => this.ComputeClient.VirtualMachineDisks.UpdateDisk(this.DiskName, parameters), - (s, response) => this.ContextFactory(response, s)); + parameters = new VirtualMachineDiskUpdateParameters + { + Name = this.DiskName, + Label = this.Label, + }; + + this.ExecuteClientActionNewSM( + null, + this.CommandRuntime.ToString(), + () => this.ComputeClient.VirtualMachineDisks.UpdateDisk(this.DiskName, parameters), + (s, response) => this.ContextFactory(response, s)); + } + else + { + if (this.Label == null) + { + var currentDisk = this.ComputeClient.VirtualMachineDisks.GetDisk(this.DiskName); + Label = currentDisk.Label; + } + + parameters = new VirtualMachineDiskUpdateParameters + { + Name = this.DiskName, + Label = this.Label, + ResizedSizeInGB = this.ResizedSizeInGB, + }; + + this.ExecuteClientActionNewSM( + null, + this.CommandRuntime.ToString(), + () => this.ComputeClient.VirtualMachineDisks.UpdateDiskSize(this.DiskName, parameters)); + } } protected override void OnProcessRecord() From 8d9bf969baba09bbaf600c3b93f704334ada1c4d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Mar 2015 02:09:26 -0800 Subject: [PATCH 2/2] Add 'ResizedSizeInGB' parameter to Set-AzureOSDisk --- .../Commands.Common/ServiceManagementTypes.cs | 13 +++++++ .../FunctionalTests/BVTTest.cs | 13 ++++--- .../IaasCmdletInfo/SetAzureOSDisk.cs | 12 +++++- .../ServiceManagementCmdletTestHelper.cs | 12 +++--- .../IaaS/DiskRepository/UpdateAzureDisk.cs | 6 ++- .../IaaS/Disks/SetAzureOSDisk.cs | 23 ++++++++++- ...re.Commands.ServiceManagement.dll-Help.xml | 38 +++++++++++++++++++ 7 files changed, 102 insertions(+), 15 deletions(-) diff --git a/src/Common/Commands.Common/ServiceManagementTypes.cs b/src/Common/Commands.Common/ServiceManagementTypes.cs index ad646843a7a7..72eca9b7c03c 100644 --- a/src/Common/Commands.Common/ServiceManagementTypes.cs +++ b/src/Common/Commands.Common/ServiceManagementTypes.cs @@ -1615,6 +1615,19 @@ public string IOType this.SetValue("IOType", value); } } + + [DataMember(Name = "ResizedSizeInGB", EmitDefaultValue = false, Order = 6)] + public int? ResizedSizeInGB + { + get + { + return this.GetValue("ResizedSizeInGB"); + } + set + { + this.SetValue("ResizedSizeInGB", value); + } + } } #endregion diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/BVTTest.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/BVTTest.cs index 2803e9e6bb10..520fc058609e 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/BVTTest.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/BVTTest.cs @@ -100,10 +100,8 @@ public void AzureIaaSBVT() string certData = Convert.ToBase64String(((X509Certificate2)certToUpload.BaseObject).RawData); string newAzureVMName = Utilities.GetUniqueShortName(vmNamePrefix); - if (string.IsNullOrEmpty(imageName)) - { - imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false); - } + + imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false, 50); RecordTimeTaken(ref prevTime); @@ -222,9 +220,13 @@ public void AzureIaaSBVT() RecordTimeTaken(ref prevTime); // - // New-AzureDns + // Set-AzureOSDisk // + vm = vmPowershellCmdlets.SetAzureOSDisk(null, vm, 100); + // + // New-AzureDns + // string dnsName = "OpenDns1"; string ipAddress = "208.67.222.222"; @@ -348,7 +350,6 @@ public void AzureIaaSBVT() // vm = vmPowershellCmdlets.SetAzureOSDisk(HostCaching.ReadOnly, vm); - // // Update-AzureVM // diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/SetAzureOSDisk.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/SetAzureOSDisk.cs index 26ebcf46f029..9dec245c2290 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/SetAzureOSDisk.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/SetAzureOSDisk.cs @@ -20,11 +20,19 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests { public class SetAzureOSDiskCmdletInfo : CmdletsInfo { - public SetAzureOSDiskCmdletInfo(HostCaching hs, PersistentVM vm) + public SetAzureOSDiskCmdletInfo(HostCaching? hs, PersistentVM vm, int? resizedSize) { cmdletName = Utilities.SetAzureOSDiskCmdletName; - this.cmdletParams.Add(new CmdletParam("HostCaching", hs.ToString())); + + if (hs != null) + { + this.cmdletParams.Add(new CmdletParam("HostCaching", hs.ToString())); + } this.cmdletParams.Add(new CmdletParam("VM", vm)); + if (resizedSize != null) + { + this.cmdletParams.Add(new CmdletParam("ResizedSizeInGB", resizedSize)); + } } } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs index 5d90caaf825d..8fe798de884c 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs @@ -670,9 +670,9 @@ public void RemoveEndPoint(string vmName, string serviceName, string [] epNames) #region AzureOSDisk - public SM.PersistentVM SetAzureOSDisk(HostCaching hc, SM.PersistentVM vm) + public SM.PersistentVM SetAzureOSDisk(HostCaching? hc, SM.PersistentVM vm, int? resizedSize = null) { - return RunPSCmdletAndReturnFirst(new SetAzureOSDiskCmdletInfo(hc, vm)); + return RunPSCmdletAndReturnFirst(new SetAzureOSDiskCmdletInfo(hc, vm, resizedSize)); } public SM.OSVirtualHardDisk GetAzureOSDisk(SM.PersistentVM vm) @@ -1463,17 +1463,19 @@ public void SaveAzureVMImage(string serviceName, string vmName, string newImageN return vmImages; } - public string GetAzureVMImageName(string[] keywords, bool exactMatch = true) + public string GetAzureVMImageName(string[] keywords, bool exactMatch = true, int? diskSize = null) { Collection vmImages = GetAzureVMImage(); foreach (SM.OSImageContext image in vmImages) { - if (Utilities.MatchKeywords(image.ImageName, keywords, exactMatch) >= 0) + if (Utilities.MatchKeywords(image.ImageName, keywords, exactMatch) >= 0 && + ((diskSize == null) || (image.LogicalSizeInGB <= diskSize))) return image.ImageName; } foreach (SM.OSImageContext image in vmImages) { - if (Utilities.MatchKeywords(image.OS, keywords, exactMatch) >= 0) + if (Utilities.MatchKeywords(image.OS, keywords, exactMatch) >= 0 && + ((diskSize == null) || (image.LogicalSizeInGB <= diskSize))) return image.ImageName; } return null; diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/DiskRepository/UpdateAzureDisk.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/DiskRepository/UpdateAzureDisk.cs index ca6475f32a85..774bea42cd84 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/DiskRepository/UpdateAzureDisk.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/DiskRepository/UpdateAzureDisk.cs @@ -37,7 +37,11 @@ public class UpdateAzureDiskCommand : ServiceManagementBaseCmdlet [ValidateNotNullOrEmpty] public string Label { get; set; } - [Parameter(Position = 2, ParameterSetName = ResizeParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Label of the disk.")] + [Parameter(Position = 2, + ParameterSetName = ResizeParameterSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Resizes the underlying blob to the indicated size in GB.")] [ValidateNotNullOrEmpty] public int ResizedSizeInGB { get; set; } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureOSDisk.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureOSDisk.cs index 69e3aca99e26..dc4ec64e39f0 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureOSDisk.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureOSDisk.cs @@ -23,7 +23,11 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS [Cmdlet(VerbsCommon.Set, "AzureOSDisk"), OutputType(typeof(IPersistentVM))] public class SetAzureOSDiskCommand : VirtualMachineConfigurationCmdletBase { - [Parameter(Position = 0, Mandatory = true, HelpMessage = "Controls the platform caching behavior of data disk blob for read / write efficiency.")] + private const string ResizeParameterSet = "Resize"; + private const string NoResizeParameteSet = "NoResize"; + + [Parameter(Position = 0, ParameterSetName = NoResizeParameteSet, Mandatory = true, HelpMessage = "Controls the platform caching behavior of data disk blob for read / write efficiency.")] + [Parameter(Position = 0, ParameterSetName = ResizeParameterSet, Mandatory = false, HelpMessage = "Controls the platform caching behavior of data disk blob for read / write efficiency.")] [ValidateSet("ReadOnly", "ReadWrite", IgnoreCase = true)] public string HostCaching { @@ -31,6 +35,18 @@ public string HostCaching set; } + [Parameter(Position = 1, + ParameterSetName = ResizeParameterSet, + Mandatory = true, + ValueFromPipelineByPropertyName = false, + HelpMessage = "Resize the new OS Disk to a larger size.")] + [ValidateNotNullOrEmpty] + public int ResizedSizeInGB + { + get; + set; + } + internal void ExecuteCommand() { var role = VM.GetInstance(); @@ -47,6 +63,11 @@ internal void ExecuteCommand() OSVirtualHardDisk disk = role.OSVirtualHardDisk; disk.HostCaching = HostCaching; + if (this.ParameterSetName.Equals(ResizeParameterSet)) + { + disk.ResizedSizeInGB = this.ResizedSizeInGB; + } + WriteObject(VM, true); } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml b/src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml index 0aac17a2f078..4f18054c25e3 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml @@ -24225,6 +24225,13 @@ C:\PS> Get-AzureVM -ServiceName "MyService" -Name "MyVM" IPersistentVM + + ResizedSizeInGB + + Resize the new OSVirtualHardDisk to a larger size. ResizedSizeInGB must be larger than the underlying OS Image's LogicalSizeInGB. + + int + @@ -24252,6 +24259,18 @@ C:\PS> Get-AzureVM -ServiceName "MyService" -Name "MyVM" + + ResizedSizeInGB + + Resize the new OSVirtualHardDisk to a larger size. ResizedSizeInGB must be larger than the underlying OS Image's LogicalSizeInGB. + + int + + int + + + + @@ -31812,6 +31831,13 @@ PS C:\> Get-AzureVM -ServiceName "ContosoService03" -Name "Con String + + ResizedSizeInGB + + + + int + @@ -31839,6 +31865,18 @@ PS C:\> Get-AzureVM -ServiceName "ContosoService03" -Name "Con + + ResizedSizeInGB + + Resizes the underlying blob to the indicated size in GB. + + int + + int + + + +