osc-lib 3.2.0__py3-none-any.whl → 4.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
osc_lib/api/api.py CHANGED
@@ -13,6 +13,9 @@
13
13
 
14
14
  """Base API Library"""
15
15
 
16
+ import typing as ty
17
+ import warnings
18
+
16
19
  from keystoneauth1 import exceptions as ksa_exceptions
17
20
  from keystoneauth1 import session as ksa_session
18
21
  import requests
@@ -42,8 +45,12 @@ class BaseAPI:
42
45
  HEADER_NAME = "OpenStack-API-Version"
43
46
 
44
47
  def __init__(
45
- self, session=None, service_type=None, endpoint=None, **kwargs
46
- ):
48
+ self,
49
+ session: ty.Optional[ksa_session.Session] = None,
50
+ service_type: ty.Optional[str] = None,
51
+ endpoint: ty.Optional[str] = None,
52
+ **kwargs: ty.Any,
53
+ ) -> None:
47
54
  """Base object that contains some common API objects and methods
48
55
 
49
56
  :param keystoneauth1.session.Session session:
@@ -58,6 +65,12 @@ class BaseAPI:
58
65
  Keyword arguments passed to keystoneauth1.session.Session().
59
66
  """
60
67
 
68
+ warnings.warn(
69
+ 'The BaseAPI class is deprecated for removal. Consider using '
70
+ 'openstacksdk instead else vendoring this code into your client',
71
+ category=DeprecationWarning,
72
+ )
73
+
61
74
  super().__init__()
62
75
 
63
76
  # Create a keystoneauth1.session.Session if one is not supplied
@@ -69,7 +82,7 @@ class BaseAPI:
69
82
  self.service_type = service_type
70
83
  self.endpoint = self._munge_endpoint(endpoint)
71
84
 
72
- def _munge_endpoint(self, endpoint):
85
+ def _munge_endpoint(self, endpoint: ty.Optional[str]) -> ty.Optional[str]:
73
86
  """Hook to allow subclasses to massage the passed-in endpoint
74
87
 
75
88
  Hook to massage passed-in endpoints from arbitrary sources,
@@ -90,7 +103,13 @@ class BaseAPI:
90
103
  else:
91
104
  return endpoint
92
105
 
93
- def _request(self, method, url, session=None, **kwargs):
106
+ def _request(
107
+ self,
108
+ method: str,
109
+ url: str,
110
+ session: ty.Optional[ksa_session.Session] = None,
111
+ **kwargs: ty.Any,
112
+ ) -> requests.Response:
94
113
  """Perform call into session
95
114
 
96
115
  All API calls are funneled through this method to provide a common
@@ -136,7 +155,13 @@ class BaseAPI:
136
155
 
137
156
  # The basic action methods all take a Session and return dict/lists
138
157
 
139
- def create(self, url, session=None, method=None, **params):
158
+ def create(
159
+ self,
160
+ url: str,
161
+ session: ty.Optional[ksa_session.Session] = None,
162
+ method: ty.Optional[str] = None,
163
+ **params: ty.Any,
164
+ ) -> ty.Union[requests.Response, ty.Any]:
140
165
  """Create a new resource
141
166
 
142
167
  :param string url:
@@ -156,7 +181,12 @@ class BaseAPI:
156
181
  except requests.JSONDecodeError:
157
182
  return ret
158
183
 
159
- def delete(self, url, session=None, **params):
184
+ def delete(
185
+ self,
186
+ url: str,
187
+ session: ty.Optional[ksa_session.Session] = None,
188
+ **params: ty.Any,
189
+ ) -> requests.Response:
160
190
  """Delete a resource
161
191
 
162
192
  :param string url:
@@ -169,13 +199,13 @@ class BaseAPI:
169
199
 
170
200
  def list(
171
201
  self,
172
- path,
173
- session=None,
174
- body=None,
175
- detailed=False,
176
- headers=None,
177
- **params,
178
- ):
202
+ path: str,
203
+ session: ty.Optional[ksa_session.Session] = None,
204
+ body: ty.Any = None,
205
+ detailed: bool = False,
206
+ headers: ty.Optional[ty.Dict[str, str]] = None,
207
+ **params: ty.Any,
208
+ ) -> ty.Union[requests.Response, ty.Any]:
179
209
  """Return a list of resources
180
210
 
181
211
  GET ${ENDPOINT}/${PATH}?${PARAMS}
@@ -226,11 +256,11 @@ class BaseAPI:
226
256
 
227
257
  def find_attr(
228
258
  self,
229
- path,
230
- value=None,
231
- attr=None,
232
- resource=None,
233
- ):
259
+ path: str,
260
+ value: ty.Optional[str] = None,
261
+ attr: ty.Optional[str] = None,
262
+ resource: ty.Optional[str] = None,
263
+ ) -> ty.Any:
234
264
  """Find a resource via attribute or ID
235
265
 
236
266
  Most APIs return a list wrapped by a dict with the resource
@@ -260,7 +290,7 @@ class BaseAPI:
260
290
  if resource is None:
261
291
  resource = path
262
292
 
263
- def getlist(kw):
293
+ def getlist(kw: ty.Dict[str, ty.Any]) -> ty.Any:
264
294
  """Do list call, unwrap resource dict if present"""
265
295
  ret = self.list(path, **kw)
266
296
  if isinstance(ret, dict) and resource in ret:
@@ -290,7 +320,12 @@ class BaseAPI:
290
320
  msg % {'resource': resource, 'attr': attr, 'value': value}
291
321
  )
292
322
 
293
- def find_bulk(self, path, headers=None, **kwargs):
323
+ def find_bulk(
324
+ self,
325
+ path: str,
326
+ headers: ty.Optional[ty.Dict[str, str]] = None,
327
+ **kwargs: ty.Any,
328
+ ) -> ty.List[ty.Any]:
294
329
  """Bulk load and filter locally
295
330
 
296
331
  :param string path:
@@ -318,7 +353,7 @@ class BaseAPI:
318
353
 
319
354
  return ret
320
355
 
321
- def find_one(self, path, **kwargs):
356
+ def find_one(self, path: str, **kwargs: ty.Any) -> ty.Any:
322
357
  """Find a resource by name or ID
323
358
 
324
359
  :param string path:
@@ -339,11 +374,11 @@ class BaseAPI:
339
374
 
340
375
  def find(
341
376
  self,
342
- path,
343
- value=None,
344
- attr=None,
345
- headers=None,
346
- ):
377
+ path: str,
378
+ value: ty.Optional[str] = None,
379
+ attr: ty.Optional[str] = None,
380
+ headers: ty.Optional[ty.Dict[str, str]] = None,
381
+ ) -> ty.Any:
347
382
  """Find a single resource by name or ID
348
383
 
349
384
  :param string path:
@@ -356,7 +391,7 @@ class BaseAPI:
356
391
  Headers dictionary to pass to requests
357
392
  """
358
393
 
359
- def raise_not_found():
394
+ def raise_not_found() -> ty.NoReturn:
360
395
  msg = _("%s not found") % value
361
396
  raise exceptions.NotFound(404, msg)
362
397
 
osc_lib/api/auth.py CHANGED
@@ -14,7 +14,9 @@
14
14
  """Authentication Library"""
15
15
 
16
16
  import argparse
17
+ import typing as ty
17
18
 
19
+ from keystoneauth1.identity import base as identity_base
18
20
  from keystoneauth1.identity.v3 import k2k
19
21
  from keystoneauth1.loading import base
20
22
 
@@ -22,16 +24,25 @@ from osc_lib import exceptions as exc
22
24
  from osc_lib.i18n import _
23
25
  from osc_lib import utils
24
26
 
27
+ if ty.TYPE_CHECKING:
28
+ from openstack import connection
29
+
25
30
 
26
31
  # Initialize the list of Authentication plugins early in order
27
32
  # to get the command-line options
28
33
  PLUGIN_LIST = None
29
34
 
35
+
36
+ class _OptionDict(ty.TypedDict):
37
+ env: str
38
+ help: str
39
+
40
+
30
41
  # List of plugin command line options
31
- OPTIONS_LIST = {}
42
+ OPTIONS_LIST: ty.Dict[str, _OptionDict] = {}
32
43
 
33
44
 
34
- def get_plugin_list():
45
+ def get_plugin_list() -> ty.FrozenSet[str]:
35
46
  """Gather plugin list and cache it"""
36
47
 
37
48
  global PLUGIN_LIST
@@ -41,7 +52,7 @@ def get_plugin_list():
41
52
  return PLUGIN_LIST
42
53
 
43
54
 
44
- def get_options_list():
55
+ def get_options_list() -> ty.Dict[str, _OptionDict]:
45
56
  """Gather plugin options so the help action has them available"""
46
57
 
47
58
  global OPTIONS_LIST
@@ -65,7 +76,10 @@ def get_options_list():
65
76
  return OPTIONS_LIST
66
77
 
67
78
 
68
- def check_valid_authorization_options(options, auth_plugin_name):
79
+ def check_valid_authorization_options(
80
+ options: 'connection.Connection',
81
+ auth_plugin_name: str,
82
+ ) -> None:
69
83
  """Validate authorization options, and provide helpful error messages."""
70
84
  if (
71
85
  options.auth.get('project_id')
@@ -86,16 +100,15 @@ def check_valid_authorization_options(options, auth_plugin_name):
86
100
  )
87
101
 
88
102
 
89
- def check_valid_authentication_options(options, auth_plugin_name):
90
- """Validate authentication options, and provide helpful error messages
91
-
92
- :param required_scope: indicate whether a scoped token is required
93
-
94
- """
95
-
103
+ def check_valid_authentication_options(
104
+ options: 'connection.Connection',
105
+ auth_plugin_name: str,
106
+ ) -> None:
107
+ """Validate authentication options, and provide helpful error messages."""
96
108
  # Get all the options defined within the plugin.
97
- plugin_opts = base.get_plugin_options(auth_plugin_name)
98
- plugin_opts = {opt.dest: opt for opt in plugin_opts}
109
+ plugin_opts = {
110
+ opt.dest: opt for opt in base.get_plugin_options(auth_plugin_name)
111
+ }
99
112
 
100
113
  # NOTE(aloga): this is an horrible hack. We need a way to specify the
101
114
  # required options in the plugins. Using the "required" argument for
@@ -141,7 +154,9 @@ def check_valid_authentication_options(options, auth_plugin_name):
141
154
  )
142
155
 
143
156
 
144
- def build_auth_plugins_option_parser(parser):
157
+ def build_auth_plugins_option_parser(
158
+ parser: argparse.ArgumentParser,
159
+ ) -> argparse.ArgumentParser:
145
160
  """Auth plugins options builder
146
161
 
147
162
  Builds dynamically the list of options expected by each available
@@ -206,13 +221,13 @@ def build_auth_plugins_option_parser(parser):
206
221
 
207
222
 
208
223
  def get_keystone2keystone_auth(
209
- local_auth,
210
- service_provider,
211
- project_id=None,
212
- project_name=None,
213
- project_domain_id=None,
214
- project_domain_name=None,
215
- ):
224
+ local_auth: identity_base.BaseIdentityPlugin,
225
+ service_provider: str,
226
+ project_id: ty.Optional[str] = None,
227
+ project_name: ty.Optional[str] = None,
228
+ project_domain_id: ty.Optional[str] = None,
229
+ project_domain_name: ty.Optional[str] = None,
230
+ ) -> k2k.Keystone2Keystone:
216
231
  """Return Keystone 2 Keystone authentication for service provider.
217
232
 
218
233
  :param local_auth: authentication to use with the local Keystone
osc_lib/api/utils.py CHANGED
@@ -13,13 +13,18 @@
13
13
 
14
14
  """API Utilities Library"""
15
15
 
16
+ import typing as ty
17
+
18
+
19
+ _T = ty.TypeVar('_T', bound=ty.List[ty.Any])
20
+
16
21
 
17
22
  def simple_filter(
18
- data=None,
19
- attr=None,
20
- value=None,
21
- property_field=None,
22
- ):
23
+ data: ty.Optional[_T] = None,
24
+ attr: ty.Optional[str] = None,
25
+ value: ty.Optional[str] = None,
26
+ property_field: ty.Optional[str] = None,
27
+ ) -> ty.Optional[_T]:
23
28
  """Filter a list of dicts
24
29
 
25
30
  :param list data:
@@ -14,7 +14,9 @@
14
14
  """OpenStackConfig subclass for argument compatibility"""
15
15
 
16
16
  import logging
17
+ import typing as ty
17
18
 
19
+ from keystoneauth1.loading import identity as ksa_loading
18
20
  from openstack.config import exceptions as sdk_exceptions
19
21
  from openstack.config import loader as config
20
22
  from oslo_utils import strutils
@@ -23,10 +25,12 @@ from oslo_utils import strutils
23
25
  LOG = logging.getLogger(__name__)
24
26
 
25
27
 
26
- # Sublcass OpenStackConfig in order to munge config values
28
+ # Subclass OpenStackConfig in order to munge config values
27
29
  # before auth plugins are loaded
28
- class OSC_Config(config.OpenStackConfig):
29
- def _auth_select_default_plugin(self, config):
30
+ class OSC_Config(config.OpenStackConfig): # type: ignore
31
+ def _auth_select_default_plugin(
32
+ self, config: ty.Dict[str, ty.Any]
33
+ ) -> ty.Dict[str, ty.Any]:
30
34
  """Select a default plugin based on supplied arguments
31
35
 
32
36
  Migrated from auth.select_auth_plugin()
@@ -59,7 +63,9 @@ class OSC_Config(config.OpenStackConfig):
59
63
  LOG.debug("Auth plugin {} selected".format(config['auth_type']))
60
64
  return config
61
65
 
62
- def _auth_v2_arguments(self, config):
66
+ def _auth_v2_arguments(
67
+ self, config: ty.Dict[str, ty.Any]
68
+ ) -> ty.Dict[str, ty.Any]:
63
69
  """Set up v2-required arguments from v3 info
64
70
 
65
71
  Migrated from auth.build_auth_params()
@@ -72,41 +78,49 @@ class OSC_Config(config.OpenStackConfig):
72
78
  config['auth']['tenant_name'] = config['auth']['project_name']
73
79
  return config
74
80
 
75
- def _auth_v2_ignore_v3(self, config):
81
+ def _auth_v2_ignore_v3(
82
+ self, config: ty.Dict[str, ty.Any]
83
+ ) -> ty.Dict[str, ty.Any]:
76
84
  """Remove v3 arguments if present for v2 plugin
77
85
 
78
86
  Migrated from clientmanager.setup_auth()
79
87
  """
80
-
81
88
  # NOTE(hieulq): If USER_DOMAIN_NAME, USER_DOMAIN_ID, PROJECT_DOMAIN_ID
82
89
  # or PROJECT_DOMAIN_NAME is present and API_VERSION is 2.0, then
83
90
  # ignore all domain related configs.
84
- if str(config.get('identity_api_version', '')).startswith(
85
- '2'
86
- ) and config.get('auth_type').endswith('password'):
87
- domain_props = [
88
- 'project_domain_id',
89
- 'project_domain_name',
90
- 'user_domain_id',
91
- 'user_domain_name',
92
- ]
93
- for prop in domain_props:
94
- if config['auth'].pop(prop, None) is not None:
95
- if config.get('cloud'):
96
- LOG.warning(
97
- "Ignoring domain related config {} for {}"
98
- "because identity API version is 2.0".format(
99
- prop, config['cloud']
100
- )
101
- )
102
- else:
103
- LOG.warning(
104
- f"Ignoring domain related config {prop} because"
105
- " identity API version is 2.0"
91
+ if not str(config.get('identity_api_version', '')).startswith('2'):
92
+ return config
93
+
94
+ if not config.get('auth_type') or not config['auth_type'].endswith(
95
+ 'password'
96
+ ):
97
+ return config
98
+
99
+ domain_props = [
100
+ 'project_domain_id',
101
+ 'project_domain_name',
102
+ 'user_domain_id',
103
+ 'user_domain_name',
104
+ ]
105
+ for prop in domain_props:
106
+ if config['auth'].pop(prop, None) is not None:
107
+ if config.get('cloud'):
108
+ LOG.warning(
109
+ "Ignoring domain related config {} for {}"
110
+ "because identity API version is 2.0".format(
111
+ prop, config['cloud']
106
112
  )
113
+ )
114
+ else:
115
+ LOG.warning(
116
+ f"Ignoring domain related config {prop} because"
117
+ " identity API version is 2.0"
118
+ )
107
119
  return config
108
120
 
109
- def _auth_default_domain(self, config):
121
+ def _auth_default_domain(
122
+ self, config: ty.Dict[str, ty.Any]
123
+ ) -> ty.Dict[str, ty.Any]:
110
124
  """Set a default domain from available arguments
111
125
 
112
126
  Migrated from clientmanager.setup_auth()
@@ -147,7 +161,9 @@ class OSC_Config(config.OpenStackConfig):
147
161
  config['auth']['user_domain_id'] = default_domain
148
162
  return config
149
163
 
150
- def auth_config_hook(self, config):
164
+ def auth_config_hook(
165
+ self, config: ty.Dict[str, ty.Any]
166
+ ) -> ty.Dict[str, ty.Any]:
151
167
  """Allow examination of config values before loading auth plugin
152
168
 
153
169
  OpenStackClient will override this to perform additional checks
@@ -165,7 +181,11 @@ class OSC_Config(config.OpenStackConfig):
165
181
  )
166
182
  return config
167
183
 
168
- def _validate_auth(self, config, loader, fixed_argparse=None):
184
+ def _validate_auth(
185
+ self,
186
+ config: ty.Dict[str, ty.Any],
187
+ loader: ksa_loading.BaseIdentityLoader, # type: ignore
188
+ ) -> ty.Dict[str, ty.Any]:
169
189
  """Validate auth plugin arguments"""
170
190
  # May throw a keystoneauth1.exceptions.NoMatchingPlugin
171
191
 
@@ -229,7 +249,8 @@ class OSC_Config(config.OpenStackConfig):
229
249
 
230
250
  return config
231
251
 
232
- def load_auth_plugin(self, config):
252
+ # TODO(stephenfin): Add type once we have typing for SDK
253
+ def load_auth_plugin(self, config: ty.Dict[str, ty.Any]) -> ty.Any:
233
254
  """Get auth plugin and validate args"""
234
255
 
235
256
  loader = self._get_auth_loader(config)
@@ -15,53 +15,55 @@
15
15
 
16
16
  """Formattable column for specify content type"""
17
17
 
18
+ import typing as ty
19
+
18
20
  from cliff import columns
19
21
 
20
22
  from osc_lib import utils
21
23
 
22
24
 
23
- class DictColumn(columns.FormattableColumn):
25
+ class DictColumn(columns.FormattableColumn): # type: ignore
24
26
  """Format column for dict content"""
25
27
 
26
- def human_readable(self):
28
+ def human_readable(self) -> str:
27
29
  return utils.format_dict(self._value)
28
30
 
29
- def machine_readable(self):
31
+ def machine_readable(self) -> ty.Dict[str, ty.Any]:
30
32
  return dict(self._value or {})
31
33
 
32
34
 
33
- class DictListColumn(columns.FormattableColumn):
35
+ class DictListColumn(columns.FormattableColumn): # type: ignore
34
36
  """Format column for dict, key is string, value is list"""
35
37
 
36
- def human_readable(self):
37
- return utils.format_dict_of_list(self._value)
38
+ def human_readable(self) -> str:
39
+ return utils.format_dict_of_list(self._value) or ''
38
40
 
39
- def machine_readable(self):
41
+ def machine_readable(self) -> ty.Dict[str, ty.List[ty.Any]]:
40
42
  return dict(self._value or {})
41
43
 
42
44
 
43
- class ListColumn(columns.FormattableColumn):
45
+ class ListColumn(columns.FormattableColumn): # type: ignore
44
46
  """Format column for list content"""
45
47
 
46
- def human_readable(self):
47
- return utils.format_list(self._value)
48
+ def human_readable(self) -> str:
49
+ return utils.format_list(self._value) or ''
48
50
 
49
- def machine_readable(self):
51
+ def machine_readable(self) -> ty.List[ty.Any]:
50
52
  return [x for x in self._value or []]
51
53
 
52
54
 
53
- class ListDictColumn(columns.FormattableColumn):
55
+ class ListDictColumn(columns.FormattableColumn): # type: ignore
54
56
  """Format column for list of dict content"""
55
57
 
56
- def human_readable(self):
57
- return utils.format_list_of_dicts(self._value)
58
+ def human_readable(self) -> str:
59
+ return utils.format_list_of_dicts(self._value) or ''
58
60
 
59
- def machine_readable(self):
61
+ def machine_readable(self) -> ty.List[ty.Dict[str, ty.Any]]:
60
62
  return [dict(x) for x in self._value or []]
61
63
 
62
64
 
63
- class SizeColumn(columns.FormattableColumn):
65
+ class SizeColumn(columns.FormattableColumn): # type: ignore
64
66
  """Format column for file size content"""
65
67
 
66
- def human_readable(self):
68
+ def human_readable(self) -> str:
67
69
  return utils.format_size(self._value)
osc_lib/cli/identity.py CHANGED
@@ -11,13 +11,19 @@
11
11
  # under the License.
12
12
  #
13
13
 
14
+ import argparse
15
+ import typing as ty
16
+
17
+ from openstack import connection
14
18
  from openstack import exceptions
15
19
  from openstack.identity.v3 import project
16
20
 
17
21
  from osc_lib.i18n import _
18
22
 
19
23
 
20
- def add_project_owner_option_to_parser(parser):
24
+ def add_project_owner_option_to_parser(
25
+ parser: argparse.ArgumentParser,
26
+ ) -> None:
21
27
  """Register project and project domain options.
22
28
 
23
29
  :param parser: argparse.Argument parser object.
@@ -38,7 +44,13 @@ def add_project_owner_option_to_parser(parser):
38
44
  )
39
45
 
40
46
 
41
- def find_project(sdk_connection, name_or_id, domain_name_or_id=None):
47
+ # TODO(stephenfin): This really doesn't belong here. This should be part of
48
+ # openstacksdk itself.
49
+ def find_project(
50
+ sdk_connection: connection.Connection,
51
+ name_or_id: str,
52
+ domain_name_or_id: ty.Optional[str] = None,
53
+ ) -> project.Project:
42
54
  """Find a project by its name name or ID.
43
55
 
44
56
  If Forbidden to find the resource (a common case if the user does not have
@@ -53,7 +65,6 @@ def find_project(sdk_connection, name_or_id, domain_name_or_id=None):
53
65
  This can be used when there are multiple projects with a same name.
54
66
  :returns: the project object found
55
67
  :rtype: `openstack.identity.v3.project.Project`
56
-
57
68
  """
58
69
  try:
59
70
  if domain_name_or_id:
@@ -0,0 +1,83 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+ # not use this file except in compliance with the License. You may obtain
3
+ # a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+ # License for the specific language governing permissions and limitations
11
+ # under the License.
12
+
13
+ import argparse
14
+
15
+ from osc_lib.cli import parseractions
16
+ from osc_lib.i18n import _
17
+
18
+
19
+ def add_marker_pagination_option_to_parser(
20
+ parser: argparse.ArgumentParser,
21
+ ) -> None:
22
+ """Add marker-based pagination options to the parser.
23
+
24
+ APIs that use marker-based paging use the marker and limit query parameters
25
+ to paginate through items in a collection.
26
+
27
+ Marker-based pagination is often used in cases where the length of the
28
+ total set of items is either changing frequently, or where the total length
29
+ might not be known upfront.
30
+ """
31
+ parser.add_argument(
32
+ '--limit',
33
+ metavar='<limit>',
34
+ type=int,
35
+ action=parseractions.NonNegativeAction,
36
+ help=_(
37
+ 'The maximum number of entries to return. If the value exceeds '
38
+ 'the server-defined maximum, then the maximum value will be used.'
39
+ ),
40
+ )
41
+ parser.add_argument(
42
+ '--marker',
43
+ metavar='<marker>',
44
+ default=None,
45
+ help=_(
46
+ 'The first position in the collection to return results from. '
47
+ 'This should be a value that was returned in a previous request.'
48
+ ),
49
+ )
50
+
51
+
52
+ def add_offset_pagination_option_to_parser(
53
+ parser: argparse.ArgumentParser,
54
+ ) -> None:
55
+ """Add offset-based pagination options to the parser.
56
+
57
+ APIs that use offset-based paging use the offset and limit query parameters
58
+ to paginate through items in a collection.
59
+
60
+ Offset-based pagination is often used where the list of items is of a fixed
61
+ and predetermined length.
62
+ """
63
+ parser.add_argument(
64
+ '--limit',
65
+ metavar='<limit>',
66
+ type=int,
67
+ action=parseractions.NonNegativeAction,
68
+ help=_(
69
+ 'The maximum number of entries to return. If the value exceeds '
70
+ 'the server-defined maximum, then the maximum value will be used.'
71
+ ),
72
+ )
73
+ parser.add_argument(
74
+ '--offset',
75
+ metavar='<offset>',
76
+ type=int,
77
+ action=parseractions.NonNegativeAction,
78
+ default=None,
79
+ help=_(
80
+ 'The (zero-based) offset of the first item in the collection to '
81
+ 'return.'
82
+ ),
83
+ )