def get_endpoint(service_catalog): """ Select an endpoint from the service catalog We search the full service catalog for services matching both type and region. If the client supplied no region then any endpoint for the service is considered a match. There must be one -- and only one -- successful match in the catalog, otherwise we will raise an exception. """ region = self.creds.get('region') service_type_matches = lambda s: s.get('type') == self.service_type region_matches = lambda e: region is None or e['region'] == region endpoints = [ ep for s in service_catalog if service_type_matches(s) for ep in s['endpoints'] if region_matches(ep) ] if len(endpoints) > 1: raise exception.RegionAmbiguity(region=region) elif not endpoints: raise exception.NoServiceEndpoint() else: # FIXME(sirp): for now just use the public url. return endpoints[0]['publicURL']
def test_openstack_exception_without_kwargs(self): wrapper = fault.FaultWrapper(None) msg = wrapper._error(heat_exc.NoServiceEndpoint()) expected = {'code': 500, 'error': {'message': 'Response from Keystone does ' 'not contain a Heat endpoint.', 'traceback': None, 'type': 'NoServiceEndpoint'}, 'explanation': 'The server has either erred or is ' 'incapable of performing the requested ' 'operation.', 'title': 'Internal Server Error'} self.assertEqual(msg, expected)