Skip to content

Commit c487776

Browse files
committed
Update Set-AzureVMSourceImage
1 parent abd055c commit c487776

File tree

3 files changed

+33
-38
lines changed

3 files changed

+33
-38
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineNetworkInterfaceTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function Test-SingleNetworkInterface
102102
# Image Reference;
103103
$p.StorageProfile.SourceImage = $null;
104104
$imgRef = Get-DefaultCRPImage;
105-
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
105+
$p = ($imgRef | Set-AzureVMSourceImage -VM $p);
106106
Assert-NotNull $p.StorageProfile.ImageReference;
107107
Assert-Null $p.StorageProfile.SourceImageId;
108108

@@ -208,7 +208,7 @@ function Test-SingleNetworkInterfaceDnsSettings
208208
# Image Reference;
209209
$p.StorageProfile.SourceImage = $null;
210210
$imgRef = Get-DefaultCRPImage;
211-
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
211+
$p = ($imgRef | Set-AzureVMSourceImage -VM $p);
212212
Assert-NotNull $p.StorageProfile.ImageReference;
213213
Assert-Null $p.StorageProfile.SourceImageId;
214214

@@ -318,7 +318,7 @@ function Test-MultipleNetworkInterface
318318
# Image Reference;
319319
$p.StorageProfile.SourceImage = $null;
320320
$imgRef = Get-DefaultCRPImage;
321-
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
321+
$p = ($imgRef | Set-AzureVMSourceImage -VM $p);
322322
Assert-NotNull $p.StorageProfile.ImageReference;
323323
Assert-Null $p.StorageProfile.SourceImageId;
324324

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ function Test-VirtualMachineSizeAndUsage
454454
# Image Reference;
455455
$p.StorageProfile.SourceImage = $null;
456456
$imgRef = Get-DefaultCRPImage;
457-
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
457+
$p = Set-AzureVMSourceImage -VM $p -PublisherName $imgRef.PublisherName -Offer $imgRef.Offer -Skus $imgRef.Skus -Version $imgRef.Version;
458458
Assert-NotNull $p.StorageProfile.ImageReference;
459459
Assert-Null $p.StorageProfile.SourceImageId;
460460

@@ -620,7 +620,7 @@ function Test-VirtualMachinePIRv2
620620
# Image Reference;
621621
$p.StorageProfile.SourceImage = $null;
622622
$imgRef = Get-DefaultCRPImage;
623-
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
623+
$p = ($imgRef | Set-AzureVMSourceImage -VM $p);
624624
Assert-NotNull $p.StorageProfile.ImageReference;
625625
Assert-Null $p.StorageProfile.SourceImageId;
626626

@@ -730,7 +730,7 @@ function Test-VirtualMachineCapture
730730
# Image Reference;
731731
$p.StorageProfile.SourceImage = $null;
732732
$imgRef = Get-DefaultCRPImage;
733-
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
733+
$p = ($imgRef | Set-AzureVMSourceImage -VM $p);
734734

735735
# TODO: Remove Data Disks for now
736736
$p.StorageProfile.DataDisks = $null;
@@ -825,7 +825,7 @@ function Test-VirtualMachineDataDisk
825825
# Image Reference;
826826
$p.StorageProfile.SourceImage = $null;
827827
$imgRef = Get-DefaultCRPImage;
828-
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
828+
$p = ($imgRef | Set-AzureVMSourceImage -VM $p);
829829

830830
# Negative Tests on A0 Size + 2 Data Disks
831831
Assert-ThrowsContains { New-AzureVM -ResourceGroupName $rgname -Location $loc -Name $vmname -VM $p; } "The maximum number of data disks allowed to be attached to a VM is 1.";
@@ -901,7 +901,7 @@ function Test-VirtualMachinePlan
901901
# Image Reference;
902902
$p.StorageProfile.SourceImage = $null;
903903
$imgRef = Get-DefaultCRPImage;
904-
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
904+
$p = ($imgRef | Set-AzureVMSourceImage -VM $p);
905905

906906
$plan = Get-ComputeTestResourceName;
907907
$p.Plan = New-Object Microsoft.Azure.Management.Compute.Models.Plan;
@@ -989,7 +989,7 @@ function Test-VirtualMachinePlan2
989989
$vmmImgVerName = '1.0.0';
990990
$imgRef = Get-AzureVMImageDetail -PublisherName $vmmImgPubName -Location $loc -Offer $vmmImgOfferName -Skus $vmmImgSkusName -Version $vmmImgVerName;
991991
$plan = $imgRef.PurchasePlan;
992-
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
992+
$p = Set-AzureVMSourceImage -VM $p -PublisherName $imgRef.PublisherName -Offer $imgRef.Offer -Skus $imgRef.Skus -Version $imgRef.Version;
993993
$p.Plan = New-Object Microsoft.Azure.Management.Compute.Models.Plan;
994994
$p.Plan.Name = $plan.Name;
995995
$p.Plan.Publisher = $plan.Publisher;

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMSourceImage.cs

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,30 @@ public class SetAzureVMSourceImageCommand : AzurePSCmdlet
3030
protected const string SourceImageParameterSet = "SourceImageParameterSet";
3131

3232
[Alias("VMProfile")]
33-
[Parameter(
34-
Mandatory = true,
35-
Position = 0,
36-
ValueFromPipeline = true,
37-
ValueFromPipelineByPropertyName = true,
38-
HelpMessage = HelpMessages.VMProfile)]
33+
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
3934
[ValidateNotNullOrEmpty]
4035
public PSVirtualMachine VM { get; set; }
4136

4237
[Alias("SourceImageName", "ImageName")]
43-
[Parameter(
44-
ParameterSetName = SourceImageParameterSet,
45-
Mandatory = true,
46-
Position = 1,
47-
ValueFromPipelineByPropertyName = true,
48-
HelpMessage = HelpMessages.VMSourceImageName)]
38+
[Parameter(ParameterSetName = SourceImageParameterSet, Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)]
4939
[ValidateNotNullOrEmpty]
5040
public string Name { get; set; }
5141

52-
[Alias("ImageConfig", "Image")]
53-
[Parameter(
54-
ParameterSetName = ImageReferenceParameterSet,
55-
Mandatory = true,
56-
Position = 1,
57-
ValueFromPipelineByPropertyName = true,
58-
HelpMessage = HelpMessages.VMImageReference)]
42+
[Parameter(ParameterSetName = ImageReferenceParameterSet, Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)]
5943
[ValidateNotNullOrEmpty]
60-
public PSVirtualMachineImage ImageReference { get; set; }
44+
public string PublisherName { get; set; }
45+
46+
[Parameter(ParameterSetName = ImageReferenceParameterSet, Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true)]
47+
[ValidateNotNullOrEmpty]
48+
public string Offer { get; set; }
49+
50+
[Parameter(ParameterSetName = ImageReferenceParameterSet, Mandatory = true, Position = 3, ValueFromPipelineByPropertyName = true)]
51+
[ValidateNotNullOrEmpty]
52+
public string Skus { get; set; }
53+
54+
[Parameter(ParameterSetName = ImageReferenceParameterSet, Mandatory = true, Position = 4, ValueFromPipelineByPropertyName = true)]
55+
[ValidateNotNullOrEmpty]
56+
public string Version { get; set; }
6157

6258
public override void ExecuteCmdlet()
6359
{
@@ -68,20 +64,19 @@ public override void ExecuteCmdlet()
6864

6965
if (this.ParameterSetName == SourceImageParameterSet)
7066
{
71-
this.VM.StorageProfile.SourceImage = string.IsNullOrEmpty(this.Name) ? null :
72-
new SourceImageReference
73-
{
74-
ReferenceUri = this.Name
75-
}.Normalize(this.Profile.Context.Subscription.Id.ToString());
67+
this.VM.StorageProfile.SourceImage = new SourceImageReference
68+
{
69+
ReferenceUri = this.Name
70+
}.Normalize(this.Profile.Context.Subscription.Id.ToString());
7671
}
7772
else if (this.ParameterSetName == ImageReferenceParameterSet)
7873
{
7974
this.VM.StorageProfile.ImageReference = new ImageReference
8075
{
81-
Publisher = ImageReference.PublisherName,
82-
Offer = ImageReference.Offer,
83-
Sku = ImageReference.Skus,
84-
Version = ImageReference.Version
76+
Publisher = PublisherName,
77+
Offer = Offer,
78+
Sku = Skus,
79+
Version = Version
8580
};
8681
}
8782

0 commit comments

Comments
 (0)