Fix object serialization about metadata

This patch fixes the problem when serializing Python objects in to DB.

Change-Id: Id8a4fd23e452ebd1c4d8ed7a39bd747d7fcc3ca4
Closes-Bug: #1613142
This commit is contained in:
tengqm 2016-08-14 22:26:41 -04:00
parent e51e7e88fc
commit 9046e39005
5 changed files with 17 additions and 1 deletions

View File

@ -47,6 +47,14 @@ class SenlinObject(base.VersionedObject):
return obj
@staticmethod
def _transpose_metadata(values):
"""Utility function to translate metadata field."""
if 'metadata' in values:
value = values.pop('metadata')
values['meta_data'] = value
return values
class SenlinObjectRegistry(base.VersionedObjectRegistry):

View File

@ -45,6 +45,7 @@ class Cluster(base.SenlinObject, base.VersionedObjectDictCompat):
@classmethod
def create(cls, context, values):
values = cls._transpose_metadata(values)
obj = db_api.cluster_create(context, values)
return cls._from_db_object(context, cls(context), obj)
@ -78,7 +79,8 @@ class Cluster(base.SenlinObject, base.VersionedObjectDictCompat):
@classmethod
def update(cls, context, obj_id, values):
db_api.cluster_update(context, obj_id, values)
values = cls._transpose_metadata(values)
return db_api.cluster_update(context, obj_id, values)
@classmethod
def delete(cls, context, obj_id):

View File

@ -44,6 +44,7 @@ class Node(base.SenlinObject, base.VersionedObjectDictCompat):
@classmethod
def create(cls, context, values):
values = cls._transpose_metadata(values)
obj = db_api.node_create(context, values)
return cls._from_db_object(context, cls(context), obj)
@ -78,6 +79,7 @@ class Node(base.SenlinObject, base.VersionedObjectDictCompat):
@classmethod
def update(cls, context, obj_id, values):
values = cls._transpose_metadata(values)
db_api.node_update(context, obj_id, values)
@classmethod

View File

@ -38,6 +38,7 @@ class Policy(base.SenlinObject, base.VersionedObjectDictCompat):
@classmethod
def create(cls, context, values):
values = cls._transpose_metadata(values)
obj = db_api.policy_create(context, values)
return cls._from_db_object(context, cls(context), obj)
@ -63,6 +64,7 @@ class Policy(base.SenlinObject, base.VersionedObjectDictCompat):
@classmethod
def update(cls, context, obj_id, values):
values = cls._transpose_metadata(values)
obj = db_api.policy_update(context, obj_id, values)
return cls._from_db_object(context, cls(), obj)

View File

@ -38,6 +38,7 @@ class Profile(base.SenlinObject, base.VersionedObjectDictCompat):
@classmethod
def create(cls, context, values):
values = cls._transpose_metadata(values)
obj = db_api.profile_create(context, values)
return cls._from_db_object(context, cls(context), obj)
@ -63,6 +64,7 @@ class Profile(base.SenlinObject, base.VersionedObjectDictCompat):
@classmethod
def update(cls, context, obj_id, values):
values = cls._transpose_metadata(values)
obj = db_api.profile_update(context, obj_id, values)
return cls._from_db_object(context, cls(), obj)