summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-06-21 21:19:16 +0000
committerGerrit Code Review <review@openstack.org>2012-06-21 21:19:16 +0000
commit3ae1660b51324cea51aeec63bb58741946d87ba3 (patch)
tree00ee6d39c2c2cdf37066f1ccd4e4f76f8fd471ac
parentf10abb101950da519cca2d47d38692babe2c8f28 (diff)
parent535cf8b0080c93283405b3df378159a4e7ee1694 (diff)
downloadoslo-context-3ae1660b51324cea51aeec63bb58741946d87ba3.tar.gz
Merge "Added dictify() and uuids to the common request context."
-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