Example #1
0
def get_client_class(version):
    version_map = {
        '1.0': 'saharaclient.api.client.Client',
        '1.1': 'saharaclient.api.client.Client',
    }
    try:
        client_path = version_map[str(version)]
    except (KeyError, ValueError):
        supported_versions = ''.join(version_map.keys())
        msg = ("Invalid client version '%(version)s'; must be one of: "
               "%(versions)s") % {'version': version,
                                  'versions': supported_versions}
        raise UnsupportedVersion(msg)

    return importutils.import_class(client_path)
    def get_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 importutils.import_class(client_path)
Example #3
0
def get_client_class(version):
    version_map = {
        '1.0': 'saharaclient.api.client.Client',
        '1.1': 'saharaclient.api.client.Client',
    }
    try:
        client_path = version_map[str(version)]
    except (KeyError, ValueError):
        supported_versions = ''.join(version_map.keys())
        msg = ("Invalid client version '%(version)s'; must be one of: "
               "%(versions)s") % {
                   'version': version,
                   'versions': supported_versions
               }
        raise UnsupportedVersion(msg)

    return importutils.import_class(client_path)