Skip to content

Commit 7849d39

Browse files
haaghaPSCmdAssistantnotyashhh
authored
[Compute] GalleryImageVersion Powershell commands to support BlockDeletionBeforeEndOfLife parameter (#27224)
Co-authored-by: PSCmdAssistant <[email protected]> Co-authored-by: Yash <[email protected]>
1 parent 5b28e54 commit 7849d39

File tree

7 files changed

+14325
-3
lines changed

7 files changed

+14325
-3
lines changed

src/Compute/Compute.Test/ScenarioTests/GalleryTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ----------------------------------------------------------------------------------
1+
// ----------------------------------------------------------------------------------
22
//
33
// Copyright Microsoft Corporation
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -71,5 +71,12 @@ public void TestGalleryImageDefinitionDefaults()
7171
{
7272
TestRunner.RunTestScript("Test-GalleryImageDefinitionDefaults");
7373
}
74+
75+
[Fact(Skip = "Cannot test EOD as it prevents deletion")]
76+
[Trait(Category.AcceptanceType, Category.CheckIn)]
77+
public void TestGalleryBlockDeletionBeforeEndOfLife()
78+
{
79+
TestRunner.RunTestScript("TestGen-BlockDeletionBeforeEndOfLife");
80+
}
7481
}
7582
}

src/Compute/Compute.Test/ScenarioTests/GalleryTests.ps1

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,3 +990,63 @@ function Test-GalleryImageDefinitionDefaults
990990
}
991991
}
992992

993+
function TestGen-BlockDeletionBeforeEndOfLife
994+
{
995+
# Setup
996+
$rgname = Get-ComputeTestResourceName;
997+
$galleryName = 'gallery' + $rgname;
998+
$imageDefinitionName = 'imageDef' + $rgname;
999+
$imageVersionName = '1.0.0';
1000+
$loc = "eastus2"
1001+
$vmname = "testvmgallery"
1002+
1003+
try
1004+
{
1005+
1006+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
1007+
1008+
# SimpleParameterSet, no config, scenario.
1009+
# create credential
1010+
$password = Get-PasswordForVM;
1011+
$user = Get-ComputeTestResourceName;
1012+
$securePassword = $password | ConvertTo-SecureString -AsPlainText -Force;
1013+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
1014+
1015+
# Step 1: Create a new virtual machine in Azure
1016+
New-AzVM -ResourceGroupName $rgname -Location $loc -Name $vmname -Credential $cred -Size "Standard_D2s_v3" -Image "Win2022AzureEdition" -SecurityType "TrustedLaunch"
1017+
$vm = get-azvm -ResourceGroupName $rgname -Name $vmname
1018+
1019+
# Create a gallery
1020+
$gallery = New-AzGallery -ResourceGroupName $rgname -Location $loc -Name $galleryName
1021+
1022+
# Create a gallery image definition
1023+
$imageDef = New-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Location $loc -Name $imageDefinitionName -OsType 'Windows' -OsState 'Specialized' -Publisher 'Contoso' -Offer 'OfferName' -Sku 'SkuName' -Feature @{Name='SecurityType';Value='TrustedLaunch'}
1024+
1025+
# Test creating a gallery image version with BlockDeletionBeforeEndOfLife set to true
1026+
$imagever = New-AzGalleryImageVersion `
1027+
-GalleryImageDefinitionName $imageDef.Name `
1028+
-GalleryImageVersionName $imageVersionName `
1029+
-GalleryName $gallery.Name `
1030+
-ResourceGroupName $rgname `
1031+
-Location $loc `
1032+
-SourceImageVMId $vm.Id.ToString() `
1033+
-PublishingProfileEndOfLifeDate '2024-12-01' `
1034+
-BlockDeletionBeforeEndOfLife
1035+
1036+
Assert-AreEqual $imagever.SafetyProfile.BlockDeletionBeforeEndOfLife $True
1037+
1038+
$imagever = Update-AzGalleryImageVersion `
1039+
-GalleryImageDefinitionName $imageDef.Name `
1040+
-GalleryImageVersionName $imageVersionName `
1041+
-GalleryName $gallery.Name `
1042+
-ResourceGroupName $rgname `
1043+
-BlockDeletionBeforeEndOfLife $False
1044+
Assert-AreEqual $imagever.SafetyProfile.BlockDeletionBeforeEndOfLife $False
1045+
1046+
}
1047+
finally
1048+
{
1049+
# Cleanup
1050+
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue;
1051+
}
1052+
}

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.GalleryTests/TestGalleryBlockDeletionBeforeEndOfLife.json

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

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.GalleryTests/testgenupdateazgalleryimageversion.json

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

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Added new parameter `BlockDeletionBeforeEndOfLife` parameter to `New-AzGalleryImageVersion` and `Update-AzGalleryImageVersion` cmdlets.
2324
* Updated `New-AzVM`, `New-AzVmss`, `Update-AzVM`, and `Update-AzVmss` to pass `Standard` as an input of `-SecurityType` parameter.
2425
* Added breaking change message for `Get-AzVMSize`.
2526

src/Compute/Compute/Generated/GalleryImageVersion/GalleryImageVersionCreateOrUpdateMethod.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) Microsoft and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -101,6 +101,14 @@ public override void ExecuteCmdlet()
101101
}
102102
galleryImageVersion.PublishingProfile.EndOfLifeDate = this.PublishingProfileEndOfLifeDate;
103103
}
104+
if (this.IsParameterBound(c => c.BlockDeletionBeforeEndOfLife))
105+
{
106+
if (galleryImageVersion.SafetyProfile == null)
107+
{
108+
galleryImageVersion.SafetyProfile = new GalleryImageVersionSafetyProfile();
109+
}
110+
galleryImageVersion.SafetyProfile.BlockDeletionBeforeEndOfLife = this.BlockDeletionBeforeEndOfLife.IsPresent;
111+
}
104112

105113
if (this.IsParameterBound(c => c.StorageAccountType))
106114
{
@@ -410,6 +418,12 @@ public override void ExecuteCmdlet()
410418
ValueFromPipelineByPropertyName = true,
411419
HelpMessage = "The target extended locations where the Image Version is going to be replicated to. This property is updatable.")]
412420
public Hashtable[] TargetExtendedLocation { get; set; }
421+
422+
[Parameter(
423+
Mandatory = false,
424+
ValueFromPipelineByPropertyName = true,
425+
HelpMessage = "This boolean will be passed by the customers to enable their GalleryImageVersion resources from accidental deletions. If this boolean is set to true, the image deletions will be blocked before its EndOfLife date.")]
426+
public SwitchParameter BlockDeletionBeforeEndOfLife { get; set; }
413427
}
414428

415429
[Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "GalleryImageVersion", DefaultParameterSetName = "DefaultParameter", SupportsShouldProcess = true)]
@@ -492,6 +506,15 @@ public override void ExecuteCmdlet()
492506
galleryImageVersion.PublishingProfile.EndOfLifeDate = this.PublishingProfileEndOfLifeDate;
493507
}
494508

509+
if (this.IsParameterBound(c => c.BlockDeletionBeforeEndOfLife))
510+
{
511+
if (galleryImageVersion.SafetyProfile == null)
512+
{
513+
galleryImageVersion.SafetyProfile = new GalleryImageVersionSafetyProfile();
514+
}
515+
galleryImageVersion.SafetyProfile.BlockDeletionBeforeEndOfLife = this.BlockDeletionBeforeEndOfLife;
516+
}
517+
495518
if (this.IsParameterBound(c => c.TargetRegion))
496519
{
497520
if (galleryImageVersion.PublishingProfile == null)
@@ -714,5 +737,11 @@ public override void ExecuteCmdlet()
714737
ValueFromPipelineByPropertyName = true,
715738
HelpMessage = "Indicates whether or not removing this Gallery Image Version from replicated regions is allowed.")]
716739
public bool AllowDeletionOfReplicatedLocation { get; set; }
740+
741+
[Parameter(
742+
Mandatory = false,
743+
ValueFromPipelineByPropertyName = true,
744+
HelpMessage = "This boolean will be passed by the customers to enable their GalleryImageVersion resources from accidental deletions. If this boolean is set to true, the image deletions will be blocked before its EndOfLife date.")]
745+
public bool? BlockDeletionBeforeEndOfLife { get; set; }
717746
}
718747
}

src/Compute/Compute/Generated/Models/PSGalleryImageVersion.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ public string ResourceGroupName
4444
public string ProvisioningState { get; set; }
4545
public GalleryImageVersionStorageProfile StorageProfile { get; set; }
4646
public ReplicationStatus ReplicationStatus { get; set; }
47+
public GalleryImageVersionSafetyProfile SafetyProfile { get; set; }
4748
public string Id { get; set; }
4849
public string Name { get; set; }
4950
public string Type { get; set; }
5051
public string Location { get; set; }
5152
public IDictionary<string, string> Tags { get; set; }
5253

5354
}
54-
}
55+
}

0 commit comments

Comments
 (0)