Skip to content

Commit 74d4bd7

Browse files
committed
Merge pull request #13 from hyonholee/dev
Dev
2 parents e12700c + 8d9bf96 commit 74d4bd7

File tree

9 files changed

+200
-35
lines changed

9 files changed

+200
-35
lines changed

src/Common/Commands.Common/ServiceManagementTypes.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,19 @@ public string IOType
16151615
this.SetValue("IOType", value);
16161616
}
16171617
}
1618+
1619+
[DataMember(Name = "ResizedSizeInGB", EmitDefaultValue = false, Order = 6)]
1620+
public int? ResizedSizeInGB
1621+
{
1622+
get
1623+
{
1624+
return this.GetValue<int?>("ResizedSizeInGB");
1625+
}
1626+
set
1627+
{
1628+
this.SetValue("ResizedSizeInGB", value);
1629+
}
1630+
}
16181631
}
16191632
#endregion
16201633

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/BVTTest.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,8 @@ public void AzureIaaSBVT()
100100
string certData = Convert.ToBase64String(((X509Certificate2)certToUpload.BaseObject).RawData);
101101

102102
string newAzureVMName = Utilities.GetUniqueShortName(vmNamePrefix);
103-
if (string.IsNullOrEmpty(imageName))
104-
{
105-
imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
106-
}
103+
104+
imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false, 50);
107105

108106
RecordTimeTaken(ref prevTime);
109107

@@ -222,9 +220,13 @@ public void AzureIaaSBVT()
222220
RecordTimeTaken(ref prevTime);
223221

224222
//
225-
// New-AzureDns
223+
// Set-AzureOSDisk
226224
//
225+
vm = vmPowershellCmdlets.SetAzureOSDisk(null, vm, 100);
227226

227+
//
228+
// New-AzureDns
229+
//
228230
string dnsName = "OpenDns1";
229231
string ipAddress = "208.67.222.222";
230232

@@ -348,7 +350,6 @@ public void AzureIaaSBVT()
348350
//
349351
vm = vmPowershellCmdlets.SetAzureOSDisk(HostCaching.ReadOnly, vm);
350352

351-
352353
//
353354
// Update-AzureVM
354355
//

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTestCommonVhd.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public class FunctionalTestCommonVhd : ServiceManagementTest
3333
[ClassInitialize]
3434
public static void ClassInit(TestContext context)
3535
{
36-
//SetTestSettings();
37-
3836
if (defaultAzureSubscription.Equals(null))
3937
{
4038
Assert.Inconclusive("No Subscription is selected!");
@@ -103,19 +101,42 @@ public void AzureDiskTest()
103101
found = true;
104102
Console.WriteLine("{0} is found", disk.DiskName);
105103
}
106-
107104
}
108105
Assert.IsTrue(found, "Error: Disk is not added");
109106

107+
// Update only label
110108
string newLabel = "NewLabel";
111109
vmPowershellCmdlets.UpdateAzureDisk(vhdName, newLabel);
112110

113-
DiskContext disk2 = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];
111+
DiskContext virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];
114112

115-
Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", disk2.DiskName, disk2.Label, disk2.DiskSizeInGB);
116-
Assert.AreEqual(newLabel, disk2.Label);
113+
Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB);
114+
Assert.AreEqual(newLabel, virtualDisk.Label);
117115
Console.WriteLine("Disk Label is successfully updated");
118116

117+
// Update only size
118+
int newSize = 100;
119+
vmPowershellCmdlets.UpdateAzureDisk(vhdName, null, newSize);
120+
121+
virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];
122+
123+
Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB);
124+
Assert.AreEqual(newLabel, virtualDisk.Label);
125+
Assert.AreEqual(newSize, virtualDisk.DiskSizeInGB);
126+
Console.WriteLine("Disk size is successfully updated");
127+
128+
// Update both label and size
129+
newLabel = "NewLabel2";
130+
newSize = 200;
131+
vmPowershellCmdlets.UpdateAzureDisk(vhdName, newLabel, newSize);
132+
133+
virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];
134+
135+
Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB);
136+
Assert.AreEqual(newLabel, virtualDisk.Label);
137+
Assert.AreEqual(newSize, virtualDisk.DiskSizeInGB);
138+
Console.WriteLine("Both disk label and size are successfully updated");
139+
119140
vmPowershellCmdlets.RemoveAzureDisk(vhdName, false);
120141
Assert.IsTrue(Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDisk, vhdName), "The disk was not removed");
121142
pass = true;
@@ -129,6 +150,15 @@ public void AzureDiskTest()
129150
Console.WriteLine("Please upload {0} file to \\vhdtest\\ blob directory before running this test", vhdName);
130151
}
131152

153+
try
154+
{
155+
vmPowershellCmdlets.RemoveAzureDisk(vhdName, false);
156+
}
157+
catch (Exception cleanupError)
158+
{
159+
Console.WriteLine("Error during cleaning up the disk.. Continue..:{0}", cleanupError);
160+
}
161+
132162
Assert.Fail("Exception occurs: {0}", e.ToString());
133163
}
134164
}

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/SetAzureOSDisk.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests
2020
{
2121
public class SetAzureOSDiskCmdletInfo : CmdletsInfo
2222
{
23-
public SetAzureOSDiskCmdletInfo(HostCaching hs, PersistentVM vm)
23+
public SetAzureOSDiskCmdletInfo(HostCaching? hs, PersistentVM vm, int? resizedSize)
2424
{
2525
cmdletName = Utilities.SetAzureOSDiskCmdletName;
26-
this.cmdletParams.Add(new CmdletParam("HostCaching", hs.ToString()));
26+
27+
if (hs != null)
28+
{
29+
this.cmdletParams.Add(new CmdletParam("HostCaching", hs.ToString()));
30+
}
2731
this.cmdletParams.Add(new CmdletParam("VM", vm));
32+
if (resizedSize != null)
33+
{
34+
this.cmdletParams.Add(new CmdletParam("ResizedSizeInGB", resizedSize));
35+
}
2836
}
2937
}
3038
}

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/UpdateAzureDiskCmdletInfo.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests
1818
{
1919
public class UpdateAzureDiskCmdletInfo : CmdletsInfo
2020
{
21-
public UpdateAzureDiskCmdletInfo(string diskName, string label)
21+
public UpdateAzureDiskCmdletInfo(string diskName, string label, int? resizedSize)
2222
{
2323
cmdletName = Utilities.UpdateAzureDiskCmdletName;
2424

2525
this.cmdletParams.Add(new CmdletParam("DiskName", diskName));
26-
this.cmdletParams.Add(new CmdletParam("Label", label));
26+
27+
if (label != null)
28+
{
29+
this.cmdletParams.Add(new CmdletParam("Label", label));
30+
}
31+
if (resizedSize != null)
32+
{
33+
this.cmdletParams.Add(new CmdletParam("ResizedSizeInGB", resizedSize));
34+
}
2735
}
2836
}
2937
}

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,12 @@ public ManagementOperationContext RemoveAzureDisk(string diskName, bool deleteVh
535535
// Update-AzureDisk
536536
public SM.DiskContext UpdateAzureDisk(string diskName, string label)
537537
{
538-
return RunPSCmdletAndReturnFirst<SM.DiskContext>(new UpdateAzureDiskCmdletInfo(diskName, label));
538+
return RunPSCmdletAndReturnFirst<SM.DiskContext>(new UpdateAzureDiskCmdletInfo(diskName, label, null));
539+
}
540+
541+
public ManagementOperationContext UpdateAzureDisk(string diskName, string label, int? resizedSize)
542+
{
543+
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new UpdateAzureDiskCmdletInfo(diskName, label, resizedSize));
539544
}
540545

541546
#endregion
@@ -665,9 +670,9 @@ public void RemoveEndPoint(string vmName, string serviceName, string [] epNames)
665670

666671
#region AzureOSDisk
667672

668-
public SM.PersistentVM SetAzureOSDisk(HostCaching hc, SM.PersistentVM vm)
673+
public SM.PersistentVM SetAzureOSDisk(HostCaching? hc, SM.PersistentVM vm, int? resizedSize = null)
669674
{
670-
return RunPSCmdletAndReturnFirst<SM.PersistentVM>(new SetAzureOSDiskCmdletInfo(hc, vm));
675+
return RunPSCmdletAndReturnFirst<SM.PersistentVM>(new SetAzureOSDiskCmdletInfo(hc, vm, resizedSize));
671676
}
672677

673678
public SM.OSVirtualHardDisk GetAzureOSDisk(SM.PersistentVM vm)
@@ -1458,17 +1463,19 @@ public void SaveAzureVMImage(string serviceName, string vmName, string newImageN
14581463
return vmImages;
14591464
}
14601465

1461-
public string GetAzureVMImageName(string[] keywords, bool exactMatch = true)
1466+
public string GetAzureVMImageName(string[] keywords, bool exactMatch = true, int? diskSize = null)
14621467
{
14631468
Collection<SM.OSImageContext> vmImages = GetAzureVMImage();
14641469
foreach (SM.OSImageContext image in vmImages)
14651470
{
1466-
if (Utilities.MatchKeywords(image.ImageName, keywords, exactMatch) >= 0)
1471+
if (Utilities.MatchKeywords(image.ImageName, keywords, exactMatch) >= 0 &&
1472+
((diskSize == null) || (image.LogicalSizeInGB <= diskSize)))
14671473
return image.ImageName;
14681474
}
14691475
foreach (SM.OSImageContext image in vmImages)
14701476
{
1471-
if (Utilities.MatchKeywords(image.OS, keywords, exactMatch) >= 0)
1477+
if (Utilities.MatchKeywords(image.OS, keywords, exactMatch) >= 0 &&
1478+
((diskSize == null) || (image.LogicalSizeInGB <= diskSize)))
14721479
return image.ImageName;
14731480
}
14741481
return null;

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/DiskRepository/UpdateAzureDisk.cs

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,67 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS
2424
[Cmdlet(VerbsData.Update, "AzureDisk"), OutputType(typeof(DiskContext))]
2525
public class UpdateAzureDiskCommand : ServiceManagementBaseCmdlet
2626
{
27-
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the disk in the disk library.")]
27+
public const string ResizeParameterSetName = "Resize";
28+
public const string NoResizeParameterSetName = "NoResize";
29+
30+
[Parameter(Position = 0, ParameterSetName = ResizeParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the disk in the disk library.")]
31+
[Parameter(Position = 0, ParameterSetName = NoResizeParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the disk in the disk library.")]
2832
[ValidateNotNullOrEmpty]
2933
public string DiskName { get; set; }
3034

31-
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Label of the disk.")]
35+
[Parameter(Position = 1, ParameterSetName = ResizeParameterSetName, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Label of the disk.")]
36+
[Parameter(Position = 1, ParameterSetName = NoResizeParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Label of the disk.")]
3237
[ValidateNotNullOrEmpty]
3338
public string Label { get; set; }
3439

40+
[Parameter(Position = 2,
41+
ParameterSetName = ResizeParameterSetName,
42+
Mandatory = true,
43+
ValueFromPipelineByPropertyName = true,
44+
HelpMessage = "Resizes the underlying blob to the indicated size in GB.")]
45+
[ValidateNotNullOrEmpty]
46+
public int ResizedSizeInGB { get; set; }
47+
3548
internal void ExecuteCommand()
3649
{
3750
ServiceManagementProfile.Initialize();
38-
var parameters = new VirtualMachineDiskUpdateParameters
51+
52+
VirtualMachineDiskUpdateParameters parameters;
53+
54+
if (this.ParameterSetName == NoResizeParameterSetName)
3955
{
40-
Name = this.DiskName,
41-
Label = this.Label
42-
};
43-
44-
this.ExecuteClientActionNewSM(
45-
null,
46-
this.CommandRuntime.ToString(),
47-
() => this.ComputeClient.VirtualMachineDisks.UpdateDisk(this.DiskName, parameters),
48-
(s, response) => this.ContextFactory<VirtualMachineDiskUpdateResponse, DiskContext>(response, s));
56+
parameters = new VirtualMachineDiskUpdateParameters
57+
{
58+
Name = this.DiskName,
59+
Label = this.Label,
60+
};
61+
62+
this.ExecuteClientActionNewSM(
63+
null,
64+
this.CommandRuntime.ToString(),
65+
() => this.ComputeClient.VirtualMachineDisks.UpdateDisk(this.DiskName, parameters),
66+
(s, response) => this.ContextFactory<VirtualMachineDiskUpdateResponse, DiskContext>(response, s));
67+
}
68+
else
69+
{
70+
if (this.Label == null)
71+
{
72+
var currentDisk = this.ComputeClient.VirtualMachineDisks.GetDisk(this.DiskName);
73+
Label = currentDisk.Label;
74+
}
75+
76+
parameters = new VirtualMachineDiskUpdateParameters
77+
{
78+
Name = this.DiskName,
79+
Label = this.Label,
80+
ResizedSizeInGB = this.ResizedSizeInGB,
81+
};
82+
83+
this.ExecuteClientActionNewSM(
84+
null,
85+
this.CommandRuntime.ToString(),
86+
() => this.ComputeClient.VirtualMachineDisks.UpdateDiskSize(this.DiskName, parameters));
87+
}
4988
}
5089

5190
protected override void OnProcessRecord()

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureOSDisk.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,30 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS
2323
[Cmdlet(VerbsCommon.Set, "AzureOSDisk"), OutputType(typeof(IPersistentVM))]
2424
public class SetAzureOSDiskCommand : VirtualMachineConfigurationCmdletBase
2525
{
26-
[Parameter(Position = 0, Mandatory = true, HelpMessage = "Controls the platform caching behavior of data disk blob for read / write efficiency.")]
26+
private const string ResizeParameterSet = "Resize";
27+
private const string NoResizeParameteSet = "NoResize";
28+
29+
[Parameter(Position = 0, ParameterSetName = NoResizeParameteSet, Mandatory = true, HelpMessage = "Controls the platform caching behavior of data disk blob for read / write efficiency.")]
30+
[Parameter(Position = 0, ParameterSetName = ResizeParameterSet, Mandatory = false, HelpMessage = "Controls the platform caching behavior of data disk blob for read / write efficiency.")]
2731
[ValidateSet("ReadOnly", "ReadWrite", IgnoreCase = true)]
2832
public string HostCaching
2933
{
3034
get;
3135
set;
3236
}
3337

38+
[Parameter(Position = 1,
39+
ParameterSetName = ResizeParameterSet,
40+
Mandatory = true,
41+
ValueFromPipelineByPropertyName = false,
42+
HelpMessage = "Resize the new OS Disk to a larger size.")]
43+
[ValidateNotNullOrEmpty]
44+
public int ResizedSizeInGB
45+
{
46+
get;
47+
set;
48+
}
49+
3450
internal void ExecuteCommand()
3551
{
3652
var role = VM.GetInstance();
@@ -47,6 +63,11 @@ internal void ExecuteCommand()
4763

4864
OSVirtualHardDisk disk = role.OSVirtualHardDisk;
4965
disk.HostCaching = HostCaching;
66+
if (this.ParameterSetName.Equals(ResizeParameterSet))
67+
{
68+
disk.ResizedSizeInGB = this.ResizedSizeInGB;
69+
}
70+
5071
WriteObject(VM, true);
5172
}
5273

0 commit comments

Comments
 (0)