Enable to set project_id when get service context

Change-Id: Id8a882e81cc8aba603dd8b9bc061566760f53a92
This commit is contained in:
lvdongbing 2016-04-12 03:20:09 -04:00
parent 1e540840c3
commit c31a3afcc4
3 changed files with 6 additions and 2 deletions

View File

@ -109,7 +109,7 @@ class RequestContext(base_context.RequestContext):
return cls(**values)
def get_service_context(**kwargs):
def get_service_context(set_project_id=False, **kwargs):
'''An abstraction layer for getting service credential.
There could be multiple cloud backends for bilean to use. This
@ -120,6 +120,9 @@ def get_service_context(**kwargs):
'''
identity_service = driver_base.BileanDriver().identity
service_creds = identity_service.get_service_credentials(**kwargs)
if set_project_id:
project = identity_service().conn.session.get_project_id()
service_creds.update(project=project)
return RequestContext(**service_creds)

View File

@ -17,6 +17,7 @@ from oslo_config import cfg
from bilean.engine import environment
CONF = cfg.CONF
CONF.import_opt('cloud_backend', 'bilean.common.config')
class DriverBase(object):

View File

@ -29,7 +29,7 @@ KEYSTONE_EVENTS = ['identity.project.created',
class EventsNotificationEndpoint(object):
def __init__(self):
self.resource_converter = converter.setup_resources()
self.cnxt = context.get_admin_context()
self.cnxt = context.get_service_context(set_project_id=True)
super(EventsNotificationEndpoint, self).__init__()
def info(self, ctxt, publisher_id, event_type, payload, metadata):