Skip to content

Commit 03f2522

Browse files
authored
Upgrade Get-AzLocation cmdlet (Azure#18161)
* upgrade get-azlocation cmd(upgrade subcriptionclient version, add extend location peremeter, and expose more info * update test for azlocation * add changlog * revise changlog.md:delete new title * revise changlog.md * change parameter to singular noun * revise session record json file
1 parent f7ee9d2 commit 03f2522

File tree

8 files changed

+156
-65
lines changed

8 files changed

+156
-65
lines changed

src/Resources/ResourceManager/Implementation/Locations/GetAzureLocationCmdlet.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
3030
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Location"), OutputType(typeof(PSResourceProviderLocation))]
3131
public class GetAzureLocationCmdlet : ResourceManagerCmdletBaseWithApiVersion
3232
{
33+
public const string ExtendedLocationsParameterSet = "ExtendedLocation";
34+
35+
[Parameter(Mandatory = false, HelpMessage = "Whether to include extended locations.", ParameterSetName = GetAzureLocationCmdlet.ExtendedLocationsParameterSet)]
36+
public bool? ExtendedLocation { get; set; }
3337
/// <summary>
3438
/// Executes the cmdlet
3539
/// </summary>
@@ -39,14 +43,15 @@ protected override void OnProcessRecord()
3943
{
4044
throw new PSInvalidOperationException(Resources.NoSubscriptionsUnderCurrentDirectory);
4145
}
42-
var allLocations = this.SubscriptionSdkClient.ListLocations(DefaultContext.Subscription.Id.ToString());
46+
var allLocations = this.SubscriptionSdkClient.ListLocations(DefaultContext.Subscription.Id.ToString(), ExtendedLocation);
4347
var providers = this.ResourceManagerSdkClient.ListResourceProviders(providerName: null, listAvailable: true);
4448
var providerLocations = ConstructResourceProviderLocations(allLocations, providers);
45-
4649
this.WriteObject(providerLocations, enumerateCollection: true);
4750
}
4851

49-
private List<PSResourceProviderLocation> ConstructResourceProviderLocations(List<Internal.Subscriptions.Models.Location> locations, List<Provider> providers)
52+
53+
54+
private List<PSResourceProviderLocation> ConstructResourceProviderLocations(List<Management.ResourceManager.Models.Location> locations, List<Provider> providers)
5055
{
5156
var locationProviderMap = GetLocationProviderMap(providers);
5257

@@ -61,7 +66,15 @@ private List<PSResourceProviderLocation> ConstructResourceProviderLocations(List
6166
{
6267
Location = location.Name,
6368
DisplayName = location.DisplayName,
64-
Providers = mapEntry.Value
69+
Longitude = location.Metadata.Longitude,
70+
Latitude = location.Metadata.Latitude,
71+
PhysicalLocation = location.Metadata.PhysicalLocation,
72+
Providers = mapEntry.Value,
73+
PairedRegion = location.Metadata.PairedRegion,
74+
RegionType = location.Metadata.RegionType,
75+
RegionCategory = location.Metadata.RegionCategory,
76+
GeographyGroup = location.Metadata.GeographyGroup,
77+
Type = location.Type
6578
},
6679
StringComparer.InvariantCultureIgnoreCase);
6780

src/Resources/ResourceManager/ResourceManager.format.ps1xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,47 @@
108108
<Label>DisplayName</Label>
109109
<PropertyName>DisplayName</PropertyName>
110110
</ListItem>
111+
<ListItem>
112+
<Label>Type</Label>
113+
<PropertyName>Type</PropertyName>
114+
</ListItem>
115+
<ListItem>
116+
<Label>Longitude</Label>
117+
<PropertyName>Longitude</PropertyName>
118+
</ListItem>
119+
<ListItem>
120+
<Label>Latitude</Label>
121+
<PropertyName>Latitude</PropertyName>
122+
</ListItem>
123+
<ListItem>
124+
<Label>PhysicalLocation</Label>
125+
<PropertyName>PhysicalLocation</PropertyName>
126+
</ListItem>
127+
<ListItem>
128+
<Label>RegionType</Label>
129+
<PropertyName>RegionType</PropertyName>
130+
</ListItem>
131+
<ListItem>
132+
<Label>RegionCategory</Label>
133+
<PropertyName>RegionCategory</PropertyName>
134+
</ListItem>
135+
<ListItem>
136+
<Label>GeographyGroup</Label>
137+
<PropertyName>GeographyGroup</PropertyName>
138+
</ListItem>
139+
<ListItem>
140+
<Label>PairedRegion</Label>
141+
<ScriptBlock>
142+
if ($_.PairedRegion -ne $null)
143+
{
144+
ConvertTo-Json $_.PairedRegion -Depth 10
145+
}
146+
else
147+
{
148+
$_.PairedRegion;
149+
}
150+
</ScriptBlock>
151+
</ListItem>
111152
<ListItem>
112153
<Label>Providers</Label>
113154
<PropertyName>Providers</PropertyName>

src/Resources/ResourceManager/SdkClient/SubscriptionSdkClient.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
17-
using Microsoft.Azure.Commands.Common.Authentication.Models;
18-
using Microsoft.Azure.Internal.Subscriptions;
19-
using Microsoft.Azure.Internal.Subscriptions.Models;
17+
using Microsoft.Azure.Management.ResourceManager;
18+
using Microsoft.Azure.Management.ResourceManager.Models;
2019
using System;
2120
using System.Collections.Generic;
2221

@@ -52,11 +51,11 @@ public SubscriptionSdkClient(ISubscriptionClient subscriptionClient)
5251
this.SubscriptionClient = subscriptionClient;
5352
}
5453

55-
public List<Location> ListLocations(string subscriptionId)
54+
public List<Location> ListLocations(string subscriptionId, bool? includeExtendedLocations = null)
5655
{
5756
var locationList = new List<Location>();
5857

59-
var tempResult = this.SubscriptionClient.Subscriptions.ListLocations(subscriptionId);
58+
var tempResult = this.SubscriptionClient.Subscriptions.ListLocations(subscriptionId, includeExtendedLocations);
6059
locationList.AddRange(tempResult);
6160

6261
return locationList;

src/Resources/ResourceManager/SdkModels/Locations/PSResourceProviderLocation.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ----------------------------------------------------------------------------------
1+
// ----------------------------------------------------------------------------------
22
//
33
// Copyright Microsoft Corporation
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System.Collections.Generic;
16+
using Microsoft.Azure.Management.ResourceManager.Models;
1617

1718
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels
1819
{
@@ -31,6 +32,23 @@ public class PSResourceProviderLocation
3132
/// </summary>
3233
public string DisplayName { get; set; }
3334

35+
public LocationType? Type { get;set; }
36+
37+
38+
public string Longitude { get;set; }
39+
40+
public string Latitude { get;set; }
41+
42+
public string PhysicalLocation { get;set; }
43+
44+
public string RegionType { get;set; }
45+
46+
public string RegionCategory { get;set; }
47+
48+
public string GeographyGroup { get;set; }
49+
50+
public IList<PairedRegion> PairedRegion { get; set; }
51+
3452
/// <summary>
3553
/// Gets or sets the providers that are supported in this location
3654
/// </summary>

src/Resources/Resources.Test/Providers/GetAzureProviderCmdletTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ public class GetAzureProviderCmdletTests : RMTestBase
5656
/// <summary>
5757
/// A mock of the ISubscriptionsOperations
5858
/// </summary>
59-
private readonly Mock<Internal.Subscriptions.ISubscriptionsOperations> subscriptionsOperationsMock;
59+
private readonly Mock<Management.ResourceManager.ISubscriptionsOperations> subscriptionsOperationsMock;
6060

6161
/// <summary>
6262
/// Initializes a new instance of the <see cref="GetAzureProviderCmdletTests"/> class.
6363
/// </summary>
6464
public GetAzureProviderCmdletTests(ITestOutputHelper output)
6565
{
6666
this.providerOperationsMock = new Mock<IProvidersOperations>();
67-
this.subscriptionsOperationsMock = new Mock<Internal.Subscriptions.ISubscriptionsOperations>();
67+
this.subscriptionsOperationsMock = new Mock<Management.ResourceManager.ISubscriptionsOperations>();
6868
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
6969
var resourceManagementClient = new Mock<Microsoft.Azure.Management.ResourceManager.IResourceManagementClient>();
70-
var subscriptionClient = new Mock<Internal.Subscriptions.ISubscriptionClient>();
70+
var subscriptionClient = new Mock<Management.ResourceManager.ISubscriptionClient>();
7171

7272
resourceManagementClient
7373
.SetupGet(client => client.Providers)
@@ -139,18 +139,18 @@ public void GetsResourceProviderTests()
139139
.Setup(f => f.ListWithHttpMessagesAsync(null, null, null, It.IsAny<CancellationToken>()))
140140
.Returns(() => Task.FromResult(result));
141141

142-
var locationList = new List<Internal.Subscriptions.Models.Location>
142+
var locationList = new List<Management.ResourceManager.Models.Location>
143143
{
144-
new Internal.Subscriptions.Models.Location(name: "southus", displayName: "South US")
144+
new Management.ResourceManager.Models.Location(name: "southus", displayName: "South US")
145145
};
146-
var pagableLocations = new Page<Internal.Subscriptions.Models.Location>();
147-
pagableLocations.SetItemValue<Internal.Subscriptions.Models.Location>(locationList);
148-
var locationsResult = new AzureOperationResponse<IEnumerable<Internal.Subscriptions.Models.Location>>()
146+
var pagableLocations = new Page<Management.ResourceManager.Models.Location>();
147+
pagableLocations.SetItemValue<Management.ResourceManager.Models.Location>(locationList);
148+
var locationsResult = new AzureOperationResponse<IEnumerable<Management.ResourceManager.Models.Location>>()
149149
{
150150
Body = pagableLocations
151151
};
152152
this.subscriptionsOperationsMock
153-
.Setup(f => f.ListLocationsWithHttpMessagesAsync(It.IsAny<string>(), null, It.IsAny<CancellationToken>()))
153+
.Setup(f => f.ListLocationsWithHttpMessagesAsync(It.IsAny<string>(), null, null, It.IsAny<CancellationToken>()))
154154
.Returns(() => Task.FromResult(locationsResult));
155155

156156

src/Resources/Resources.Test/ScenarioTests/LocationTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#>
1919
function Test-AzureLocation
2020
{
21-
$providerLocations = Get-AzLocation
21+
$providerLocations = Get-AzLocation -ExtendedLocation $true
2222

2323
Assert-True { $providerLocations.Count -gt 0 }
2424
foreach ($location in $providerLocations)

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.LocationTests/TestAzureLocation.json

Lines changed: 61 additions & 45 deletions
Large diffs are not rendered by default.

src/Resources/Resources/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Upgraded and rivised `Get-AzLocation` cmdlet:
23+
- Upgraded `subscriptionClient` for `Get-AzLocation`. Changed its apiVersion from 2016-01-01 to 2021-01-01.[#18002]
24+
- Added all attributes of location info for `Get-AzLocation`, including `pairedRegion` and so on. [#18045][#17536]
25+
- Support ExtendedLocations by `Get-AzLocation` [#18046]
2226
* Added the following cmdlets to remain in parity with 2021-04-01 API version:
2327
- `New-AzHierarchySetting`
2428
- `Get-AzHierarchySetting`

0 commit comments

Comments
 (0)