Skip to content

Commit 6c03ba4

Browse files
authored
Merge pull request #4111 from DeepakRajendranMsft/AddPaginationSupport
add pagination support
2 parents 4b49871 + e986eb4 commit 6c03ba4

17 files changed

+194
-151
lines changed

src/ResourceManager/Network/Commands.Network/ApplicationGateway/GetAzureApplicationGatewayCommand.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using Microsoft.Azure.Management.Network;
1717
using System.Collections.Generic;
1818
using System.Management.Automation;
19+
using Microsoft.Azure.Management.Network.Models;
20+
using Microsoft.Rest.Azure;
1921

2022
namespace Microsoft.Azure.Commands.Network
2123
{
@@ -46,24 +48,20 @@ public override void ExecuteCmdlet()
4648

4749
WriteObject(applicationGateway);
4850
}
49-
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
51+
else
5052
{
51-
var appGateway = this.ApplicationGatewayClient.List(this.ResourceGroupName);
52-
53-
var psApplicationGateways = new List<PSApplicationGateway>();
54-
55-
foreach (var appGw in appGateway)
53+
IPage<ApplicationGateway> appGatewayPage;
54+
if (!string.IsNullOrEmpty(this.ResourceGroupName))
5655
{
57-
var psAppGw = this.ToPsApplicationGateway(appGw);
58-
psAppGw.ResourceGroupName = this.ResourceGroupName;
59-
psApplicationGateways.Add(psAppGw);
56+
appGatewayPage = this.ApplicationGatewayClient.List(this.ResourceGroupName);
57+
}
58+
else
59+
{
60+
appGatewayPage = this.ApplicationGatewayClient.ListAll();
6061
}
6162

62-
WriteObject(psApplicationGateways, true);
63-
}
64-
else
65-
{
66-
var appGwResponseList = this.ApplicationGatewayClient.ListAll();
63+
// Get all resources by polling on next page link
64+
var appGwResponseList = ListNextLink<ApplicationGateway>.GetAllResourcesByPollingNextLink(appGatewayPage, this.ApplicationGatewayClient.ListNext);
6765

6866
var psApplicationGateways = new List<PSApplicationGateway>();
6967

src/ResourceManager/Network/Commands.Network/Commands.Network.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
<Compile Include="ApplicationGateway\UrlPathMap\NewAzureApplicationGatewayUrlPathMapConfigCommand.cs" />
245245
<Compile Include="ApplicationGateway\UrlPathMap\RemoveAzureApplicationGatewayUrlPathMapConfigCommand.cs" />
246246
<Compile Include="ApplicationGateway\UrlPathMap\SetAzureApplicationGatewayUrlPathMapConfigCommand.cs" />
247+
<Compile Include="Common\ListNextLink.cs" />
247248
<Compile Include="Common\NetworkBaseCmdlet.cs" />
248249
<Compile Include="Common\NetworkClient.cs" />
249250
<Compile Include="Common\NetworkCloudException.cs" />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 System;
16+
using System.Collections.Generic;
17+
using Microsoft.Rest.Azure;
18+
19+
namespace Microsoft.Azure.Commands.Network
20+
{
21+
public static class ListNextLink<T>
22+
{
23+
public static List<T> GetAllResourcesByPollingNextLink(IPage<T> resourcePage, Func<string, IPage<T>> getNextLink)
24+
{
25+
var resourceList = new List<T>();
26+
27+
var nextPageLink = AddResourceToListAndReturnNextPageLink(resourcePage, resourceList);
28+
29+
while (!string.IsNullOrEmpty(nextPageLink))
30+
{
31+
var nextVnetPage = getNextLink(nextPageLink);
32+
nextPageLink = AddResourceToListAndReturnNextPageLink(nextVnetPage, resourceList);
33+
}
34+
35+
return resourceList;
36+
}
37+
38+
private static string AddResourceToListAndReturnNextPageLink(IPage<T> resourcePage, List<T> resourceList)
39+
{
40+
foreach (var resource in resourcePage)
41+
{
42+
resourceList.Add(resource);
43+
}
44+
45+
return resourcePage.NextPageLink;
46+
}
47+
}
48+
}

src/ResourceManager/Network/Commands.Network/ExpressRouteCircuit/GetAzureExpressRouteCircuitCommand.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using Microsoft.Azure.Management.Network;
1717
using System.Collections.Generic;
1818
using System.Management.Automation;
19+
using Microsoft.Azure.Management.Network.Models;
20+
using Microsoft.Rest.Azure;
1921

2022
namespace Microsoft.Azure.Commands.Network
2123
{
@@ -46,23 +48,20 @@ public override void Execute()
4648

4749
WriteObject(circuit);
4850
}
49-
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
51+
else
5052
{
51-
var circuitList = this.ExpressRouteCircuitClient.List(this.ResourceGroupName);
52-
53-
var psCircuits = new List<PSExpressRouteCircuit>();
54-
foreach (var ExpressRouteCircuit in circuitList)
53+
IPage<ExpressRouteCircuit> circuitPage;
54+
if (!string.IsNullOrEmpty(this.ResourceGroupName))
5555
{
56-
var psVnet = this.ToPsExpressRouteCircuit(ExpressRouteCircuit);
57-
psVnet.ResourceGroupName = this.ResourceGroupName;
58-
psCircuits.Add(psVnet);
56+
circuitPage = this.ExpressRouteCircuitClient.List(this.ResourceGroupName);
57+
}
58+
else
59+
{
60+
circuitPage = this.ExpressRouteCircuitClient.ListAll();
5961
}
6062

61-
WriteObject(psCircuits, true);
62-
}
63-
else
64-
{
65-
var circuitList = this.ExpressRouteCircuitClient.ListAll();
63+
// Get all resources by polling on next page link
64+
var circuitList = ListNextLink<ExpressRouteCircuit>.GetAllResourcesByPollingNextLink(circuitPage, this.ExpressRouteCircuitClient.ListNext);
6665

6766
var psCircuits = new List<PSExpressRouteCircuit>();
6867
foreach (var ExpressRouteCircuit in circuitList)

src/ResourceManager/Network/Commands.Network/LoadBalancer/GetAzureLoadBalancerCommand.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using Microsoft.Azure.Management.Network;
1717
using System.Collections.Generic;
1818
using System.Management.Automation;
19+
using Microsoft.Azure.Management.Network.Models;
20+
using Microsoft.Rest.Azure;
1921

2022
namespace Microsoft.Azure.Commands.Network
2123
{
@@ -66,25 +68,21 @@ public override void Execute()
6668

6769
WriteObject(loadBalancer);
6870
}
69-
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
71+
else
7072
{
71-
var lbList = this.LoadBalancerClient.List(this.ResourceGroupName);
72-
73-
var psLoadBalancers = new List<PSLoadBalancer>();
74-
75-
foreach (var lb in lbList)
73+
IPage<LoadBalancer> lbPage;
74+
if (!string.IsNullOrEmpty(this.ResourceGroupName))
7675
{
77-
var psLb = this.ToPsLoadBalancer(lb);
78-
psLb.ResourceGroupName = this.ResourceGroupName;
79-
psLoadBalancers.Add(psLb);
76+
lbPage = this.LoadBalancerClient.List(this.ResourceGroupName);
8077
}
8178

82-
WriteObject(psLoadBalancers, true);
83-
}
79+
else
80+
{
81+
lbPage = this.LoadBalancerClient.ListAll();
82+
}
8483

85-
else
86-
{
87-
var lbList = this.LoadBalancerClient.ListAll();
84+
// Get all resources by polling on next page link
85+
var lbList = ListNextLink<LoadBalancer>.GetAllResourcesByPollingNextLink(lbPage, this.LoadBalancerClient.ListNext);
8886

8987
var psLoadBalancers = new List<PSLoadBalancer>();
9088

src/ResourceManager/Network/Commands.Network/LocalNetworkGateway/GetAzureLocalNetworkGatewayCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.Commands.Network.Models;
1616
using Microsoft.Azure.Management.Network;
17+
using Microsoft.Azure.Management.Network.Models;
1718
using System.Collections.Generic;
1819
using System.Management.Automation;
1920

@@ -48,7 +49,10 @@ public override void Execute()
4849
}
4950
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
5051
{
51-
var localnetGatewayList = this.LocalNetworkGatewayClient.List(this.ResourceGroupName);
52+
var localnetGatewayPage = this.LocalNetworkGatewayClient.List(this.ResourceGroupName);
53+
54+
// Get all resources by polling on next page link
55+
var localnetGatewayList = ListNextLink<LocalNetworkGateway>.GetAllResourcesByPollingNextLink(localnetGatewayPage, this.LocalNetworkGatewayClient.ListNext);
5256

5357
var psLocalnetGateways = new List<PSLocalNetworkGateway>();
5458
foreach (var localNetworkGateway in localnetGatewayList)

src/ResourceManager/Network/Commands.Network/Microsoft.Azure.Commands.Network.format.ps1xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,10 @@
832832
<Label>Primary</Label>
833833
<PropertyName>Primary</PropertyName>
834834
</ListItem>
835+
<ListItem>
836+
<Label>MacAddress</Label>
837+
<PropertyName>MacAddress</PropertyName>
838+
</ListItem>
835839
</ListItems>
836840
</ListEntry>
837841
</ListEntries>

src/ResourceManager/Network/Commands.Network/NetworkInterface/GetAzureNetworkInterfaceCommand.cs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
using Microsoft.Azure.Commands.Network.Models;
1818
using Microsoft.Azure.Management.Network;
19+
using Microsoft.Azure.Management.Network.Models;
1920
using System.Collections.Generic;
2021
using System.Management.Automation;
2122
using MNM = Microsoft.Azure.Management.Network.Models;
23+
using Microsoft.Rest.Azure;
2224

2325
namespace Microsoft.Azure.Commands.Network
2426
{
@@ -129,48 +131,42 @@ public override void Execute()
129131

130132
WriteObject(networkInterface);
131133
}
132-
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
134+
else
133135
{
134-
IEnumerable<MNM.NetworkInterface> nicList;
135-
136-
if (ParameterSetName.Contains("ScaleSetNic"))
136+
IPage<MNM.NetworkInterface> nicPage;
137+
if (!string.IsNullOrEmpty(this.ResourceGroupName))
137138
{
138-
if (string.IsNullOrEmpty(this.VirtualMachineIndex))
139+
if (ParameterSetName.Contains("ScaleSetNic"))
139140
{
140-
nicList =
141-
this.NetworkInterfaceClient.ListVirtualMachineScaleSetNetworkInterfaces(
142-
this.ResourceGroupName,
143-
this.VirtualMachineScaleSetName);
141+
if (string.IsNullOrEmpty(this.VirtualMachineIndex))
142+
{
143+
nicPage =
144+
this.NetworkInterfaceClient.ListVirtualMachineScaleSetNetworkInterfaces(
145+
this.ResourceGroupName,
146+
this.VirtualMachineScaleSetName);
147+
}
148+
else
149+
{
150+
nicPage =
151+
this.NetworkInterfaceClient.ListVirtualMachineScaleSetVMNetworkInterfaces(
152+
this.ResourceGroupName,
153+
this.VirtualMachineScaleSetName,
154+
this.VirtualMachineIndex);
155+
}
144156
}
145157
else
146158
{
147-
nicList =
148-
this.NetworkInterfaceClient.ListVirtualMachineScaleSetVMNetworkInterfaces(
149-
this.ResourceGroupName,
150-
this.VirtualMachineScaleSetName,
151-
this.VirtualMachineIndex);
152-
}
159+
nicPage = this.NetworkInterfaceClient.List(this.ResourceGroupName);
160+
}
153161
}
154-
else
155-
{
156-
nicList = this.NetworkInterfaceClient.List(this.ResourceGroupName);
157-
}
158-
159-
var psNetworkInterfaces = new List<PSNetworkInterface>();
160162

161-
foreach (var nic in nicList)
163+
else
162164
{
163-
var psNic = this.ToPsNetworkInterface(nic);
164-
psNic.ResourceGroupName = this.ResourceGroupName;
165-
psNetworkInterfaces.Add(psNic);
165+
nicPage = this.NetworkInterfaceClient.ListAll();
166166
}
167167

168-
WriteObject(psNetworkInterfaces, true);
169-
}
170-
171-
else
172-
{
173-
var nicList = this.NetworkInterfaceClient.ListAll();
168+
// Get all resources by polling on next page link
169+
var nicList = ListNextLink<NetworkInterface>.GetAllResourcesByPollingNextLink(nicPage, this.NetworkInterfaceClient.ListNext);
174170

175171
var psNetworkInterfaces = new List<PSNetworkInterface>();
176172

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/GetAzureNetworkSecurityGroupCommand.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using Microsoft.Azure.Management.Network;
1717
using System.Collections.Generic;
1818
using System.Management.Automation;
19+
using Microsoft.Azure.Management.Network.Models;
20+
using Microsoft.Rest.Azure;
1921

2022
namespace Microsoft.Azure.Commands.Network
2123
{
@@ -66,24 +68,20 @@ public override void Execute()
6668

6769
WriteObject(nsg);
6870
}
69-
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
71+
else
7072
{
71-
var nsgList = this.NetworkSecurityGroupClient.List(this.ResourceGroupName);
72-
73-
var psNsgs = new List<PSNetworkSecurityGroup>();
74-
75-
foreach (var networkSecurityGroup in nsgList)
73+
IPage<NetworkSecurityGroup> nsgPage;
74+
if (!string.IsNullOrEmpty(this.ResourceGroupName))
7675
{
77-
var psNsg = this.ToPsNetworkSecurityGroup(networkSecurityGroup);
78-
psNsg.ResourceGroupName = this.ResourceGroupName;
79-
psNsgs.Add(psNsg);
76+
nsgPage = this.NetworkSecurityGroupClient.List(this.ResourceGroupName);
77+
}
78+
else
79+
{
80+
nsgPage = this.NetworkSecurityGroupClient.ListAll();
8081
}
8182

82-
WriteObject(psNsgs, true);
83-
}
84-
else
85-
{
86-
var nsgList = this.NetworkSecurityGroupClient.ListAll();
83+
// Get all resources by polling on next page link
84+
var nsgList = ListNextLink<NetworkSecurityGroup>.GetAllResourcesByPollingNextLink(nsgPage, this.NetworkSecurityGroupClient.ListNext);
8785

8886
var psNsgs = new List<PSNetworkSecurityGroup>();
8987

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/NetworkSecurityGroupBaseCmdlet.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
1919
using Microsoft.Azure.Management.Network;
2020
using System.Net;
21+
using Microsoft.Azure.Management.Network.Models;
2122

2223
namespace Microsoft.Azure.Commands.Network
2324
{
24-
using Microsoft.Azure.Management.Network.Models;
25-
2625
public abstract class NetworkSecurityGroupBaseCmdlet : NetworkBaseCmdlet
2726
{
2827
public INetworkSecurityGroupsOperations NetworkSecurityGroupClient

0 commit comments

Comments
 (0)