def _get_alarm_client(self, **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: if aodh_endpoint: kwargs['endpoint_override'] = aodh_endpoint else: kwargs["service_type"] = "alarming" try: return ceiloclient._construct_http_client(**kwargs), True except exceptions.EndpointNotFound: return self.http_client, False 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 exceptions.EndpointNotFound: return self.http_client, False return ceiloclient._construct_http_client(**kwargs), True
def __init__(self, *args, **kwargs): """Initialize a new client for the Ceilometer v2 API.""" 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 = 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) self.statistics = statistics.StatisticsManager(self.http_client) self.resources = resources.ResourceManager(self.http_client) self.alarms = alarms.AlarmManager(self.alarm_client, aodh_enabled) self.events = events.EventManager(self.http_client) self.event_types = event_types.EventTypeManager(self.http_client) self.traits = traits.TraitManager(self.http_client) self.trait_descriptions = trait_descriptions.\ TraitDescriptionManager(self.http_client) self.query_samples = query.QuerySamplesManager( self.http_client) self.query_alarms = query.QueryAlarmsManager(self.alarm_client) self.query_alarm_history = query.QueryAlarmHistoryManager( self.alarm_client) self.capabilities = capabilities.CapabilitiesManager(self.http_client)
def test_http_client_with_session_and_aodh(self, mock_sc): session = mock.Mock() kwargs = {"session": session, "service_type": "metering", "user_agent": "python-ceilometerclient"} expected = { "auth": None, "interface": 'publicURL', "region_name": None, "timings": None, "session": session, "service_type": "metering", "user_agent": "python-ceilometerclient"} kwargs['aodh_endpoint'] = 'http://aodh.where' client._construct_http_client(**kwargs) mock_sc.assert_called_with(**expected)
def __init__(self, *args, **kwargs): """Initialize a new client for the Ceilometer v2 API.""" 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 = 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) self.statistics = statistics.StatisticsManager(self.http_client) self.resources = resources.ResourceManager(self.http_client) self.alarms = alarms.AlarmManager(self.alarm_client, aodh_enabled) self.events = events.EventManager(self.http_client) self.event_types = event_types.EventTypeManager(self.http_client) self.traits = traits.TraitManager(self.http_client) self.trait_descriptions = trait_descriptions.\ TraitDescriptionManager(self.http_client) self.query_samples = query.QuerySamplesManager(self.http_client) self.query_alarms = query.QueryAlarmsManager(self.alarm_client) self.query_alarm_history = query.QueryAlarmHistoryManager( self.alarm_client) self.capabilities = capabilities.CapabilitiesManager(self.http_client)
def test_http_client_with_session_and_aodh(self, mock_sc): session = mock.Mock() kwargs = {"session": session, "service_type": "metering", "user_agent": "python-ceilometerclient"} expected = { "auth": None, "interface": 'publicURL', "region_name": None, "timings": None, "session": session, "service_type": "metering", "user_agent": "python-ceilometerclient"} kwargs['aodh_endpoint'] = 'http://aodh.where' client._construct_http_client(**kwargs) mock_sc.assert_called_with(**expected)
def _get_alarm_client(**ceilo_kwargs): """Get client for alarm manager that redirect to aodh.""" # 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 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: # Users may just provide ceilometer endpoint and token, and no # auth_url, in this case, we need 'aodh_endpoint' also to be # 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 except requests.exceptions.ConnectionError: return None
def _get_alarm_client(**ceilo_kwargs): """Get client for alarm manager that redirect to aodh.""" # 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 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: # Users may just provide ceilometer endpoint and token, and no # auth_url, in this case, we need 'aodh_endpoint' also to be # 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 except requests.exceptions.ConnectionError: return None
def _get_redirect_client(new_service_type, new_service, **ceilo_kwargs): """Get client for new service manager to redirect to.""" # 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"] = new_service_type endpoint = ceilo_kwargs.get('%s_endpoint' % new_service) if session: # keystone session can be shared between client ceilo_kwargs['session'] = kwargs['session'] = session # session must be unverified to allow alarms in https session.verify = False if endpoint: kwargs['endpoint_override'] = endpoint 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( endpoint, **kwargs) else: # Users may just provide ceilometer endpoint and token, and no # auth_url, in this case, we need 'aodh_endpoint' also to be # provided, otherwise we cannot get aodh endpoint from # keystone, and assume aodh is unavailable. Same applies to panko. return None try: # NOTE(sileht): try to use redirect c = ceiloclient._construct_http_client(**kwargs) c.get("/") return c except ka_exc.EndpointNotFound: return None except requests.exceptions.ConnectionError: return None