diff options
-rw-r--r-- | openstack/common/context.py | 15 | ||||
-rw-r--r-- | openstack/common/exception.py | 17 | ||||
-rw-r--r-- | openstack/common/notifier/api.py | 7 |
3 files changed, 18 insertions, 21 deletions
diff --git a/openstack/common/context.py b/openstack/common/context.py index 35724e9..dd7dd04 100644 --- a/openstack/common/context.py +++ b/openstack/common/context.py @@ -22,6 +22,7 @@ Projects should subclass this class if they wish to enhance the request context or provide additional information in their specific WSGI pipeline. """ +import itertools import uuid @@ -64,3 +65,17 @@ def get_admin_context(show_deleted="no"): is_admin=True, show_deleted=show_deleted) return context + + +def get_context_from_function_and_args(function, args, kwargs): + """Find an arg of type RequestContext and return it. + + This is useful in a couple of decorators where we don't + know much about the function we're wrapping. + """ + + for arg in itertools.chain(kwargs.values(), args): + if isinstance(arg, RequestContext): + return arg + + return None diff --git a/openstack/common/exception.py b/openstack/common/exception.py index e8ea110..e5da94b 100644 --- a/openstack/common/exception.py +++ b/openstack/common/exception.py @@ -146,20 +146,3 @@ class MalformedRequestBody(OpenstackException): class InvalidContentType(OpenstackException): message = "Invalid content type %(content_type)s" - - -def get_context_from_function_and_args(function, args, kwargs): - """Find an arg of type RequestContext and return it. - - This is useful in a couple of decorators where we don't - know much about the function we're wrapping. - """ - - # import here to avoid circularity: - from openstack.common import context - - for arg in itertools.chain(kwargs.values(), args): - if isinstance(arg, context.RequestContext): - return arg - - return None diff --git a/openstack/common/notifier/api.py b/openstack/common/notifier/api.py index 6a46cd2..45af4ed 100644 --- a/openstack/common/notifier/api.py +++ b/openstack/common/notifier/api.py @@ -17,12 +17,11 @@ import inspect import uuid from openstack.common import cfg -from openstack.common import exception +from openstack.common import context from openstack.common import importutils from openstack.common import jsonutils from openstack.common import log as logging from openstack.common import timeutils -from openstack.common import utils LOG = logging.getLogger(__name__) @@ -72,8 +71,8 @@ def notify_decorator(name, fn): for key in kwarg: body['kwarg'][key] = kwarg[key] - context = exception.get_context_from_function_and_args(fn, args, kwarg) - notify(context, + ctxt = context.get_context_from_function_and_args(fn, args, kwarg) + notify(ctxt, CONF.default_publisher_id, name, CONF.default_notification_level, |