Exemple #1
0
def get_endpoint_for_project(ctx, service_name=None, service_type=None,
                             region_name=None):
    if service_name is None and service_type is None:
        raise ValueError(
            "Either 'service_name' or 'service_type' must be provided."
        )

    service_catalog = obtain_service_catalog(ctx)

    # When region_name is not passed, first get from context as region_name
    # could be passed to rest api in http header ('X-Region-Name'). Otherwise,
    # just get region from mistral configuration.
    region = (region_name or ctx.region_name)

    service_endpoints = service_catalog.get_endpoints(
        service_name=service_name,
        service_type=service_type,
        region_name=region
    )

    endpoint = None
    os_actions_endpoint_type = 'public'

    for endpoints in six.itervalues(service_endpoints):
        for ep in endpoints:
            # is V3 interface?
            if 'interface' in ep:
                interface_type = ep['interface']
                if os_actions_endpoint_type in interface_type:
                    endpoint = ks_endpoints.Endpoint(
                        None,
                        ep,
                        loaded=True
                    )
                    break
            # is V2 interface?
            if 'publicURL' in ep:
                endpoint_data = {
                    'url': ep['publicURL'],
                    'region': ep['region']
                }
                endpoint = ks_endpoints.Endpoint(
                    None,
                    endpoint_data,
                    loaded=True
                )
                break

    if not endpoint:
        raise RuntimeError(
            "No endpoints found [service_name=%s, service_type=%s,"
            " region_name=%s]"
            % (service_name, service_type, region)
        )
    else:
        return endpoint
Exemple #2
0
def get_endpoint_for_project(service_name=None,
                             service_type=None,
                             region_name=None):
    if service_name is None and service_type is None:
        raise exceptions.MistralException(
            "Either 'service_name' or 'service_type' must be provided.")

    ctx = context.ctx()

    service_catalog = obtain_service_catalog(ctx)

    # When region_name is not passed, first get from context as region_name
    # could be passed to rest api in http header ('X-Region-Name'). Otherwise,
    # just get region from mistral configuration.
    region = (region_name or ctx.region_name)
    if service_name == 'keystone':
        # Determining keystone endpoint should be done using
        # keystone_authtoken section as this option is special for keystone.
        region = region or CONF.keystone_authtoken.region_name
    else:
        region = region or CONF.openstack_actions.default_region

    service_endpoints = service_catalog.get_endpoints(
        service_name=service_name,
        service_type=service_type,
        region_name=region)

    endpoint = None
    os_actions_endpoint_type = CONF.openstack_actions.os_actions_endpoint_type

    for endpoints in six.itervalues(service_endpoints):
        for ep in endpoints:
            # is V3 interface?
            if 'interface' in ep:
                interface_type = ep['interface']
                if os_actions_endpoint_type in interface_type:
                    endpoint = ks_endpoints.Endpoint(None, ep, loaded=True)
                    break
            # is V2 interface?
            if 'publicURL' in ep:
                endpoint_data = {
                    'url': ep['publicURL'],
                    'region': ep['region']
                }
                endpoint = ks_endpoints.Endpoint(None,
                                                 endpoint_data,
                                                 loaded=True)
                break

    if not endpoint:
        raise exceptions.MistralException(
            "No endpoints found [service_name=%s, service_type=%s,"
            " region_name=%s]" % (service_name, service_type, region))
    else:
        return endpoint
Exemple #3
0
def get_endpoint_for_project(service_name=None, service_type=None):
    if service_name is None and service_type is None:
        raise Exception(
            "Either 'service_name' or 'service_type' must be provided."
        )

    ctx = context.ctx()

    service_catalog = obtain_service_catalog(ctx)

    catalog = service_catalog.get_endpoints(
        service_name=service_name,
        service_type=service_type
    )

    endpoint = None
    for service_type in catalog:
        service = catalog.get(service_type)
        for interface in service:
            # is V3 interface?
            if 'interface' in interface:
                interface_type = interface['interface']
                if CONF.os_actions_endpoint_type in interface_type:
                    endpoint = ks_endpoints.Endpoint(
                        None,
                        interface,
                        loaded=True
                    )
                    break
            # is V2 interface?
            if 'publicURL' in interface:
                endpoint_data = {
                    'url': interface['publicURL'],
                    'region': interface['region']
                }
                endpoint = ks_endpoints.Endpoint(
                    None,
                    endpoint_data,
                    loaded=True
                )
                break

    if not endpoint:
        raise Exception(
            "No endpoints found [service_name=%s, service_type=%s]"
            % (service_name, service_type)
        )
    else:
        # TODO(rakhmerov): We may have more than one endpoint because
        # TODO(rakhmerov): of regions and ideally we need a config option
        # TODO(rakhmerov): for region
        return endpoint
Exemple #4
0
def get_endpoint_for_project(service_name=None, service_type=None):
    if service_name is None and service_type is None:
        raise exceptions.MistralException(
            "Either 'service_name' or 'service_type' must be provided.")

    ctx = context.ctx()

    service_catalog = obtain_service_catalog(ctx)

    service_endpoints = service_catalog.get_endpoints(
        service_name=service_name,
        service_type=service_type,
        region_name=ctx.region_name)

    endpoint = None
    for endpoints in six.itervalues(service_endpoints):
        for ep in endpoints:
            # is V3 interface?
            if 'interface' in ep:
                interface_type = ep['interface']
                if CONF.os_actions_endpoint_type in interface_type:
                    endpoint = ks_endpoints.Endpoint(None, ep, loaded=True)
                    break
            # is V2 interface?
            if 'publicURL' in ep:
                endpoint_data = {
                    'url': ep['publicURL'],
                    'region': ep['region']
                }
                endpoint = ks_endpoints.Endpoint(None,
                                                 endpoint_data,
                                                 loaded=True)
                break

    if not endpoint:
        raise exceptions.MistralException(
            "No endpoints found [service_name=%s, service_type=%s,"
            " region_name=%s]" % (service_name, service_type, ctx.region_name))
    else:
        return endpoint
Exemple #5
0
def translate_v2_endpoints(v2_endpoints, interface=None):
    interfaces = interface and [interface] or v3_endpoints.VALID_INTERFACES
    endpoints = []
    for endpoint in v2_endpoints:
        for interface in interfaces:
            url = getattr(endpoint, interface + 'url')
            info = dict(id=endpoint.id,
                        interface=interface,
                        region_id=endpoint.region,
                        service_id=endpoint.service_id,
                        url=url,
                        enabled=endpoint.enabled)
            endpoints.append(v3_endpoints.Endpoint(manager=None,
                                                   info=info))
    return endpoints
Exemple #6
0
def select_service_endpoints(service_name, service_type, services):
    endpoints = []

    for catalog in services:

        if service_name and catalog["name"] != service_name:
            continue

        if service_type and catalog["type"] != service_type:
            continue

        for endpoint in catalog["endpoints"]:
            if endpoint["interface"] == 'public':
                endpoints.append(enp.Endpoint(None, endpoint, loaded=True))

    return endpoints
Exemple #7
0
class KeystoneModulePatch(unit.PatchFixture):

    client = object()
    endpoint = endpoints.Endpoint(manager=None,
                                  info={'url': 'http://some/endpoint'})
    session = None
    name = None

    def setup_fixture(self):
        module = inspect.getmodule(octavia.OctaviaClientFixture)
        self.patch(module, 'keystone', self)

    def get_keystone_client(self, session):
        self.session = session
        return self.client

    def find_service_endpoint(self, name, client):
        self.name = name
        assert self.client is client
        return self.endpoint