def get_endpoint(service_catalog, service_type='image', endpoint_region=None, endpoint_type='publicURL'): """ 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 'image' endpoint is considered a match. There must be one -- and only one -- successful match in the catalog, otherwise we will raise an exception. """ endpoints = ks_service_catalog.ServiceCatalogV2({ 'serviceCatalog': service_catalog }).get_urls(service_type=service_type, region_name=endpoint_region, endpoint_type=endpoint_type) if endpoints is None: raise exception.NoServiceEndpoint() elif len(endpoints) == 1: return endpoints[0] else: raise exception.RegionAmbiguity(region=endpoint_region)
def get_cinderclient(conf, context=None): glance_store = conf.glance_store user_overriden = is_user_overriden(conf) if user_overriden: username = glance_store.cinder_store_user_name password = glance_store.cinder_store_password project = glance_store.cinder_store_project_name url = glance_store.cinder_store_auth_address else: username = context.user password = context.auth_token project = context.tenant if glance_store.cinder_endpoint_template: url = glance_store.cinder_endpoint_template % context.to_dict() else: info = glance_store.cinder_catalog_info service_type, service_name, endpoint_type = info.split(':') sc = {'serviceCatalog': context.service_catalog} try: url = keystone_sc.ServiceCatalogV2(sc).url_for( region_name=glance_store.cinder_os_region_name, service_type=service_type, service_name=service_name, endpoint_type=endpoint_type) except keystone_exc.EndpointNotFound: reason = _("Failed to find Cinder from a service catalog.") raise exceptions.BadStoreConfiguration(store_name="cinder", reason=reason) c = cinderclient.Client(username, password, project, auth_url=url, insecure=glance_store.cinder_api_insecure, retries=glance_store.cinder_http_retries, cacert=glance_store.cinder_ca_certificates_file) LOG.debug( 'Cinderclient connection created for user %(user)s using URL: ' '%(url)s.', { 'user': username, 'url': url }) # noauth extracts user_id:project_id from auth_token if not user_overriden: c.client.auth_token = context.auth_token or '%s:%s' % (username, project) c.client.management_url = url return c
def _get_glare_url(self, request): sc = request.context.service_catalog token = request.context.auth_token try: return service_catalog.ServiceCatalogV2({ 'serviceCatalog': sc }).url_for(service_type='artifact', endpoint_type=CONF.glare.endpoint_type, region_name=CONF.home_region) except keystone_ex.EndpointNotFound: return service_catalog.ServiceCatalogV3(token, { 'catalog': sc }).url_for(service_type='artifact', endpoint_type=CONF.glare.endpoint_type, region_name=CONF.home_region)
def url_for(service_catalog=None, service_type='identity', endpoint_type='publicURL'): if not service_catalog: service_catalog = context.current().service_catalog try: return keystone_service_catalog.ServiceCatalogV2( {'serviceCatalog': json.loads(service_catalog)}).url_for( service_type=service_type, endpoint_type=endpoint_type, region_name=CONF.os_region_name) except keystone_ex.EndpointNotFound: ctx = context.current() return keystone_service_catalog.ServiceCatalogV3( ctx.auth_token, {'catalog': json.loads(service_catalog)}).url_for( service_type=service_type, endpoint_type=endpoint_type, region_name=CONF.os_region_name)
from keystoneclient.auth.identity import v2 as auth_v2 from keystoneclient import service_catalog from oslo.serialization import jsonutils from openstackclient.api import auth from openstackclient.common import clientmanager from openstackclient.common import exceptions as exc from openstackclient.tests import fakes from openstackclient.tests import utils API_VERSION = {"identity": "2.0"} AUTH_REF = {'version': 'v2.0'} AUTH_REF.update(fakes.TEST_RESPONSE_DICT['access']) SERVICE_CATALOG = service_catalog.ServiceCatalogV2(AUTH_REF) class Container(object): attr = clientmanager.ClientCache(lambda x: object()) def __init__(self): pass class FakeOptions(object): def __init__(self, **kwargs): for option in auth.OPTIONS_LIST: setattr(self, 'os_' + option.replace('-', '_'), None) self.os_auth_type = None self.os_identity_api_version = '2.0'
def _get_endpoint_url(self, context): catalog = service_catalog.ServiceCatalogV2( {'serviceCatalog': context.service_catalog}) return catalog.url_for(service_type='object-store')
def __init__(self, auth_token, sc): super(_ContextAuthPlugin, self).__init__() self.auth_token = auth_token sc = {'serviceCatalog': sc} self.service_catalog = service_catalog.ServiceCatalogV2(sc)
def __init__(self, client_name): self.client = client_name self.service_catalog = service_catalog.ServiceCatalogV2({}) self.images = DummyImages()