Return Bunch objects instead of plain dicts
Bunch objects are dot-accessible dictionaries, so we can say server.name or server['name'] equally. Change-Id: I792c9792116824c4f8f840f961eaddc0b2060e6f
This commit is contained in:
parent
f525c032a6
commit
2e3498d76a
@ -1,5 +1,6 @@
|
||||
pbr>=0.5.21,<1.0
|
||||
|
||||
bunch
|
||||
jsonpatch
|
||||
os-client-config>=0.8.1
|
||||
six
|
||||
|
@ -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
|
||||
|
@ -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'])
|
||||
|
Loading…
Reference in New Issue
Block a user