summaryrefslogtreecommitdiff
path: root/ceilometerclient/v2/client.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-01-12 11:01:02 +0000
committerGerrit Code Review <review@openstack.org>2016-01-12 11:01:03 +0000
commit25517d0226e69bbabf9679c80445746a5cab846d (patch)
tree5f16a4c3414cf595d84fc451696f31b4f772fa6e /ceilometerclient/v2/client.py
parentd3a048311ac7ac7986a6b1478c5b399e1727a7bb (diff)
parent71cb6b3d0ee1f393c2bafee13aa2f013cc82f77d (diff)
downloadpython-ceilometerclient-2.2.0.tar.gz
Merge "Don't copy the auth_plugin for aodh"2.2.0
Diffstat (limited to 'ceilometerclient/v2/client.py')
-rw-r--r--ceilometerclient/v2/client.py78
1 files changed, 40 insertions, 38 deletions
diff --git a/ceilometerclient/v2/client.py b/ceilometerclient/v2/client.py
index e6a6075..f613cec 100644
--- a/ceilometerclient/v2/client.py
+++ b/ceilometerclient/v2/client.py
@@ -57,13 +57,17 @@ class Client(object):
def __init__(self, *args, **kwargs):
"""Initialize a new client for the Ceilometer v2 API."""
- if not kwargs.get('auth_plugin'):
+ if not kwargs.get('auth_plugin') and not kwargs.get('session'):
kwargs['auth_plugin'] = ceiloclient.get_auth_plugin(*args,
**kwargs)
+
self.auth_plugin = kwargs.get('auth_plugin')
self.http_client = ceiloclient._construct_http_client(**kwargs)
- self.alarm_client, aodh_enabled = self._get_alarm_client(**kwargs)
+ self.alarm_client = self._get_alarm_client(**kwargs)
+ aodh_enabled = self.alarm_client is not None
+ if not aodh_enabled:
+ self.alarm_client = self.http_client
self.meters = meters.MeterManager(self.http_client)
self.samples = samples.OldSampleManager(self.http_client)
self.new_samples = samples.SampleManager(self.http_client)
@@ -83,43 +87,41 @@ class Client(object):
self.alarm_client)
self.capabilities = capabilities.CapabilitiesManager(self.http_client)
- def _get_alarm_client(self, **kwargs):
+ @staticmethod
+ def _get_alarm_client(**ceilo_kwargs):
"""Get client for alarm manager that redirect to aodh."""
- kwargs = copy.deepcopy(kwargs)
- self.alarm_auth_plugin = kwargs.get('auth_plugin')
- aodh_endpoint = kwargs.get('aodh_endpoint')
- if kwargs.get('session') is not None:
+ # NOTE(sileht): the auth_plugin/keystone session cannot be copied
+ # because they rely on threading module.
+ auth_plugin = ceilo_kwargs.pop('auth_plugin', None)
+ session = ceilo_kwargs.pop('session', None)
+
+ kwargs = copy.deepcopy(ceilo_kwargs)
+ kwargs["service_type"] = "alarming"
+ aodh_endpoint = ceilo_kwargs.get('aodh_endpoint')
+
+ if session:
+ # keystone session can be shared between client
+ ceilo_kwargs['session'] = kwargs['session'] = session
if aodh_endpoint:
kwargs['endpoint_override'] = aodh_endpoint
- else:
- kwargs["service_type"] = "alarming"
- try:
- c = ceiloclient._construct_http_client(**kwargs)
- # NOTE(sileht): when a keystoneauth1 session object is used
- # endpoint looking is done on first request, so do it.
- c.get("/")
- return c, True
- except ka_exc.EndpointNotFound:
- return self.http_client, False
- except kc_exc.EndpointNotFound:
- return self.http_client, False
+ elif auth_plugin and kwargs.get('auth_url'):
+ ceilo_kwargs['auth_plugin'] = auth_plugin
+ kwargs.pop('endpoint', None)
+ kwargs['auth_plugin'] = ceiloclient.get_auth_plugin(
+ aodh_endpoint, **kwargs)
else:
- if aodh_endpoint:
- kwargs["auth_plugin"].opts['endpoint'] = aodh_endpoint
- elif not kwargs.get('auth_url'):
- # Users may just provided ceilometer endpoint and token, and no
- # auth_url, in this case, we need 'aodh_endpoint' also
- # provided, otherwise we cannot get aodh endpoint from
- # keystone, and assume aodh is unavailable.
- return self.http_client, False
- else:
- try:
- # NOTE(liusheng): Getting the aodh's endpoint to rewrite
- # the endpoint of alarm auth_plugin.
- kwargs["auth_plugin"].redirect_to_aodh_endpoint(
- kwargs.get('timeout'))
- except ka_exc.EndpointNotFound:
- return self.http_client, False
- except kc_exc.EndpointNotFound:
- return self.http_client, False
- return ceiloclient._construct_http_client(**kwargs), True
+ # Users may just provided ceilometer endpoint and token, and no
+ # auth_url, in this case, we need 'aodh_endpoint' also
+ # provided, otherwise we cannot get aodh endpoint from
+ # keystone, and assume aodh is unavailable.
+ return None
+
+ try:
+ # NOTE(sileht): try to use aodh
+ c = ceiloclient._construct_http_client(**kwargs)
+ c.get("/")
+ return c
+ except ka_exc.EndpointNotFound:
+ return None
+ except kc_exc.EndpointNotFound:
+ return None