diff --git a/src/Compute/Compute.Test/ScenarioTests/DiskRPTests.cs b/src/Compute/Compute.Test/ScenarioTests/DiskRPTests.cs index 700af4de4cb1..cd7f26c828ad 100644 --- a/src/Compute/Compute.Test/ScenarioTests/DiskRPTests.cs +++ b/src/Compute/Compute.Test/ScenarioTests/DiskRPTests.cs @@ -199,5 +199,19 @@ public void TestDiskGrantAccessGetSASWithTL() TestRunner.RunTestScript("Test-DiskGrantAccessGetSASWithTL"); } - } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void testgennewazdiskconfig() + { + TestRunner.RunTestScript("TestGen-newazdiskconfig"); + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void testgennewazdisk() + { + TestRunner.RunTestScript("TestGen-newazdisk"); + } + } } diff --git a/src/Compute/Compute.Test/ScenarioTests/DiskRPTests.ps1 b/src/Compute/Compute.Test/ScenarioTests/DiskRPTests.ps1 index 153bee5c2953..87e9e53eeef2 100644 --- a/src/Compute/Compute.Test/ScenarioTests/DiskRPTests.ps1 +++ b/src/Compute/Compute.Test/ScenarioTests/DiskRPTests.ps1 @@ -1863,4 +1863,93 @@ function Test-DiskGrantAccessGetSASWithTL # Cleanup Clean-ResourceGroup $rgname; } -} \ No newline at end of file +} +function TestGen-newazdiskconfig +{ + $rgname = Get-ComputeTestResourceName; + $loc = Get-Location; + + try + { + # Create Resource Group + New-AzResourceGroup -Name $rgname -Location $loc -Force; + + # Setup + $diskName = 'disk' + $rgname; + $diskAccountType = 'Premium_LRS'; + $createOption = 'Empty'; + $diskSize = 32; + $diskControllerType1 = 'SCSI'; + $diskControllerType2 = 'NVME'; + $encryptionSettingsVersion1 = '1.0'; + $encryptionSettingsVersion2 = '2.0'; + + # Test DiskConfig with DiskControllerType and EncryptionSettingsVersion + $diskConfig1 = New-AzDiskConfig -Location $loc -AccountType $diskAccountType -CreateOption $createOption -DiskSizeGB $diskSize -DiskControllerType $diskControllerType1 -EncryptionSettingsVersion $encryptionSettingsVersion1; + New-AzDisk -ResourceGroupName $rgname -DiskName $diskName -Disk $diskConfig1; + $disk1 = Get-AzDisk -ResourceGroupName $rgname -DiskName $diskName; + Assert-AreEqual $disk1.DiskControllerType $diskControllerType1; + Assert-AreEqual $disk1.EncryptionSettingsVersion $encryptionSettingsVersion1; + + # Update DiskConfig with new DiskControllerType and EncryptionSettingsVersion + $diskUpdateConfig = New-AzDiskUpdateConfig -DiskControllerType $diskControllerType2 -EncryptionSettingsVersion $encryptionSettingsVersion2; + Update-AzDisk -ResourceGroupName $rgname -DiskName $diskName -DiskUpdate $diskUpdateConfig; + $diskUpdated = Get-AzDisk -ResourceGroupName $rgname -DiskName $diskName; + Assert-AreEqual $diskUpdated.DiskControllerType $diskControllerType2; + Assert-AreEqual $diskUpdated.EncryptionSettingsVersion $encryptionSettingsVersion2; + + # Cleanup + Remove-AzDisk -ResourceGroupName $rgname -DiskName $diskName -Force; + Remove-AzResourceGroup -Name $rgname -Force; + } + catch + { + Write-Error "Test failed: $_"; + throw $_; + } +} + +function TestGen-newazdisk +{ + $rgname = Get-ComputeTestResourceName; + $loc = Get-Location; + + try + { + # Create Resource Group + New-AzResourceGroup -Name $rgname -Location $loc -Force; + + # Setup + $diskName = 'disk' + $rgname; + $diskAccountType = 'Premium_LRS'; + $createOption = 'Empty'; + $diskSize = 32; + $diskControllerType1 = 'SCSI'; + $diskControllerType2 = 'NVME'; + $encryptionSettingsVersion1 = '1.0'; + $encryptionSettingsVersion2 = '2.0'; + + # Test DiskControllerType and EncryptionSettingsVersion in New-AzDiskConfig + $diskConfig1 = New-AzDiskConfig -Location $loc -AccountType $diskAccountType -CreateOption $createOption -DiskSizeGB $diskSize -DiskControllerType $diskControllerType1 -EncryptionSettingsVersion $encryptionSettingsVersion1; + New-AzDisk -ResourceGroupName $rgname -DiskName $diskName -Disk $diskConfig1; + $disk1 = Get-AzDisk -ResourceGroupName $rgname -DiskName $diskName; + Assert-AreEqual $disk1.DiskControllerType $diskControllerType1; + Assert-AreEqual $disk1.EncryptionSettingsVersion $encryptionSettingsVersion1; + + # Update DiskControllerType and EncryptionSettingsVersion + $diskUpdateConfig = New-AzDiskUpdateConfig -DiskControllerType $diskControllerType2 -EncryptionSettingsVersion $encryptionSettingsVersion2; + Update-AzDisk -ResourceGroupName $rgname -DiskName $diskName -DiskUpdate $diskUpdateConfig; + $diskUpdated = Get-AzDisk -ResourceGroupName $rgname -DiskName $diskName; + Assert-AreEqual $diskUpdated.DiskControllerType $diskControllerType2; + Assert-AreEqual $diskUpdated.EncryptionSettingsVersion $encryptionSettingsVersion2; + + # Cleanup + Remove-AzDisk -ResourceGroupName $rgname -DiskName $diskName -Force; + Remove-AzResourceGroup -Name $rgname -Force; + } + catch + { + Write-Error "Test failed: $_"; + throw; + } +} diff --git a/src/Compute/Compute/ChangeLog.md b/src/Compute/Compute/ChangeLog.md index dd327ab98cbb..2158a314ce7f 100644 --- a/src/Compute/Compute/ChangeLog.md +++ b/src/Compute/Compute/ChangeLog.md @@ -20,6 +20,7 @@ --> ## Upcoming Release +* Added parameters `DiskControllerType` and `EncryptionSettingsVersion` to `New-AzDisk` and `New-AzDiskConfig`. * Added new properties `Architecture`, `HyperVGeneration`, and `ImageDeprecationStatus` to be returned in `Get-AzVMImage` ListVMImage parameter set. * Deprecated `Get-AzVMSize` 'List Virtual Machine Size' parameter set. * Added new parameters `EnableAutomaticZoneRebalance`, `AutomaticZoneRebalanceStrategy` and `AutomaticZoneRebalanceBehavior` to `New-AzVmssConfig` and `Update-AzVmss` cmdlets for VMSS Automatic Zone Rebalancing. diff --git a/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs b/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs index e1c7982b6042..fbecfc68fcaf 100644 --- a/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs +++ b/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs @@ -1,4 +1,4 @@ -// + // // Copyright (c) Microsoft and contributors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -254,6 +254,17 @@ public partial class NewAzureRmDiskConfigCommand : Microsoft.Azure.Commands.Reso 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.")] public bool? OptimizedForFrequentAttach { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true)] + [PSArgumentCompleter("SCSI", "NVME")] + public string DiskControllerType { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true)] + public string EncryptionSettingsVersion { get; set; } + protected override void ProcessRecord() { if (ShouldProcess("Disk", "New")) @@ -421,6 +432,15 @@ private void Run() vEncryptionSettingsCollection.EncryptionSettings[0].KeyEncryptionKey = this.KeyEncryptionKey; } + if (this.IsParameterBound(c => c.EncryptionSettingsVersion)) + { + if (vEncryptionSettingsCollection == null) + { + vEncryptionSettingsCollection = new EncryptionSettingsCollection(); + } + vEncryptionSettingsCollection.EncryptionSettingsVersion = this.EncryptionSettingsVersion; + } + if (this.IsParameterBound(c => c.DiskEncryptionSetId)) { if (vEncryption == null) @@ -489,7 +509,8 @@ private void Run() SupportedCapabilities = vSupportedCapabilities, PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null, DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? DataAccessAuthMode : null, - OptimizedForFrequentAttach = this.IsParameterBound(c => c.OptimizedForFrequentAttach) ? OptimizedForFrequentAttach : null + OptimizedForFrequentAttach = this.IsParameterBound(c => c.OptimizedForFrequentAttach) ? OptimizedForFrequentAttach : null, + DiskControllerType = this.IsParameterBound(c => c.DiskControllerType) ? this.DiskControllerType : null }; WriteObject(vDisk); diff --git a/src/Compute/Compute/Generated/Disk/DiskCreateOrUpdateMethod.cs b/src/Compute/Compute/Generated/Disk/DiskCreateOrUpdateMethod.cs index 3a3e0e58d930..016d4670c0c4 100644 --- a/src/Compute/Compute/Generated/Disk/DiskCreateOrUpdateMethod.cs +++ b/src/Compute/Compute/Generated/Disk/DiskCreateOrUpdateMethod.cs @@ -1,4 +1,4 @@ -// + // // Copyright (c) Microsoft and contributors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -7,7 +7,7 @@ // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, +distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // // See the License for the specific language governing permissions and @@ -56,6 +56,17 @@ public override void ExecuteCmdlet() Disk disk = new Disk(); ComputeAutomationAutoMapperProfile.Mapper.Map(this.Disk, disk); + // Apply overrides from cmdlet parameters if provided + if (!string.IsNullOrEmpty(this.DiskControllerType)) + { + disk.DiskControllerType = this.DiskControllerType; + } + + if (!string.IsNullOrEmpty(this.EncryptionSettingsVersion)) + { + disk.EncryptionSettingsVersion = this.EncryptionSettingsVersion; + } + Dictionary> auxAuthHeader = null; if (!string.IsNullOrEmpty(disk.CreationData?.GalleryImageReference?.Id)) { @@ -205,5 +216,18 @@ public override void ExecuteCmdlet() [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] public SwitchParameter AsJob { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Specifies the disk controller type.")] + [ValidateSet("SCSI", "NVME", IgnoreCase = true)] + public string DiskControllerType { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Specifies the encryption settings version.")] + public string EncryptionSettingsVersion { get; set; } } -} +} \ No newline at end of file diff --git a/src/Compute/Compute/Generated/Models/PSDisk.cs b/src/Compute/Compute/Generated/Models/PSDisk.cs index d257855adaae..29d051f052e6 100644 --- a/src/Compute/Compute/Generated/Models/PSDisk.cs +++ b/src/Compute/Compute/Generated/Models/PSDisk.cs @@ -79,5 +79,7 @@ public string ResourceGroupName public string DataAccessAuthMode { get; set; } public double? CompletionPercent { get; set; } public bool? OptimizedForFrequentAttach { get; set; } + public string DiskControllerType { get; set; } + public string EncryptionSettingsVersion { get; set; } } }