diff --git a/senlin/objects/base.py b/senlin/objects/base.py index 3d344b2ef..6143e2aa2 100644 --- a/senlin/objects/base.py +++ b/senlin/objects/base.py @@ -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): diff --git a/senlin/objects/cluster.py b/senlin/objects/cluster.py index ffca8c0b1..581bebde8 100644 --- a/senlin/objects/cluster.py +++ b/senlin/objects/cluster.py @@ -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): diff --git a/senlin/objects/node.py b/senlin/objects/node.py index d4277a254..95b878f2a 100644 --- a/senlin/objects/node.py +++ b/senlin/objects/node.py @@ -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 diff --git a/senlin/objects/policy.py b/senlin/objects/policy.py index 99fffa5f8..689ffd9fc 100644 --- a/senlin/objects/policy.py +++ b/senlin/objects/policy.py @@ -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) diff --git a/senlin/objects/profile.py b/senlin/objects/profile.py index 6c20e4314..9a70fe24e 100644 --- a/senlin/objects/profile.py +++ b/senlin/objects/profile.py @@ -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)