# Pastebin EMh4NjC5 commit b388044a3a2f37015c0e2ae4525be9ecc49fa51f Author: Duncan Thomas Date: Mon Sep 21 18:50:20 2015 +0300 Get keystone endpoint from catalog by default Change-Id: Ic816034ffc682f5a86efc420d80951512651570a diff --git a/cinder/api/contrib/quotas.py b/cinder/api/contrib/quotas.py index 27f0401..f5dd579 100644 --- a/cinder/api/contrib/quotas.py +++ b/cinder/api/contrib/quotas.py @@ -32,7 +32,23 @@ from oslo_config import cfg from oslo_utils import strutils +quota_opts = [ + cfg.StrOpt('quota_keystone_api_url', + default=None, + help='Authentication url for quota service.' + ' Set to "None" to use catalog.'), + cfg.StrOpt('quota_auth_catalog_info', + default='identity:keystone:publicURL', + help='Info to match when looking for keystone in the service ' + 'catalog. Format is: separated values of the form: ' + ':: - ' + 'Only used if encryption_auth_url is "None"'), +] + + CONF = cfg.CONF +CONF.register_opts(quota_opts, 'quota') + QUOTAS = quota.QUOTAS NON_QUOTA_KEYS = ['tenant_id', 'id'] @@ -179,8 +195,31 @@ class QuotaSetsController(wsgi.Controller): organized. Therefore, we need to know the project hierarchy, if any, in order to do quota operations properly. """ + if getattr(self, "_base_auth_url", None) is None: + self._base_auth_url = CONF.quota.quota_auth_url + if self._base_auth_url is None: + try: + info = CONF.quota.quota_auth_catalog_info + service_type, service_name, endpoint_type = info.split(':') + except ValueError: + raise exception.QuotamgrConfigException(_( + "Failed to parse the configuration option " + "'quota_auth_catalog_info', must be in the form " + "::.")) + for entry in context.service_catalog: + if entry.get('type') == service_type: + self._base_auth_url = entry.get( + 'endpoints')[0].get(endpoint_type) + + if self._base_auth_url is None: + raise exception.QuotamgrConfigException(_( + "Could not determine which endpoint to use. This can " + "either be set in the service catalog or with the " + "cinder.conf config option 'quota_auth_url' in the " + "section [quota].")) + try: - keystone = client.Client(auth_url=CONF.keymgr.encryption_auth_url, + keystone = client.Client(auth_url=self._base_auth_url, token=context.auth_token, project_id=context.project_id) project = keystone.projects.get(id, subtree_as_ids=subtree_as_ids)