def get_service_url(service_type='baremetal', endpoint_type='internal'): """Wrapper for get service url from keystone service catalog. Given a service_type and an endpoint_type, this method queries keystone service catalog and provides the url for the desired endpoint. :param service_type: the keystone service for which url is required. :param endpoint_type: the type of endpoint for the service. :returns: an http/https url for the desired endpoint. """ ksclient = _get_ksclient() if not ksclient.has_service_catalog(): raise exception.KeystoneFailure( _('No Keystone service catalog ' 'loaded')) try: endpoint = ksclient.service_catalog.url_for( service_type=service_type, endpoint_type=endpoint_type) except ksexception.EndpointNotFound: raise exception.CatalogNotFound(service_type=service_type, endpoint_type=endpoint_type) return endpoint
def get_service_url(service_type='baremetal', endpoint_type='internal'): """Wrapper for get service url from keystone service catalog. Given a service_type and an endpoint_type, this method queries keystone service catalog and provides the url for the desired endpoint. :param service_type: the keystone service for which url is required. :param endpoint_type: the type of endpoint for the service. :returns: an http/https url for the desired endpoint. """ auth_url = CONF.keystone_authtoken.auth_uri if not auth_url: raise exception.CatalogFailure(_('Keystone API endpoint is missing')) auth_version = CONF.keystone_authtoken.auth_version api_v3 = _is_apiv3(auth_url, auth_version) if api_v3: from keystoneclient.v3 import client else: from keystoneclient.v2_0 import client auth_url = get_keystone_url(auth_url, auth_version) try: ksclient = client.Client( username=CONF.keystone_authtoken.admin_user, password=CONF.keystone_authtoken.admin_password, tenant_name=CONF.keystone_authtoken.admin_tenant_name, auth_url=auth_url) except ksexception.Unauthorized: raise exception.CatalogUnauthorized except ksexception.AuthorizationFailure as err: raise exception.CatalogFailure( _('Could not perform authorization ' 'process for service catalog: %s') % err) if not ksclient.has_service_catalog(): raise exception.CatalogFailure(_('No keystone service catalog loaded')) try: endpoint = ksclient.service_catalog.url_for( service_type=service_type, endpoint_type=endpoint_type) except ksexception.EndpointNotFound: raise exception.CatalogNotFound(service_type=service_type, endpoint_type=endpoint_type) return endpoint
def wrapper(*args, **kwargs): try: return f(*args, **kwargs) except ks_exception.EndpointNotFound: service_type = kwargs.get('service_type', 'baremetal') endpoint_type = kwargs.get('endpoint_type', 'internal') raise exception.CatalogNotFound(service_type=service_type, endpoint_type=endpoint_type) except (ks_exception.Unauthorized, ks_exception.AuthorizationFailure): raise exception.KeystoneUnauthorized() except (ks_exception.NoMatchingPlugin, ks_exception.MissingRequiredOptions) as e: raise exception.ConfigInvalid(str(e)) except Exception as e: LOG.exception('Keystone request failed: %(msg)s', {'msg': str(e)}) raise exception.KeystoneFailure(str(e))
def get_endpoint(group, **adapter_kwargs): """Get an endpoint from an adapter. The adapter_kwargs will be passed directly to keystoneauth1 Adapter and will override the values loaded from config. Consult keystoneauth1 docs for available adapter options. :param group: name of the config section to load adapter options from :raises: CatalogNotFound if the endpoint is not found """ result = get_adapter(group, **adapter_kwargs).get_endpoint() if not result: service_type = adapter_kwargs.get('service_type', 'baremetal') endpoint_type = adapter_kwargs.get('endpoint_type', 'internal') raise exception.CatalogNotFound(service_type=service_type, endpoint_type=endpoint_type) return result
def get_service_url(service_type='baremetal', endpoint_type='internal'): """Wrapper for get service url from keystone service catalog.""" auth_url = CONF.keystone_authtoken.auth_uri if not auth_url: raise exception.CatalogFailure(_('Keystone API endpoint is missing')) api_v3 = CONF.keystone_authtoken.auth_version == 'v3.0' or \ 'v3' in parse.urlparse(auth_url).path if api_v3: from keystoneclient.v3 import client else: from keystoneclient.v2_0 import client api_version = 'v3' if api_v3 else 'v2.0' # NOTE(lucasagomes): Get rid of the trailing '/' otherwise urljoin() # fails to override the version in the URL auth_url = parse.urljoin(auth_url.rstrip('/'), api_version) try: ksclient = client.Client( username=CONF.keystone_authtoken.admin_user, password=CONF.keystone_authtoken.admin_password, tenant_name=CONF.keystone_authtoken.admin_tenant_name, auth_url=auth_url) except ksexception.Unauthorized: raise exception.CatalogUnauthorized except ksexception.AuthorizationFailure as err: raise exception.CatalogFailure( _('Could not perform authorization ' 'process for service catalog: %s') % err) if not ksclient.has_service_catalog(): raise exception.CatalogFailure(_('No keystone service catalog loaded')) try: endpoint = ksclient.service_catalog.url_for( service_type=service_type, endpoint_type=endpoint_type) except ksexception.EndpointNotFound: raise exception.CatalogNotFound(service_type=service_type, endpoint_type=endpoint_type) return endpoint
def get_service_url(service_type='baremetal', endpoint_type='internal'): """Wrapper for get service url from keystone service catalog.""" auth_url = CONF.keystone_authtoken.auth_uri or '' api_v3 = CONF.keystone_authtoken.auth_version == 'v3.0' or \ 'v3' in parse.urlparse(auth_url).path if api_v3: from keystoneclient.v3 import client else: from keystoneclient.v2_0 import client try: ksclient = client.Client( username=CONF.keystone_authtoken.admin_user, password=CONF.keystone_authtoken.admin_password, tenant_name=CONF.keystone_authtoken.admin_tenant_name, auth_url=auth_url) except ksexception.Unauthorized: raise exception.CatalogUnauthorized except ksexception.AuthorizationFailure as err: raise exception.CatalogFailure( _('Could not perform authorization ' 'process for service catalog: %s') % err) if not ksclient.has_service_catalog(): raise exception.CatalogFailure(_('No keystone service catalog loaded')) try: endpoint = ksclient.service_catalog.url_for( service_type=service_type, endpoint_type=endpoint_type) except ksexception.EndpointNotFound: raise exception.CatalogNotFound(service_type=service_type, endpoint_type=endpoint_type) return endpoint