summaryrefslogtreecommitdiffstats
path: root/nova/context.py
diff options
context:
space:
mode:
authorRick Harris <rconradharris@gmail.com>2011-12-07 16:06:31 -0600
committerRick Harris <rconradharris@gmail.com>2011-12-07 16:06:31 -0600
commitc40ee5cfe75e8b1209dc53fc7eb2097812efa54e (patch)
tree657bd8f5a633bd69b9eba0649e513486bbb91306 /nova/context.py
parentc3b7cce8101548428b64abb23ab88482bc79c36e (diff)
downloadnova-c40ee5cfe75e8b1209dc53fc7eb2097812efa54e.tar.gz
nova-c40ee5cfe75e8b1209dc53fc7eb2097812efa54e.tar.xz
nova-c40ee5cfe75e8b1209dc53fc7eb2097812efa54e.zip
Add ability to see deleted and active records.
Fixes bug #900564 Changes `Context`.`read_deleted` from a bool to an enum string with values "yes" (can read deleted records), "no" (cannot read deleted records), and "only" (can only see deleted records, for backwards compatibility). Change-Id: Ic81db3664c33f23f751b73973782efb06fce90d9
Diffstat (limited to 'nova/context.py')
-rw-r--r--nova/context.py37
1 files changed, 21 insertions, 16 deletions
diff --git a/nova/context.py b/nova/context.py
index 36d15ba08..cd07ca629 100644
--- a/nova/context.py
+++ b/nova/context.py
@@ -19,6 +19,7 @@
"""RequestContext: context for requests that persist through all of nova."""
+import copy
import uuid
from nova import local
@@ -32,9 +33,14 @@ class RequestContext(object):
"""
- def __init__(self, user_id, project_id, is_admin=None, read_deleted=False,
+ def __init__(self, user_id, project_id, is_admin=None, read_deleted="no",
roles=None, remote_address=None, timestamp=None,
request_id=None, auth_token=None, strategy='noauth'):
+ """
+ :param read_deleted: 'no' indicates deleted records are hidden, 'yes'
+ indicates deleted records are visible, 'only' indicates that
+ *only* deleted records are visible.
+ """
self.user_id = user_id
self.project_id = project_id
self.roles = roles or []
@@ -73,18 +79,17 @@ class RequestContext(object):
def elevated(self, read_deleted=None):
"""Return a version of this context with admin flag set."""
- rd = self.read_deleted if read_deleted is None else read_deleted
- return RequestContext(user_id=self.user_id,
- project_id=self.project_id,
- is_admin=True,
- read_deleted=rd,
- roles=self.roles,
- remote_address=self.remote_address,
- timestamp=self.timestamp,
- request_id=self.request_id,
- auth_token=self.auth_token,
- strategy=self.strategy)
-
-
-def get_admin_context(read_deleted=False):
- return RequestContext(None, None, True, read_deleted)
+ context = copy.copy(self)
+ context.is_admin = True
+
+ if read_deleted is not None:
+ context.read_deleted = read_deleted
+
+ return context
+
+
+def get_admin_context(read_deleted="no"):
+ return RequestContext(user_id=None,
+ project_id=None,
+ is_admin=True,
+ read_deleted=read_deleted)