summaryrefslogtreecommitdiff
path: root/openstackclient/common
diff options
context:
space:
mode:
authorSteve Martinelli <stevemar@ca.ibm.com>2015-09-24 23:39:37 -0400
committerDean Troyer <dtroyer@gmail.com>2015-09-30 13:19:56 -0500
commitfe2d9f479fc869491131f94c5bc598fa11e143f3 (patch)
tree951c9ef1a35d95ba860658ac59f164e9ee2cfc31 /openstackclient/common
parent8bd92949fa52e8458928c247be53f2825fbc0621 (diff)
downloadpython-openstackclient-fe2d9f479fc869491131f94c5bc598fa11e143f3.tar.gz
attempt to find resource by listing
add a last-ditch effort to find the resource in question by listing all the resources and doing a simply match for name and id. if no match is found then raise an error, if the list call is unsuccessful, raise the same error. we have failed this city. Closes-Bug: #1501362 Change-Id: I0d3d7002e9ac47b17b1ef1a5534406c85b1fc753 (cherry picked from commit 83282bc5e133d8cd1718df524c1fa06add130b8a)
Diffstat (limited to 'openstackclient/common')
-rw-r--r--openstackclient/common/utils.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index 7a5d33e3..51e2a2f9 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -121,8 +121,24 @@ def find_resource(manager, name_or_id, **kwargs):
(manager.resource_class.__name__.lower(), name_or_id)
raise exceptions.CommandError(msg)
else:
- msg = "Could not find resource %s" % name_or_id
- raise exceptions.CommandError(msg)
+ pass
+
+ try:
+ for resource in manager.list():
+ # short circuit and return the first match
+ if (resource.get('id') == name_or_id or
+ resource.get('name') == name_or_id):
+ return resource
+ else:
+ # we found no match, keep going to bomb out
+ pass
+ except Exception:
+ # in case the list fails for some reason
+ pass
+
+ # if we hit here, we've failed, report back this error:
+ msg = "Could not find resource %s" % name_or_id
+ raise exceptions.CommandError(msg)
def format_dict(data):