From 7448d61cc5dfa9c658a739cbb2dae678971a347b Mon Sep 17 00:00:00 2001 From: Andy Ning Date: Thu, 14 Jun 2018 16:35:44 -0400 Subject: [PATCH 1/1] Add image download support to DC config --- glance_store/_drivers/glance.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/glance_store/_drivers/glance.py b/glance_store/_drivers/glance.py index 554a5a1..70f3e65 100644 --- a/glance_store/_drivers/glance.py +++ b/glance_store/_drivers/glance.py @@ -34,13 +34,23 @@ import glance_store.location from keystoneclient import exceptions as keystone_exc from keystoneclient import service_catalog as keystone_sc -import keystoneauth1.loading -import keystoneauth1.session +import keystoneauth1.loading as loading +import keystoneauth1.session as session from glanceclient import client as glance_client +from glanceclient import Client from cinderclient import exceptions as glance_exception CONF = cfg.CONF +_registry_client = 'glance.registry.client' +CONF.import_opt('use_user_token', _registry_client) +CONF.import_opt('admin_user', _registry_client) +CONF.import_opt('admin_password', _registry_client) +CONF.import_opt('admin_tenant_name', _registry_client) +CONF.import_opt('auth_url', _registry_client) +CONF.import_opt('auth_strategy', _registry_client) +CONF.import_opt('auth_region', _registry_client) + LOG = logging.getLogger(__name__) _GLANCE_OPTS = [ @@ -51,8 +61,30 @@ _GLANCE_OPTS = [ default='image:glance:internalURL', help=_("Glance catalog info")),] +def get_glanceclient_dc(): + + loader = loading.get_plugin_loader('password') + auth = loader.load_from_options( + auth_url=CONF.auth_url, + username=CONF.admin_user, + password=CONF.admin_password, + user_domain_id='default', + project_name=CONF.admin_tenant_name, + project_domain_id='default') + auth_session = session.Session(auth=auth) + c = Client('2', session=auth_session) + + return c + + def get_glanceclient(conf, remote_region, context=None): + # In DC config, need to authentication against central region + # keystone. + if not CONF.use_user_token: + c = get_glanceclient_dc() + return c + glance_store = conf.glance_store if glance_store.cinder_endpoint_template: -- 2.7.4