Skip to content

Commit 1d1c780

Browse files
committed
Add StorageAccountType parameter to Set-AzureRmVMDataDisk
1 parent 4eca069 commit 1d1c780

File tree

8 files changed

+74
-10
lines changed

8 files changed

+74
-10
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,23 @@ function Test-VirtualMachineProfile
5757
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/os.vhd";
5858
$dataDiskVhdUri1 = "https://$stoname.blob.core.windows.net/test/data1.vhd";
5959
$dataDiskVhdUri2 = "https://$stoname.blob.core.windows.net/test/data2.vhd";
60-
$dataDiskVhdUri3 = "https://$stoname.blob.core.windows.net/test/data3.vhd";
6160

6261
$p = Set-AzureRmVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption Empty;
6362

6463
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
6564
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $dataDiskVhdUri2 -CreateOption Empty;
66-
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk3' -Caching 'ReadOnly' -DiskSizeInGB $null -Lun 2 -VhdUri $dataDiskVhdUri3 -CreateOption Empty;
65+
66+
# Managed data disk setting
67+
$managedDataDiskId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rggroup/providers/Microsoft.Compute/disks/dataDisk";
68+
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk3' -Caching 'ReadOnly' -DiskSizeInGB $null -Lun 2 -CreateOption Empty -ManagedDiskId $managedDataDiskId -StorageAccountType StandardLRS;
69+
Assert-AreEqual $managedDataDiskId $p.StorageProfile.DataDisks[2].ManagedDisk.Id;
70+
Assert-AreEqual "StandardLRS" $p.StorageProfile.DataDisks[2].ManagedDisk.StorageAccountType;
6771
Assert-Null $p.StorageProfile.DataDisks[2].DiskSizeGB;
72+
73+
$p = Set-AzureRmVMDataDisk -VM $p -Name 'testDataDisk3' -StorageAccountType PremiumLRS;
74+
Assert-AreEqual $managedDataDiskId $p.StorageProfile.DataDisks[2].ManagedDisk.Id;
75+
Assert-AreEqual "PremiumLRS" $p.StorageProfile.DataDisks[2].ManagedDisk.StorageAccountType;
76+
6877
$p = Remove-AzureRmVMDataDisk -VM $p -Name 'testDataDisk3';
6978

7079
Assert-AreEqual $p.StorageProfile.OSDisk.Caching $osDiskCaching;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public static class HelpMessages
4242
public const string VMDataDiskLun = "The virtual machine data disk's Lun.";
4343
public const string VMDataDiskCreateOption = "The virtual machine data disk's create option.";
4444

45+
public const string VMManagedDiskId = "The virtual machine managed disk's Id.";
46+
public const string VMManagedDiskAccountType = "The virtual machine managed disk's account type.";
47+
4548
public const string VMNetworkInterfaceName = "The virtual machine network interface's name.";
4649
public const string VMNetworkInterfaceID = "The virtual machine network interface's ID.";
4750
public const string VMPublicIPAddressName = "The virtual machine public IP address's name.";

src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,4 +565,7 @@ The file needs to be a PowerShell script (.ps1 or .psm1) or a ZIP archive (.zip)
565565
<data name="DiagnosticsExtensionMismatchStorageAccountName" xml:space="preserve">
566566
<value>Storage account names provided in public and private configs do not match.</value>
567567
</data>
568+
<data name="NotManagedDisk" xml:space="preserve">
569+
<value>The given disk is not a managed disk.</value>
570+
</data>
568571
</root>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ public class AddAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManage
9393

9494
[Parameter(
9595
Position = 8,
96-
ValueFromPipelineByPropertyName = true)]
96+
ValueFromPipelineByPropertyName = true,
97+
HelpMessage = HelpMessages.VMManagedDiskId)]
9798
[ValidateNotNullOrEmpty]
9899
public string ManagedDiskId { get; set; }
99100

100101
[Parameter(
101102
Position = 9,
102-
ValueFromPipelineByPropertyName = true)]
103+
ValueFromPipelineByPropertyName = true,
104+
HelpMessage = HelpMessages.VMManagedDiskAccountType)]
103105
[ValidateNotNullOrEmpty]
104106
public StorageAccountTypes? StorageAccountType { get; set; }
105107

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ public class SetAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManage
7575
[AllowNull]
7676
public int? DiskSizeInGB { get; set; }
7777

78+
[Parameter(
79+
Mandatory = false,
80+
ValueFromPipelineByPropertyName = true,
81+
HelpMessage = HelpMessages.VMManagedDiskAccountType)]
82+
[ValidateNotNullOrEmpty]
83+
public StorageAccountTypes? StorageAccountType { get; set; }
84+
7885
public override void ExecuteCmdlet()
7986
{
8087
var storageProfile = this.VM.StorageProfile;
@@ -102,6 +109,22 @@ public override void ExecuteCmdlet()
102109
{
103110
dataDisk.DiskSizeGB = this.DiskSizeInGB;
104111
}
112+
if (this.StorageAccountType != null)
113+
{
114+
if (dataDisk.ManagedDisk == null)
115+
{
116+
ThrowTerminatingError
117+
(new ErrorRecord(
118+
new InvalidOperationException(Properties.Resources.NotManagedDisk),
119+
string.Empty,
120+
ErrorCategory.InvalidData,
121+
null));
122+
}
123+
else
124+
{
125+
dataDisk.ManagedDisk.StorageAccountType = this.StorageAccountType;
126+
}
127+
}
105128
}
106129

107130
this.VM.StorageProfile = storageProfile;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,15 @@ public class SetAzureVMOSDiskCommand : Microsoft.Azure.Commands.ResourceManager.
172172

173173
[Parameter(
174174
Mandatory = false,
175-
ValueFromPipelineByPropertyName = true)]
175+
ValueFromPipelineByPropertyName = true,
176+
HelpMessage = HelpMessages.VMManagedDiskId)]
176177
[ValidateNotNullOrEmpty]
177178
public string ManagedDiskId { get; set; }
178179

179180
[Parameter(
180181
Mandatory = false,
181-
ValueFromPipelineByPropertyName = true)]
182+
ValueFromPipelineByPropertyName = true,
183+
HelpMessage = HelpMessages.VMManagedDiskAccountType)]
182184
[ValidateNotNullOrEmpty]
183185
public StorageAccountTypes? StorageAccountType { get; set; }
184186

src/ResourceManager/Compute/Commands.Compute/help/Set-AzureRMVMDataDisk.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Modifies properties of a virtual machine data disk.
1515
### ChangeWithName
1616
```
1717
Set-AzureRmVMDataDisk [-VM] <PSVirtualMachine> [-Name] <String> [[-Caching] <CachingTypes>]
18-
[[-DiskSizeInGB] <Int32>] [<CommonParameters>]
18+
[[-DiskSizeInGB] <Int32>] [-StorageAccountType <StorageAccountTypes>] [<CommonParameters>]
1919
```
2020

2121
### ChangeWithLun
2222
```
2323
Set-AzureRmVMDataDisk [-VM] <PSVirtualMachine> [-Lun] <Int32> [[-Caching] <CachingTypes>]
24-
[[-DiskSizeInGB] <Int32>] [<CommonParameters>]
24+
[[-DiskSizeInGB] <Int32>] [-StorageAccountType <StorageAccountTypes>] [<CommonParameters>]
2525
```
2626

2727
## DESCRIPTION
@@ -114,6 +114,20 @@ Accept pipeline input: True (ByPropertyName)
114114
Accept wildcard characters: False
115115
```
116116
117+
### -StorageAccountType
118+
The virtual machine managed disk's account type.```yaml
119+
Type: StorageAccountTypes
120+
Parameter Sets: (All)
121+
Aliases:
122+
Accepted values: StandardLRS, PremiumLRS
123+
124+
Required: False
125+
Position: Named
126+
Default value: None
127+
Accept pipeline input: True (ByPropertyName)
128+
Accept wildcard characters: False
129+
```
130+
117131
### -VM
118132
Specifies the virtual machine for which this cmdlet modifies a data disk.
119133
To obtain a virtual machine object, use the Get-AzureRmVM cmdlet.
@@ -136,7 +150,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
136150
## INPUTS
137151
138152
### PSVirtualMachine
139-
140153
Parameter 'VM' accepts value of type 'PSVirtualMachine' from the pipeline
141154
142155
## OUTPUTS

0 commit comments

Comments
 (0)