Skip to content

Commit caf7fae

Browse files
committed
Add support for --max-items
openstacksdk commit d649aada8 added support for a max_items parameter to allow users to distinguish between the page size and the total amount of resources to return. Wire this option through to OSC by adding a new --max-items parameter. This is implemented for all services that currently use SDK as their client and support pagination. Change-Id: I98a61daf097418ad59e2c47c39440476d5a0b7c7 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent e15c231 commit caf7fae

49 files changed

Lines changed: 149 additions & 9 deletions

Some content is hidden

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

openstackclient/common/pagination.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
# useful
2222

2323

24+
# TODO(stephenfin): include_max_items should not be necessary once we need to
25+
# migrate remaining users to openstacksdk
2426
def add_marker_pagination_option_to_parser(
2527
parser: argparse.ArgumentParser,
28+
include_max_items: bool = True,
2629
) -> None:
2730
"""Add marker-based pagination options to the parser.
2831
@@ -39,8 +42,11 @@ def add_marker_pagination_option_to_parser(
3942
type=int,
4043
action=parseractions.NonNegativeAction,
4144
help=_(
42-
'The maximum number of entries to return. If the value exceeds '
43-
'the server-defined maximum, then the maximum value will be used.'
45+
'The maximum number of entries to return per page. If the value '
46+
'exceeds the server-defined maximum, then the server-defined '
47+
'value will be used. Note that this controls the page size, not '
48+
'the total number of entries returned. Use --max-items to limit '
49+
'the total number of entries returned.'
4450
),
4551
)
4652
parser.add_argument(
@@ -52,10 +58,26 @@ def add_marker_pagination_option_to_parser(
5258
'This should be a value that was returned in a previous request.'
5359
),
5460
)
61+
if include_max_items:
62+
parser.add_argument(
63+
'--max-items',
64+
metavar='<max-items>',
65+
type=int,
66+
action=parseractions.NonNegativeAction,
67+
default=None,
68+
help=_(
69+
'The maximum number of entries to return in total, paging '
70+
'through multiple requests if needed. Use --limit to control '
71+
'the page size.'
72+
),
73+
)
5574

5675

76+
# TODO(stephenfin): include_max_items should not be necessary once we need to
77+
# migrate remaining users to openstacksdk
5778
def add_offset_pagination_option_to_parser(
5879
parser: argparse.ArgumentParser,
80+
include_max_items: bool = True,
5981
) -> None:
6082
"""Add offset-based pagination options to the parser.
6183
@@ -71,8 +93,11 @@ def add_offset_pagination_option_to_parser(
7193
type=int,
7294
action=parseractions.NonNegativeAction,
7395
help=_(
74-
'The maximum number of entries to return. If the value exceeds '
75-
'the server-defined maximum, then the maximum value will be used.'
96+
'The maximum number of entries to return per page. If the value '
97+
'exceeds the server-defined maximum, then the maximum value will '
98+
'be used. Note that this controls the page size, not the total '
99+
'number of entries returned. Use --max-items to limit the total '
100+
'number of entries returned.'
76101
),
77102
)
78103
parser.add_argument(
@@ -86,3 +111,16 @@ def add_offset_pagination_option_to_parser(
86111
'return.'
87112
),
88113
)
114+
if include_max_items:
115+
parser.add_argument(
116+
'--max-items',
117+
metavar='<max-items>',
118+
type=int,
119+
action=parseractions.NonNegativeAction,
120+
default=None,
121+
help=_(
122+
'The maximum number of entries to return in total, paging '
123+
'through multiple requests if needed. Use --limit to control '
124+
'the page size.'
125+
),
126+
)

openstackclient/compute/v2/flavor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ def take_action(
339339

340340
if parsed_args.limit:
341341
query_attrs['limit'] = parsed_args.limit
342+
if parsed_args.max_items is not None:
343+
query_attrs['max_items'] = parsed_args.max_items
342344

343345
if parsed_args.limit or parsed_args.marker:
344346
# User passed explicit pagination request, switch off SDK

openstackclient/compute/v2/hypervisor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ def take_action(
122122
)
123123
raise exceptions.CommandError(msg)
124124
list_opts['limit'] = parsed_args.limit
125+
if parsed_args.max_items is not None:
126+
list_opts['max_items'] = parsed_args.max_items
125127

126128
if parsed_args.matching:
127129
list_opts['hypervisor_hostname_pattern'] = parsed_args.matching

openstackclient/compute/v2/keypair.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ def take_action(
336336
raise exceptions.CommandError(msg)
337337

338338
kwargs['limit'] = parsed_args.limit
339+
if parsed_args.max_items is not None:
340+
kwargs['max_items'] = parsed_args.max_items
339341

340342
if parsed_args.project:
341343
if not sdk_utils.supports_microversion(compute_client, '2.10'):

openstackclient/compute/v2/server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,9 @@ def take_action(
28542854
search_opts['limit'] = parsed_args.limit
28552855
search_opts['paginated'] = False
28562856

2857+
if parsed_args.max_items is not None:
2858+
search_opts['max_items'] = parsed_args.max_items
2859+
28572860
LOG.debug('search options: %s', search_opts)
28582861

28592862
if search_opts['changes-before']:

openstackclient/compute/v2/server_event.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ def take_action(
171171
kwargs['limit'] = parsed_args.limit
172172
kwargs['paginated'] = False
173173

174+
if parsed_args.max_items is not None:
175+
kwargs['max_items'] = parsed_args.max_items
176+
174177
if parsed_args.changes_since:
175178
if not sdk_utils.supports_microversion(compute_client, '2.58'):
176179
msg = _(

openstackclient/compute/v2/server_group.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ def take_action(
219219

220220
if parsed_args.limit:
221221
kwargs['limit'] = parsed_args.limit
222+
if parsed_args.max_items is not None:
223+
kwargs['max_items'] = parsed_args.max_items
222224

223225
data = compute_client.server_groups(**kwargs)
224226

openstackclient/compute/v2/server_migration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ def take_action(
207207
search_opts['limit'] = parsed_args.limit
208208
search_opts['paginated'] = False
209209

210+
if parsed_args.max_items is not None:
211+
search_opts['max_items'] = parsed_args.max_items
212+
210213
if parsed_args.changes_since:
211214
if not sdk_utils.supports_microversion(compute_client, "2.59"):
212215
msg = _(

openstackclient/identity/v3/project.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ def take_action(
352352

353353
if parsed_args.limit is not None:
354354
kwargs['limit'] = parsed_args.limit
355+
if parsed_args.max_items is not None:
356+
kwargs['max_items'] = parsed_args.max_items
355357
if parsed_args.marker is not None:
356358
kwargs['marker'] = parsed_args.marker
357359

openstackclient/identity/v3/user.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ def take_action(
486486
pagination_kwargs: dict[str, Any] = {}
487487
if parsed_args.limit is not None:
488488
pagination_kwargs['limit'] = parsed_args.limit
489+
if parsed_args.max_items is not None:
490+
pagination_kwargs['max_items'] = parsed_args.max_items
489491
if parsed_args.marker is not None:
490492
pagination_kwargs['marker'] = parsed_args.marker
491493

0 commit comments

Comments
 (0)