Skip to content

add pagination support #4111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Microsoft.Azure.Management.Network;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Rest.Azure;

namespace Microsoft.Azure.Commands.Network
{
Expand Down Expand Up @@ -46,24 +48,20 @@ public override void ExecuteCmdlet()

WriteObject(applicationGateway);
}
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
else
{
var appGateway = this.ApplicationGatewayClient.List(this.ResourceGroupName);

var psApplicationGateways = new List<PSApplicationGateway>();

foreach (var appGw in appGateway)
IPage<ApplicationGateway> appGatewayPage;
if (!string.IsNullOrEmpty(this.ResourceGroupName))
{
var psAppGw = this.ToPsApplicationGateway(appGw);
psAppGw.ResourceGroupName = this.ResourceGroupName;
psApplicationGateways.Add(psAppGw);
appGatewayPage = this.ApplicationGatewayClient.List(this.ResourceGroupName);
}
else
{
appGatewayPage = this.ApplicationGatewayClient.ListAll();
}

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

var psApplicationGateways = new List<PSApplicationGateway>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
<Compile Include="ApplicationGateway\UrlPathMap\NewAzureApplicationGatewayUrlPathMapConfigCommand.cs" />
<Compile Include="ApplicationGateway\UrlPathMap\RemoveAzureApplicationGatewayUrlPathMapConfigCommand.cs" />
<Compile Include="ApplicationGateway\UrlPathMap\SetAzureApplicationGatewayUrlPathMapConfigCommand.cs" />
<Compile Include="Common\ListNextLink.cs" />
<Compile Include="Common\NetworkBaseCmdlet.cs" />
<Compile Include="Common\NetworkClient.cs" />
<Compile Include="Common\NetworkCloudException.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Rest.Azure;

namespace Microsoft.Azure.Commands.Network
{
public static class ListNextLink<T>
{
public static List<T> GetAllResourcesByPollingNextLink(IPage<T> resourcePage, Func<string, IPage<T>> getNextLink)
{
var resourceList = new List<T>();

var nextPageLink = AddResourceToListAndReturnNextPageLink(resourcePage, resourceList);

while (!string.IsNullOrEmpty(nextPageLink))
{
var nextVnetPage = getNextLink(nextPageLink);
nextPageLink = AddResourceToListAndReturnNextPageLink(nextVnetPage, resourceList);
}

return resourceList;
}

private static string AddResourceToListAndReturnNextPageLink(IPage<T> resourcePage, List<T> resourceList)
{
foreach (var resource in resourcePage)
{
resourceList.Add(resource);
}

return resourcePage.NextPageLink;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Microsoft.Azure.Management.Network;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Rest.Azure;

namespace Microsoft.Azure.Commands.Network
{
Expand Down Expand Up @@ -46,23 +48,20 @@ public override void Execute()

WriteObject(circuit);
}
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
else
{
var circuitList = this.ExpressRouteCircuitClient.List(this.ResourceGroupName);

var psCircuits = new List<PSExpressRouteCircuit>();
foreach (var ExpressRouteCircuit in circuitList)
IPage<ExpressRouteCircuit> circuitPage;
if (!string.IsNullOrEmpty(this.ResourceGroupName))
{
var psVnet = this.ToPsExpressRouteCircuit(ExpressRouteCircuit);
psVnet.ResourceGroupName = this.ResourceGroupName;
psCircuits.Add(psVnet);
circuitPage = this.ExpressRouteCircuitClient.List(this.ResourceGroupName);
}
else
{
circuitPage = this.ExpressRouteCircuitClient.ListAll();
}

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

var psCircuits = new List<PSExpressRouteCircuit>();
foreach (var ExpressRouteCircuit in circuitList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Microsoft.Azure.Management.Network;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Rest.Azure;

namespace Microsoft.Azure.Commands.Network
{
Expand Down Expand Up @@ -66,25 +68,21 @@ public override void Execute()

WriteObject(loadBalancer);
}
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
else
{
var lbList = this.LoadBalancerClient.List(this.ResourceGroupName);

var psLoadBalancers = new List<PSLoadBalancer>();

foreach (var lb in lbList)
IPage<LoadBalancer> lbPage;
if (!string.IsNullOrEmpty(this.ResourceGroupName))
{
var psLb = this.ToPsLoadBalancer(lb);
psLb.ResourceGroupName = this.ResourceGroupName;
psLoadBalancers.Add(psLb);
lbPage = this.LoadBalancerClient.List(this.ResourceGroupName);
}

WriteObject(psLoadBalancers, true);
}
else
{
lbPage = this.LoadBalancerClient.ListAll();
}

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

var psLoadBalancers = new List<PSLoadBalancer>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using Microsoft.Azure.Commands.Network.Models;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using System.Collections.Generic;
using System.Management.Automation;

Expand Down Expand Up @@ -48,7 +49,10 @@ public override void Execute()
}
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
{
var localnetGatewayList = this.LocalNetworkGatewayClient.List(this.ResourceGroupName);
var localnetGatewayPage = this.LocalNetworkGatewayClient.List(this.ResourceGroupName);

// Get all resources by polling on next page link
var localnetGatewayList = ListNextLink<LocalNetworkGateway>.GetAllResourcesByPollingNextLink(localnetGatewayPage, this.LocalNetworkGatewayClient.ListNext);

var psLocalnetGateways = new List<PSLocalNetworkGateway>();
foreach (var localNetworkGateway in localnetGatewayList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,10 @@
<Label>Primary</Label>
<PropertyName>Primary</PropertyName>
</ListItem>
<ListItem>
<Label>MacAddress</Label>
<PropertyName>MacAddress</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

using Microsoft.Azure.Commands.Network.Models;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using System.Collections.Generic;
using System.Management.Automation;
using MNM = Microsoft.Azure.Management.Network.Models;
using Microsoft.Rest.Azure;

namespace Microsoft.Azure.Commands.Network
{
Expand Down Expand Up @@ -129,48 +131,42 @@ public override void Execute()

WriteObject(networkInterface);
}
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
else
{
IEnumerable<MNM.NetworkInterface> nicList;

if (ParameterSetName.Contains("ScaleSetNic"))
IPage<MNM.NetworkInterface> nicPage;
if (!string.IsNullOrEmpty(this.ResourceGroupName))
{
if (string.IsNullOrEmpty(this.VirtualMachineIndex))
if (ParameterSetName.Contains("ScaleSetNic"))
{
nicList =
this.NetworkInterfaceClient.ListVirtualMachineScaleSetNetworkInterfaces(
this.ResourceGroupName,
this.VirtualMachineScaleSetName);
if (string.IsNullOrEmpty(this.VirtualMachineIndex))
{
nicPage =
this.NetworkInterfaceClient.ListVirtualMachineScaleSetNetworkInterfaces(
this.ResourceGroupName,
this.VirtualMachineScaleSetName);
}
else
{
nicPage =
this.NetworkInterfaceClient.ListVirtualMachineScaleSetVMNetworkInterfaces(
this.ResourceGroupName,
this.VirtualMachineScaleSetName,
this.VirtualMachineIndex);
}
}
else
{
nicList =
this.NetworkInterfaceClient.ListVirtualMachineScaleSetVMNetworkInterfaces(
this.ResourceGroupName,
this.VirtualMachineScaleSetName,
this.VirtualMachineIndex);
}
nicPage = this.NetworkInterfaceClient.List(this.ResourceGroupName);
}
}
else
{
nicList = this.NetworkInterfaceClient.List(this.ResourceGroupName);
}

var psNetworkInterfaces = new List<PSNetworkInterface>();

foreach (var nic in nicList)
else
{
var psNic = this.ToPsNetworkInterface(nic);
psNic.ResourceGroupName = this.ResourceGroupName;
psNetworkInterfaces.Add(psNic);
nicPage = this.NetworkInterfaceClient.ListAll();
}

WriteObject(psNetworkInterfaces, true);
}

else
{
var nicList = this.NetworkInterfaceClient.ListAll();
// Get all resources by polling on next page link
var nicList = ListNextLink<NetworkInterface>.GetAllResourcesByPollingNextLink(nicPage, this.NetworkInterfaceClient.ListNext);

var psNetworkInterfaces = new List<PSNetworkInterface>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Microsoft.Azure.Management.Network;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Rest.Azure;

namespace Microsoft.Azure.Commands.Network
{
Expand Down Expand Up @@ -66,24 +68,20 @@ public override void Execute()

WriteObject(nsg);
}
else if (!string.IsNullOrEmpty(this.ResourceGroupName))
else
{
var nsgList = this.NetworkSecurityGroupClient.List(this.ResourceGroupName);

var psNsgs = new List<PSNetworkSecurityGroup>();

foreach (var networkSecurityGroup in nsgList)
IPage<NetworkSecurityGroup> nsgPage;
if (!string.IsNullOrEmpty(this.ResourceGroupName))
{
var psNsg = this.ToPsNetworkSecurityGroup(networkSecurityGroup);
psNsg.ResourceGroupName = this.ResourceGroupName;
psNsgs.Add(psNsg);
nsgPage = this.NetworkSecurityGroupClient.List(this.ResourceGroupName);
}
else
{
nsgPage = this.NetworkSecurityGroupClient.ListAll();
}

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

var psNsgs = new List<PSNetworkSecurityGroup>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
using Microsoft.Azure.Management.Network;
using System.Net;
using Microsoft.Azure.Management.Network.Models;

namespace Microsoft.Azure.Commands.Network
{
using Microsoft.Azure.Management.Network.Models;

public abstract class NetworkSecurityGroupBaseCmdlet : NetworkBaseCmdlet
{
public INetworkSecurityGroupsOperations NetworkSecurityGroupClient
Expand Down
Loading