Merge "Use oslo.versionedobjects remotable decorators"

This commit is contained in:
Jenkins 2015-05-12 02:54:41 +00:00 committed by Gerrit Code Review
commit 2833ec1d05
1 changed files with 3 additions and 54 deletions

View File

@ -16,7 +16,6 @@
import collections
from oslo_context import context as oslo_context
from oslo_versionedobjects import base as ovoo_base
from oslo_versionedobjects import fields as ovoo_fields
import six
@ -30,6 +29,9 @@ from magnum.openstack.common import versionutils
LOG = logging.getLogger('object')
remotable_classmethod = ovoo_base.remotable_classmethod
remotable = ovoo_base.remotable
class MagnumObjectMetaclass(type):
"""Metaclass that allows tracking of object classes."""
@ -50,59 +52,6 @@ class MagnumObjectMetaclass(type):
# scheme from oslo.versionedobjects, which uses decorators
# These are decorators that mark an object's method as remotable.
# If the metaclass is configured to forward object methods to an
# indirection service, these will result in making an RPC call
# instead of directly calling the implementation in the object. Instead,
# the object implementation on the remote end will perform the
# requested action and the result will be returned here.
def remotable_classmethod(fn):
"""Decorator for remotable classmethods."""
def wrapper(cls, context, *args, **kwargs):
if MagnumObject.indirection_api:
result = MagnumObject.indirection_api.object_class_action(
context, cls.obj_name(), fn.__name__, cls.VERSION,
args, kwargs)
else:
result = fn(cls, context, *args, **kwargs)
if isinstance(result, MagnumObject):
result._context = context
return result
return classmethod(wrapper)
# See comment above for remotable_classmethod()
#
# Note that this will use either the provided context, or the one
# stashed in the object. If neither are present, the object is
# "orphaned" and remotable methods cannot be called.
def remotable(fn):
"""Decorator for remotable object methods."""
def wrapper(self, *args, **kwargs):
context = self._context
try:
if isinstance(args[0], (oslo_context.RequestContext)):
context = args[0]
args = args[1:]
except IndexError:
pass
if context is None:
raise exception.OrphanedObjectError(method=fn.__name__,
objtype=self.obj_name())
if MagnumObject.indirection_api:
updates, result = MagnumObject.indirection_api.object_action(
context, self, fn.__name__, args, kwargs)
for key, value in updates.iteritems():
if key in self.fields:
field = self.fields[key]
self[key] = field.from_primitive(self, key, value)
self._changed_fields = set(updates.get('obj_what_changed', []))
return result
else:
return fn(self, context, *args, **kwargs)
return wrapper
# Object versioning rules
#
# Each service has its set of objects, each with a version attached. When