Skip to content

Commit 86a7690

Browse files
committed
Update VM Image Cmdlets
1 parent 8e47d2d commit 86a7690

File tree

8 files changed

+89
-51
lines changed

8 files changed

+89
-51
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,19 @@ function Test-VirtualMachineImageList
238238
$skus = $s3.Resources | select -ExpandProperty Name;
239239
foreach ($sku in $skus)
240240
{
241-
$s4 = Get-AzureVMImage -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku;
241+
$s4 = Get-AzureVMImageVersion -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku;
242242
if ($s4.Resources.Count -gt 0)
243243
{
244244
$versions = $s4.Resources | select -ExpandProperty Name;
245245

246-
$s6 = Get-AzureVMImage -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -FilterExpression ('name -eq *');
246+
$s6 = Get-AzureVMImageVersion -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -FilterExpression ('name -eq *');
247247
Assert-NotNull $s6;
248248
Assert-NotNull $s6.Resources;
249249
$verNames = $s6.Resources | select -ExpandProperty Name;
250250

251251
foreach ($ver in $versions)
252252
{
253+
if ($ver -eq $null -or $ver -eq '') { continue; }
253254
$s6 = Get-AzureVMImage -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -Version $ver;
254255
Assert-NotNull $s6;
255256
Assert-NotNull $s6.VirtualMachineImage;
@@ -318,10 +319,10 @@ function Test-VirtualMachineImageList
318319
Assert-ThrowsContains { $s3 = Get-AzureVMImageSku -Location $locStr -PublisherName $publisherName -Offer $offerName; } "$offerName was not found";
319320

320321
$skusName = Get-ComputeTestResourceName;
321-
Assert-ThrowsContains { $s4 = Get-AzureVMImage -Location $locStr -PublisherName $publisherName -Offer $offerName -Skus $skusName; } "$skusName was not found";
322+
Assert-ThrowsContains { $s4 = Get-AzureVMImageVersion -Location $locStr -PublisherName $publisherName -Offer $offerName -Skus $skusName; } "$skusName was not found";
322323

323324
$filter = "name eq 'latest'";
324-
Assert-ThrowsContains { $s5 = Get-AzureVMImage -Location $locStr -PublisherName $publisherName -Offer $offerName -Skus $skusName -FilterExpression $filter; } "was not found";
325+
Assert-ThrowsContains { $s5 = Get-AzureVMImageVersion -Location $locStr -PublisherName $publisherName -Offer $offerName -Skus $skusName -FilterExpression $filter; } "was not found";
325326

326327
$version = '1.0.0';
327328
Assert-ThrowsContains { $s6 = Get-AzureVMImage -Location $locStr -PublisherName $publisherName -Offer $offerName -Skus $skusName -Version $version; } "was not found";

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
<Compile Include="Extension\SetAzureVMExtensionCommand.cs" />
152152
<Compile Include="Extension\RemoveAzureVMExtensionCommand.cs" />
153153
<Compile Include="Extension\GetAzureVMExtensionCommand.cs" />
154+
<Compile Include="Images\GetAzureVMImageVersionCommand.cs" />
154155
<Compile Include="Models\PSStorageAccount.cs" />
155156
<Compile Include="Extension\VMAccess\GetAzureVMAccessExtension.cs" />
156157
<Compile Include="Extension\VMAccess\RemoveAzureVMAccessExtension.cs" />
@@ -285,4 +286,4 @@
285286
<Target Name="AfterBuild">
286287
</Target>
287288
-->
288-
</Project>
289+
</Project>

src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public static class ProfileNouns
8282
public const string VirtualMachineImagePublisher = "AzureVMImagePublisher";
8383
public const string VirtualMachineImageOffer = "AzureVMImageOffer";
8484
public const string VirtualMachineImageSku = "AzureVMImageSku";
85+
public const string VirtualMachineImageVersion = "AzureVMImageVersion";
8586

8687
public const string VirtualMachineUsage = "AzureVMUsage";
8788

src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageCommand.cs

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,63 +19,40 @@
1919

2020
namespace Microsoft.Azure.Commands.Compute
2121
{
22-
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineImage, DefaultParameterSetName = ListVirtualMachineImageParamSet)]
23-
[OutputType(typeof(VirtualMachineImageGetResponse), typeof(VirtualMachineImageResourceList))]
22+
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineImage)]
23+
[OutputType(typeof(VirtualMachineImageGetResponse))]
2424
public class GetAzureVMImageCommand : VirtualMachineImageBaseCmdlet
2525
{
26-
protected const string GetVirtualMachineImageDetailsParamSet = "GetVirtualMachineImageDetailsParamSet";
27-
protected const string ListVirtualMachineImageParamSet = "ListVirtualMachineImageParamSet";
28-
29-
[Parameter(Mandatory = true), ValidateNotNullOrEmpty]
26+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
3027
public string Location { get; set; }
3128

32-
[Parameter(Mandatory = true), ValidateNotNullOrEmpty]
29+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
3330
public string Offer { get; set; }
3431

35-
[Parameter(Mandatory = true), ValidateNotNullOrEmpty]
32+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
3633
public string PublisherName { get; set; }
3734

38-
[Parameter(Mandatory = true), ValidateNotNullOrEmpty]
35+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
3936
public string Skus { get; set; }
4037

41-
[Parameter(ParameterSetName = GetVirtualMachineImageDetailsParamSet), ValidateNotNullOrEmpty]
38+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
4239
public string Version { get; set; }
4340

44-
[Parameter(ParameterSetName = ListVirtualMachineImageParamSet), ValidateNotNullOrEmpty]
45-
public string FilterExpression { get; set; }
46-
4741
public override void ExecuteCmdlet()
4842
{
4943
base.ExecuteCmdlet();
5044

51-
if (this.ParameterSetName == GetVirtualMachineImageDetailsParamSet)
45+
var parameters = new VirtualMachineImageGetParameters
5246
{
53-
var parameters = new VirtualMachineImageGetParameters
54-
{
55-
Location = Location,
56-
Offer = Offer,
57-
PublisherName = PublisherName,
58-
Skus = Skus,
59-
Version = Version
60-
};
61-
62-
VirtualMachineImageGetResponse result = this.VirtualMachineImageClient.Get(parameters);
63-
WriteObject(result);
64-
}
65-
else if (this.ParameterSetName == ListVirtualMachineImageParamSet)
66-
{
67-
var parameters = new VirtualMachineImageListParameters
68-
{
69-
Location = Location,
70-
Offer = Offer,
71-
PublisherName = PublisherName,
72-
Skus = Skus,
73-
FilterExpression = FilterExpression
74-
};
75-
76-
VirtualMachineImageResourceList result = this.VirtualMachineImageClient.List(parameters);
77-
WriteObject(result);
78-
}
47+
Location = Location,
48+
Offer = Offer,
49+
PublisherName = PublisherName,
50+
Skus = Skus,
51+
Version = Version
52+
};
53+
54+
VirtualMachineImageGetResponse result = this.VirtualMachineImageClient.Get(parameters);
55+
WriteObject(result);
7956
}
8057
}
8158
}

src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageOfferCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ namespace Microsoft.Azure.Commands.Compute
2323
[OutputType(typeof(VirtualMachineImageResourceList))]
2424
public class GetAzureVMImageOfferCommand : VirtualMachineImageBaseCmdlet
2525
{
26-
[Parameter(Mandatory = true), ValidateNotNullOrEmpty]
26+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
2727
public string Location { get; set; }
2828

29-
[Parameter(Mandatory = true), ValidateNotNullOrEmpty]
29+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
3030
public string PublisherName { get; set; }
3131

3232
public override void ExecuteCmdlet()

src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImagePublisherCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.Azure.Commands.Compute
2323
[OutputType(typeof(VirtualMachineImageResourceList))]
2424
public class GetAzureVMImagePublisherCommand : VirtualMachineImageBaseCmdlet
2525
{
26-
[Parameter(Mandatory = true), ValidateNotNullOrEmpty]
26+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
2727
public string Location { get; set; }
2828

2929
public override void ExecuteCmdlet()

src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageSkuCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ namespace Microsoft.Azure.Commands.Compute
2323
[OutputType(typeof(VirtualMachineImageResourceList))]
2424
public class GetAzureVMImageSkuCommand : VirtualMachineImageBaseCmdlet
2525
{
26-
[Parameter(Mandatory = true), ValidateNotNullOrEmpty]
26+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
2727
public string Location { get; set; }
2828

29-
[Parameter(Mandatory = true), ValidateNotNullOrEmpty]
29+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
3030
public string PublisherName { get; set; }
3131

32-
[Parameter(Mandatory = true), ValidateNotNullOrEmpty]
32+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
3333
public string Offer { get; set; }
3434

3535
public override void ExecuteCmdlet()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Compute.Common;
16+
using Microsoft.Azure.Management.Compute;
17+
using Microsoft.Azure.Management.Compute.Models;
18+
using System.Management.Automation;
19+
20+
namespace Microsoft.Azure.Commands.Compute
21+
{
22+
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineImageVersion)]
23+
[OutputType(typeof(VirtualMachineImageResourceList))]
24+
public class GetAzureVMImageVersionCommand : VirtualMachineImageBaseCmdlet
25+
{
26+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
27+
public string Location { get; set; }
28+
29+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
30+
public string Offer { get; set; }
31+
32+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
33+
public string PublisherName { get; set; }
34+
35+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
36+
public string Skus { get; set; }
37+
38+
[Parameter, ValidateNotNullOrEmpty]
39+
public string FilterExpression { get; set; }
40+
41+
public override void ExecuteCmdlet()
42+
{
43+
base.ExecuteCmdlet();
44+
45+
var parameters = new VirtualMachineImageListParameters
46+
{
47+
Location = Location,
48+
Offer = Offer,
49+
PublisherName = PublisherName,
50+
Skus = Skus,
51+
FilterExpression = FilterExpression
52+
};
53+
54+
VirtualMachineImageResourceList result = this.VirtualMachineImageClient.List(parameters);
55+
WriteObject(result);
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)