Adding ability to access context from openstack.common.log
implements bp: logs-improvement Change-Id: I6ac66028e00a6c68d1dd3b94d86123db3403d768
This commit is contained in:
parent
bd545f7a27
commit
41906262dd
@ -25,6 +25,7 @@ from sahara import exceptions as ex
|
|||||||
from sahara.i18n import _
|
from sahara.i18n import _
|
||||||
from sahara.i18n import _LE
|
from sahara.i18n import _LE
|
||||||
from sahara.i18n import _LW
|
from sahara.i18n import _LW
|
||||||
|
from sahara.openstack.common import local
|
||||||
from sahara.openstack.common import log as logging
|
from sahara.openstack.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
@ -44,6 +45,8 @@ class Context(context.RequestContext):
|
|||||||
is_admin=None,
|
is_admin=None,
|
||||||
remote_semaphore=None,
|
remote_semaphore=None,
|
||||||
auth_uri=None,
|
auth_uri=None,
|
||||||
|
resource_uuid=None,
|
||||||
|
overwrite=True,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
if kwargs:
|
if kwargs:
|
||||||
LOG.warn(_LW('Arguments dropped when creating context: %s'),
|
LOG.warn(_LW('Arguments dropped when creating context: %s'),
|
||||||
@ -52,7 +55,8 @@ class Context(context.RequestContext):
|
|||||||
super(Context, self).__init__(auth_token=auth_token,
|
super(Context, self).__init__(auth_token=auth_token,
|
||||||
user=user_id,
|
user=user_id,
|
||||||
tenant=tenant_id,
|
tenant=tenant_id,
|
||||||
is_admin=is_admin)
|
is_admin=is_admin,
|
||||||
|
resource_uuid=resource_uuid)
|
||||||
self.service_catalog = service_catalog
|
self.service_catalog = service_catalog
|
||||||
self.username = username
|
self.username = username
|
||||||
self.tenant_name = tenant_name
|
self.tenant_name = tenant_name
|
||||||
@ -63,6 +67,8 @@ class Context(context.RequestContext):
|
|||||||
self.auth_uri = auth_uri
|
self.auth_uri = auth_uri
|
||||||
else:
|
else:
|
||||||
self.auth_uri = _get_auth_uri()
|
self.auth_uri = _get_auth_uri()
|
||||||
|
if overwrite or not hasattr(local.store, 'context'):
|
||||||
|
local.store.context = self
|
||||||
|
|
||||||
def clone(self):
|
def clone(self):
|
||||||
return Context(
|
return Context(
|
||||||
@ -75,7 +81,9 @@ class Context(context.RequestContext):
|
|||||||
self.roles,
|
self.roles,
|
||||||
self.is_admin,
|
self.is_admin,
|
||||||
self.remote_semaphore,
|
self.remote_semaphore,
|
||||||
self.auth_uri)
|
self.auth_uri,
|
||||||
|
self.resource_uuid,
|
||||||
|
overwrite=False)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return {
|
return {
|
||||||
@ -88,6 +96,7 @@ class Context(context.RequestContext):
|
|||||||
'is_admin': self.is_admin,
|
'is_admin': self.is_admin,
|
||||||
'roles': self.roles,
|
'roles': self.roles,
|
||||||
'auth_uri': self.auth_uri,
|
'auth_uri': self.auth_uri,
|
||||||
|
'instance_uuid': self.resource_uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
def is_auth_capable(self):
|
def is_auth_capable(self):
|
||||||
@ -139,9 +148,12 @@ def current():
|
|||||||
def set_ctx(new_ctx):
|
def set_ctx(new_ctx):
|
||||||
if not new_ctx and has_ctx():
|
if not new_ctx and has_ctx():
|
||||||
delattr(_CTX_STORE, _CTX_KEY)
|
delattr(_CTX_STORE, _CTX_KEY)
|
||||||
|
if hasattr(local.store, 'context'):
|
||||||
|
delattr(local.store, 'context')
|
||||||
|
|
||||||
if new_ctx:
|
if new_ctx:
|
||||||
setattr(_CTX_STORE, _CTX_KEY, new_ctx)
|
setattr(_CTX_STORE, _CTX_KEY, new_ctx)
|
||||||
|
setattr(local.store, 'context', new_ctx)
|
||||||
|
|
||||||
|
|
||||||
def _get_auth_uri():
|
def _get_auth_uri():
|
||||||
|
Loading…
Reference in New Issue
Block a user