diff options
| author | Steve Martinelli <stevemar@ca.ibm.com> | 2014-10-07 02:15:15 -0400 |
|---|---|---|
| committer | Steve Martinelli <stevemar@ca.ibm.com> | 2014-10-09 14:34:48 -0400 |
| commit | 364071a90bfe9dcec1d02a349c33dc8422fc14f3 (patch) | |
| tree | 704c8a12ce913ceb735af4adabb54f1498c16a53 /openstackclient/common | |
| parent | 0c77a9fe8baa4df9ea2d0055db9c700af3cae310 (diff) | |
| download | python-openstackclient-364071a90bfe9dcec1d02a349c33dc8422fc14f3.tar.gz | |
Add domain parameters to user show for Identity V3
Update `user show` for Identity V3 to account for a domain argument,
in doing so, also update `find resource` to be more flexible by
allowing **kwargs.
Also update `group show` and `project show` since they follow the
same logic as a user within a group.
Change-Id: Ib828e4dbeb0bd31164396069ce8a64c873179779
Closes-Bug: #1378165
Diffstat (limited to 'openstackclient/common')
| -rw-r--r-- | openstackclient/common/utils.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index 818f8d47..9ad3823c 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -26,8 +26,27 @@ from oslo.utils import importutils from openstackclient.common import exceptions -def find_resource(manager, name_or_id): - """Helper for the _find_* methods.""" +def find_resource(manager, name_or_id, **kwargs): + """Helper for the _find_* methods. + + :param manager: A client manager class + :param name_or_id: The resource we are trying to find + :param kwargs: To be used in calling .find() + :rtype: The found resource + + This method will attempt to find a resource in a variety of ways. + Primarily .get() methods will be called with `name_or_id` as an integer + value, and tried again as a string value. + + If both fail, then a .find() is attempted, which is essentially calling + a .list() function with a 'name' query parameter that is set to + `name_or_id`. + + Lastly, if any kwargs are passed in, they will be treated as additional + query parameters. This is particularly handy in the case of finding + resources in a domain. + + """ # Try to get entity as integer id try: @@ -49,7 +68,10 @@ def find_resource(manager, name_or_id): except Exception: pass - kwargs = {} + if len(kwargs) == 0: + kwargs = {} + + # Prepare the kwargs for calling find if 'NAME_ATTR' in manager.resource_class.__dict__: # novaclient does this for oddball resources kwargs[manager.resource_class.NAME_ATTR] = name_or_id |
