Skip to content

Commit 184b451

Browse files
haaghaPSCmdAssistantnotyashhh
authored
Az.Compute - Shallow Replication for GalleryImageVersion (#27225)
Co-authored-by: PSCmdAssistant <[email protected]> Co-authored-by: Yash <[email protected]>
1 parent 7849d39 commit 184b451

File tree

7 files changed

+5872
-3
lines changed

7 files changed

+5872
-3
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public void TestGalleryImageDefinitionDefaults()
7272
TestRunner.RunTestScript("Test-GalleryImageDefinitionDefaults");
7373
}
7474

75+
[Fact]
76+
[Trait(Category.AcceptanceType, Category.CheckIn)]
77+
public void testgennewazgallery()
78+
{
79+
TestRunner.RunTestScript("TestGen-newazgallery");
80+
}
81+
7582
[Fact(Skip = "Cannot test EOD as it prevents deletion")]
7683
[Trait(Category.AcceptanceType, Category.CheckIn)]
7784
public void TestGalleryBlockDeletionBeforeEndOfLife()

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

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,9 @@ function Test-GalleryImageDefinitionDefaults
990990
}
991991
}
992992

993+
<#
994+
.SYNOPSIS
995+
#>
993996
function TestGen-BlockDeletionBeforeEndOfLife
994997
{
995998
# Setup
@@ -1034,7 +1037,7 @@ function TestGen-BlockDeletionBeforeEndOfLife
10341037
-BlockDeletionBeforeEndOfLife
10351038

10361039
Assert-AreEqual $imagever.SafetyProfile.BlockDeletionBeforeEndOfLife $True
1037-
1040+
10381041
$imagever = Update-AzGalleryImageVersion `
10391042
-GalleryImageDefinitionName $imageDef.Name `
10401043
-GalleryImageVersionName $imageVersionName `
@@ -1049,4 +1052,61 @@ function TestGen-BlockDeletionBeforeEndOfLife
10491052
# Cleanup
10501053
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue;
10511054
}
1052-
}
1055+
}
1056+
1057+
<#
1058+
.SYNOPSIS
1059+
#>
1060+
function TestGen-newazgallery
1061+
{
1062+
# Setup
1063+
$rgname = Get-ComputeTestResourceName;
1064+
$galleryName = 'gallery' + $rgname;
1065+
$imageDefinitionName = 'imageDef' + $rgname;
1066+
$imageVersionName = '1.0.0';
1067+
$loc = "eastus2"
1068+
$vmname = "vmgallerytest"
1069+
$domainNameLabel="123"+$rgname
1070+
1071+
try
1072+
{
1073+
1074+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
1075+
1076+
# SimpleParameterSet, no config, scenario.
1077+
# create credential
1078+
$password = Get-PasswordForVM;
1079+
$user = Get-ComputeTestResourceName;
1080+
$securePassword = $password | ConvertTo-SecureString -AsPlainText -Force;
1081+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
1082+
1083+
# Step 1: Create a new virtual machine in Azure
1084+
New-AzVM -ResourceGroupName $rgname -Location $loc -Name $vmname -Credential $cred -Size "Standard_D2s_v3" -Image "Win2022AzureEdition" -SecurityType "TrustedLaunch" -DomainNameLabel $domainNameLabel
1085+
$vm = get-azvm -ResourceGroupName $rgname -Name $vmname
1086+
1087+
# Create a gallery
1088+
$gallery = New-AzGallery -ResourceGroupName $rgname -Location $loc -Name $galleryName
1089+
1090+
# Create a gallery image definition
1091+
$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'}
1092+
1093+
# Test creating a gallery image version with ReplicationMode = Full
1094+
$imagever = New-AzGalleryImageVersion `
1095+
-GalleryImageDefinitionName $imageDef.Name `
1096+
-GalleryImageVersionName $imageVersionName `
1097+
-GalleryName $gallery.Name `
1098+
-ResourceGroupName $rgname `
1099+
-Location $loc `
1100+
-SourceImageVMId $vm.Id.ToString() `
1101+
-PublishingProfileEndOfLifeDate '2030-12-01' `
1102+
-ReplicationMode 'Full'
1103+
1104+
Assert-AreEqual $imagever.PublishingProfile.ReplicationMode 'Full'
1105+
1106+
}
1107+
finally
1108+
{
1109+
# Cleanup
1110+
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue;
1111+
}
1112+
}

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

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

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

Lines changed: 1332 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 `-ReplicationMode` to `New-AzGalleryImageVersion` cmdlet.
2324
* Added new parameter `BlockDeletionBeforeEndOfLife` parameter to `New-AzGalleryImageVersion` and `Update-AzGalleryImageVersion` cmdlets.
2425
* Updated `New-AzVM`, `New-AzVmss`, `Update-AzVM`, and `Update-AzVmss` to pass `Standard` as an input of `-SecurityType` parameter.
2526
* Added breaking change message for `Get-AzVMSize`.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ public override void ExecuteCmdlet()
119119
galleryImageVersion.PublishingProfile.StorageAccountType = this.StorageAccountType;
120120
}
121121

122+
if (this.IsParameterBound(c => c.ReplicationMode))
123+
{
124+
if (galleryImageVersion.PublishingProfile == null)
125+
{
126+
galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile();
127+
}
128+
galleryImageVersion.PublishingProfile.ReplicationMode = this.ReplicationMode;
129+
}
130+
122131
if (this.IsParameterBound(c => c.TargetRegion))
123132
{
124133
if (galleryImageVersion.PublishingProfile == null)
@@ -424,6 +433,13 @@ public override void ExecuteCmdlet()
424433
ValueFromPipelineByPropertyName = true,
425434
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.")]
426435
public SwitchParameter BlockDeletionBeforeEndOfLife { get; set; }
436+
437+
[Parameter(
438+
Mandatory = false,
439+
ValueFromPipelineByPropertyName = true,
440+
HelpMessage = "To achieve parity with managed images, the Gallery service allows customers to designate an image version as being used for 'testing' by choosing ReplicationMode = Shallow. When choosing Shallow replication, the gallery image version is provisioned much quicker as a full copy of the source image is not made.")]
441+
[PSArgumentCompleter("Full", "Shallow")]
442+
public string ReplicationMode { get; set; }
427443
}
428444

429445
[Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "GalleryImageVersion", DefaultParameterSetName = "DefaultParameter", SupportsShouldProcess = true)]

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,5 @@ public string ResourceGroupName
5050
public string Type { get; set; }
5151
public string Location { get; set; }
5252
public IDictionary<string, string> Tags { get; set; }
53-
5453
}
5554
}

0 commit comments

Comments
 (0)