Sync latest RPC changes from oslo

Pulls in capped version support and RPC_API_NAMESPACE support for
RpcProxy.

Change-Id: I8334ed62c0ffd16a05b35bbcd4d9352538ab0243
This commit is contained in:
Chris Behrens
2013-05-21 08:37:56 +00:00
parent eaa9cc6de0
commit e66bbeeb6e
2 changed files with 21 additions and 6 deletions

View File

@@ -158,6 +158,10 @@ class UnsupportedRpcEnvelopeVersion(RPCException):
"not supported by this endpoint.") "not supported by this endpoint.")
class RpcVersionCapError(RPCException):
message = _("Specified RPC version cap, %(version_cap)s, is too low")
class Connection(object): class Connection(object):
"""A connection, returned by rpc.create_connection(). """A connection, returned by rpc.create_connection().

View File

@@ -1,6 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4 # vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 Red Hat, Inc. # Copyright 2012-2013 Red Hat, Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain # not use this file except in compliance with the License. You may obtain
@@ -23,6 +23,7 @@ For more information about rpc API version numbers, see:
from nova.openstack.common import rpc from nova.openstack.common import rpc
from nova.openstack.common.rpc import common as rpc_common
class RpcProxy(object): class RpcProxy(object):
@@ -34,16 +35,22 @@ class RpcProxy(object):
rpc API. rpc API.
""" """
def __init__(self, topic, default_version): # The default namespace, which can be overriden in a subclass.
RPC_API_NAMESPACE = None
def __init__(self, topic, default_version, version_cap=None):
"""Initialize an RpcProxy. """Initialize an RpcProxy.
:param topic: The topic to use for all messages. :param topic: The topic to use for all messages.
:param default_version: The default API version to request in all :param default_version: The default API version to request in all
outgoing messages. This can be overridden on a per-message outgoing messages. This can be overridden on a per-message
basis. basis.
:param version_cap: Optionally cap the maximum version used for sent
messages.
""" """
self.topic = topic self.topic = topic
self.default_version = default_version self.default_version = default_version
self.version_cap = version_cap
super(RpcProxy, self).__init__() super(RpcProxy, self).__init__()
def _set_version(self, msg, vers): def _set_version(self, msg, vers):
@@ -52,7 +59,11 @@ class RpcProxy(object):
:param msg: The message having a version added to it. :param msg: The message having a version added to it.
:param vers: The version number to add to the message. :param vers: The version number to add to the message.
""" """
msg['version'] = vers if vers else self.default_version v = vers if vers else self.default_version
if (self.version_cap and not
rpc_common.version_is_compatible(self.version_cap, v)):
raise rpc_common.RpcVersionCapError(version=self.version_cap)
msg['version'] = v
def _get_topic(self, topic): def _get_topic(self, topic):
"""Return the topic to use for a message.""" """Return the topic to use for a message."""
@@ -62,9 +73,9 @@ class RpcProxy(object):
def make_namespaced_msg(method, namespace, **kwargs): def make_namespaced_msg(method, namespace, **kwargs):
return {'method': method, 'namespace': namespace, 'args': kwargs} return {'method': method, 'namespace': namespace, 'args': kwargs}
@staticmethod def make_msg(self, method, **kwargs):
def make_msg(method, **kwargs): return self.make_namespaced_msg(method, self.RPC_API_NAMESPACE,
return RpcProxy.make_namespaced_msg(method, None, **kwargs) **kwargs)
def call(self, context, msg, topic=None, version=None, timeout=None): def call(self, context, msg, topic=None, version=None, timeout=None):
"""rpc.call() a remote method. """rpc.call() a remote method.