Skip to content

Commit 83282bc

Browse files
Steve MartinelliDean Troyer
authored andcommitted
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
1 parent 05f5e04 commit 83282bc

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

openstackclient/common/utils.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,24 @@ def find_resource(manager, name_or_id, **kwargs):
121121
(manager.resource_class.__name__.lower(), name_or_id)
122122
raise exceptions.CommandError(msg)
123123
else:
124-
msg = "Could not find resource %s" % name_or_id
125-
raise exceptions.CommandError(msg)
124+
pass
125+
126+
try:
127+
for resource in manager.list():
128+
# short circuit and return the first match
129+
if (resource.get('id') == name_or_id or
130+
resource.get('name') == name_or_id):
131+
return resource
132+
else:
133+
# we found no match, keep going to bomb out
134+
pass
135+
except Exception:
136+
# in case the list fails for some reason
137+
pass
138+
139+
# if we hit here, we've failed, report back this error:
140+
msg = "Could not find resource %s" % name_or_id
141+
raise exceptions.CommandError(msg)
126142

127143

128144
def format_dict(data):

0 commit comments

Comments
 (0)