Merge "Add obj_make_compatible()"
This commit is contained in:
commit
7ecc9c08d9
@ -16,6 +16,7 @@
|
|||||||
"""Cyborg common internal object model"""
|
"""Cyborg common internal object model"""
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
|
from oslo_log import log as logging
|
||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
from oslo_versionedobjects import base as object_base
|
from oslo_versionedobjects import base as object_base
|
||||||
|
|
||||||
@ -23,6 +24,9 @@ from cyborg import objects
|
|||||||
from cyborg.objects import fields as object_fields
|
from cyborg.objects import fields as object_fields
|
||||||
|
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CyborgObjectRegistry(object_base.VersionedObjectRegistry):
|
class CyborgObjectRegistry(object_base.VersionedObjectRegistry):
|
||||||
def registration_hook(self, cls, index):
|
def registration_hook(self, cls, index):
|
||||||
# NOTE(jroll): blatantly stolen from nova
|
# NOTE(jroll): blatantly stolen from nova
|
||||||
@ -95,6 +99,22 @@ class CyborgObject(object_base.VersionedObject):
|
|||||||
objs.append(cls._from_db_object(cls(context), db_obj))
|
objs.append(cls._from_db_object(cls(context), db_obj))
|
||||||
return objs
|
return objs
|
||||||
|
|
||||||
|
def obj_make_compatible(self, primitive, target_version):
|
||||||
|
"""Make an object representation compatible with a target version.
|
||||||
|
|
||||||
|
This is responsible for taking the primitive representation of
|
||||||
|
an object and making it suitable for the given target_version.
|
||||||
|
This may mean converting the format of object attributes, removing
|
||||||
|
attributes that have been added since the target version, etc.
|
||||||
|
|
||||||
|
:param:primitive: The result of self.obj_to_primitive()
|
||||||
|
:param:target_version: The version string requested by the recipient
|
||||||
|
of the object.
|
||||||
|
"""
|
||||||
|
_log_backport(self, target_version)
|
||||||
|
super(CyborgObject, self).obj_make_compatible(primitive,
|
||||||
|
target_version)
|
||||||
|
|
||||||
|
|
||||||
class CyborgObjectSerializer(object_base.VersionedObjectSerializer):
|
class CyborgObjectSerializer(object_base.VersionedObjectSerializer):
|
||||||
# Base class to use for object hydration
|
# Base class to use for object hydration
|
||||||
@ -199,3 +219,13 @@ class DriverObjectBase(CyborgObject):
|
|||||||
|
|
||||||
obj.obj_reset_changes()
|
obj.obj_reset_changes()
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
def _log_backport(ovo, target_version):
|
||||||
|
"""Log backported versioned objects."""
|
||||||
|
if target_version and target_version != ovo.VERSION:
|
||||||
|
LOG.debug('Backporting %(obj_name)s from version %(src_vers)s '
|
||||||
|
'to version %(dst_vers)s',
|
||||||
|
{'obj_name': ovo.obj_name(),
|
||||||
|
'src_vers': ovo.VERSION,
|
||||||
|
'dst_vers': target_version})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user