diff options
author | Andrew Bogott <abogott@wikimedia.org> | 2012-06-13 22:46:28 -0500 |
---|---|---|
committer | Andrew Bogott <abogott@wikimedia.org> | 2012-06-25 14:16:02 -0500 |
commit | 16916b6129f075e54c1ead915d5131f6d34218ed (patch) | |
tree | 6afce48a04eb3624998df1e8939023f5187898f0 /openstack/common/exception.py | |
parent | 2db4e6855ef82c18e95bdf4c0b8af52269624c0a (diff) | |
download | oslo-16916b6129f075e54c1ead915d5131f6d34218ed.tar.gz oslo-16916b6129f075e54c1ead915d5131f6d34218ed.tar.xz oslo-16916b6129f075e54c1ead915d5131f6d34218ed.zip |
Add common logging and notification.
This code is migrated from Nova, and will soon replace it.
Change-Id: I2dacac3ef251d419c7049154f6aaf0c18fdb9bb4
Diffstat (limited to 'openstack/common/exception.py')
-rw-r--r-- | openstack/common/exception.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/openstack/common/exception.py b/openstack/common/exception.py index ba32da5..e8ea110 100644 --- a/openstack/common/exception.py +++ b/openstack/common/exception.py @@ -19,6 +19,7 @@ Exceptions common to OpenStack projects """ +import itertools import logging @@ -145,3 +146,20 @@ 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 |