summaryrefslogtreecommitdiffstats
path: root/nova/network/quantumv2/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'nova/network/quantumv2/__init__.py')
-rw-r--r--nova/network/quantumv2/__init__.py59
1 files changed, 23 insertions, 36 deletions
diff --git a/nova/network/quantumv2/__init__.py b/nova/network/quantumv2/__init__.py
index 89c08311f..6d6e7c7bc 100644
--- a/nova/network/quantumv2/__init__.py
+++ b/nova/network/quantumv2/__init__.py
@@ -16,7 +16,9 @@
# under the License.
from oslo.config import cfg
-from quantumclient.v2_0 import client
+from quantumclient import client
+from quantumclient.common import exceptions
+from quantumclient.v2_0 import client as clientv20
from nova.openstack.common import excutils
from nova.openstack.common import log as logging
@@ -25,24 +27,27 @@ CONF = cfg.CONF
LOG = logging.getLogger(__name__)
-cached_admin_client = None
-
-
-def _fill_admin_details(params):
- params['username'] = CONF.quantum_admin_username
- params['tenant_name'] = CONF.quantum_admin_tenant_name
- params['region_name'] = CONF.quantum_region_name
- params['password'] = CONF.quantum_admin_password
- params['auth_url'] = CONF.quantum_admin_auth_url
- params['timeout'] = CONF.quantum_url_timeout
- params['auth_strategy'] = CONF.quantum_auth_strategy
- params['insecure'] = CONF.quantum_api_insecure
+def _get_auth_token():
+ try:
+ httpclient = client.HTTPClient(
+ username=CONF.quantum_admin_username,
+ tenant_name=CONF.quantum_admin_tenant_name,
+ region_name=CONF.quantum_region_name,
+ password=CONF.quantum_admin_password,
+ auth_url=CONF.quantum_admin_auth_url,
+ timeout=CONF.quantum_url_timeout,
+ auth_strategy=CONF.quantum_auth_strategy,
+ insecure=CONF.quantum_api_insecure)
+ httpclient.authenticate()
+ return httpclient.auth_token
+ except exceptions.QuantumClientException as e:
+ with excutils.save_and_reraise_exception():
+ LOG.error(_('Quantum client authentication failed: %s'), e)
def _get_client(token=None):
- global cached_admin_client
-
- should_cache = False
+ if not token and CONF.quantum_auth_strategy:
+ token = _get_auth_token()
params = {
'endpoint_url': CONF.quantum_url,
'timeout': CONF.quantum_url_timeout,
@@ -51,30 +56,12 @@ def _get_client(token=None):
if token:
params['token'] = token
else:
- if CONF.quantum_auth_strategy:
- should_cache = True
- _fill_admin_details(params)
- else:
- params['auth_strategy'] = None
-
- new_client = client.Client(**params)
- if should_cache:
- # in this case, we don't have the token yet
- try:
- new_client.httpclient.authenticate()
- except Exception:
- with excutils.save_and_reraise_exception():
- LOG.exception(_("quantum authentication failed"))
-
- cached_admin_client = new_client
- return new_client
+ params['auth_strategy'] = None
+ return clientv20.Client(**params)
def get_client(context, admin=False):
if admin:
- if cached_admin_client is not None:
- return cached_admin_client
-
token = None
else:
token = context.auth_token