Skip to content

Dev #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 2, 2015
Merged

Dev #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Common/Commands.Common/ServiceManagementTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int?>("ResizedSizeInGB");
}
set
{
this.SetValue("ResizedSizeInGB", value);
}
}
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -348,7 +350,6 @@ public void AzureIaaSBVT()
//
vm = vmPowershellCmdlets.SetAzureOSDisk(HostCaching.ReadOnly, vm);


//
// Update-AzureVM
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down Expand Up @@ -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;
Expand All @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,12 @@ public ManagementOperationContext RemoveAzureDisk(string diskName, bool deleteVh
// Update-AzureDisk
public SM.DiskContext UpdateAzureDisk(string diskName, string label)
{
return RunPSCmdletAndReturnFirst<SM.DiskContext>(new UpdateAzureDiskCmdletInfo(diskName, label));
return RunPSCmdletAndReturnFirst<SM.DiskContext>(new UpdateAzureDiskCmdletInfo(diskName, label, null));
}

public ManagementOperationContext UpdateAzureDisk(string diskName, string label, int? resizedSize)
{
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new UpdateAzureDiskCmdletInfo(diskName, label, resizedSize));
}

#endregion
Expand Down Expand Up @@ -665,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<SM.PersistentVM>(new SetAzureOSDiskCmdletInfo(hc, vm));
return RunPSCmdletAndReturnFirst<SM.PersistentVM>(new SetAzureOSDiskCmdletInfo(hc, vm, resizedSize));
}

public SM.OSVirtualHardDisk GetAzureOSDisk(SM.PersistentVM vm)
Expand Down Expand Up @@ -1458,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<SM.OSImageContext> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,67 @@ 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 = "Resizes the underlying blob to the indicated size in GB.")]
[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<VirtualMachineDiskUpdateResponse, DiskContext>(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<VirtualMachineDiskUpdateResponse, DiskContext>(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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,30 @@ 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
{
get;
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();
Expand All @@ -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);
}

Expand Down
Loading