summaryrefslogtreecommitdiffstats
path: root/nova/objects
diff options
context:
space:
mode:
Diffstat (limited to 'nova/objects')
-rw-r--r--nova/objects/base.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/nova/objects/base.py b/nova/objects/base.py
index 147d55c23..4f973de0c 100644
--- a/nova/objects/base.py
+++ b/nova/objects/base.py
@@ -464,3 +464,20 @@ class NovaObjectSerializer(nova.openstack.common.rpc.serializer.Serializer):
entity = self._process_iterable(context, self.deserialize_entity,
entity)
return entity
+
+
+def obj_to_primitive(obj):
+ """Recrusively turn an object into a python primitive.
+
+ A NovaObject becomes a dict, and anything that implements ObjectListBase
+ becomes a list.
+ """
+ if isinstance(obj, ObjectListBase):
+ return [obj_to_primitive(x) for x in obj]
+ elif isinstance(obj, NovaObject):
+ result = {}
+ for key, value in obj.iteritems():
+ result[key] = obj_to_primitive(value)
+ return result
+ else:
+ return obj