diff --git a/requirements.txt b/requirements.txt index ec2cb7793..7cca7eac9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ pbr>=0.5.21,<1.0 +bunch jsonpatch os-client-config>=0.8.1 six diff --git a/shade/meta.py b/shade/meta.py index 0cc82bcdd..c794df6e4 100644 --- a/shade/meta.py +++ b/shade/meta.py @@ -13,6 +13,7 @@ # limitations under the License. +import bunch import six from shade import exc @@ -160,7 +161,7 @@ def obj_to_dict(obj): that we can just have a plain dict of all of the values that exist in the nova metadata for a server. """ - instance = {} + instance = bunch.Bunch() for key in dir(obj): value = getattr(obj, key) if isinstance(value, NON_CALLABLES) and not key.startswith('_'): @@ -185,7 +186,7 @@ def warlock_to_dict(obj): # glanceclient v2 uses warlock to construct its objects. Warlock does # deep black magic to attribute look up to support validation things that # means we cannot use normal obj_to_dict - obj_dict = {} + obj_dict = bunch.Bunch() for (key, value) in obj.items(): if isinstance(value, NON_CALLABLES) and not key.startswith('_'): obj_dict[key] = value diff --git a/shade/tests/unit/test_meta.py b/shade/tests/unit/test_meta.py index 885c8a77d..a36d9929f 100644 --- a/shade/tests/unit/test_meta.py +++ b/shade/tests/unit/test_meta.py @@ -184,6 +184,8 @@ class TestMeta(testtools.TestCase): self.assertNotIn('_unused', cloud_dict) self.assertNotIn('get_flavor_name', cloud_dict) self.assertNotIn('server', cloud_dict) + self.assertTrue(hasattr(cloud_dict, 'name')) + self.assertEquals(cloud_dict.name, cloud_dict['name']) def test_warlock_to_dict(self): schema = { @@ -201,3 +203,5 @@ class TestMeta(testtools.TestCase): test_dict = meta.warlock_to_dict(test_obj) self.assertNotIn('_unused', test_dict) self.assertEqual('test-image', test_dict['name']) + self.assertTrue(hasattr(test_dict, 'name')) + self.assertEquals(test_dict.name, test_dict['name'])