Exemplo n.º 1
0
def _get_client(service_key):
    class_mapping = constructors.get_constructor_mapping()
    if service_key not in class_mapping:
        raise exceptions.OpenStackConfigException(
            "Service {service_key} is unkown. Please pass in a client"
            " constructor or submit a patch to os-client-config".format(
                service_key=service_key))
    mod_name, ctr_name = class_mapping[service_key].rsplit('.', 1)
    lib_name = mod_name.split('.')[0]
    try:
        mod = importlib.import_module(mod_name)
    except ImportError:
        raise exceptions.OpenStackConfigException(
            "Client for '{service_key}' was requested, but"
            " {mod_name} was unable to be imported. Either import"
            " the module yourself and pass the constructor in as an argument,"
            " or perhaps you do not have python-{lib_name} installed.".format(
                service_key=service_key, mod_name=mod_name, lib_name=lib_name))
    try:
        ctr = getattr(mod, ctr_name)
    except AttributeError:
        raise exceptions.OpenStackConfigException(
            "Client for '{service_key}' was requested, but although"
            " {mod_name} imported fine, the constructor at {fullname}"
            " as not found. Please check your installation, we have no"
            " clue what is wrong with your computer.".format(
                service_key=service_key,
                mod_name=mod_name,
                fullname=class_mapping[service_key]))
    return ctr
def _get_client(service_key):
    class_mapping = constructors.get_constructor_mapping()
    if service_key not in class_mapping:
        raise exceptions.OpenStackConfigException(
            "Service {service_key} is unkown. Please pass in a client"
            " constructor or submit a patch to os-client-config".format(
                service_key=service_key))
    mod_name, ctr_name = class_mapping[service_key].rsplit('.', 1)
    lib_name = mod_name.split('.')[0]
    try:
        mod = importlib.import_module(mod_name)
    except ImportError:
        raise exceptions.OpenStackConfigException(
            "Client for '{service_key}' was requested, but"
            " {mod_name} was unable to be imported. Either import"
            " the module yourself and pass the constructor in as an argument,"
            " or perhaps you do not have python-{lib_name} installed.".format(
                service_key=service_key,
                mod_name=mod_name,
                lib_name=lib_name))
    try:
        ctr = getattr(mod, ctr_name)
    except AttributeError:
        raise exceptions.OpenStackConfigException(
            "Client for '{service_key}' was requested, but although"
            " {mod_name} imported fine, the constructor at {fullname}"
            " as not found. Please check your installation, we have no"
            " clue what is wrong with your computer.".format(
                service_key=service_key,
                mod_name=mod_name,
                fullname=class_mapping[service_key]))
    return ctr
Exemplo n.º 3
0
 def _create_legacy_client(
         self, client, service, deprecated=True,
         module_name=None, **kwargs):
     if client not in self._legacy_clients:
         if deprecated:
             self._deprecated_import_check(client)
         if module_name:
             constructors.get_constructor_mapping()[service] = module_name
         self._legacy_clients[client] = self._get_client(service, **kwargs)
     return self._legacy_clients[client]
Exemplo n.º 4
0
 def _create_legacy_client(
         self, client, service, deprecated=True,
         module_name=None, **kwargs):
     if client not in self._legacy_clients:
         if deprecated:
             self._deprecated_import_check(client)
         if module_name:
             constructors.get_constructor_mapping()[service] = module_name
         self._legacy_clients[client] = self._get_client(service, **kwargs)
     return self._legacy_clients[client]