diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-06-21 21:19:16 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-06-21 21:19:16 +0000 |
| commit | 9cc979fee72e8b64ddca5cf5f4889541001e7c1b (patch) | |
| tree | 1ef49bcf8c1c24402ad54863e74a3b51cd5b26af /openstack | |
| parent | 3b9143fe10c3502e3b935214941c9ccafed3e82b (diff) | |
| parent | c797a1d651f844bea4276cbef9ac67f85c87d99c (diff) | |
| download | oslo-9cc979fee72e8b64ddca5cf5f4889541001e7c1b.tar.gz oslo-9cc979fee72e8b64ddca5cf5f4889541001e7c1b.tar.xz oslo-9cc979fee72e8b64ddca5cf5f4889541001e7c1b.zip | |
Merge "Added dictify() and uuids to the common request context."
Diffstat (limited to 'openstack')
| -rw-r--r-- | openstack/common/context.py | 28 |
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 |
