Skip to content

Dev #14

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 2 commits into from
Mar 3, 2015
Merged

Dev #14

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
46 changes: 46 additions & 0 deletions src/Common/Commands.Common/ServiceManagementTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,38 @@ public int? ResizedSizeInGB
}
#endregion

#region VMImageInput
[DataContract(Namespace = Constants.ServiceManagementNS)]
public class VMImageInput : Mergable<VMImageInput>
{
[DataMember(Name = "OSDiskConfiguration", EmitDefaultValue = false, Order = 1)]
public OSDiskConfiguration OSDiskConfiguration
{
get
{
return this.GetValue<OSDiskConfiguration>("OSDiskConfiguration");
}
set
{
this.SetValue("OSDiskConfiguration", value);
}
}

[DataMember(Name = "DataDiskConfigurations", EmitDefaultValue = false, Order = 2)]
public DataDiskConfigurationList DataDiskConfigurations
{
get
{
return this.GetValue<DataDiskConfigurationList>("DataDiskConfigurations");
}
set
{
this.SetValue("DataDiskConfigurations", value);
}
}
}
#endregion

#region RoleOperation
[DataContract(Namespace = Constants.ServiceManagementNS)]
public class RoleOperation : IExtensibleDataObject
Expand Down Expand Up @@ -2636,6 +2668,13 @@ public string IOType
set;
}

[DataMember(EmitDefaultValue = false, Order = 7)]
public int ResizedSizeInGB
{
get;
set;
}

public ExtensionDataObject ExtensionData { get; set; }
}

Expand Down Expand Up @@ -2684,6 +2723,13 @@ public string IOType
set;
}

[DataMember(EmitDefaultValue = false, Order = 6)]
public int ResizedSizeInGB
{
get;
set;
}

public ExtensionDataObject ExtensionData { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
using DataVirtualHardDisk = Microsoft.WindowsAzure.Commands.ServiceManagement.Model.DataVirtualHardDisk;
using OSVirtualHardDisk = Microsoft.WindowsAzure.Commands.ServiceManagement.Model.OSVirtualHardDisk;
using RoleInstance = Microsoft.WindowsAzure.Management.Compute.Models.RoleInstance;
using CSM = Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
using MCM = Microsoft.WindowsAzure.Management.Compute.Models;

namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Helpers
{
Expand Down Expand Up @@ -127,7 +129,7 @@ public static Collection<ConfigurationSet> MapConfigurationSets(IList<Management
return result;
}

public static IList<Management.Compute.Models.ConfigurationSet> MapConfigurationSets(Collection<ConfigurationSet> configurationSets)
public static IList<MCM.ConfigurationSet> MapConfigurationSets(Collection<ConfigurationSet> configurationSets)
{
var result = new Collection<Management.Compute.Models.ConfigurationSet>();
foreach (var networkConfig in configurationSets.OfType<NetworkConfigurationSet>())
Expand Down Expand Up @@ -187,6 +189,34 @@ public static string GetPublicIPName(Microsoft.WindowsAzure.Management.Compute.M
return name;
}

public static MCM.VMImageInput MapVMImageInput(CSM.VMImageInput vmImageInput)
{
var result = new MCM.VMImageInput();

if (vmImageInput.OSDiskConfiguration != null)
{
result.OSDiskConfiguration = new MCM.OSDiskConfiguration()
{
ResizedSizeInGB = vmImageInput.OSDiskConfiguration.ResizedSizeInGB
};
}

if (vmImageInput.DataDiskConfigurations != null)
{
result.DataDiskConfigurations = new Collection<MCM.DataDiskConfiguration>();
foreach (var dataDiskConfig in vmImageInput.DataDiskConfigurations)
{
result.DataDiskConfigurations.Add(
new MCM.DataDiskConfiguration()
{
DiskName = dataDiskConfig.Name,
ResizedSizeInGB = dataDiskConfig.ResizedSizeInGB
});
}
}
return result;
}

public static string ConvertCustomDataFileToBase64(string fileName)
{
byte[] bytes = new byte[3 * 4096]; // Make buffer be a factor of 3 for encoding correctly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,109 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS
[Cmdlet(VerbsCommon.Set, "AzureDataDisk"), OutputType(typeof(IPersistentVM))]
public class SetAzureDataDiskCommand : VirtualMachineConfigurationCmdletBase
{
[Parameter(Position = 0, Mandatory = true, HelpMessage = "Controls the platform caching behavior of data disk blob for read 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 efficiency.")]
[ValidateSet("None", "ReadOnly", "ReadWrite", IgnoreCase = true)]
public string HostCaching
{
get;
set;
}

[Parameter(Position = 1, Mandatory = true, HelpMessage = "Numerical value that defines the slot where the data drive will be mounted in the virtual machine.")]
[Parameter(Position = 1,
ParameterSetName = NoResizeParameteSet,
Mandatory = true,
HelpMessage = "Numerical value that defines the slot where the data drive will be mounted in the virtual machine.")]
[ValidateNotNullOrEmpty]
public int LUN
{
get;
set;
}

internal void ExecuteCommand()
[Parameter(Position = 3,
ParameterSetName = ResizeParameterSet,
Mandatory = true,
ValueFromPipelineByPropertyName = false,
HelpMessage = "The Name of the DataDiskConfiguration being referenced to")]
[ValidateNotNullOrEmpty]
public string DiskName
{
var dataDisks = GetDataDisks();
var dataDisk = dataDisks.SingleOrDefault(disk => disk.Lun == LUN);
get;
set;
}

[Parameter(Position = 4,
ParameterSetName = ResizeParameterSet,
Mandatory = true,
ValueFromPipelineByPropertyName = false,
HelpMessage = "Resize the new data disk to a larger size.")]
[ValidateNotNullOrEmpty]
public int ResizedSizeInGB
{
get;
set;
}

if (dataDisk == null)
internal void ExecuteCommand()
{
if (this.ParameterSetName == NoResizeParameteSet)
{
ThrowTerminatingError(
new ErrorRecord(
new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.DataDiskNotAssignedForVM, this.LUN)),
string.Empty,
ErrorCategory.InvalidData,
null));
var dataDisks = GetDataDisks();
var dataDisk = dataDisks.SingleOrDefault(disk => disk.Lun == LUN);

if (dataDisk == null)
{
ThrowTerminatingError(
new ErrorRecord(
new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.DataDiskNotAssignedForVM, this.LUN)),
string.Empty,
ErrorCategory.InvalidData,
null));
}

dataDisk.HostCaching = HostCaching;
}
else
{
PersistentVM role = VM.GetInstance();

dataDisk.HostCaching = HostCaching;
if (role.VMImageInput == null)
{
role.VMImageInput = new VMImageInput();
}

if (role.VMImageInput.DataDiskConfigurations == null)
{
role.VMImageInput.DataDiskConfigurations = new DataDiskConfigurationList();
};

bool diskNameAlreadyExist = false;

foreach (var dataDiskConfig in role.VMImageInput.DataDiskConfigurations)
{
if (string.Equals(dataDiskConfig.Name, this.DiskName, StringComparison.OrdinalIgnoreCase))
{
dataDiskConfig.ResizedSizeInGB = this.ResizedSizeInGB;
diskNameAlreadyExist = true;
}
}

if (! diskNameAlreadyExist)
{
role.VMImageInput.DataDiskConfigurations.Add(
new DataDiskConfiguration()
{
Name = this.DiskName,
ResizedSizeInGB = this.ResizedSizeInGB,
});
}
}

WriteObject(VM, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public int ResizedSizeInGB

internal void ExecuteCommand()
{
var role = VM.GetInstance();
var role = VM.GetInstance();

if (role.OSVirtualHardDisk == null)
{
Expand All @@ -61,11 +61,22 @@ internal void ExecuteCommand()
null));
}

OSVirtualHardDisk disk = role.OSVirtualHardDisk;
disk.HostCaching = HostCaching;
role.OSVirtualHardDisk.HostCaching = HostCaching;
if (this.ParameterSetName.Equals(ResizeParameterSet))
{
disk.ResizedSizeInGB = this.ResizedSizeInGB;
role.OSVirtualHardDisk.ResizedSizeInGB = this.ResizedSizeInGB;

if (role.VMImageInput == null)
{
role.VMImageInput = new VMImageInput();
}

if (role.VMImageInput.OSDiskConfiguration == null)
{
role.VMImageInput.OSDiskConfiguration = new OSDiskConfiguration();
};

role.VMImageInput.OSDiskConfiguration.ResizedSizeInGB = this.ResizedSizeInGB;
}

WriteObject(VM, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ private Management.Compute.Models.Role CreatePersistentVMRole(Tuple<Model.Persis
ProvisionGuestAgent = persistentVM.ProvisionGuestAgent,
ResourceExtensionReferences = persistentVM.ProvisionGuestAgent != null && persistentVM.ProvisionGuestAgent.Value ? Mapper.Map<List<ResourceExtensionReference>>(persistentVM.ResourceExtensionReferences) : null,
VMImageName = isVMImage ? persistentVM.OSVirtualHardDisk.SourceImageName : null,
MediaLocation = isVMImage ? persistentVM.OSVirtualHardDisk.MediaLink : null
MediaLocation = isVMImage ? persistentVM.OSVirtualHardDisk.MediaLink : null,
VMImageInput = isVMImage ? PersistentVMHelper.MapVMImageInput(persistentVM.VMImageInput) : null
};

if (result.OSVirtualHardDisk != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22489,8 +22489,44 @@ C:\PS&gt; Get-AzureVM -ServiceName &quot;MyService&quot; -Name &quot;MyVM&quot;
<command:parameterValue required="true" variableLength="false">IPersistentVM</command:parameterValue>
</command:parameter>
</command:syntaxItem>
<command:syntaxItem>
<maml:name>Set-AzureDataDisk</maml:name>
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1">
<maml:name>DiskName</maml:name>
<maml:description>
<maml:para>The Name of the DataDiskConfiguration being referenced to.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
</command:parameter>
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2">
<maml:name>ResizedSizeInGB</maml:name>
<maml:description>
<maml:para>Resize the new data disk to a larger size.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">int</command:parameterValue>
</command:parameter>
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="named">
<maml:name>VM</maml:name>
<maml:description>
<maml:para>The virtual machine where the data disk is mounted.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">IPersistentVM</command:parameterValue>
</command:parameter>
</command:syntaxItem>
</command:syntax>
<command:parameters>
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1">
<maml:name>DiskName</maml:name>
<maml:description>
<maml:para>The Name of the DataDiskConfiguration being referenced to.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
<dev:type>
<maml:name>string</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="0">
<maml:name>HostCaching</maml:name>
<maml:description>
Expand All @@ -22515,6 +22551,18 @@ C:\PS&gt; Get-AzureVM -ServiceName &quot;MyService&quot; -Name &quot;MyVM&quot;
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2">
<maml:name>ResizedSizeInGB</maml:name>
<maml:description>
<maml:para>Resize the new data disk to a larger size.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">int</command:parameterValue>
<dev:type>
<maml:name>int</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="named">
<maml:name>VM</maml:name>
<maml:description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public Collection<DataVirtualHardDisk> DataVirtualHardDisksToBeDeleted
set;
}

public VMImageInput VMImageInput
{
get;
set;
}

public PersistentVM GetInstance()
{
return this;
Expand Down