summaryrefslogtreecommitdiff
path: root/openstackclient/identity
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-07-27 03:37:52 +0000
committerGerrit Code Review <review@openstack.org>2016-07-27 03:37:52 +0000
commit97ccb65f8391a54c00f8f43e74f69941e7a4736c (patch)
treead9da1fa127de42dbf0ca27f82a96c4eac5cd57b /openstackclient/identity
parent7a667d700f97dda386c3db3bffc8138182fbeccb (diff)
parentc45b1d7b230e900d0416a4953607e5d4e1dc9cfd (diff)
downloadpython-openstackclient-97ccb65f8391a54c00f8f43e74f69941e7a4736c.tar.gz
Merge "Fix error for find_service() in identity"
Diffstat (limited to 'openstackclient/identity')
-rw-r--r--openstackclient/identity/common.py41
1 files changed, 26 insertions, 15 deletions
diff --git a/openstackclient/identity/common.py b/openstackclient/identity/common.py
index 379f4114..1e40f396 100644
--- a/openstackclient/identity/common.py
+++ b/openstackclient/identity/common.py
@@ -30,21 +30,32 @@ def find_service(identity_client, name_type_or_id):
"""Find a service by id, name or type."""
try:
- # search for the usual ID or name
- return utils.find_resource(identity_client.services, name_type_or_id)
- except exceptions.CommandError:
- try:
- # search for service type
- return identity_client.services.find(type=name_type_or_id)
- # FIXME(dtroyer): This exception should eventually come from
- # common client exceptions
- except identity_exc.NotFound:
- msg = _("No service with a type, name or ID of '%s' exists.")
- raise exceptions.CommandError(msg % name_type_or_id)
- except identity_exc.NoUniqueMatch:
- msg = _("Multiple service matches found for '%s', "
- "use an ID to be more specific.")
- raise exceptions.CommandError(msg % name_type_or_id)
+ # search for service id
+ return identity_client.services.get(name_type_or_id)
+ except identity_exc.NotFound:
+ # ignore NotFound exception, raise others
+ pass
+
+ try:
+ # search for service name
+ return identity_client.services.find(name=name_type_or_id)
+ except identity_exc.NotFound:
+ pass
+ except identity_exc.NoUniqueMatch:
+ msg = _("Multiple service matches found for '%s', "
+ "use an ID to be more specific.")
+ raise exceptions.CommandError(msg % name_type_or_id)
+
+ try:
+ # search for service type
+ return identity_client.services.find(type=name_type_or_id)
+ except identity_exc.NotFound:
+ msg = _("No service with a type, name or ID of '%s' exists.")
+ raise exceptions.CommandError(msg % name_type_or_id)
+ except identity_exc.NoUniqueMatch:
+ msg = _("Multiple service matches found for '%s', "
+ "use an ID to be more specific.")
+ raise exceptions.CommandError(msg % name_type_or_id)
def _get_token_resource(client, resource, parsed_name):