diff --git a/src/Common/Commands.Common/ServiceManagementTypes.cs b/src/Common/Commands.Common/ServiceManagementTypes.cs index 72eca9b7c03c..d3746fc01154 100644 --- a/src/Common/Commands.Common/ServiceManagementTypes.cs +++ b/src/Common/Commands.Common/ServiceManagementTypes.cs @@ -1631,6 +1631,38 @@ public int? ResizedSizeInGB } #endregion + #region VMImageInput + [DataContract(Namespace = Constants.ServiceManagementNS)] + public class VMImageInput : Mergable + { + [DataMember(Name = "OSDiskConfiguration", EmitDefaultValue = false, Order = 1)] + public OSDiskConfiguration OSDiskConfiguration + { + get + { + return this.GetValue("OSDiskConfiguration"); + } + set + { + this.SetValue("OSDiskConfiguration", value); + } + } + + [DataMember(Name = "DataDiskConfigurations", EmitDefaultValue = false, Order = 2)] + public DataDiskConfigurationList DataDiskConfigurations + { + get + { + return this.GetValue("DataDiskConfigurations"); + } + set + { + this.SetValue("DataDiskConfigurations", value); + } + } + } + #endregion + #region RoleOperation [DataContract(Namespace = Constants.ServiceManagementNS)] public class RoleOperation : IExtensibleDataObject @@ -2636,6 +2668,13 @@ public string IOType set; } + [DataMember(EmitDefaultValue = false, Order = 7)] + public int ResizedSizeInGB + { + get; + set; + } + public ExtensionDataObject ExtensionData { get; set; } } @@ -2684,6 +2723,13 @@ public string IOType set; } + [DataMember(EmitDefaultValue = false, Order = 6)] + public int ResizedSizeInGB + { + get; + set; + } + public ExtensionDataObject ExtensionData { get; set; } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Helpers/PersistentVMHelper.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Helpers/PersistentVMHelper.cs index b868a0bc47bc..ee410fe55ff2 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Helpers/PersistentVMHelper.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Helpers/PersistentVMHelper.cs @@ -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 { @@ -127,7 +129,7 @@ public static Collection MapConfigurationSets(IList MapConfigurationSets(Collection configurationSets) + public static IList MapConfigurationSets(Collection configurationSets) { var result = new Collection(); foreach (var networkConfig in configurationSets.OfType()) @@ -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(); + 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 diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureDataDisk.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureDataDisk.cs index a98f4190d91d..58e36bbca734 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureDataDisk.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureDataDisk.cs @@ -26,7 +26,13 @@ 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 { @@ -34,7 +40,10 @@ public string HostCaching 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 { @@ -42,22 +51,84 @@ public int LUN 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); } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureOSDisk.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureOSDisk.cs index dc4ec64e39f0..cd6fe0940d48 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureOSDisk.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Disks/SetAzureOSDisk.cs @@ -49,7 +49,7 @@ public int ResizedSizeInGB internal void ExecuteCommand() { - var role = VM.GetInstance(); + var role = VM.GetInstance(); if (role.OSVirtualHardDisk == null) { @@ -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); diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/NewAzureVM.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/NewAzureVM.cs index f4a4d4f297c5..768c194f268e 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/NewAzureVM.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/NewAzureVM.cs @@ -433,7 +433,8 @@ private Management.Compute.Models.Role CreatePersistentVMRole(Tuple>(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) 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 4f18054c25e3..d6a25ac57bf5 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 @@ -22489,8 +22489,44 @@ C:\PS> Get-AzureVM -ServiceName "MyService" -Name "MyVM" IPersistentVM + + Set-AzureDataDisk + + DiskName + + The Name of the DataDiskConfiguration being referenced to. + + string + + + ResizedSizeInGB + + Resize the new data disk to a larger size. + + int + + + VM + + The virtual machine where the data disk is mounted. + + IPersistentVM + + + + DiskName + + The Name of the DataDiskConfiguration being referenced to. + + string + + string + + + + HostCaching @@ -22515,6 +22551,18 @@ C:\PS> Get-AzureVM -ServiceName "MyService" -Name "MyVM" + + ResizedSizeInGB + + Resize the new data disk to a larger size. + + int + + int + + + + VM diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/PersistentVM.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/PersistentVM.cs index 7f1ba15db88e..4dc3feb05afb 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/PersistentVM.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/PersistentVM.cs @@ -127,6 +127,12 @@ public Collection DataVirtualHardDisksToBeDeleted set; } + public VMImageInput VMImageInput + { + get; + set; + } + public PersistentVM GetInstance() { return this;