Exemplo n.º 1
0
def get_client_class(api_name, version, version_map):
    """Returns the client class for the requested API version

    :param api_name: the name of the API, e.g. 'compute', 'image', etc
    :param version: the requested API version
    :param version_map: a dict of client classes keyed by version
    :rtype: a client class for the requested API version
    """
    try:
        client_path = version_map[str(version)]
    except (KeyError, ValueError):
        msg = "Invalid %s client version '%s'. must be one of: %s" % (
            (api_name, version, ', '.join(version_map.keys())))
        raise exceptions.UnsupportedVersion(msg)

    return import_class(client_path)
Exemplo n.º 2
0
def make_client(instance):
    """Returns a baremetal service client."""
    try:
        baremetal_client = ironic_client.get_client_class(
            instance._api_version[API_NAME])
    except Exception:
        msg = (_("Invalid %(api_name)s client version '%(ver)s'. Must be one "
                 "of %(supported_ver)s") % {
                     'api_name': API_NAME,
                     'ver': instance._api_version[API_NAME],
                     'supported_ver': ", ".join(sorted(API_VERSIONS))
                 })
        raise exceptions.UnsupportedVersion(msg)
    LOG.debug('Instantiating baremetal client: %s', baremetal_client)

    client = baremetal_client(
        os_ironic_api_version=instance._api_version[API_NAME],
        session=instance.session,
        region_name=instance._region_name,
        endpoint=instance.auth_ref.auth_url,
    )

    return client