Skip to content

Commit bcf0445

Browse files
committed
Merge pull request #14 from hyonholee/dev
Dev
2 parents 6df9a7d + 393bfe6 commit bcf0445

File tree

7 files changed

+232
-19
lines changed

7 files changed

+232
-19
lines changed

src/Common/Commands.Common/ServiceManagementTypes.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,38 @@ public int? ResizedSizeInGB
16311631
}
16321632
#endregion
16331633

1634+
#region VMImageInput
1635+
[DataContract(Namespace = Constants.ServiceManagementNS)]
1636+
public class VMImageInput : Mergable<VMImageInput>
1637+
{
1638+
[DataMember(Name = "OSDiskConfiguration", EmitDefaultValue = false, Order = 1)]
1639+
public OSDiskConfiguration OSDiskConfiguration
1640+
{
1641+
get
1642+
{
1643+
return this.GetValue<OSDiskConfiguration>("OSDiskConfiguration");
1644+
}
1645+
set
1646+
{
1647+
this.SetValue("OSDiskConfiguration", value);
1648+
}
1649+
}
1650+
1651+
[DataMember(Name = "DataDiskConfigurations", EmitDefaultValue = false, Order = 2)]
1652+
public DataDiskConfigurationList DataDiskConfigurations
1653+
{
1654+
get
1655+
{
1656+
return this.GetValue<DataDiskConfigurationList>("DataDiskConfigurations");
1657+
}
1658+
set
1659+
{
1660+
this.SetValue("DataDiskConfigurations", value);
1661+
}
1662+
}
1663+
}
1664+
#endregion
1665+
16341666
#region RoleOperation
16351667
[DataContract(Namespace = Constants.ServiceManagementNS)]
16361668
public class RoleOperation : IExtensibleDataObject
@@ -2636,6 +2668,13 @@ public string IOType
26362668
set;
26372669
}
26382670

2671+
[DataMember(EmitDefaultValue = false, Order = 7)]
2672+
public int ResizedSizeInGB
2673+
{
2674+
get;
2675+
set;
2676+
}
2677+
26392678
public ExtensionDataObject ExtensionData { get; set; }
26402679
}
26412680

@@ -2684,6 +2723,13 @@ public string IOType
26842723
set;
26852724
}
26862725

2726+
[DataMember(EmitDefaultValue = false, Order = 6)]
2727+
public int ResizedSizeInGB
2728+
{
2729+
get;
2730+
set;
2731+
}
2732+
26872733
public ExtensionDataObject ExtensionData { get; set; }
26882734
}
26892735

src/ServiceManagement/Compute/Commands.ServiceManagement/Helpers/PersistentVMHelper.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
using DataVirtualHardDisk = Microsoft.WindowsAzure.Commands.ServiceManagement.Model.DataVirtualHardDisk;
2929
using OSVirtualHardDisk = Microsoft.WindowsAzure.Commands.ServiceManagement.Model.OSVirtualHardDisk;
3030
using RoleInstance = Microsoft.WindowsAzure.Management.Compute.Models.RoleInstance;
31+
using CSM = Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
32+
using MCM = Microsoft.WindowsAzure.Management.Compute.Models;
3133

3234
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Helpers
3335
{
@@ -127,7 +129,7 @@ public static Collection<ConfigurationSet> MapConfigurationSets(IList<Management
127129
return result;
128130
}
129131

130-
public static IList<Management.Compute.Models.ConfigurationSet> MapConfigurationSets(Collection<ConfigurationSet> configurationSets)
132+
public static IList<MCM.ConfigurationSet> MapConfigurationSets(Collection<ConfigurationSet> configurationSets)
131133
{
132134
var result = new Collection<Management.Compute.Models.ConfigurationSet>();
133135
foreach (var networkConfig in configurationSets.OfType<NetworkConfigurationSet>())
@@ -187,6 +189,34 @@ public static string GetPublicIPName(Microsoft.WindowsAzure.Management.Compute.M
187189
return name;
188190
}
189191

192+
public static MCM.VMImageInput MapVMImageInput(CSM.VMImageInput vmImageInput)
193+
{
194+
var result = new MCM.VMImageInput();
195+
196+
if (vmImageInput.OSDiskConfiguration != null)
197+
{
198+
result.OSDiskConfiguration = new MCM.OSDiskConfiguration()
199+
{
200+
ResizedSizeInGB = vmImageInput.OSDiskConfiguration.ResizedSizeInGB
201+
};
202+
}
203+
204+
if (vmImageInput.DataDiskConfigurations != null)
205+
{
206+
result.DataDiskConfigurations = new Collection<MCM.DataDiskConfiguration>();
207+
foreach (var dataDiskConfig in vmImageInput.DataDiskConfigurations)
208+
{
209+
result.DataDiskConfigurations.Add(
210+
new MCM.DataDiskConfiguration()
211+
{
212+
DiskName = dataDiskConfig.Name,
213+
ResizedSizeInGB = dataDiskConfig.ResizedSizeInGB
214+
});
215+
}
216+
}
217+
return result;
218+
}
219+
190220
public static string ConvertCustomDataFileToBase64(string fileName)
191221
{
192222
byte[] bytes = new byte[3 * 4096]; // Make buffer be a factor of 3 for encoding correctly

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

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,109 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS
2626
[Cmdlet(VerbsCommon.Set, "AzureDataDisk"), OutputType(typeof(IPersistentVM))]
2727
public class SetAzureDataDiskCommand : VirtualMachineConfigurationCmdletBase
2828
{
29-
[Parameter(Position = 0, Mandatory = true, HelpMessage = "Controls the platform caching behavior of data disk blob for read efficiency.")]
29+
private const string ResizeParameterSet = "Resize";
30+
private const string NoResizeParameteSet = "NoResize";
31+
32+
[Parameter(Position = 0,
33+
ParameterSetName = NoResizeParameteSet,
34+
Mandatory = true,
35+
HelpMessage = "Controls the platform caching behavior of data disk blob for read efficiency.")]
3036
[ValidateSet("None", "ReadOnly", "ReadWrite", IgnoreCase = true)]
3137
public string HostCaching
3238
{
3339
get;
3440
set;
3541
}
3642

37-
[Parameter(Position = 1, Mandatory = true, HelpMessage = "Numerical value that defines the slot where the data drive will be mounted in the virtual machine.")]
43+
[Parameter(Position = 1,
44+
ParameterSetName = NoResizeParameteSet,
45+
Mandatory = true,
46+
HelpMessage = "Numerical value that defines the slot where the data drive will be mounted in the virtual machine.")]
3847
[ValidateNotNullOrEmpty]
3948
public int LUN
4049
{
4150
get;
4251
set;
4352
}
4453

45-
internal void ExecuteCommand()
54+
[Parameter(Position = 3,
55+
ParameterSetName = ResizeParameterSet,
56+
Mandatory = true,
57+
ValueFromPipelineByPropertyName = false,
58+
HelpMessage = "The Name of the DataDiskConfiguration being referenced to")]
59+
[ValidateNotNullOrEmpty]
60+
public string DiskName
4661
{
47-
var dataDisks = GetDataDisks();
48-
var dataDisk = dataDisks.SingleOrDefault(disk => disk.Lun == LUN);
62+
get;
63+
set;
64+
}
65+
66+
[Parameter(Position = 4,
67+
ParameterSetName = ResizeParameterSet,
68+
Mandatory = true,
69+
ValueFromPipelineByPropertyName = false,
70+
HelpMessage = "Resize the new data disk to a larger size.")]
71+
[ValidateNotNullOrEmpty]
72+
public int ResizedSizeInGB
73+
{
74+
get;
75+
set;
76+
}
4977

50-
if (dataDisk == null)
78+
internal void ExecuteCommand()
79+
{
80+
if (this.ParameterSetName == NoResizeParameteSet)
5181
{
52-
ThrowTerminatingError(
53-
new ErrorRecord(
54-
new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.DataDiskNotAssignedForVM, this.LUN)),
55-
string.Empty,
56-
ErrorCategory.InvalidData,
57-
null));
82+
var dataDisks = GetDataDisks();
83+
var dataDisk = dataDisks.SingleOrDefault(disk => disk.Lun == LUN);
84+
85+
if (dataDisk == null)
86+
{
87+
ThrowTerminatingError(
88+
new ErrorRecord(
89+
new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.DataDiskNotAssignedForVM, this.LUN)),
90+
string.Empty,
91+
ErrorCategory.InvalidData,
92+
null));
93+
}
94+
95+
dataDisk.HostCaching = HostCaching;
5896
}
97+
else
98+
{
99+
PersistentVM role = VM.GetInstance();
59100

60-
dataDisk.HostCaching = HostCaching;
101+
if (role.VMImageInput == null)
102+
{
103+
role.VMImageInput = new VMImageInput();
104+
}
105+
106+
if (role.VMImageInput.DataDiskConfigurations == null)
107+
{
108+
role.VMImageInput.DataDiskConfigurations = new DataDiskConfigurationList();
109+
};
110+
111+
bool diskNameAlreadyExist = false;
112+
113+
foreach (var dataDiskConfig in role.VMImageInput.DataDiskConfigurations)
114+
{
115+
if (string.Equals(dataDiskConfig.Name, this.DiskName, StringComparison.OrdinalIgnoreCase))
116+
{
117+
dataDiskConfig.ResizedSizeInGB = this.ResizedSizeInGB;
118+
diskNameAlreadyExist = true;
119+
}
120+
}
121+
122+
if (! diskNameAlreadyExist)
123+
{
124+
role.VMImageInput.DataDiskConfigurations.Add(
125+
new DataDiskConfiguration()
126+
{
127+
Name = this.DiskName,
128+
ResizedSizeInGB = this.ResizedSizeInGB,
129+
});
130+
}
131+
}
61132

62133
WriteObject(VM, true);
63134
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public int ResizedSizeInGB
4949

5050
internal void ExecuteCommand()
5151
{
52-
var role = VM.GetInstance();
52+
var role = VM.GetInstance();
5353

5454
if (role.OSVirtualHardDisk == null)
5555
{
@@ -61,11 +61,22 @@ internal void ExecuteCommand()
6161
null));
6262
}
6363

64-
OSVirtualHardDisk disk = role.OSVirtualHardDisk;
65-
disk.HostCaching = HostCaching;
64+
role.OSVirtualHardDisk.HostCaching = HostCaching;
6665
if (this.ParameterSetName.Equals(ResizeParameterSet))
6766
{
68-
disk.ResizedSizeInGB = this.ResizedSizeInGB;
67+
role.OSVirtualHardDisk.ResizedSizeInGB = this.ResizedSizeInGB;
68+
69+
if (role.VMImageInput == null)
70+
{
71+
role.VMImageInput = new VMImageInput();
72+
}
73+
74+
if (role.VMImageInput.OSDiskConfiguration == null)
75+
{
76+
role.VMImageInput.OSDiskConfiguration = new OSDiskConfiguration();
77+
};
78+
79+
role.VMImageInput.OSDiskConfiguration.ResizedSizeInGB = this.ResizedSizeInGB;
6980
}
7081

7182
WriteObject(VM, true);

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/NewAzureVM.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ private Management.Compute.Models.Role CreatePersistentVMRole(Tuple<Model.Persis
433433
ProvisionGuestAgent = persistentVM.ProvisionGuestAgent,
434434
ResourceExtensionReferences = persistentVM.ProvisionGuestAgent != null && persistentVM.ProvisionGuestAgent.Value ? Mapper.Map<List<ResourceExtensionReference>>(persistentVM.ResourceExtensionReferences) : null,
435435
VMImageName = isVMImage ? persistentVM.OSVirtualHardDisk.SourceImageName : null,
436-
MediaLocation = isVMImage ? persistentVM.OSVirtualHardDisk.MediaLink : null
436+
MediaLocation = isVMImage ? persistentVM.OSVirtualHardDisk.MediaLink : null,
437+
VMImageInput = isVMImage ? PersistentVMHelper.MapVMImageInput(persistentVM.VMImageInput) : null
437438
};
438439

439440
if (result.OSVirtualHardDisk != null)

src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22489,8 +22489,44 @@ C:\PS&gt; Get-AzureVM -ServiceName &quot;MyService&quot; -Name &quot;MyVM&quot;
2248922489
<command:parameterValue required="true" variableLength="false">IPersistentVM</command:parameterValue>
2249022490
</command:parameter>
2249122491
</command:syntaxItem>
22492+
<command:syntaxItem>
22493+
<maml:name>Set-AzureDataDisk</maml:name>
22494+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1">
22495+
<maml:name>DiskName</maml:name>
22496+
<maml:description>
22497+
<maml:para>The Name of the DataDiskConfiguration being referenced to.</maml:para>
22498+
</maml:description>
22499+
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
22500+
</command:parameter>
22501+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2">
22502+
<maml:name>ResizedSizeInGB</maml:name>
22503+
<maml:description>
22504+
<maml:para>Resize the new data disk to a larger size.</maml:para>
22505+
</maml:description>
22506+
<command:parameterValue required="true" variableLength="false">int</command:parameterValue>
22507+
</command:parameter>
22508+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="named">
22509+
<maml:name>VM</maml:name>
22510+
<maml:description>
22511+
<maml:para>The virtual machine where the data disk is mounted.</maml:para>
22512+
</maml:description>
22513+
<command:parameterValue required="true" variableLength="false">IPersistentVM</command:parameterValue>
22514+
</command:parameter>
22515+
</command:syntaxItem>
2249222516
</command:syntax>
2249322517
<command:parameters>
22518+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1">
22519+
<maml:name>DiskName</maml:name>
22520+
<maml:description>
22521+
<maml:para>The Name of the DataDiskConfiguration being referenced to.</maml:para>
22522+
</maml:description>
22523+
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
22524+
<dev:type>
22525+
<maml:name>string</maml:name>
22526+
<maml:uri/>
22527+
</dev:type>
22528+
<dev:defaultValue></dev:defaultValue>
22529+
</command:parameter>
2249422530
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="0">
2249522531
<maml:name>HostCaching</maml:name>
2249622532
<maml:description>
@@ -22515,6 +22551,18 @@ C:\PS&gt; Get-AzureVM -ServiceName &quot;MyService&quot; -Name &quot;MyVM&quot;
2251522551
</dev:type>
2251622552
<dev:defaultValue></dev:defaultValue>
2251722553
</command:parameter>
22554+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2">
22555+
<maml:name>ResizedSizeInGB</maml:name>
22556+
<maml:description>
22557+
<maml:para>Resize the new data disk to a larger size.</maml:para>
22558+
</maml:description>
22559+
<command:parameterValue required="true" variableLength="false">int</command:parameterValue>
22560+
<dev:type>
22561+
<maml:name>int</maml:name>
22562+
<maml:uri/>
22563+
</dev:type>
22564+
<dev:defaultValue></dev:defaultValue>
22565+
</command:parameter>
2251822566
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="named">
2251922567
<maml:name>VM</maml:name>
2252022568
<maml:description>

src/ServiceManagement/Compute/Commands.ServiceManagement/Model/PersistentVM.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ public Collection<DataVirtualHardDisk> DataVirtualHardDisksToBeDeleted
127127
set;
128128
}
129129

130+
public VMImageInput VMImageInput
131+
{
132+
get;
133+
set;
134+
}
135+
130136
public PersistentVM GetInstance()
131137
{
132138
return this;

0 commit comments

Comments
 (0)