def obj_to_primitive(obj):
 if isinstance(obj, ObjectListBase):
  return [obj_to_primitive(x) for x in obj]
 elif isinstance(obj, NovaObject):
  result = {}
  for key in obj.obj_fields:
   if (obj.obj_attr_is_set(key) or (key in obj.obj_extra_fields)):
    result[key] = obj_to_primitive(getattr(obj, key))
  return result
 elif isinstance(obj, netaddr.IPAddress):
  return str(obj)
 elif isinstance(obj, netaddr.IPNetwork):
  return str(obj)
 else:
  return obj

def obj_to_primitive ( obj ) : if isinstance ( obj , ObjectListBase ) : return [ obj_to_primitive ( x ) for x in obj ] elif isinstance ( obj , NovaObject ) : result = { } for key in obj . obj_fields : if ( obj . obj_attr_is_set ( key ) or ( key in obj . obj_extra_fields ) ) : result [ key ] = obj_to_primitive ( getattr ( obj , key ) ) return result elif isinstance ( obj , netaddr . IPAddress ) : return str ( obj ) elif isinstance ( obj , netaddr . IPNetwork ) : return str ( obj ) else : return obj
recursively turn an object into a python primitive .