Skip to content

Commit

Permalink
New-AzGalleryImageVersion new parameter SourceImageVMId (Azure#24449)
Browse files Browse the repository at this point in the history
* dev and test

* test success

* comment

* error msg

* test error fix

* changelog

* help doc

* tmp

* help doc

* remove errors already in backend
  • Loading branch information
Sandido authored Mar 26, 2024
1 parent ee7a92d commit 24ac91f
Show file tree
Hide file tree
Showing 7 changed files with 4,450 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/GalleryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,12 @@ public void TestGalleryDirectSharing()
{
TestRunner.RunTestScript("Test-GalleryDirectSharing");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGalleryVersionWithSourceImageVMId()
{
TestRunner.RunTestScript("Test-GalleryVersionWithSourceImageVMId");
}
}
}
112 changes: 111 additions & 1 deletion src/Compute/Compute.Test/ScenarioTests/GalleryTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -767,4 +767,114 @@ function Test-GalleryDirectSharing
# Cleanup
Clean-ResourceGroup $rgname
}
}
}

<#
.SYNOPSIS
Tests the New-AzGalleryImageVersion new parameter SourceImageVMId.
#>
function Test-GalleryVersionWithSourceImageVMId
{
# Setup
$rgname = Get-ComputeTestResourceName;
$loc = Get-ComputeVMLocation;

try
{

$location = $loc;
New-AzResourceGroup -Name $rgname -Location $loc -Force;
# create credential
$password = Get-PasswordForVM;
$securePassword = $password | ConvertTo-SecureString -AsPlainText -Force;
$user = Get-ComputeTestResourceName;
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);

# Add one VM from creation
$vmname = 'vm' + $rgname;
$domainNameLabel = "d1" + $rgname;
$securityType_TL = "TrustedLaunch";
$PublisherName = "MicrosoftWindowsServer";
$Offer = "WindowsServer";
$SKU = "2022-datacenter-azure-edition";
$version = "latest";
$disable = $false;
$enable = $true;
$galleryName = "g" + $rgname;
$VMSize = "Standard_DS2_v2";
$vnetname = "vn" + $rgname;
$vnetAddress = "10.0.0.0/16";
$subnetname = "slb" + $rgname;
$subnetAddress = "10.0.2.0/24";
$pubipname = "p" + $rgname;
$OSDiskName = $vmname + "-osdisk";
$NICName = $vmname+ "-nic";
$NSGName = $vmname + "-NSG";
$nsgrulename = "nsr" + $rgname;
$OSDiskSizeinGB = 128;
$VMSize = "Standard_DS2_v2";
$vmname2 = "2" + $vmname;


# Gallery variables
$resourceGroup = $rgname
$galleryName = 'gl' + $rgname
$definitionName = 'def' + $rgname
$skuDetails = @{
Publisher = 'test'
Offer = 'test'
Sku = 'test'
}
$osType = 'Windows'
$osState = 'Specialized'
[bool]$trustedLaunch = $false
$storageAccountSku = 'Standard_LRS'
$hyperVGeneration = 'v1'

# create new VM
$vm = New-AzVM -ResourceGroupName $rgname -Location $loc -Name $vmname -Credential $cred -SecurityType "Standard" -DomainNameLabel $domainNameLabel;
start-sleep -seconds 300

# Setup Image Gallery
New-AzGallery -ResourceGroupName $rgname -Name $galleryName -location $location -ErrorAction 'Stop' | Out-Null;

# Setup Image Definition
$paramNewAzImageDef = @{
ResourceGroupName = $rgname
GalleryName = $galleryName
Name = $definitionName
Publisher = $skuDetails.Publisher
Offer = $skuDetails.Offer
Sku = $skuDetails.Sku
Location = $location
OSState = $osState
OsType = $osType
HyperVGeneration = $hyperVGeneration
ErrorAction = 'Stop'
}

New-AzGalleryImageDefinition @paramNewAzImageDef;

# Setup Image Version
$imageVersionName = "1.0.0";
$paramNewAzImageVer = @{
ResourceGroupName = $rgname
GalleryName = $galleryName
GalleryImageDefinitionName = $definitionName
Name = $imageVersionName
Location = $location
SourceImageVMId = $vm.Id
ErrorAction = 'Stop'
StorageAccountType = $storageAccountSku
}
$galversion = New-AzGalleryImageVersion @paramNewAzImageVer;

# Assert VMId in version was set to the vm.Id value and was created.
Assert-AreEqual $galversion.StorageProfile.Source.VirtualMachineId $vm.Id;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7442,7 +7442,6 @@ function Test-VMTLWithGallerySourceImage
}
}


<#
.SYNOPSIS
Testing Capacity Reservation Sharing profile parameter
Expand Down Expand Up @@ -7488,4 +7487,4 @@ function Test-CapacityReservationSharingProfile
# Cleanup
Clean-ResourceGroup $rgname;
}
}
}

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
`New-AzVM` and `New-AzVmss` will default to the image `Windows Server 2022 Azure Edition` instead of `Windows 2016 Datacenter` by default.
`Get-AzVmss` will no longer allow empty values to `ResourceGroupName` and `VMScaleSetName` to avoid a bug where it will just return nothing.
* Added a new parameter `-SharingProfile` to `New-AzCapacityReservationGroup` and `Update-AzCapacityReservationGroup`.
* Added the new parameter `SourceImageVMId` to the `New-AzGalleryImageVersion` cmdlet. Also added some error messages for this new parameter and the existing parameter `SourceImageId`.

## Version 7.1.2
* Fixed `New-AzVM` when a source image is specified to avoid an error on the `Version` value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,33 @@ public override void ExecuteCmdlet()
}
}
if (this.IsParameterBound(c => c.SourceImageVMId))
{
if (galleryImageVersion.StorageProfile == null)
{
galleryImageVersion.StorageProfile = new GalleryImageVersionStorageProfile();
}
if (galleryImageVersion.StorageProfile.Source == null)
{
galleryImageVersion.StorageProfile.Source = new GalleryArtifactVersionFullSource();
}
galleryImageVersion.StorageProfile.Source.VirtualMachineId = this.SourceImageVMId;
var resourceId = ResourceId.TryParse(this.SourceImageVMId);
if (string.Equals("galleries", resourceId?.ResourceType?.Provider, StringComparison.OrdinalIgnoreCase)
&& !string.Equals(this.ComputeClient?.ComputeManagementClient?.SubscriptionId, resourceId?.SubscriptionId, StringComparison.OrdinalIgnoreCase))
{
List<string> resourceIds = new List<string>();
resourceIds.Add(this.SourceImageVMId);
var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds);
if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
{
auxAuthHeader = new Dictionary<string, List<string>>(auxHeaderDictionary);
}
}
}
GalleryImageVersion result;
if (auxAuthHeader != null)
{
Expand Down Expand Up @@ -355,6 +382,12 @@ public override void ExecuteCmdlet()
ValueFromPipelineByPropertyName = true)]
public string SourceImageId { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource Id of the source virtual machine. Only required when capturing a virtual machine to source this Gallery Image Version.")]
public string SourceImageVMId { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
Expand Down
18 changes: 17 additions & 1 deletion src/Compute/Compute/help/New-AzGalleryImageVersion.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ New-AzGalleryImageVersion [-ResourceGroupName] <String> [-GalleryName] <String>
[-GalleryImageDefinitionName] <String> [-Name] <String> [-AsJob] -Location <String>
[-DataDiskImage <GalleryDataDiskImage[]>] [-OSDiskImage <GalleryOSDiskImage>]
[-PublishingProfileEndOfLifeDate <DateTime>] [-PublishingProfileExcludeFromLatest] [-ReplicaCount <Int32>]
[-SourceImageId <String>] [-StorageAccountType <String>] [-Tag <Hashtable>] [-TargetRegion <Hashtable[]>]
[-SourceImageId <String>] [-StorageAccountType <String>] [-SourceImageVMId <String>] [-Tag <Hashtable>] [-TargetRegion <Hashtable[]>]
[-TargetExtendedLocation <Hashtable[]>] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```
Expand Down Expand Up @@ -509,6 +509,22 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -SourceImageVMId
The resource Id of the source virtual machine. Only required when capturing a virtual machine to source this Gallery Image Version.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Tag
Resource tags
Expand Down

0 comments on commit 24ac91f

Please sign in to comment.