summaryrefslogtreecommitdiffstats
path: root/openstack/common
diff options
context:
space:
mode:
authorAndrew Bogott <abogott@wikimedia.org>2012-06-15 02:13:13 -0500
committerAndrew Bogott <abogott@wikimedia.org>2012-06-20 18:59:48 -0500
commitc797a1d651f844bea4276cbef9ac67f85c87d99c (patch)
tree71c9d1774d58a7dcd166e60ff13b3495c4a66943 /openstack/common
parente54850fb59ad226961022ff07c8777e0c276df3a (diff)
downloadoslo-c797a1d651f844bea4276cbef9ac67f85c87d99c.tar.gz
oslo-c797a1d651f844bea4276cbef9ac67f85c87d99c.tar.xz
oslo-c797a1d651f844bea4276cbef9ac67f85c87d99c.zip
Added dictify() and uuids to the common request context.
This makes the common context similar enough to the nova context that we can use it for annotating logs like we do in nova. Change-Id: I622c76f2e3013e4ff5e8c228d197a55918672447
Diffstat (limited to 'openstack/common')
-rw-r--r--openstack/common/context.py28
1 files changed, 27 insertions, 1 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