diff options
Diffstat (limited to 'openstack/common')
| -rw-r--r-- | openstack/common/context.py | 28 | ||||
| -rw-r--r-- | openstack/common/rpc/dispatcher.py | 10 | ||||
| -rw-r--r-- | openstack/common/rpc/impl_qpid.py | 2 |
3 files changed, 36 insertions, 4 deletions
diff --git a/openstack/common/context.py b/openstack/common/context.py index a9a16f8..35724e9 100644 --- a/openstack/common/context.py +++ b/openstack/common/context.py @@ -22,6 +22,12 @@ Projects should subclass this class if they wish to enhance the request context or provide additional information in their specific WSGI pipeline. """ +import uuid + + +def generate_request_id(): + return 'req-' + str(uuid.uuid4()) + class RequestContext(object): @@ -31,10 +37,30 @@ class RequestContext(object): """ def __init__(self, auth_tok=None, user=None, tenant=None, is_admin=False, - read_only=False, show_deleted=False): + read_only=False, show_deleted=False, request_id=None): self.auth_tok = auth_tok self.user = user self.tenant = tenant self.is_admin = is_admin self.read_only = read_only self.show_deleted = show_deleted + if not request_id: + request_id = generate_request_id() + self.request_id = request_id + + def to_dict(self): + return {'user': self.user, + 'tenant': self.tenant, + 'is_admin': self.is_admin, + 'read_only': self.read_only, + 'show_deleted': self.show_deleted, + 'auth_token': self.auth_tok, + 'request_id': self.request_id} + + +def get_admin_context(show_deleted="no"): + context = RequestContext(None, + tenant=None, + is_admin=True, + show_deleted=show_deleted) + return context diff --git a/openstack/common/rpc/dispatcher.py b/openstack/common/rpc/dispatcher.py index 7319eb2..4aabce2 100644 --- a/openstack/common/rpc/dispatcher.py +++ b/openstack/common/rpc/dispatcher.py @@ -92,14 +92,20 @@ class RpcDispatcher(object): if not version: version = '1.0' + had_compatible = False for proxyobj in self.callbacks: if hasattr(proxyobj, 'RPC_API_VERSION'): rpc_api_version = proxyobj.RPC_API_VERSION else: rpc_api_version = '1.0' + is_compatible = self._is_compatible(rpc_api_version, version) + had_compatible = had_compatible or is_compatible if not hasattr(proxyobj, method): continue - if self._is_compatible(rpc_api_version, version): + if is_compatible: return getattr(proxyobj, method)(ctxt, **kwargs) - raise rpc_common.UnsupportedRpcVersion(version=version) + if had_compatible: + raise AttributeError("No such RPC function '%s'" % method) + else: + raise rpc_common.UnsupportedRpcVersion(version=version) diff --git a/openstack/common/rpc/impl_qpid.py b/openstack/common/rpc/impl_qpid.py index 850a60c..d01bf0d 100644 --- a/openstack/common/rpc/impl_qpid.py +++ b/openstack/common/rpc/impl_qpid.py @@ -141,7 +141,7 @@ class ConsumerBase(object): try: self.callback(message.content) except Exception: - logging.exception(_("Failed to process message... skipping it.")) + LOG.exception(_("Failed to process message... skipping it.")) finally: self.session.acknowledge(message) |
