Skip to content

Commit e15c231

Browse files
committed
network: Add '--marker', '--limit' to most list commands
As noted in the neutron API reference guide [1]: To reduce load on the service, list operations will return a maximum number of items at a time. To navigate the collection, the parameters limit, marker and page_reverse can be set in the URI. Take advantage of the common pagination helpers introduced in change I551bb4c3ff0568c6df5244a1d0f0669497bee58f to expose this functionality to end users. [1] https://docs.openstack.org/api-ref/network/v2/#pagination Change-Id: Idea9c995ad412efdc11ecb64baaece6ab35cbb48 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
1 parent b75f741 commit e15c231

46 files changed

Lines changed: 773 additions & 33 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

openstackclient/network/v2/address_group.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from osc_lib import utils
2424

2525
from openstackclient import command
26+
from openstackclient.common import pagination
2627
from openstackclient.i18n import _
2728
from openstackclient.identity import common as identity_common
2829
from openstackclient.network import common
@@ -169,6 +170,7 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
169170
),
170171
)
171172
identity_common.add_project_domain_option_to_parser(parser)
173+
pagination.add_marker_pagination_option_to_parser(parser)
172174

173175
return parser
174176

@@ -201,6 +203,11 @@ def take_action(
201203
parsed_args.project_domain,
202204
).id
203205
attrs['project_id'] = project_id
206+
if parsed_args.marker is not None:
207+
attrs['marker'] = parsed_args.marker
208+
if parsed_args.limit is not None:
209+
attrs['limit'] = parsed_args.limit
210+
204211
data = client.address_groups(**attrs)
205212

206213
return (

openstackclient/network/v2/address_scope.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from osc_lib import utils
2323

2424
from openstackclient import command
25+
from openstackclient.common import pagination
2526
from openstackclient.i18n import _
2627
from openstackclient.identity import common as identity_common
2728
from openstackclient.network import common
@@ -185,7 +186,7 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
185186
),
186187
)
187188
identity_common.add_project_domain_option_to_parser(parser)
188-
189+
pagination.add_marker_pagination_option_to_parser(parser)
189190
shared_group = parser.add_mutually_exclusive_group()
190191
shared_group.add_argument(
191192
'--share',
@@ -197,6 +198,7 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
197198
action='store_true',
198199
help=_("List only address scopes not shared between projects"),
199200
)
201+
200202
return parser
201203

202204
def take_action(
@@ -234,6 +236,10 @@ def take_action(
234236
parsed_args.project_domain,
235237
).id
236238
attrs['project_id'] = project_id
239+
if parsed_args.marker is not None:
240+
attrs['marker'] = parsed_args.marker
241+
if parsed_args.limit is not None:
242+
attrs['limit'] = parsed_args.limit
237243
data = client.address_scopes(**attrs)
238244

239245
return (

openstackclient/network/v2/floating_ip.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from osc_lib.utils import tags as _tag
2525

2626
from openstackclient import command
27+
from openstackclient.common import pagination
2728
from openstackclient.i18n import _
2829
from openstackclient.identity import common as identity_common
2930
from openstackclient.network import common
@@ -308,6 +309,7 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
308309
default=False,
309310
help=_("List additional fields in output"),
310311
)
312+
pagination.add_marker_pagination_option_to_parser(parser)
311313
return parser
312314

313315
def take_action(
@@ -395,6 +397,10 @@ def take_action(
395397
).id
396398
router_ids.append(router_id)
397399
query['router_id'] = router_ids
400+
if parsed_args.marker is not None:
401+
query['marker'] = parsed_args.marker
402+
if parsed_args.limit is not None:
403+
query['limit'] = parsed_args.limit
398404

399405
_tag.get_tag_filtering_args(parsed_args, query)
400406

openstackclient/network/v2/floating_ip_port_forwarding.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from osc_lib import utils
2323

2424
from openstackclient import command
25+
from openstackclient.common import pagination
2526
from openstackclient.i18n import _
2627
from openstackclient.network import common
2728

@@ -294,7 +295,7 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
294295
"specified protocol number"
295296
),
296297
)
297-
298+
pagination.add_marker_pagination_option_to_parser(parser)
298299
return parser
299300

300301
def take_action(
@@ -340,6 +341,10 @@ def take_action(
340341
)
341342
if parsed_args.protocol is not None:
342343
query['protocol'] = parsed_args.protocol
344+
if parsed_args.marker is not None:
345+
query['marker'] = parsed_args.marker
346+
if parsed_args.limit is not None:
347+
query['limit'] = parsed_args.limit
343348

344349
obj = client.find_ip(
345350
parsed_args.floating_ip,

openstackclient/network/v2/ip_availability.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from osc_lib import utils
2222

2323
from openstackclient import command
24+
from openstackclient.common import pagination
2425
from openstackclient.i18n import _
2526
from openstackclient.identity import common as identity_common
2627

@@ -62,6 +63,7 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
6263
),
6364
)
6465
identity_common.add_project_domain_option_to_parser(parser)
66+
pagination.add_marker_pagination_option_to_parser(parser)
6567
return parser
6668

6769
def take_action(
@@ -85,7 +87,6 @@ def take_action(
8587
filters = {}
8688
if parsed_args.ip_version:
8789
filters['ip_version'] = parsed_args.ip_version
88-
8990
if parsed_args.project:
9091
identity_client = self.app.client_manager.identity
9192
project_id = identity_common.find_project(
@@ -94,6 +95,11 @@ def take_action(
9495
parsed_args.project_domain,
9596
).id
9697
filters['project_id'] = project_id
98+
if parsed_args.marker is not None:
99+
filters['marker'] = parsed_args.marker
100+
if parsed_args.limit is not None:
101+
filters['limit'] = parsed_args.limit
102+
97103
data = client.network_ip_availabilities(**filters)
98104
return (
99105
column_headers,

openstackclient/network/v2/l3_conntrack_helper.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from osc_lib import utils
2323

2424
from openstackclient import command
25+
from openstackclient.common import pagination
2526
from openstackclient.i18n import _
2627

2728
LOG = logging.getLogger(__name__)
@@ -176,6 +177,7 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
176177
'the netfilter conntrack target rule (name or ID)'
177178
),
178179
)
180+
pagination.add_marker_pagination_option_to_parser(parser)
179181

180182
return parser
181183

@@ -197,7 +199,13 @@ def take_action(
197199
'Protocol',
198200
'Port',
199201
)
202+
200203
attrs = _get_attrs(client, parsed_args)
204+
if parsed_args.marker is not None:
205+
attrs['marker'] = parsed_args.marker
206+
if parsed_args.limit is not None:
207+
attrs['limit'] = parsed_args.limit
208+
201209
data = client.conntrack_helpers(attrs.pop('router_id'), **attrs)
202210

203211
return (

openstackclient/network/v2/network.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from osc_lib.utils import tags as _tag
2525

2626
from openstackclient import command
27+
from openstackclient.common import pagination
2728
from openstackclient.i18n import _
2829
from openstackclient.identity import common as identity_common
2930
from openstackclient.network import common
@@ -538,6 +539,7 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
538539
help=_('List only networks hosted the specified agent (ID only)'),
539540
)
540541
_tag.add_tag_filtering_option_to_parser(parser, _('networks'))
542+
pagination.add_marker_pagination_option_to_parser(parser)
541543
return parser
542544

543545
def take_action(
@@ -650,6 +652,11 @@ def take_action(
650652
args['provider:segmentation_id'] = parsed_args.segmentation_id
651653
args['provider_segmentation_id'] = parsed_args.segmentation_id
652654

655+
if parsed_args.marker is not None:
656+
args['marker'] = parsed_args.marker
657+
if parsed_args.limit is not None:
658+
args['limit'] = parsed_args.limit
659+
653660
_tag.get_tag_filtering_args(parsed_args, args)
654661

655662
data = client.networks(**args)

openstackclient/network/v2/network_agent.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from osc_lib import utils
2525

2626
from openstackclient import command
27+
from openstackclient.common import pagination
2728
from openstackclient.i18n import _
2829

2930
LOG = logging.getLogger(__name__)
@@ -246,6 +247,7 @@ def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
246247
default=False,
247248
help=_("List additional fields in output"),
248249
)
250+
pagination.add_marker_pagination_option_to_parser(parser)
249251

250252
return parser
251253

@@ -273,6 +275,10 @@ def take_action(
273275
)
274276

275277
filters = {}
278+
if parsed_args.marker is not None:
279+
filters['marker'] = parsed_args.marker
280+
if parsed_args.limit is not None:
281+
filters['limit'] = parsed_args.limit
276282

277283
if parsed_args.network is not None:
278284
network = client.find_network(

openstackclient/network/v2/network_flavor.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from osc_lib import utils
2323

2424
from openstackclient import command
25+
from openstackclient.common import pagination
2526
from openstackclient.i18n import _
2627
from openstackclient.identity import common as identity_common
2728
from openstackclient.network import common
@@ -190,6 +191,11 @@ def take_action(self, parsed_args: argparse.Namespace) -> None:
190191
class ListNetworkFlavor(command.Lister):
191192
_description = _("List network flavors")
192193

194+
def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
195+
parser = super().get_parser(prog_name)
196+
pagination.add_marker_pagination_option_to_parser(parser)
197+
return parser
198+
193199
def take_action(
194200
self, parsed_args: argparse.Namespace
195201
) -> tuple[tuple[str, ...], Iterable[tuple[Any, ...]]]:
@@ -204,7 +210,13 @@ def take_action(
204210
'Description',
205211
)
206212

207-
data = client.flavors()
213+
filters = {}
214+
if parsed_args.marker is not None:
215+
filters['marker'] = parsed_args.marker
216+
if parsed_args.limit is not None:
217+
filters['limit'] = parsed_args.limit
218+
219+
data = client.flavors(**filters)
208220
return (
209221
column_headers,
210222
(

openstackclient/network/v2/network_flavor_profile.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from osc_lib import utils
2121

2222
from openstackclient import command
23+
from openstackclient.common import pagination
2324
from openstackclient.i18n import _
2425
from openstackclient.network import common
2526

@@ -159,6 +160,11 @@ def take_action(self, parsed_args: argparse.Namespace) -> None:
159160
class ListNetworkFlavorProfile(command.Lister):
160161
_description = _("List network flavor profile(s)")
161162

163+
def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
164+
parser = super().get_parser(prog_name)
165+
pagination.add_marker_pagination_option_to_parser(parser)
166+
return parser
167+
162168
def take_action(
163169
self, parsed_args: argparse.Namespace
164170
) -> tuple[tuple[str, ...], Iterable[tuple[Any, ...]]]:
@@ -179,7 +185,14 @@ def take_action(
179185
'Description',
180186
)
181187

182-
data = client.service_profiles()
188+
filters = {}
189+
if parsed_args.marker is not None:
190+
filters['marker'] = parsed_args.marker
191+
if parsed_args.limit is not None:
192+
filters['limit'] = parsed_args.limit
193+
194+
data = client.service_profiles(**filters)
195+
183196
return (
184197
column_headers,
185198
(

0 commit comments

Comments
 (0)