From ce098ccce9d67df8c243fa885640989a4703ac53 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 10 Jan 2013 18:22:00 +0000 Subject: Add user/tenant shim to RequestContext This is necessary because we pass the Nova context object to openstack-common/code (logging, for example), which expects the attributes to be named user/tenant not user_id/project_id. Fixes bug 1098278 Change-Id: Ic0dc49ef54515fc0ffaa0895cf4d88701afb1e16 --- nova/context.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/nova/context.py b/nova/context.py index 094e2bffb..1a566cb5a 100644 --- a/nova/context.py +++ b/nova/context.py @@ -124,7 +124,9 @@ class RequestContext(object): 'user_name': self.user_name, 'service_catalog': self.service_catalog, 'project_name': self.project_name, - 'instance_lock_checked': self.instance_lock_checked} + 'instance_lock_checked': self.instance_lock_checked, + 'tenant': self.tenant, + 'user': self.user} @classmethod def from_dict(cls, values): @@ -143,6 +145,19 @@ class RequestContext(object): return context + # NOTE(sirp): the openstack/common version of RequestContext uses + # tenant/user whereas the Nova version uses project_id/user_id. We need + # this shim in order to use context-aware code from openstack/common, like + # logging, until we make the switch to using openstack/common's version of + # RequestContext. + @property + def tenant(self): + return self.project_id + + @property + def user(self): + return self.user_id + def get_admin_context(read_deleted="no"): return RequestContext(user_id=None, -- cgit