osc-lib 3.2.0__py3-none-any.whl → 4.0.0__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 +63 -27
- osc_lib/api/auth.py +36 -21
- osc_lib/api/utils.py +10 -5
- osc_lib/cli/client_config.py +51 -32
- osc_lib/cli/format_columns.py +19 -17
- osc_lib/cli/identity.py +14 -3
- osc_lib/cli/pagination.py +83 -0
- osc_lib/cli/parseractions.py +99 -20
- osc_lib/clientmanager.py +45 -24
- osc_lib/command/command.py +19 -8
- osc_lib/command/timing.py +11 -1
- osc_lib/exceptions.py +12 -2
- osc_lib/logs.py +18 -8
- osc_lib/py.typed +0 -0
- osc_lib/shell.py +64 -44
- osc_lib/tests/test_shell.py +4 -4
- osc_lib/tests/utils/__init__.py +0 -19
- osc_lib/tests/utils/test_tags.py +22 -7
- osc_lib/tests/utils/test_utils.py +1 -11
- osc_lib/utils/__init__.py +180 -108
- osc_lib/utils/columns.py +15 -4
- osc_lib/utils/tags.py +39 -21
- {osc_lib-3.2.0.dist-info → osc_lib-4.0.0.dist-info}/METADATA +11 -13
- osc_lib-4.0.0.dist-info/RECORD +53 -0
- {osc_lib-3.2.0.dist-info → osc_lib-4.0.0.dist-info}/WHEEL +1 -1
- osc_lib-4.0.0.dist-info/pbr.json +1 -0
- osc_lib-3.2.0.dist-info/RECORD +0 -51
- osc_lib-3.2.0.dist-info/pbr.json +0 -1
- {osc_lib-3.2.0.dist-info → osc_lib-4.0.0.dist-info}/AUTHORS +0 -0
- {osc_lib-3.2.0.dist-info → osc_lib-4.0.0.dist-info}/LICENSE +0 -0
- {osc_lib-3.2.0.dist-info → osc_lib-4.0.0.dist-info}/top_level.txt +0 -0
osc_lib/api/api.py
CHANGED
@@ -13,6 +13,10 @@
|
|
13
13
|
|
14
14
|
"""Base API Library"""
|
15
15
|
|
16
|
+
import builtins
|
17
|
+
import typing as ty
|
18
|
+
import warnings
|
19
|
+
|
16
20
|
from keystoneauth1 import exceptions as ksa_exceptions
|
17
21
|
from keystoneauth1 import session as ksa_session
|
18
22
|
import requests
|
@@ -42,8 +46,12 @@ class BaseAPI:
|
|
42
46
|
HEADER_NAME = "OpenStack-API-Version"
|
43
47
|
|
44
48
|
def __init__(
|
45
|
-
self,
|
46
|
-
|
49
|
+
self,
|
50
|
+
session: ty.Optional[ksa_session.Session] = None,
|
51
|
+
service_type: ty.Optional[str] = None,
|
52
|
+
endpoint: ty.Optional[str] = None,
|
53
|
+
**kwargs: ty.Any,
|
54
|
+
) -> None:
|
47
55
|
"""Base object that contains some common API objects and methods
|
48
56
|
|
49
57
|
:param keystoneauth1.session.Session session:
|
@@ -58,6 +66,12 @@ class BaseAPI:
|
|
58
66
|
Keyword arguments passed to keystoneauth1.session.Session().
|
59
67
|
"""
|
60
68
|
|
69
|
+
warnings.warn(
|
70
|
+
'The BaseAPI class is deprecated for removal. Consider using '
|
71
|
+
'openstacksdk instead else vendoring this code into your client',
|
72
|
+
category=DeprecationWarning,
|
73
|
+
)
|
74
|
+
|
61
75
|
super().__init__()
|
62
76
|
|
63
77
|
# Create a keystoneauth1.session.Session if one is not supplied
|
@@ -69,7 +83,7 @@ class BaseAPI:
|
|
69
83
|
self.service_type = service_type
|
70
84
|
self.endpoint = self._munge_endpoint(endpoint)
|
71
85
|
|
72
|
-
def _munge_endpoint(self, endpoint):
|
86
|
+
def _munge_endpoint(self, endpoint: ty.Optional[str]) -> ty.Optional[str]:
|
73
87
|
"""Hook to allow subclasses to massage the passed-in endpoint
|
74
88
|
|
75
89
|
Hook to massage passed-in endpoints from arbitrary sources,
|
@@ -90,7 +104,13 @@ class BaseAPI:
|
|
90
104
|
else:
|
91
105
|
return endpoint
|
92
106
|
|
93
|
-
def _request(
|
107
|
+
def _request(
|
108
|
+
self,
|
109
|
+
method: str,
|
110
|
+
url: str,
|
111
|
+
session: ty.Optional[ksa_session.Session] = None,
|
112
|
+
**kwargs: ty.Any,
|
113
|
+
) -> requests.Response:
|
94
114
|
"""Perform call into session
|
95
115
|
|
96
116
|
All API calls are funneled through this method to provide a common
|
@@ -136,7 +156,13 @@ class BaseAPI:
|
|
136
156
|
|
137
157
|
# The basic action methods all take a Session and return dict/lists
|
138
158
|
|
139
|
-
def create(
|
159
|
+
def create(
|
160
|
+
self,
|
161
|
+
url: str,
|
162
|
+
session: ty.Optional[ksa_session.Session] = None,
|
163
|
+
method: ty.Optional[str] = None,
|
164
|
+
**params: ty.Any,
|
165
|
+
) -> ty.Union[requests.Response, ty.Any]:
|
140
166
|
"""Create a new resource
|
141
167
|
|
142
168
|
:param string url:
|
@@ -156,7 +182,12 @@ class BaseAPI:
|
|
156
182
|
except requests.JSONDecodeError:
|
157
183
|
return ret
|
158
184
|
|
159
|
-
def delete(
|
185
|
+
def delete(
|
186
|
+
self,
|
187
|
+
url: str,
|
188
|
+
session: ty.Optional[ksa_session.Session] = None,
|
189
|
+
**params: ty.Any,
|
190
|
+
) -> requests.Response:
|
160
191
|
"""Delete a resource
|
161
192
|
|
162
193
|
:param string url:
|
@@ -169,13 +200,13 @@ class BaseAPI:
|
|
169
200
|
|
170
201
|
def list(
|
171
202
|
self,
|
172
|
-
path,
|
173
|
-
session=None,
|
174
|
-
body=None,
|
175
|
-
detailed=False,
|
176
|
-
headers=None,
|
177
|
-
**params,
|
178
|
-
):
|
203
|
+
path: str,
|
204
|
+
session: ty.Optional[ksa_session.Session] = None,
|
205
|
+
body: ty.Any = None,
|
206
|
+
detailed: bool = False,
|
207
|
+
headers: ty.Optional[dict[str, str]] = None,
|
208
|
+
**params: ty.Any,
|
209
|
+
) -> ty.Union[requests.Response, ty.Any]:
|
179
210
|
"""Return a list of resources
|
180
211
|
|
181
212
|
GET ${ENDPOINT}/${PATH}?${PARAMS}
|
@@ -226,11 +257,11 @@ class BaseAPI:
|
|
226
257
|
|
227
258
|
def find_attr(
|
228
259
|
self,
|
229
|
-
path,
|
230
|
-
value=None,
|
231
|
-
attr=None,
|
232
|
-
resource=None,
|
233
|
-
):
|
260
|
+
path: str,
|
261
|
+
value: ty.Optional[str] = None,
|
262
|
+
attr: ty.Optional[str] = None,
|
263
|
+
resource: ty.Optional[str] = None,
|
264
|
+
) -> ty.Any:
|
234
265
|
"""Find a resource via attribute or ID
|
235
266
|
|
236
267
|
Most APIs return a list wrapped by a dict with the resource
|
@@ -260,7 +291,7 @@ class BaseAPI:
|
|
260
291
|
if resource is None:
|
261
292
|
resource = path
|
262
293
|
|
263
|
-
def getlist(kw):
|
294
|
+
def getlist(kw: dict[str, ty.Any]) -> ty.Any:
|
264
295
|
"""Do list call, unwrap resource dict if present"""
|
265
296
|
ret = self.list(path, **kw)
|
266
297
|
if isinstance(ret, dict) and resource in ret:
|
@@ -290,7 +321,12 @@ class BaseAPI:
|
|
290
321
|
msg % {'resource': resource, 'attr': attr, 'value': value}
|
291
322
|
)
|
292
323
|
|
293
|
-
def find_bulk(
|
324
|
+
def find_bulk(
|
325
|
+
self,
|
326
|
+
path: str,
|
327
|
+
headers: ty.Optional[dict[str, str]] = None,
|
328
|
+
**kwargs: ty.Any,
|
329
|
+
) -> builtins.list[ty.Any]:
|
294
330
|
"""Bulk load and filter locally
|
295
331
|
|
296
332
|
:param string path:
|
@@ -318,7 +354,7 @@ class BaseAPI:
|
|
318
354
|
|
319
355
|
return ret
|
320
356
|
|
321
|
-
def find_one(self, path, **kwargs):
|
357
|
+
def find_one(self, path: str, **kwargs: ty.Any) -> ty.Any:
|
322
358
|
"""Find a resource by name or ID
|
323
359
|
|
324
360
|
:param string path:
|
@@ -339,11 +375,11 @@ class BaseAPI:
|
|
339
375
|
|
340
376
|
def find(
|
341
377
|
self,
|
342
|
-
path,
|
343
|
-
value=None,
|
344
|
-
attr=None,
|
345
|
-
headers=None,
|
346
|
-
):
|
378
|
+
path: str,
|
379
|
+
value: ty.Optional[str] = None,
|
380
|
+
attr: ty.Optional[str] = None,
|
381
|
+
headers: ty.Optional[dict[str, str]] = None,
|
382
|
+
) -> ty.Any:
|
347
383
|
"""Find a single resource by name or ID
|
348
384
|
|
349
385
|
:param string path:
|
@@ -356,7 +392,7 @@ class BaseAPI:
|
|
356
392
|
Headers dictionary to pass to requests
|
357
393
|
"""
|
358
394
|
|
359
|
-
def raise_not_found():
|
395
|
+
def raise_not_found() -> ty.NoReturn:
|
360
396
|
msg = _("%s not found") % value
|
361
397
|
raise exceptions.NotFound(404, msg)
|
362
398
|
|
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: dict[str, _OptionDict] = {}
|
32
43
|
|
33
44
|
|
34
|
-
def get_plugin_list():
|
45
|
+
def get_plugin_list() -> 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() -> 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(
|
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(
|
90
|
-
|
91
|
-
|
92
|
-
|
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 =
|
98
|
-
|
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(
|
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=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:
|
osc_lib/cli/client_config.py
CHANGED
@@ -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
|
-
#
|
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(
|
30
|
+
class OSC_Config(config.OpenStackConfig): # type: ignore
|
31
|
+
def _auth_select_default_plugin(
|
32
|
+
self, config: dict[str, ty.Any]
|
33
|
+
) -> 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(
|
66
|
+
def _auth_v2_arguments(
|
67
|
+
self, config: dict[str, ty.Any]
|
68
|
+
) -> 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(
|
81
|
+
def _auth_v2_ignore_v3(
|
82
|
+
self, config: dict[str, ty.Any]
|
83
|
+
) -> 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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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(
|
121
|
+
def _auth_default_domain(
|
122
|
+
self, config: dict[str, ty.Any]
|
123
|
+
) -> 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,7 @@ 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(self, config: dict[str, ty.Any]) -> dict[str, ty.Any]:
|
151
165
|
"""Allow examination of config values before loading auth plugin
|
152
166
|
|
153
167
|
OpenStackClient will override this to perform additional checks
|
@@ -165,7 +179,11 @@ class OSC_Config(config.OpenStackConfig):
|
|
165
179
|
)
|
166
180
|
return config
|
167
181
|
|
168
|
-
def _validate_auth(
|
182
|
+
def _validate_auth(
|
183
|
+
self,
|
184
|
+
config: dict[str, ty.Any],
|
185
|
+
loader: ksa_loading.BaseIdentityLoader[ty.Any],
|
186
|
+
) -> dict[str, ty.Any]:
|
169
187
|
"""Validate auth plugin arguments"""
|
170
188
|
# May throw a keystoneauth1.exceptions.NoMatchingPlugin
|
171
189
|
|
@@ -229,7 +247,8 @@ class OSC_Config(config.OpenStackConfig):
|
|
229
247
|
|
230
248
|
return config
|
231
249
|
|
232
|
-
|
250
|
+
# TODO(stephenfin): Add type once we have typing for SDK
|
251
|
+
def load_auth_plugin(self, config: dict[str, ty.Any]) -> ty.Any:
|
233
252
|
"""Get auth plugin and validate args"""
|
234
253
|
|
235
254
|
loader = self._get_auth_loader(config)
|
osc_lib/cli/format_columns.py
CHANGED
@@ -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[dict[str, ty.Any]]):
|
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) -> 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[dict[str, list[ty.Any]]]):
|
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) -> dict[str, list[ty.Any]]:
|
40
42
|
return dict(self._value or {})
|
41
43
|
|
42
44
|
|
43
|
-
class ListColumn(columns.FormattableColumn):
|
45
|
+
class ListColumn(columns.FormattableColumn[list[ty.Any]]):
|
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) -> 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[list[dict[str, ty.Any]]]):
|
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) -> list[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[ty.Union[int, float]]):
|
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(
|
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
|
-
|
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
|
+
)
|