Skip to content

Commit e867fd0

Browse files
bluewwNoriZC
andauthored
[Compute] Add ElasticSanResourceId in New-AzSnapshotConfig, OptimizedForFrequentAttach New-AzDiskConfig (#23408)
* [Compute] support ElasticSanResourceId in New-AzSnapshotConfig * Add Test * Update the ElasticSanResourceId to mock one * [Compute] Add -OptimizedForFrequentAttach to cmdlet New-AzDiskConfig * Update src/Compute/Compute/ChangeLog.md Co-authored-by: NoriZC <[email protected]> --------- Co-authored-by: NoriZC <[email protected]>
1 parent 90f3196 commit e867fd0

File tree

10 files changed

+1598
-530
lines changed

10 files changed

+1598
-530
lines changed

src/Compute/Compute.Test/ScenarioTests/DiskRPTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,13 @@ public void TestNewDiskSecurityTypeDefaulting()
177177
{
178178
TestRunner.RunTestScript("Test-NewDiskSecurityTypeDefaulting");
179179
}
180+
181+
[Fact]
182+
[Trait(Category.AcceptanceType, Category.LiveOnly)]
183+
public void TestSnapshotConfigElasticSanResourceId()
184+
{
185+
TestRunner.RunTestScript("Test-SnapshotConfigElasticSanResourceId");
186+
}
187+
180188
}
181189
}

src/Compute/Compute.Test/ScenarioTests/DiskRPTests.ps1

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,11 +1101,12 @@ function Test-DiskConfigDiskAccessNetworkAccess
11011101
#Testing disk access
11021102
$diskAccess = New-AzDiskAccess -ResourceGroupName $rgname -Name "diskaccessname" -location $loc
11031103
$diskconfig = New-AzDiskConfig -Location $loc -SkuName 'Standard_LRS' -OsType 'Windows' `
1104-
-UploadSizeInBytes 35183298347520 -CreateOption 'Upload' -DiskAccessId $diskAccess.Id;
1104+
-UploadSizeInBytes 35183298347520 -CreateOption 'Upload' -DiskAccessId $diskAccess.Id -OptimizedForFrequentAttach $true;
11051105
New-AzDisk -ResourceGroupName $rgname -DiskName $diskname0 -Disk $diskconfig;
11061106
$disk = Get-AzDisk -ResourceGroupName $rgname -DiskName $diskname0;
11071107

11081108
Assert-AreEqual $diskAccess.Id $disk.DiskAccessId;
1109+
Assert-AreEqual $true $disk.OptimizedForFrequentAttach;
11091110

11101111
Remove-AzDisk -ResourceGroupName $rgname -DiskName $diskname0 -Force;
11111112

@@ -1735,4 +1736,59 @@ function Test-NewDiskSecurityTypeDefaulting
17351736
# Cleanup
17361737
Clean-ResourceGroup $rgname;
17371738
}
1739+
}
1740+
1741+
<#
1742+
.SYNOPSIS
1743+
Testing SnapshotConfig create with ElasticSanResourceId
1744+
#>
1745+
function Test-SnapshotConfigElasticSanResourceId
1746+
{
1747+
# Setup
1748+
$rgname = Get-ComputeTestResourceName;
1749+
$snapshotname = 'snapshot' + $rgname;
1750+
1751+
try
1752+
{
1753+
#
1754+
# Note: In order to record this test, you need to run the following commands to create ElasticSan volumn snapshot in a separate Powershell window.
1755+
#
1756+
# New-AzResourceGroup -Name $rgname -Location $loc -Force;
1757+
# New-AzElasticSan -ResourceGroupName $rgname -Name $ElasticSanName -BaseSizeTiB 1 -SkuName 'Premium_LRS' -Location $loc -ExtendedCapacitySizeTiB 3
1758+
# New-AzElasticSanVolumeGroup -ResourceGroupName $rgname -ElasticSanName $ElasticSanName -Name $VolumeGroupName -Encryption 'EncryptionAtRestWithPlatformKey' -ProtocolType 'Iscsi'
1759+
# $volumn = New-AzElasticSanVolume -ResourceGroupName $rgname -ElasticSanName $ElasticSanName -VolumeGroupName $VolumeGroupName -Name $volumnName -SizeGiB 100
1760+
# $volumnSnapshot = New-AzElasticSanVolumeSnapshot -ResourceGroupName $rgname -ElasticSanName $ElasticSanName -VolumeGroupName $VolumeGroupName -Name $volumnSnapshotName -CreationDataSourceId $volumn.Id
1761+
# $mockElasticSanVolumeSnapshotResourceId = $volumnSnapshot.Id
1762+
1763+
# Common
1764+
$loc = Get-Location "Microsoft.Compute" "snapshots" "France Central"
1765+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
1766+
1767+
$mockElasticSanVolumeSnapshotResourceId = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/ResourceGroup01/providers/Microsoft.ElasticSan/elasticSans/san1/volumeGroups/volumegroup1/snapshots/snapshot1"
1768+
1769+
# Config and create test
1770+
$snapshotconfig = New-AzSnapshotConfig -Location $loc -AccountType Standard_LRS -CreateOption CopyFromSanSnapshot -ElasticSanResourceId $mockElasticSanVolumeSnapshotResourceId -Incremental
1771+
Assert-AreEqual CopyFromSanSnapshot $snapshotconfig.CreationData.CreateOption
1772+
Assert-AreEqual $mockElasticSanVolumeSnapshotResourceId $snapshotconfig.CreationData.ElasticSanResourceId
1773+
1774+
$snapshot = New-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname -Snapshot $snapshotconfig
1775+
Assert-AreEqual CopyFromSanSnapshot $snapshot.CreationData.CreateOption
1776+
Assert-AreEqual $mockElasticSanVolumeSnapshotResourceId $snapshot.CreationData.ElasticSanResourceId
1777+
1778+
$snapshot = Get-AzSnapshot -ResourceGroupName $rgname
1779+
Assert-AreEqual CopyFromSanSnapshot $snapshot.CreationData.CreateOption
1780+
Assert-AreEqual $mockElasticSanVolumeSnapshotResourceId $snapshot.CreationData.ElasticSanResourceId
1781+
1782+
# Remove test
1783+
$job = Remove-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname -Force -AsJob;
1784+
$result = $job | Wait-Job;
1785+
Assert-AreEqual "Completed" $result.State;
1786+
$st = $job | Receive-Job;
1787+
Verify-PSOperationStatusResponse $st;
1788+
}
1789+
finally
1790+
{
1791+
# Cleanup
1792+
Clean-ResourceGroup $rgname
1793+
}
17381794
}

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DiskRPTests/TestDiskConfigDiskAccessNetworkAccess.json

Lines changed: 377 additions & 524 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DiskRPTests/TestSnapshotConfigElasticSanResourceId.json

Lines changed: 1078 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Added new parameter `-ElasticSanResourceId` to `New-AzSnapshotConfig` cmdlet.
24+
* Added new parameter `-OptimizedForFrequentAttach` to `New-AzDiskConfig` cmdlet.
2325
* Added new examples in `New-AzVM` and `New-AzVmss` for TrustedLaunch default usage.
2426

2527
## Version 7.0.0

src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ public partial class NewAzureRmDiskConfigCommand : Microsoft.Azure.Commands.Reso
248248
HelpMessage = "Set this flag to true to get a boost on the performance target of the disk deployed, see here on the respective performance target. This flag can only be set on disk creation time and cannot be disabled after enabled.")]
249249
public bool? PerformancePlus { get; set; }
250250

251+
[Parameter(
252+
Mandatory = false,
253+
ValueFromPipelineByPropertyName = true,
254+
HelpMessage = "Setting this property to true improves reliability and performance of data disks that are frequently (more than 5 times a day) by detached from one virtual machine and attached to another. This property should not be set for disks that are not detached and attached frequently as it causes the disks to not align with the fault domain of the virtual machine.")]
255+
public bool? OptimizedForFrequentAttach { get; set; }
256+
251257
protected override void ProcessRecord()
252258
{
253259
if (ShouldProcess("Disk", "New"))
@@ -482,7 +488,8 @@ private void Run()
482488
SupportsHibernation = this.IsParameterBound(c => c.SupportsHibernation) ? SupportsHibernation : null,
483489
SupportedCapabilities = vSupportedCapabilities,
484490
PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null,
485-
DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? DataAccessAuthMode : null
491+
DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? DataAccessAuthMode : null,
492+
OptimizedForFrequentAttach = this.IsParameterBound(c => c.OptimizedForFrequentAttach) ? OptimizedForFrequentAttach : null
486493
};
487494

488495
WriteObject(vDisk);

src/Compute/Compute/Generated/Models/PSDisk.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ public string ResourceGroupName
7878
public SupportedCapabilities SupportedCapabilities { get; set; }
7979
public string DataAccessAuthMode { get; set; }
8080
public double? CompletionPercent { get; set; }
81+
public bool? OptimizedForFrequentAttach { get; set; }
8182
}
8283
}

src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotConfigCommand.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ public partial class NewAzureRmSnapshotConfigCommand : Microsoft.Azure.Commands.
186186
[PSArgumentCompleter("X64", "Arm64")]
187187
public string Architecture { get; set; }
188188

189+
[Parameter(
190+
Mandatory = false,
191+
ValueFromPipelineByPropertyName = true,
192+
HelpMessage = "Required if createOption is CopyFromSanSnapshot. This is the ARM id of the source elastic san volume snapshot.")]
193+
public string ElasticSanResourceId { get; set; }
194+
189195
protected override void ProcessRecord()
190196
{
191197
if (ShouldProcess("Snapshot", "New"))
@@ -268,6 +274,15 @@ private void Run()
268274
vCreationData.SourceResourceId = this.SourceResourceId;
269275
}
270276

277+
if (this.IsParameterBound(c => c.ElasticSanResourceId))
278+
{
279+
if (vCreationData == null)
280+
{
281+
vCreationData = new CreationData();
282+
}
283+
vCreationData.ElasticSanResourceId = this.ElasticSanResourceId;
284+
}
285+
271286
if (this.IsParameterBound(c => c.EncryptionSettingsEnabled))
272287
{
273288
if (vEncryptionSettingsCollection == null)

src/Compute/Compute/help/New-AzDiskConfig.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ New-AzDiskConfig [[-SkuName] <String>] [-Tier <String>] [-LogicalSectorSize <Int
2525
[-DiskEncryptionSetId <String>] [-EncryptionType <String>] [-DiskAccessId <String>]
2626
[-NetworkAccessPolicy <String>] [-BurstingEnabled <Boolean>] [-PublicNetworkAccess <String>]
2727
[-AcceleratedNetwork <Boolean>] [-DataAccessAuthMode <String>] [-Architecture <String>]
28-
[-PerformancePlus <Boolean>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
29-
[<CommonParameters>]
28+
[-PerformancePlus <Boolean>] [-OptimizedForFrequentAttach <Boolean>]
29+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
3030
```
3131

3232
## DESCRIPTION
@@ -84,6 +84,14 @@ New-AzDisk -ResourceGroupName 'ResourceGroup01' -DiskName 'Disk01' -Disk $diskCo
8484

8585
Create a disk from a Shared Gallery Image Version. Id is the id of the shared gallery image version. Lun is needed only if the source is a data disk.
8686

87+
### Example 4
88+
```powershell
89+
$diskconfig = New-AzDiskConfig -Location 'Central US' -SkuName 'Standard_LRS' -OsType 'Windows' -UploadSizeInBytes 35183298347520 -CreateOption 'Upload' -OptimizedForFrequentAttach $true
90+
New-AzDisk -ResourceGroupName 'ResourceGroup01' -DiskName 'Disk01' -Disk $diskConfig
91+
```
92+
93+
Create a disk with OptimizedForFrequentAttach as true, to improves reliability and performance of the data disks that will be frequently (more than 5 times a day) detached from one virtual machine and attached to another.
94+
8795
## PARAMETERS
8896

8997
### -AcceleratedNetwork
@@ -469,6 +477,21 @@ Accept pipeline input: True (ByPropertyName)
469477
Accept wildcard characters: False
470478
```
471479
480+
### -OptimizedForFrequentAttach
481+
Setting this property to true improves reliability and performance of data disks that are frequently (more than 5 times a day) by detached from one virtual machine and attached to another. This property should not be set for disks that are not detached and attached frequently as it causes the disks to not align with the fault domain of the virtual machine.
482+
483+
```yaml
484+
Type: System.Nullable`1[System.Boolean]
485+
Parameter Sets: (All)
486+
Aliases:
487+
488+
Required: False
489+
Position: Named
490+
Default value: None
491+
Accept pipeline input: True (ByPropertyName)
492+
Accept wildcard characters: False
493+
```
494+
472495
### -OsType
473496
Specifies the OS type.
474497

src/Compute/Compute/help/New-AzSnapshotConfig.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ New-AzSnapshotConfig [[-SkuName] <String>] [[-OsType] <OperatingSystemTypes>] [[
2121
[-DiskEncryptionKey <KeyVaultAndSecretReference>] [-KeyEncryptionKey <KeyVaultAndKeyReference>]
2222
[-DiskEncryptionSetId <String>] [-EncryptionType <String>] [-DiskAccessId <String>]
2323
[-NetworkAccessPolicy <String>] [-PublicNetworkAccess <String>] [-AcceleratedNetwork <Boolean>]
24-
[-DataAccessAuthMode <String>] [-Architecture <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
25-
[-Confirm] [<CommonParameters>]
24+
[-DataAccessAuthMode <String>] [-Architecture <String>] [-ElasticSanResourceId <String>]
25+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2626
```
2727

2828
## DESCRIPTION
@@ -47,6 +47,16 @@ The second and third commands set the disk encryption key and key encryption key
4747
The last command takes the snapshot object and creates a snapshot with name 'Snapshot01' in resource group 'ResourceGroup01'.
4848

4949
### Example 2
50+
```powershell
51+
$elasticSanVolumeSnapshotResourceId = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/ResourceGroup01/providers/Microsoft.ElasticSan/elasticSans/san1/volumeGroups/volumegroup1/snapshots/snapshot1"
52+
$snapshotconfig = New-AzSnapshotConfig -Location 'France Central' -AccountType Standard_LRS -CreateOption CopyFromSanSnapshot -ElasticSanResourceId $elasticSanVolumeSnapshotResourceId
53+
New-AzSnapshot -ResourceGroupName 'ResourceGroup01' -SnapshotName 'Snapshot01' -Snapshot $snapshotconfig;
54+
```
55+
56+
The first command creates a local empty snapshot object with a ElasticSan Volume snapshot resource Id, with CreateOption as CopyFromSanSnapshot.
57+
The second command takes the snapshot object and creates a snapshot with name 'Snapshot01' in resource group 'ResourceGroup01'.
58+
59+
### Example 3
5060

5161
Creates a configurable snapshot object. (autogenerated)
5262

@@ -209,6 +219,21 @@ Accept pipeline input: True (ByPropertyName)
209219
Accept wildcard characters: False
210220
```
211221
222+
### -ElasticSanResourceId
223+
Required if createOption is CopyFromSanSnapshot. This is the ARM id of the source elastic san volume snapshot.
224+
225+
```yaml
226+
Type: System.String
227+
Parameter Sets: (All)
228+
Aliases:
229+
230+
Required: False
231+
Position: Named
232+
Default value: None
233+
Accept pipeline input: True (ByPropertyName)
234+
Accept wildcard characters: False
235+
```
236+
212237
### -EncryptionSettingsEnabled
213238
Enable encryption settings.
214239

0 commit comments

Comments
 (0)