diff --git a/shade/_utils.py b/shade/_utils.py index e5117b368..3ca54d128 100644 --- a/shade/_utils.py +++ b/shade/_utils.py @@ -207,7 +207,9 @@ def _get_entity(cloud, resource, name_or_id, filters, **kwargs): get_<>_by_id or search_s methods(Example: network) or a callable to invoke. :param string name_or_id: - The name or ID of the entity being filtered or a dict + The name or ID of the entity being filtered or an object or dict. + If this is an object/dict with an 'id' attr/key, we return it and + bypass resource lookup. :param filters: A dictionary of meta data to use for further filtering. OR @@ -221,7 +223,8 @@ def _get_entity(cloud, resource, name_or_id, filters, **kwargs): # an additional call, it's simple enough to test to see if we got an # object and just short-circuit return it. - if hasattr(name_or_id, 'id'): + if (hasattr(name_or_id, 'id') or + (isinstance(name_or_id, dict) and 'id' in name_or_id)): return name_or_id # If a uuid is passed short-circuit it calling the diff --git a/shade/tests/unit/test__utils.py b/shade/tests/unit/test__utils.py index 1c453f426..a67fdf30d 100644 --- a/shade/tests/unit/test__utils.py +++ b/shade/tests/unit/test__utils.py @@ -326,6 +326,11 @@ class TestUtils(base.TestCase): self.cloud.use_direct_get = True self.assertEqual(obj, _utils._get_entity(self.cloud, '', obj, {})) + def test_get_entity_pass_dict(self): + d = dict(id=uuid4().hex) + self.cloud.use_direct_get = True + self.assertEqual(d, _utils._get_entity(self.cloud, '', d, {})) + def test_get_entity_no_use_direct_get(self): # test we are defaulting to the search_ methods # if the use_direct_get flag is set to False(default).