Skip to content

Commit 3e3d9b9

Browse files
grizzlytheodoreTheodore Chang
authored andcommitted
add sharedGalleryImageId (#21139)
Co-authored-by: Theodore Chang <[email protected]>
1 parent 68d89c2 commit 3e3d9b9

15 files changed

+251
-21
lines changed

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 `-SharedGalleryImageId` parameter to `New-AzVM`, `New-AzVmConfig`, `New-AzVmss`, `New-AzVmssConfig`, `Update-AzVmss`, and `Set-AzVmssStorageProfile`.
2324

2425
## Version 5.5.0
2526
* Added breaking change message for `New-AzVmss`.

src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssConfigCommand.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
310310
[ResourceIdCompleter("Microsoft.Compute galleries/images/versions")]
311311
public string ImageReferenceId { get; set; }
312312

313+
[Parameter(
314+
Mandatory = false,
315+
HelpMessage = "Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.")]
316+
public string SharedGalleryImageId { get; set; }
317+
313318
protected override void ProcessRecord()
314319
{
315320
if (ShouldProcess("VirtualMachineScaleSet", "New"))
@@ -769,6 +774,25 @@ private void Run()
769774
vVirtualMachineProfile.StorageProfile.ImageReference.Id = this.ImageReferenceId;
770775
}
771776

777+
if (this.IsParameterBound(c => c.SharedGalleryImageId))
778+
{
779+
if (vVirtualMachineProfile == null)
780+
{
781+
vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile();
782+
}
783+
784+
if (vVirtualMachineProfile.StorageProfile == null)
785+
{
786+
vVirtualMachineProfile.StorageProfile = new VirtualMachineScaleSetStorageProfile();
787+
}
788+
789+
if (vVirtualMachineProfile.StorageProfile.ImageReference == null)
790+
{
791+
vVirtualMachineProfile.StorageProfile.ImageReference = new ImageReference();
792+
}
793+
vVirtualMachineProfile.StorageProfile.ImageReference.SharedGalleryImageId = this.SharedGalleryImageId;
794+
}
795+
772796
var vVirtualMachineScaleSet = new PSVirtualMachineScaleSet
773797
{
774798
Overprovision = this.IsParameterBound(c => c.Overprovision) ? this.Overprovision : (bool?)null,

src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/SetAzureRmVmssStorageProfileCommand.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ public partial class SetAzureRmVmssStorageProfileCommand : Microsoft.Azure.Comma
175175
HelpMessage = "ResourceId of the disk encryption set to use for enabling encryption at rest.")]
176176
public string SecureVMDiskEncryptionSet { get; set; }
177177

178+
[Parameter(
179+
Mandatory = false,
180+
HelpMessage = "Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.")]
181+
public string SharedGalleryImageId { get; set; }
182+
178183
protected override void ProcessRecord()
179184
{
180185
if (ShouldProcess("VirtualMachineScaleSet", "Set"))
@@ -285,6 +290,26 @@ private void Run()
285290
this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile.ImageReference.Id = this.ImageReferenceId;
286291
}
287292

293+
if (this.IsParameterBound(c => c.SharedGalleryImageId))
294+
{
295+
// VirtualMachineProfile
296+
if (this.VirtualMachineScaleSet.VirtualMachineProfile == null)
297+
{
298+
this.VirtualMachineScaleSet.VirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile();
299+
}
300+
// StorageProfile
301+
if (this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile == null)
302+
{
303+
this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile = new VirtualMachineScaleSetStorageProfile();
304+
}
305+
// ImageReference
306+
if (this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile.ImageReference == null)
307+
{
308+
this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile.ImageReference = new ImageReference();
309+
}
310+
this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile.ImageReference.SharedGalleryImageId = this.SharedGalleryImageId;
311+
}
312+
288313
if (this.IsParameterBound(c => c.OsDiskName))
289314
{
290315
// VirtualMachineProfile

src/Compute/Compute/Generated/VirtualMachineScaleSet/VirtualMachineScaleSetUpdateMethod.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ public override void ExecuteCmdlet()
371371
ValueFromPipelineByPropertyName = true)]
372372
public int RegularPriorityPercentage { get; set; }
373373

374+
[Parameter(
375+
Mandatory = false,
376+
HelpMessage = "Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.")]
377+
public string SharedGalleryImageId { get; set; }
378+
374379
private void BuildPatchObject()
375380
{
376381
if (this.IsParameterBound(c => c.AutomaticOSUpgrade))
@@ -590,6 +595,28 @@ private void BuildPatchObject()
590595
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile.ImageReference.Id = this.ImageReferenceId;
591596
}
592597

598+
if (this.IsParameterBound(c => c.SharedGalleryImageId))
599+
{
600+
if (this.VirtualMachineScaleSetUpdate == null)
601+
{
602+
this.VirtualMachineScaleSetUpdate = new VirtualMachineScaleSetUpdate();
603+
}
604+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile == null)
605+
{
606+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile = new VirtualMachineScaleSetUpdateVMProfile();
607+
}
608+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile == null)
609+
{
610+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile = new VirtualMachineScaleSetUpdateStorageProfile();
611+
}
612+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile.ImageReference == null)
613+
{
614+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile.ImageReference = new ImageReference();
615+
}
616+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile.ImageReference.SharedGalleryImageId = this.SharedGalleryImageId;
617+
}
618+
619+
593620
if (this.IsParameterBound(c => c.ImageReferenceOffer))
594621
{
595622
if (this.VirtualMachineScaleSetUpdate == null)
@@ -1412,6 +1439,27 @@ private void BuildPutObject()
14121439
this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile.ImageReference.Id = this.ImageReferenceId;
14131440
}
14141441

1442+
if (this.IsParameterBound(c => c.SharedGalleryImageId))
1443+
{
1444+
if (this.VirtualMachineScaleSetUpdate == null)
1445+
{
1446+
this.VirtualMachineScaleSetUpdate = new VirtualMachineScaleSetUpdate();
1447+
}
1448+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile == null)
1449+
{
1450+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile = new VirtualMachineScaleSetUpdateVMProfile();
1451+
}
1452+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile == null)
1453+
{
1454+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile = new VirtualMachineScaleSetUpdateStorageProfile();
1455+
}
1456+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile.ImageReference == null)
1457+
{
1458+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile.ImageReference = new ImageReference();
1459+
}
1460+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.StorageProfile.ImageReference.SharedGalleryImageId = this.SharedGalleryImageId;
1461+
}
1462+
14151463
if (this.IsParameterBound(c => c.ImageReferenceOffer))
14161464
{
14171465
if (this.VirtualMachineScaleSet.VirtualMachineProfile == null)

src/Compute/Compute/Manual/VirtualMachineScaleSetCreateOrUpdateMethod.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ public partial class NewAzureRmVmss : ComputeAutomationBaseCmdlet
221221
[PSArgumentCompleter("SCSI", "NVMe")]
222222
public string DiskControllerType { get; set; }
223223

224+
[Parameter(
225+
Mandatory = false,
226+
ParameterSetName = SimpleParameterSet,
227+
HelpMessage = "Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.")]
228+
public string SharedGalleryImageId { get; set; }
229+
224230
const int FirstPortRangeStart = 50000;
225231

226232
sealed class Parameters : IParameters<VirtualMachineScaleSet>
@@ -414,7 +420,8 @@ private async Task<ResourceConfig<VirtualMachineScaleSet>> SimpleParameterSetNor
414420
userData: _cmdlet.IsParameterBound(c => c.UserData) ? _cmdlet.UserData : null,
415421
imageReferenceId: _cmdlet.IsParameterBound(c => c.ImageReferenceId) ? _cmdlet.ImageReferenceId : null,
416422
auxAuthHeader: auxAuthHeader,
417-
diskControllerType: _cmdlet.DiskControllerType
423+
diskControllerType: _cmdlet.DiskControllerType,
424+
sharedImageGalleryId: _cmdlet.IsParameterBound(c => c.SharedGalleryImageId) ? _cmdlet.SharedGalleryImageId : null
418425
);
419426
}
420427

src/Compute/Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ internal static ResourceConfig<VirtualMachineScaleSet> CreateVirtualMachineScale
7070
string userData,
7171
string imageReferenceId,
7272
Dictionary<string, List<string>> auxAuthHeader,
73-
string diskControllerType
73+
string diskControllerType,
74+
string sharedImageGalleryId
7475
)
7576
=> Strategy.CreateResourceConfig(
7677
resourceGroup: resourceGroup,
@@ -108,10 +109,12 @@ string diskControllerType
108109
{
109110
ImageReference = (imageReferenceId == null) ? imageAndOsType?.Image : (imageReferenceId.ToLower().StartsWith("/communitygalleries/") ? new ImageReference
110111
{
111-
CommunityGalleryImageId = imageReferenceId
112+
CommunityGalleryImageId = imageReferenceId,
113+
SharedGalleryImageId = sharedImageGalleryId
112114
} : new ImageReference
113115
{
114-
Id = imageReferenceId
116+
Id = imageReferenceId,
117+
SharedGalleryImageId = sharedImageGalleryId
115118
}),
116119
DataDisks = DataDiskStrategy.CreateVmssDataDisks(
117120
imageAndOsType?.DataDiskLuns, dataDisks),

src/Compute/Compute/Strategies/ComputeRp/VirtualMachineStrategy.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
7373
string imageReferenceId = null,
7474
Dictionary<string, List<string>> auxAuthHeader = null,
7575
string diskControllerType = null,
76-
Microsoft.Azure.Management.Compute.Models.ExtendedLocation extendedLocation = null
76+
Microsoft.Azure.Management.Compute.Models.ExtendedLocation extendedLocation = null,
77+
string sharedGalleryImageId = null
7778
)
7879
=> Strategy.CreateResourceConfig(
7980
resourceGroup: resourceGroup,
@@ -114,10 +115,12 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
114115
//ImageReference = (imageReferenceId.Contains("CommunityGalleries")) ? new ImageReference { CommunityGalleryImageId = imageReferenceId}
115116
ImageReference = (imageReferenceId == null) ? imageAndOsType?.Image : (imageReferenceId.ToLower().StartsWith("/communitygalleries/") ? new ImageReference
116117
{
117-
CommunityGalleryImageId = imageReferenceId
118+
CommunityGalleryImageId = imageReferenceId,
119+
SharedGalleryImageId = sharedGalleryImageId
118120
}: new ImageReference
119121
{
120-
Id = imageReferenceId
122+
Id = imageReferenceId,
123+
SharedGalleryImageId = sharedGalleryImageId
121124
}),
122125
OsDisk = new OSDisk(
123126
createOption: DiskCreateOptionTypes.FromImage,

src/Compute/Compute/VirtualMachine/Config/NewAzureVMConfigCommand.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ protected override bool IsUsageMetricEnabled
185185
HelpMessage = "Specifies the vCPU to physical core ratio. When this property is not specified in the request body the default behavior is set to the value of vCPUsPerCore for the VM Size exposed in api response of [List all available virtual machine sizes in a region](https://learn.microsoft.com/en-us/rest/api/compute/resource-skus/list). Setting this property to 1 also means that hyper-threading is disabled.")]
186186
public int vCPUCountPerCore { get; set; }
187187

188+
[Parameter(
189+
Mandatory = false,
190+
HelpMessage = "Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.")]
191+
public string SharedGalleryImageId { get; set; }
192+
188193
public override void ExecuteCmdlet()
189194
{
190195
var vm = new PSVirtualMachine
@@ -329,6 +334,19 @@ public override void ExecuteCmdlet()
329334
vm.StorageProfile.ImageReference.Id = this.ImageReferenceId;
330335
}
331336

337+
if (this.IsParameterBound(c => c.SharedGalleryImageId))
338+
{
339+
if (vm.StorageProfile == null)
340+
{
341+
vm.StorageProfile = new StorageProfile();
342+
}
343+
if (vm.StorageProfile.ImageReference == null)
344+
{
345+
vm.StorageProfile.ImageReference = new ImageReference();
346+
}
347+
vm.StorageProfile.ImageReference.SharedGalleryImageId = this.SharedGalleryImageId;
348+
}
349+
332350
if (this.IsParameterBound(c => c.DiskControllerType))
333351
{
334352
if (vm.StorageProfile == null)

src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ public class NewAzureVMCommand : VirtualMachineBaseCmdlet
413413
[PSArgumentCompleter("SCSI", "NVMe")]
414414
public string DiskControllerType { get; set; }
415415

416+
[Parameter(
417+
Mandatory = false,
418+
ParameterSetName = SimpleParameterSet,
419+
HelpMessage = "Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.")]
420+
public string SharedGalleryImageId { get; set; }
421+
416422
public override void ExecuteCmdlet()
417423
{
418424
if (this.IsParameterBound(c => c.UserData))
@@ -650,7 +656,8 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
650656
imageReferenceId: _cmdlet.ImageReferenceId,
651657
auxAuthHeader: auxAuthHeader,
652658
diskControllerType: _cmdlet.DiskControllerType,
653-
extendedLocation: extLoc
659+
extendedLocation: extLoc,
660+
sharedGalleryImageId: _cmdlet.SharedGalleryImageId
654661
);
655662
}
656663
else

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ New-AzVM [[-ResourceGroupName] <String>] [[-Location] <String>] [-EdgeZone <Stri
2727
[-HostGroupId <String>] [-SshKeyName <String>] [-GenerateSshKey] [-CapacityReservationGroupId <String>]
2828
[-UserData <String>] [-ImageReferenceId <String>] [-PlatformFaultDomain <Int32>] [-HibernationEnabled]
2929
[-vCPUCountAvailable <Int32>] [-vCPUCountPerCore <Int32>] [-DiskControllerType <String>]
30-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
30+
[-SharedGalleryImageId <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
31+
[<CommonParameters>]
3132
```
3233

3334
### DefaultParameterSet
@@ -953,6 +954,21 @@ Accept pipeline input: False
953954
Accept wildcard characters: False
954955
```
955956

957+
### -SharedGalleryImageId
958+
Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.
959+
960+
```yaml
961+
Type: System.String
962+
Parameter Sets: SimpleParameterSet
963+
Aliases:
964+
965+
Required: False
966+
Position: Named
967+
Default value: None
968+
Accept pipeline input: False
969+
Accept wildcard characters: False
970+
```
971+
956972
### -Size
957973
The Virtual Machine Size. [Get-AzComputeResourceSku](https://learn.microsoft.com/en-us/powershell/module/az.compute/get-azcomputeresourcesku) can be used to find out available sizes for your subscription and region.<br>
958974
The Default Value is: Standard_D2s_v3.

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ New-AzVMConfig [-VMName] <String> [-VMSize] <String> [[-AvailabilitySetId] <Stri
2020
[-MaxPrice <Double>] [-EvictionPolicy <String>] [-Priority <String>] [-Tags <Hashtable>] [-EnableUltraSSD]
2121
[-EncryptionAtHost] [-CapacityReservationGroupId <String>] [-ImageReferenceId <String>]
2222
[-DiskControllerType <String>] [-UserData <String>] [-PlatformFaultDomain <Int32>] [-HibernationEnabled]
23-
[-vCPUCountAvailable <Int32>] [-vCPUCountPerCore <Int32>] [-DefaultProfile <IAzureContextContainer>]
24-
[<CommonParameters>]
23+
[-vCPUCountAvailable <Int32>] [-vCPUCountPerCore <Int32>] [-SharedGalleryImageId <String>]
24+
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2525
```
2626

2727
### ExplicitIdentityParameterSet
@@ -32,7 +32,8 @@ New-AzVMConfig [-VMName] <String> [-VMSize] <String> [[-AvailabilitySetId] <Stri
3232
[-EvictionPolicy <String>] [-Priority <String>] [-Tags <Hashtable>] [-EnableUltraSSD] [-EncryptionAtHost]
3333
[-CapacityReservationGroupId <String>] [-ImageReferenceId <String>] [-DiskControllerType <String>]
3434
[-UserData <String>] [-PlatformFaultDomain <Int32>] [-HibernationEnabled] [-vCPUCountAvailable <Int32>]
35-
[-vCPUCountPerCore <Int32>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
35+
[-vCPUCountPerCore <Int32>] [-SharedGalleryImageId <String>] [-DefaultProfile <IAzureContextContainer>]
36+
[<CommonParameters>]
3637
```
3738

3839
## DESCRIPTION
@@ -340,6 +341,21 @@ Accept pipeline input: True (ByPropertyName)
340341
Accept wildcard characters: False
341342
```
342343
344+
### -SharedGalleryImageId
345+
Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.
346+
347+
```yaml
348+
Type: System.String
349+
Parameter Sets: (All)
350+
Aliases:
351+
352+
Required: False
353+
Position: Named
354+
Default value: None
355+
Accept pipeline input: False
356+
Accept wildcard characters: False
357+
```
358+
343359
### -Tags
344360
The tags attached to the resource.
345361

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ New-AzVmss [[-ResourceGroupName] <String>] [-VMScaleSetName] <String> [-AsJob] [
3535
[-Priority <String>] [-EvictionPolicy <String>] [-MaxPrice <Double>] [-ScaleInPolicy <String[]>]
3636
[-SkipExtensionsOnOverprovisionedVMs] [-EncryptionAtHost] [-PlatformFaultDomainCount <Int32>]
3737
[-OrchestrationMode <String>] [-CapacityReservationGroupId <String>] [-ImageReferenceId <String>]
38-
[-DiskControllerType <String>] [-DefaultProfile <IAzureContextContainer>] [-SinglePlacementGroup] [-WhatIf]
39-
[-Confirm] [<CommonParameters>]
38+
[-DiskControllerType <String>] [-SharedGalleryImageId <String>] [-DefaultProfile <IAzureContextContainer>]
39+
[-SinglePlacementGroup] [-WhatIf] [-Confirm] [<CommonParameters>]
4040
```
4141

4242
## DESCRIPTION
@@ -763,6 +763,21 @@ Accept pipeline input: False
763763
Accept wildcard characters: False
764764
```
765765

766+
### -SharedGalleryImageId
767+
Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.
768+
769+
```yaml
770+
Type: System.String
771+
Parameter Sets: SimpleParameterSet
772+
Aliases:
773+
774+
Required: False
775+
Position: Named
776+
Default value: None
777+
Accept pipeline input: False
778+
Accept wildcard characters: False
779+
```
780+
766781
### -SinglePlacementGroup
767782
Use this to create the Scale set in a single placement group, default is multiple groups
768783

0 commit comments

Comments
 (0)