Skip to content

Commit 9d36a08

Browse files
Get-AzVMImage list to return additional properties (Azure#27617)
Co-authored-by: Yabo Hu <[email protected]>
1 parent 633f763 commit 9d36a08

File tree

11 files changed

+345
-185
lines changed

11 files changed

+345
-185
lines changed

src/Compute/Compute.Management.Sdk/Generated/IVirtualMachineImagesOperations.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ public partial interface IVirtualMachineImagesOperations
212212
/// <param name='skus'>
213213
/// A valid image SKU.
214214
/// </param>
215+
/// <param name='expand'>
216+
/// The expand expression to apply on the operation.
217+
/// </param>
215218
/// <param name='top'>
216219
/// </param>
217220
/// <param name='orderby'>
@@ -231,7 +234,7 @@ public partial interface IVirtualMachineImagesOperations
231234
/// <exception cref="Microsoft.Rest.ValidationException">
232235
/// Thrown when a required parameter is null
233236
/// </exception>
234-
Task<AzureOperationResponse<IPage<VirtualMachineImage>>> ListWithPropertiesWithHttpMessagesAsync(string location, string publisherName, string offer, string skus, int? top = default(int?), string orderby = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
237+
Task<AzureOperationResponse<IList<VirtualMachineImage>>> ListWithPropertiesWithHttpMessagesAsync(string location, string publisherName, string offer, string skus, string expand, int? top = default(int?), string orderby = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
235238
/// <param name='nextPageLink'>
236239
/// The NextLink from the previous successful call to List operation.
237240
/// </param>
@@ -250,6 +253,6 @@ public partial interface IVirtualMachineImagesOperations
250253
/// <exception cref="Microsoft.Rest.ValidationException">
251254
/// Thrown when a required parameter is null
252255
/// </exception>
253-
Task<AzureOperationResponse<IPage<VirtualMachineImage>>> ListWithPropertiesNextWithHttpMessagesAsync(string nextPageLink, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
256+
Task<AzureOperationResponse<IList<VirtualMachineImage>>> ListWithPropertiesNextWithHttpMessagesAsync(string nextPageLink, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
254257
}
255258
}

src/Compute/Compute.Management.Sdk/Generated/VirtualMachineImagesOperations.cs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,9 @@ internal VirtualMachineImagesOperations(ComputeManagementClient client)
12981298
/// <param name='skus'>
12991299
/// A valid image SKU.
13001300
/// </param>
1301+
/// <param name='expand'>
1302+
/// The expand expression to apply on the operation.
1303+
/// </param>
13011304
/// <param name='top'>
13021305
/// </param>
13031306
/// <param name='orderby'>
@@ -1323,7 +1326,7 @@ internal VirtualMachineImagesOperations(ComputeManagementClient client)
13231326
/// <return>
13241327
/// A response object containing the response body and response headers.
13251328
/// </return>
1326-
public async Task<AzureOperationResponse<IPage<VirtualMachineImage>>> ListWithPropertiesWithHttpMessagesAsync(string location, string publisherName, string offer, string skus, int? top = default(int?), string orderby = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
1329+
public async Task<AzureOperationResponse<IList<VirtualMachineImage>>> ListWithPropertiesWithHttpMessagesAsync(string location, string publisherName, string offer, string skus, string expand, int? top = default(int?), string orderby = default(string), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
13271330
{
13281331
if (location == null)
13291332
{
@@ -1341,11 +1344,14 @@ internal VirtualMachineImagesOperations(ComputeManagementClient client)
13411344
{
13421345
throw new ValidationException(ValidationRules.CannotBeNull, "skus");
13431346
}
1347+
if (expand == null)
1348+
{
1349+
throw new ValidationException(ValidationRules.CannotBeNull, "expand");
1350+
}
13441351
if (Client.SubscriptionId == null)
13451352
{
13461353
throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId");
13471354
}
1348-
string expand = "Properties";
13491355
string apiVersion = "2024-11-01";
13501356
// Tracing
13511357
bool _shouldTrace = ServiceClientTracing.IsEnabled;
@@ -1483,7 +1489,7 @@ internal VirtualMachineImagesOperations(ComputeManagementClient client)
14831489
throw ex;
14841490
}
14851491
// Create Result
1486-
var _result = new AzureOperationResponse<IPage<VirtualMachineImage>>();
1492+
var _result = new AzureOperationResponse<IList<VirtualMachineImage>>();
14871493
_result.Request = _httpRequest;
14881494
_result.Response = _httpResponse;
14891495
if (_httpResponse.Headers.Contains("x-ms-request-id"))
@@ -1496,7 +1502,7 @@ internal VirtualMachineImagesOperations(ComputeManagementClient client)
14961502
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
14971503
try
14981504
{
1499-
_result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<VirtualMachineImage>>(_responseContent, Client.DeserializationSettings);
1505+
_result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<VirtualMachineImage>>(_responseContent, Client.DeserializationSettings);
15001506
}
15011507
catch (JsonException ex)
15021508
{
@@ -1539,7 +1545,7 @@ internal VirtualMachineImagesOperations(ComputeManagementClient client)
15391545
/// <return>
15401546
/// A response object containing the response body and response headers.
15411547
/// </return>
1542-
public async Task<AzureOperationResponse<IPage<VirtualMachineImage>>> ListWithPropertiesNextWithHttpMessagesAsync(string nextPageLink, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
1548+
public async Task<AzureOperationResponse<IList<VirtualMachineImage>>> ListWithPropertiesNextWithHttpMessagesAsync(string nextPageLink, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
15431549
{
15441550
if (nextPageLink == null)
15451551
{
@@ -1653,7 +1659,7 @@ internal VirtualMachineImagesOperations(ComputeManagementClient client)
16531659
throw ex;
16541660
}
16551661
// Create Result
1656-
var _result = new AzureOperationResponse<IPage<VirtualMachineImage>>();
1662+
var _result = new AzureOperationResponse<IList<VirtualMachineImage>>();
16571663
_result.Request = _httpRequest;
16581664
_result.Response = _httpResponse;
16591665
if (_httpResponse.Headers.Contains("x-ms-request-id"))
@@ -1666,7 +1672,7 @@ internal VirtualMachineImagesOperations(ComputeManagementClient client)
16661672
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
16671673
try
16681674
{
1669-
_result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<VirtualMachineImage>>(_responseContent, Client.DeserializationSettings);
1675+
_result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<VirtualMachineImage>>(_responseContent, Client.DeserializationSettings);
16701676
}
16711677
catch (JsonException ex)
16721678
{

src/Compute/Compute.Management.Sdk/Generated/VirtualMachineImagesOperationsExtensions.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,16 @@ public static VmImagesInEdgeZoneListResult ListByEdgeZone(this IVirtualMachineIm
332332
/// <param name='skus'>
333333
/// A valid image SKU.
334334
/// </param>
335+
/// <param name='expand'>
336+
/// The expand expression to apply on the operation.
337+
/// </param>
335338
/// <param name='top'>
336339
/// </param>
337340
/// <param name='orderby'>
338341
/// </param>
339-
public static IPage<VirtualMachineImage> ListWithProperties(this IVirtualMachineImagesOperations operations, string location, string publisherName, string offer, string skus, int? top = default(int?), string orderby = default(string))
342+
public static IList<VirtualMachineImage> ListWithProperties(this IVirtualMachineImagesOperations operations, string location, string publisherName, string offer, string skus, string expand, int? top = default(int?), string orderby = default(string))
340343
{
341-
return operations.ListWithPropertiesAsync(location, publisherName, offer, skus, top, orderby).GetAwaiter().GetResult();
344+
return operations.ListWithPropertiesAsync(location, publisherName, offer, skus, expand, top, orderby).GetAwaiter().GetResult();
342345
}
343346

344347
/// <param name='operations'>
@@ -356,16 +359,19 @@ public static VmImagesInEdgeZoneListResult ListByEdgeZone(this IVirtualMachineIm
356359
/// <param name='skus'>
357360
/// A valid image SKU.
358361
/// </param>
362+
/// <param name='expand'>
363+
/// The expand expression to apply on the operation.
364+
/// </param>
359365
/// <param name='top'>
360366
/// </param>
361367
/// <param name='orderby'>
362368
/// </param>
363369
/// <param name='cancellationToken'>
364370
/// The cancellation token.
365371
/// </param>
366-
public static async Task<IPage<VirtualMachineImage>> ListWithPropertiesAsync(this IVirtualMachineImagesOperations operations, string location, string publisherName, string offer, string skus, int? top = default(int?), string orderby = default(string), CancellationToken cancellationToken = default(CancellationToken))
372+
public static async Task<IList<VirtualMachineImage>> ListWithPropertiesAsync(this IVirtualMachineImagesOperations operations, string location, string publisherName, string offer, string skus, string expand, int? top = default(int?), string orderby = default(string), CancellationToken cancellationToken = default(CancellationToken))
367373
{
368-
using (var _result = await operations.ListWithPropertiesWithHttpMessagesAsync(location, publisherName, offer, skus, top, orderby, null, cancellationToken).ConfigureAwait(false))
374+
using (var _result = await operations.ListWithPropertiesWithHttpMessagesAsync(location, publisherName, offer, skus, expand, top, orderby, null, cancellationToken).ConfigureAwait(false))
369375
{
370376
return _result.Body;
371377
}
@@ -377,7 +383,7 @@ public static VmImagesInEdgeZoneListResult ListByEdgeZone(this IVirtualMachineIm
377383
/// <param name='nextPageLink'>
378384
/// The NextLink from the previous successful call to List operation.
379385
/// </param>
380-
public static IPage<VirtualMachineImage> ListWithPropertiesNext(this IVirtualMachineImagesOperations operations, string nextPageLink)
386+
public static IList<VirtualMachineImage> ListWithPropertiesNext(this IVirtualMachineImagesOperations operations, string nextPageLink)
381387
{
382388
return operations.ListWithPropertiesNextAsync(nextPageLink).GetAwaiter().GetResult();
383389
}
@@ -391,7 +397,7 @@ public static IPage<VirtualMachineImage> ListWithPropertiesNext(this IVirtualMac
391397
/// <param name='cancellationToken'>
392398
/// The cancellation token.
393399
/// </param>
394-
public static async Task<IPage<VirtualMachineImage>> ListWithPropertiesNextAsync(this IVirtualMachineImagesOperations operations, string nextPageLink, CancellationToken cancellationToken = default(CancellationToken))
400+
public static async Task<IList<VirtualMachineImage>> ListWithPropertiesNextAsync(this IVirtualMachineImagesOperations operations, string nextPageLink, CancellationToken cancellationToken = default(CancellationToken))
395401
{
396402
using (var _result = await operations.ListWithPropertiesNextWithHttpMessagesAsync(nextPageLink, null, cancellationToken).ConfigureAwait(false))
397403
{

src/Compute/Compute.Management.Sdk/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ directive:
5151
5252
###
5353
``` yaml
54-
commit: 8e064cb38f22bc60d94ce8ec2c987aa04dbc618e
54+
commit: e2bdeadfb399be0691fb9d0425bd2b32d252538c
5555
input-file:
5656
- https://github.com/Azure/azure-rest-api-specs/blob/$(commit)/specification/compute/resource-manager/Microsoft.Compute/common-types/v1/common.json
5757
- https://github.com/Azure/azure-rest-api-specs/blob/$(commit)/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-11-01/computeRPCommon.json

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,8 @@ function Test-VMImageCmdletOutputFormat
21372137

21382138
Assert-OutputContains " Get-AzVMImagePublisher -Location '$locStr' | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzVMImageOffer | Get-AzVMImageSku " @('Publisher', 'Offer', 'Skus');
21392139

2140-
Assert-OutputContains " Get-AzVMImagePublisher -Location '$locStr' | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzVMImageOffer | Get-AzVMImageSku | Get-AzVMImage " @('Version', 'Skus');
2140+
# Updated Get-AzVmImage list output. No need to output sku when user inputed that. There are more valuable information to display.
2141+
Assert-OutputContains " Get-AzVMImagePublisher -Location '$locStr' | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzVMImageOffer | Get-AzVMImageSku | Get-AzVMImage " @('Version', 'Location');
21412142

21422143
Assert-OutputContains " Get-AzVMImage -Location '$locStr' -PublisherName $publisher -Offer $offer -Skus $sku -Version $ver " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku', 'Version', 'Name', 'DataDiskImages', 'OSDiskImage', 'PurchasePlan');
21432144

@@ -2162,7 +2163,7 @@ function Test-VMImageEdgeZoneCmdletOutputFormat
21622163

21632164
Assert-OutputContains " Get-AzVMImagePublisher -Location '$locStr' | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzVMImageOffer -EdgeZone '$edgeZone'| Get-AzVMImageSku " @('Publisher', 'Offer', 'Skus');
21642165

2165-
Assert-OutputContains " Get-AzVMImagePublisher -Location '$locStr' | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzVMImageOffer -EdgeZone '$edgeZone' | Get-AzVMImageSku | Get-AzVMImage " @('Version', 'Skus');
2166+
Assert-OutputContains " Get-AzVMImagePublisher -Location '$locStr' | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzVMImageOffer -EdgeZone '$edgeZone' | Get-AzVMImageSku | Get-AzVMImage " @('Version', 'Location');
21662167

21672168
Assert-OutputContains " Get-AzVMImage -Location '$locStr' -EdgeZone '$edgeZone' -PublisherName $publisher -Offer $offer -Skus $sku -Version $ver " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku', 'Version', 'Name', 'DataDiskImages', 'OSDiskImage', 'PurchasePlan');
21682169

@@ -4850,14 +4851,19 @@ function Test-VirtualMachineImageListTopOrderExpand
48504851
$pubNames = "MicrosoftWindowsServer";
48514852
$pubNameFilter = '*Windows*';
48524853
$offer = "windowsserver";
4853-
$sku = "2012-R2-Datacenter";
4854+
$sku = "2025-datacenter";
48544855
$numRecords = 3;
48554856
$orderNameDesc = "name desc";
48564857
$orderNameAsc = "name asc";
48574858

48584859
# Test -Top
4859-
$vmImagesTop = Get-AzVMImage -Location $loc -PublisherName $pubNames -Offer $offer -Sku $sku -Top $numRecords;
4860+
$vmImagesTop = Get-AzVMImage -Location $loc -PublisherName $pubNames -Offer $offer -Sku $sku -Top $numRecords -Expand "properties";
48604861
Assert-AreEqual $numRecords $vmImagesTop.Count;
4862+
Assert-NotNull $vmImagesTop[0].Architecture;
4863+
Assert-NotNull $vmImagesTop[0].HyperVGeneration;
4864+
4865+
$vmImagesTop = Get-AzVMImage -Location $loc -PublisherName $pubNames -Offer $offer -Sku $sku -Top $numRecords -Expand "properties/imageDeprecationStatus"
4866+
Assert-NotNull $vmImagesTop[0].ImageDeprecationStatus
48614867

48624868
# Test -OrderBy
48634869
$vmImagesOrderDesc = Get-AzVMImage -Location $loc -PublisherName $pubNames -Offer $offer -Sku $sku -OrderBy $orderNameDesc;

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests/TestVirtualMachineImageListTopOrderExpand.json

+155-102
Large diffs are not rendered by default.

src/Compute/Compute/ChangeLog.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Added new properties `Architecture`, `HyperVGeneration`, and `ImageDeprecationStatus` to be returned in `Get-AzVMImage` ListVMImage parameter set.
2324
* Deprecated `Get-AzVMSize` 'List Virtual Machine Size' parameter set.
2425
* Added new parameters `EnableAutomaticZoneRebalance`, `AutomaticZoneRebalanceStrategy` and `AutomaticZoneRebalanceBehavior` to `New-AzVmssConfig` and `Update-AzVmss` cmdlets for VMSS Automatic Zone Rebalancing.
2526

src/Compute/Compute/Compute.format.ps1xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,19 @@
191191
<PropertyName>Version</PropertyName>
192192
</TableColumnItem>
193193
<TableColumnItem>
194-
<PropertyName>Skus</PropertyName>
194+
<PropertyName>Location</PropertyName>
195195
</TableColumnItem>
196196
<TableColumnItem>
197-
<PropertyName>Offer</PropertyName>
197+
<PropertyName>PublisherName</PropertyName>
198198
</TableColumnItem>
199199
<TableColumnItem>
200-
<PropertyName>PublisherName</PropertyName>
200+
<PropertyName>HyperVGeneration</PropertyName>
201201
</TableColumnItem>
202202
<TableColumnItem>
203-
<PropertyName>Location</PropertyName>
203+
<PropertyName>Architecture</PropertyName>
204204
</TableColumnItem>
205205
<TableColumnItem>
206-
<PropertyName>Id</PropertyName>
206+
<PropertyName>ImageDeprecationStatus</PropertyName>
207207
</TableColumnItem>
208208
</TableColumnItems>
209209
</TableRowEntry>

0 commit comments

Comments
 (0)