Skip to content

Commit 373ba27

Browse files
purbchCopilotaudreytttCopilot
authored
Copilot/az compute update galleryimage feature (#29368)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: audreyttt <225061541+audreyttt@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f919b93 commit 373ba27

7 files changed

Lines changed: 1914 additions & 3 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,12 @@ public void TestInVMAccessControlProfileVersion()
9393
TestRunner.RunTestScript("Test-InVMAccessControlProfileVersion");
9494
}
9595

96+
[Fact]
97+
[Trait(Category.AcceptanceType, Category.CheckIn)]
98+
public void TestGalleryImageDefinitionUpdateFeature()
99+
{
100+
TestRunner.RunTestScript("Test-GalleryImageDefinitionUpdateFeature");
101+
}
102+
96103
}
97104
}

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

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,4 +1224,82 @@ function Test-InVMAccessControlProfileVersion
12241224
# Cleanup
12251225
Clean-ResourceGroup $rgname;
12261226
}
1227-
}
1227+
}
1228+
1229+
<#
1230+
.SYNOPSIS
1231+
Tests updating gallery image definition features with StartsAtVersion and AllowUpdateImage parameters
1232+
#>
1233+
function Test-GalleryImageDefinitionUpdateFeature
1234+
{
1235+
# Setup
1236+
$rgname = Get-ComputeTestResourceName;
1237+
$loc = Get-ComputeVMLocation;
1238+
1239+
try
1240+
{
1241+
$location = $loc;
1242+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
1243+
1244+
# Gallery variables
1245+
$galleryName = 'gl' + $rgname;
1246+
$definitionName = 'def' + $rgname;
1247+
$skuDetails = @{
1248+
Publisher = 'testpub'
1249+
Offer = 'testoffer'
1250+
Sku = 'testsku'
1251+
}
1252+
$osType = 'Windows'
1253+
$osState = 'Specialized'
1254+
1255+
# Create gallery
1256+
New-AzGallery -ResourceGroupName $rgname -Name $galleryName -Location $location;
1257+
1258+
# Create image definition with features including StartsAtVersion
1259+
$initialSecurityFeature = New-Object -TypeName Microsoft.Azure.Management.Compute.Models.GalleryImageFeature `
1260+
-Property @{Name = 'SecurityType'; Value = 'TrustedLaunch'; StartsAtVersion = '4.0.0'}
1261+
$initialDiskControllerFeature = New-Object -TypeName Microsoft.Azure.Management.Compute.Models.GalleryImageFeature `
1262+
-Property @{Name = 'DiskControllerTypes'; Value = 'SCSI'; StartsAtVersion = '4.0.0'}
1263+
$initialFeatures = @($initialSecurityFeature, $initialDiskControllerFeature);
1264+
1265+
New-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName `
1266+
-Name $definitionName -Location $location `
1267+
-Publisher $skuDetails.Publisher -Offer $skuDetails.Offer -Sku $skuDetails.Sku `
1268+
-OsState $osState -OsType $osType -Feature $initialFeatures -ErrorAction Stop;
1269+
1270+
$definition = Get-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Name $definitionName;
1271+
Assert-NotNull $definition;
1272+
Assert-AreEqual $definition.Name $definitionName;
1273+
Assert-AreEqual $definition.Features.Count 2;
1274+
1275+
# Update with AllowUpdateImage using different feature values
1276+
$securityFeature = New-Object -TypeName Microsoft.Azure.Management.Compute.Models.GalleryImageFeature `
1277+
-Property @{Name = 'SecurityType'; Value = 'TrustedLaunch'; StartsAtVersion = '4.0.0'}
1278+
$diskControllerFeature = New-Object -TypeName Microsoft.Azure.Management.Compute.Models.GalleryImageFeature `
1279+
-Property @{Name = 'DiskControllerTypes'; Value = 'SCSI, NVMe'; StartsAtVersion = '4.0.0'}
1280+
$features = @($securityFeature, $diskControllerFeature);
1281+
1282+
Update-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName `
1283+
-Name $definitionName -Feature $features -AllowUpdateImage $true;
1284+
1285+
# Verify the updated definition
1286+
$updatedDefinition = Get-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Name $definitionName;
1287+
Assert-NotNull $updatedDefinition;
1288+
Assert-AreEqual $updatedDefinition.Features.Count 2;
1289+
1290+
$diskControllerUpdated = $updatedDefinition.Features | Where-Object { $_.Name -eq 'DiskControllerTypes' };
1291+
Assert-NotNull $diskControllerUpdated;
1292+
Assert-AreEqual $diskControllerUpdated.Value 'SCSI, NVMe';
1293+
Assert-AreEqual $diskControllerUpdated.StartsAtVersion '4.0.0';
1294+
1295+
$securityUpdated = $updatedDefinition.Features | Where-Object { $_.Name -eq 'SecurityType' };
1296+
Assert-NotNull $securityUpdated;
1297+
Assert-AreEqual $securityUpdated.Value 'TrustedLaunch';
1298+
Assert-AreEqual $securityUpdated.StartsAtVersion '4.0.0';
1299+
}
1300+
finally
1301+
{
1302+
# Cleanup
1303+
Clean-ResourceGroup $rgname;
1304+
}
1305+
}

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

Lines changed: 1746 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 `-Feature` parameter to `Update-AzGalleryImageDefinition` cmdlet to allow updating existing gallery image features (such as DiskControllerTypes, SecurityType, IsAcceleratedNetwork, and IsHibernate). Each feature supports a `StartsAtVersion` property to specify the minimum gallery image version that supports the updated feature.
24+
* Added `-AllowUpdateImage` parameter to `Update-AzGalleryImageDefinition` cmdlet. Must be set to true when using the `-Feature` parameter to update gallery image features.
2325

2426
## Version 11.4.0
2527
* Added `-DiskIOPSReadWrite` and `-DiskMBpsReadWrite` parameters to `Add-AzVMDataDisk` cmdlet

src/Compute/Compute/Generated/GalleryImage/GalleryImageCreateOrUpdateMethod.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,20 @@ public override void ExecuteCmdlet()
521521
galleryImage.PurchasePlan.Product = this.PurchasePlanProduct;
522522
}
523523

524+
if (this.IsParameterBound(c => c.Feature))
525+
{
526+
galleryImage.Features = new List<GalleryImageFeature>();
527+
for (int i = 0; i < this.Feature.Length; i++)
528+
{
529+
galleryImage.Features.Add(this.Feature[i]);
530+
}
531+
}
532+
533+
if (this.IsParameterBound(c => c.AllowUpdateImage))
534+
{
535+
galleryImage.AllowUpdateImage = this.AllowUpdateImage;
536+
}
537+
524538
var result = GalleryImagesClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImage);
525539
var psObject = new PSGalleryImage();
526540
ComputeAutomationAutoMapperProfile.Mapper.Map<GalleryImage, PSGalleryImage>(result, psObject);
@@ -639,5 +653,17 @@ public override void ExecuteCmdlet()
639653
Mandatory = false,
640654
ValueFromPipelineByPropertyName = true)]
641655
public Hashtable Tag { get; set; }
656+
657+
[Parameter(
658+
Mandatory = false,
659+
ValueFromPipelineByPropertyName = true,
660+
HelpMessage = "A list of gallery image features to update. Each feature can include a StartsAtVersion property to indicate the minimum gallery image version that supports it.")]
661+
public GalleryImageFeature[] Feature { get; set; }
662+
663+
[Parameter(
664+
Mandatory = false,
665+
ValueFromPipelineByPropertyName = true,
666+
HelpMessage = "Must be set to true if the gallery image features are being updated.")]
667+
public bool AllowUpdateImage { get; set; }
642668
}
643669
}

src/Compute/Compute/Generated/Models/PSGalleryImage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public string ResourceGroupName
5959
public string Location { get; set; }
6060
public IDictionary<string, string> Tags { get; set; }
6161
public IList<GalleryImageFeature> Features { get; set; }
62+
public bool? AllowUpdateImage { get; set; }
6263
public string Architecture { get; set; }
6364

6465
}

src/Compute/Compute/help/Update-AzGalleryImageDefinition.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Update-AzGalleryImageDefinition [-ResourceGroupName] <String> [-GalleryName] <St
1919
[-MinimumMemory <Int32>] [-MinimumVCPU <Int32>] [-MaximumMemory <Int32>] [-MaximumVCPU <Int32>]
2020
[-PrivacyStatementUri <String>] [-PurchasePlanName <String>] [-PurchasePlanProduct <String>]
2121
[-PurchasePlanPublisher <String>] [-ReleaseNoteUri <String>] [-Tag <Hashtable>]
22+
[-Feature <GalleryImageFeature[]>] [-AllowUpdateImage <Boolean>]
2223
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
2324
[<CommonParameters>]
2425
```
@@ -29,7 +30,8 @@ Update-AzGalleryImageDefinition [-ResourceId] <String> [-AsJob] [-Description <S
2930
[-DisallowedDiskType <String[]>] [-EndOfLifeDate <DateTime>] [-Eula <String>] [-MinimumMemory <Int32>]
3031
[-MinimumVCPU <Int32>] [-MaximumMemory <Int32>] [-MaximumVCPU <Int32>] [-PrivacyStatementUri <String>]
3132
[-PurchasePlanName <String>] [-PurchasePlanProduct <String>] [-PurchasePlanPublisher <String>]
32-
[-ReleaseNoteUri <String>] [-Tag <Hashtable>] [-DefaultProfile <IAzureContextContainer>]
33+
[-ReleaseNoteUri <String>] [-Tag <Hashtable>] [-Feature <GalleryImageFeature[]>]
34+
[-AllowUpdateImage <Boolean>] [-DefaultProfile <IAzureContextContainer>]
3335
[-WhatIf] [-Confirm] [<CommonParameters>]
3436
```
3537

@@ -39,7 +41,8 @@ Update-AzGalleryImageDefinition [-InputObject] <PSGalleryImage> [-AsJob] [-Descr
3941
[-DisallowedDiskType <String[]>] [-EndOfLifeDate <DateTime>] [-Eula <String>] [-MinimumMemory <Int32>]
4042
[-MinimumVCPU <Int32>] [-MaximumMemory <Int32>] [-MaximumVCPU <Int32>] [-PrivacyStatementUri <String>]
4143
[-PurchasePlanName <String>] [-PurchasePlanProduct <String>] [-PurchasePlanPublisher <String>]
42-
[-ReleaseNoteUri <String>] [-Tag <Hashtable>] [-DefaultProfile <IAzureContextContainer>]
44+
[-ReleaseNoteUri <String>] [-Tag <Hashtable>] [-Feature <GalleryImageFeature[]>]
45+
[-AllowUpdateImage <Boolean>] [-DefaultProfile <IAzureContextContainer>]
4346
[-WhatIf] [-Confirm] [<CommonParameters>]
4447
```
4548

@@ -66,6 +69,20 @@ Update-AzGalleryImageDefinition -ResourceGroupName $resourceGroupName -GalleryNa
6669

6770
Update a gallery image definition's recommended configuration settings
6871

72+
### Example 2: Update gallery image features with StartsAtVersion
73+
74+
```powershell
75+
$rgName = "myResourceGroup"
76+
$galleryName = "myGallery"
77+
$imageDefinitionName = "myImageDefinition"
78+
$DiskControllerType = @{Name='DiskControllerTypes'; Value='SCSI'; StartsAtVersion='4.0.0'}
79+
$SecurityType = @{Name='SecurityType'; Value='TrustedLaunch'; StartsAtVersion='4.0.0'}
80+
$features = @($DiskControllerType, $SecurityType)
81+
Update-AzGalleryImageDefinition -ResourceGroupName $rgName -GalleryName $galleryName -Name $imageDefinitionName -Feature $features -AllowUpdateImage $true
82+
```
83+
84+
Update a gallery image definition's features, setting the minimum gallery image version that supports each feature via StartsAtVersion. The AllowUpdateImage parameter must be set to true when updating features.
85+
6986
## PARAMETERS
7087

7188
### -AsJob
@@ -83,6 +100,21 @@ Accept pipeline input: False
83100
Accept wildcard characters: False
84101
```
85102
103+
### -AllowUpdateImage
104+
Must be set to `$true` when the gallery image features are being updated using the `-Feature` parameter.
105+
106+
```yaml
107+
Type: System.Boolean
108+
Parameter Sets: (All)
109+
Aliases:
110+
111+
Required: False
112+
Position: Named
113+
Default value: None
114+
Accept pipeline input: True (ByPropertyName)
115+
Accept wildcard characters: False
116+
```
117+
86118
### -DefaultProfile
87119
The credentials, account, tenant, and subscription used for communication with Azure.
88120

@@ -158,6 +190,21 @@ Accept pipeline input: True (ByPropertyName)
158190
Accept wildcard characters: False
159191
```
160192

193+
### -Feature
194+
A list of gallery image features to update. Each feature can include a StartsAtVersion property to indicate the minimum gallery image version that supports it.
195+
196+
```yaml
197+
Type: Microsoft.Azure.Management.Compute.Models.GalleryImageFeature[]
198+
Parameter Sets: (All)
199+
Aliases:
200+
201+
Required: False
202+
Position: Named
203+
Default value: None
204+
Accept pipeline input: True (ByPropertyName)
205+
Accept wildcard characters: False
206+
```
207+
161208
### -GalleryName
162209
The name of the gallery.
163210

@@ -431,6 +478,10 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
431478

432479
### System.String[]
433480

481+
### Microsoft.Azure.Management.Compute.Models.GalleryImageFeature[]
482+
483+
### System.Boolean
484+
434485
## OUTPUTS
435486

436487
### Microsoft.Azure.Commands.Compute.Automation.Models.PSGalleryImage

0 commit comments

Comments
 (0)