Merge "Add obj_make_compatible()"

This commit is contained in:
Zuul 2020-03-02 16:35:36 +00:00 committed by Gerrit Code Review
commit 7ecc9c08d9

View File

@ -16,6 +16,7 @@
"""Cyborg common internal object model"""
import netaddr
from oslo_log import log as logging
from oslo_utils import versionutils
from oslo_versionedobjects import base as object_base
@ -23,6 +24,9 @@ from cyborg import objects
from cyborg.objects import fields as object_fields
LOG = logging.getLogger(__name__)
class CyborgObjectRegistry(object_base.VersionedObjectRegistry):
def registration_hook(self, cls, index):
# 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))
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):
# Base class to use for object hydration
@ -199,3 +219,13 @@ class DriverObjectBase(CyborgObject):
obj.obj_reset_changes()
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})