Skip to content

Commit cc655ce

Browse files
committed
Add-AzureRmVmssVMDataDisk and Remove-AzureRmVmssVMDataDisk
1 parent 0410718 commit cc655ce

File tree

15 files changed

+535
-12
lines changed

15 files changed

+535
-12
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,8 +1828,18 @@ function Test-VirtualMachineScaleSetVMUpdate
18281828
| New-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname0;
18291829
$disk0 = Get-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname0;
18301830

1831+
$vmssVM = Add-AzureRmVmssVMDataDisk -VirtualMachineScaleSetVM $vmssVMs[0] -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -CreateOption Attach -StorageAccountType Standard_LRS -ManagedDiskId $disk0.Id;
1832+
$vmssVM = Add-AzureRmVmssVMDataDisk -VirtualMachineScaleSetVM $vmssVM -Caching 'ReadOnly' -DiskSizeInGB 100 -Lun 0 -CreateOption Attach -StorageAccountType Standard_LRS -ManagedDiskId $disk0.Id;
1833+
Assert-AreEqual 2 $vmssVM.StorageProfile.DataDisks.Count;
1834+
1835+
$vmssVM = Remove-AzureRmVmssVMDataDisk -VirtualMachineScaleSetVM $vmssVM -Lun 1;
1836+
Assert-AreEqual 1 $vmssVM.StorageProfile.DataDisks.Count;
1837+
1838+
$vmssVM = Remove-AzureRmVmssVMDataDisk -VirtualMachineScaleSetVM $vmssVM -Lun 0;
1839+
Assert-Null $vmssVM.StorageProfile.DataDisks;
1840+
18311841
$result = $vmssVMs[0] `
1832-
| Add-AzureRmVmDataDisk -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -CreateOption Attach -StorageAccountType Standard_LRS -ManagedDiskId $disk0.Id `
1842+
| Add-AzureRmVmssVMDataDisk -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -CreateOption Attach -StorageAccountType Standard_LRS -ManagedDiskId $disk0.Id `
18331843
| Update-AzureRmVmssVM;
18341844

18351845
$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;

src/ResourceManager/Compute/Commands.Compute/Az.Compute.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ CmdletsToExport = 'Remove-AzAvailabilitySet', 'Get-AzAvailabilitySet',
181181
'New-AzGalleryImageDefinition', 'Update-AzGalleryImageDefinition',
182182
'Get-AzGalleryImageDefinition', 'Remove-AzGalleryImageDefinition',
183183
'New-AzGalleryImageVersion', 'Update-AzGalleryImageVersion',
184-
'Get-AzGalleryImageVersion', 'Remove-AzGalleryImageVersion'
184+
'Get-AzGalleryImageVersion', 'Remove-AzGalleryImageVersion',
185+
'Add-AzVmssVMDataDisk', 'Remove-AzVmssVMDataDisk'
185186

186187
# Variables to export from this module
187188
# VariablesToExport = @()

src/ResourceManager/Compute/Commands.Compute/AzureRM.Compute.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ CmdletsToExport = 'Remove-AzureRmAvailabilitySet', 'Get-AzureRmAvailabilitySet',
181181
'New-AzureRmGalleryImageDefinition', 'Update-AzureRmGalleryImageDefinition',
182182
'Get-AzureRmGalleryImageDefinition', 'Remove-AzureRmGalleryImageDefinition',
183183
'New-AzureRmGalleryImageVersion', 'Update-AzureRmGalleryImageVersion',
184-
'Get-AzureRmGalleryImageVersion', 'Remove-AzureRmGalleryImageVersion'
184+
'Get-AzureRmGalleryImageVersion', 'Remove-AzureRmGalleryImageVersion',
185+
'Add-AzureRmVmssVMDataDisk', 'Remove-AzureRmVmssVMDataDisk'
185186

186187
# Variables to export from this module
187188
# VariablesToExport = @()

src/ResourceManager/Compute/Commands.Compute/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
- Additional information about change #1
2020
-->
2121
## Current Release
22+
* Add Add-AzureRmVmssVMDataDisk and Remove-AzureRmVmssVMDataDisk cmdlets
23+
* Get-AzureRmVMImage shows AutomaticOSUpgradeProperties
2224

2325
## Version 5.7.2
2426
* Add EnableUltraSSD switch parameter to New-AzureRmVMConfiig and New-AzureRmVmssConfig.

src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public static class HelpMessages
4646
public const string VMManagedDiskId = "The virtual machine managed disk's Id.";
4747
public const string VMManagedDiskAccountType = "The virtual machine managed disk's account type.";
4848

49+
public const string VmssVMDataDiskCaching = "The virtual machine scale set VM data disk's caching.";
50+
public const string VmssVMDataDiskSizeInGB = "The virtual machine scale set VM data disk's size in GB.";
51+
public const string VmssVMDataDiskLun = "The virtual machine scale set VM data disk's Lun.";
52+
public const string VmssVMDataDiskCreateOption = "The virtual machine scale set VM data disk's create option.";
53+
public const string VmssVMManagedDiskId = "The virtual machine scale set VM managed disk's Id.";
54+
public const string VmssVMManagedDiskAccountType = "The virtual scale set VM machine managed disk's account type.";
55+
4956
public const string VMNetworkInterfaceName = "The virtual machine network interface's name.";
5057
public const string VMNetworkInterfaceID = "The virtual machine network interface's ID.";
5158
public const string VMPublicIPAddressName = "The virtual machine public IP address's name.";

src/ResourceManager/Compute/Commands.Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssConfigCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ private void Run()
344344
vVirtualMachineProfile.StorageProfile = this.StorageProfile;
345345
}
346346

347-
if (this.EnableUltraSSD.IsPresent)
347+
if (this.EnableUltraSSD.IsPresent)
348348
{
349349
if (vVirtualMachineProfile == null)
350350
{
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.Compute.Automation.Models;
18+
using Microsoft.Azure.Commands.Compute.Common;
19+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
20+
using Microsoft.Azure.Management.Compute.Models;
21+
22+
namespace Microsoft.Azure.Commands.Compute.Automation
23+
{
24+
[Cmdlet(VerbsCommon.Add, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssVMDataDisk")]
25+
[OutputType(typeof (PSVirtualMachineScaleSetVM))]
26+
public class AddAzureRmVmssVMDataDiskCommand : ComputeClientBaseCmdlet
27+
{
28+
[Parameter(
29+
Mandatory = true,
30+
Position = 0,
31+
ValueFromPipeline = true,
32+
HelpMessage = HelpMessages.VmssVMProfile)]
33+
[ValidateNotNullOrEmpty]
34+
public PSVirtualMachineScaleSetVM VirtualMachineScaleSetVM { get; set; }
35+
36+
[Parameter(
37+
Mandatory = true,
38+
Position = 1,
39+
ValueFromPipelineByPropertyName = true,
40+
HelpMessage = HelpMessages.VmssVMDataDiskLun)]
41+
[ValidateNotNullOrEmpty]
42+
public int Lun { get; set; }
43+
44+
[Parameter(
45+
Mandatory = true,
46+
Position = 2,
47+
ValueFromPipelineByPropertyName = true,
48+
HelpMessage = HelpMessages.VmssVMDataDiskCreateOption)]
49+
[PSArgumentCompleter("Attach", "Empty", "FromImage")]
50+
public string CreateOption { get; set; }
51+
52+
[Parameter(
53+
Mandatory = true,
54+
Position = 3,
55+
ValueFromPipelineByPropertyName = true,
56+
HelpMessage = HelpMessages.VmssVMManagedDiskId)]
57+
[ValidateNotNullOrEmpty]
58+
public string ManagedDiskId { get; set; }
59+
60+
[Parameter(
61+
ValueFromPipelineByPropertyName = true,
62+
HelpMessage = HelpMessages.VmssVMManagedDiskAccountType)]
63+
[ValidateNotNullOrEmpty]
64+
[PSArgumentCompleter("Standard_LRS", "Premium_LRS", "StandardSSD_LRS", "UltraSSD_LRS")]
65+
public string StorageAccountType { get; set; }
66+
67+
[Parameter(
68+
ValueFromPipelineByPropertyName = true,
69+
HelpMessage = HelpMessages.VmssVMDataDiskCaching)]
70+
public CachingTypes Caching { get; set; }
71+
72+
[Parameter(
73+
ValueFromPipelineByPropertyName = true,
74+
HelpMessage = HelpMessages.VmssVMDataDiskSizeInGB)]
75+
public int DiskSizeInGB { get; set; }
76+
77+
[Parameter(
78+
ValueFromPipelineByPropertyName = false)]
79+
public SwitchParameter WriteAccelerator { get; set; }
80+
81+
public override void ExecuteCmdlet()
82+
{
83+
var storageProfile = this.VirtualMachineScaleSetVM.StorageProfile;
84+
85+
if (storageProfile == null)
86+
{
87+
storageProfile = new StorageProfile();
88+
}
89+
90+
if (storageProfile.DataDisks == null)
91+
{
92+
storageProfile.DataDisks = new List<DataDisk>();
93+
}
94+
95+
storageProfile.DataDisks.Add(new DataDisk
96+
{
97+
Caching = this.MyInvocation.BoundParameters.ContainsKey("Caching") ? this.Caching : (CachingTypes?)null,
98+
DiskSizeGB = this.MyInvocation.BoundParameters.ContainsKey("DiskSizeInGB") ? this.DiskSizeInGB: (int?)null,
99+
Lun = this.Lun,
100+
CreateOption = this.CreateOption,
101+
ManagedDisk = SetManagedDisk(this.ManagedDiskId, this.StorageAccountType),
102+
WriteAcceleratorEnabled = this.WriteAccelerator.IsPresent
103+
});
104+
105+
this.VirtualMachineScaleSetVM.StorageProfile = storageProfile;
106+
WriteObject(this.VirtualMachineScaleSetVM);
107+
}
108+
}
109+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Linq;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.Compute.Automation.Models;
18+
using Microsoft.Azure.Commands.Compute.Common;
19+
20+
namespace Microsoft.Azure.Commands.Compute.Automation
21+
{
22+
[Cmdlet(VerbsCommon.Remove, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssVMDataDisk")]
23+
[OutputType(typeof(PSVirtualMachineScaleSetVM))]
24+
public class RemoveAzureRmVmssVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
25+
{
26+
[Parameter(
27+
Mandatory = true,
28+
Position = 0,
29+
ValueFromPipeline = true,
30+
HelpMessage = HelpMessages.VmssVMProfile)]
31+
[ValidateNotNullOrEmpty]
32+
public PSVirtualMachineScaleSetVM VirtualMachineScaleSetVM { get; set; }
33+
34+
[Parameter(
35+
Mandatory = true,
36+
Position = 1,
37+
ValueFromPipelineByPropertyName = false,
38+
HelpMessage = HelpMessages.VmssVMDataDiskLun)]
39+
[ValidateNotNullOrEmpty]
40+
public int Lun { get; set; }
41+
42+
public override void ExecuteCmdlet()
43+
{
44+
var storageProfile = this.VirtualMachineScaleSetVM.StorageProfile;
45+
46+
if (storageProfile != null && storageProfile.DataDisks != null)
47+
{
48+
var disks = storageProfile.DataDisks.ToList();
49+
disks.RemoveAll(d => d.Lun == this.Lun);
50+
51+
if (disks.Count == 0)
52+
{
53+
storageProfile.DataDisks = null;
54+
}
55+
else
56+
{
57+
storageProfile.DataDisks = disks;
58+
}
59+
}
60+
61+
this.VirtualMachineScaleSetVM.StorageProfile = storageProfile;
62+
WriteObject(this.VirtualMachineScaleSetVM);
63+
}
64+
}
65+
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/AddAzureVMDataDiskCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
1516
using System.Collections.Generic;
1617
using System.Management.Automation;
1718
using Microsoft.Azure.Commands.Compute.Automation.Models;
@@ -234,6 +235,8 @@ public override void ExecuteCmdlet()
234235
}
235236
else
236237
{
238+
WriteWarning("VirtualMachineScaleSetVM parameter will be deprecated. Use Add-AzureRmVmssVMDataDisk instead.");
239+
237240
var storageProfile = this.VirtualMachineScaleSetVM.StorageProfile;
238241

239242
if (storageProfile == null)

0 commit comments

Comments
 (0)