コード例 #1
0
ファイル: __init__.py プロジェクト: varunarya10/ironic
def _get_impl():
    """Delay import of rpc_backend until configuration is loaded."""
    global _RPCIMPL
    if _RPCIMPL is None:
        try:
            _RPCIMPL = importutils.import_module(CONF.rpc_backend)
        except ImportError:
            # For backwards compatibility with older nova config.
            impl = CONF.rpc_backend.replace('nova.rpc',
                                            'nova.openstack.common.rpc')
            _RPCIMPL = importutils.import_module(impl)
    return _RPCIMPL
コード例 #2
0
ファイル: __init__.py プロジェクト: PeterMartini/ironic
def _get_impl():
    """Delay import of rpc_backend until configuration is loaded."""
    global _RPCIMPL
    if _RPCIMPL is None:
        try:
            _RPCIMPL = importutils.import_module(CONF.rpc_backend)
        except ImportError:
            # For backwards compatibility with older nova config.
            impl = CONF.rpc_backend.replace('nova.rpc',
                                            'nova.openstack.common.rpc')
            _RPCIMPL = importutils.import_module(impl)
    return _RPCIMPL
コード例 #3
0
ファイル: service.py プロジェクト: deniscostadsc/ironic
 def __init__(self, host, manager_module, manager_class):
     super(RPCService, self).__init__()
     self.host = host
     manager_module = importutils.import_module(manager_module)
     manager_class = getattr(manager_module, manager_class)
     self.manager = manager_class(host, manager_module.MANAGER_TOPIC)
     self.topic = self.manager.topic
     self.rpcserver = None
コード例 #4
0
 def _load_backend(self):
     with self._lock:
         if not self._backend:
             # Import the untranslated name if we don't have a mapping
             backend_path = self._backend_mapping.get(self._backend_name,
                                                      self._backend_name)
             backend_mod = importutils.import_module(backend_path)
             self._backend = backend_mod.get_backend()
コード例 #5
0
 def __init__(self, host, manager_module, manager_class):
     super(RPCService, self).__init__()
     self.host = host
     manager_module = importutils.import_module(manager_module)
     manager_class = getattr(manager_module, manager_class)
     self.manager = manager_class(host, manager_module.MANAGER_TOPIC)
     self.topic = self.manager.topic
     self.rpcserver = None
コード例 #6
0
ファイル: generator.py プロジェクト: zaletniy/ironic
def _import_module(mod_str):
    try:
        if mod_str.startswith('bin.'):
            imp.load_source(mod_str[4:], os.path.join('bin', mod_str[4:]))
            return sys.modules[mod_str[4:]]
        else:
            return importutils.import_module(mod_str)
    except Exception as e:
        sys.stderr.write("Error importing module %s: %s\n" % (mod_str, str(e)))
        return None
コード例 #7
0
ファイル: generator.py プロジェクト: COSHPC/ironic
def _import_module(mod_str):
    try:
        if mod_str.startswith('bin.'):
            imp.load_source(mod_str[4:], os.path.join('bin', mod_str[4:]))
            return sys.modules[mod_str[4:]]
        else:
            return importutils.import_module(mod_str)
    except Exception as e:
        sys.stderr.write("Error importing module %s: %s\n" % (mod_str, str(e)))
        return None
コード例 #8
0
ファイル: generator.py プロジェクト: mydaisy2/ironic
def _import_module(mod_str):
    try:
        if mod_str.startswith('bin.'):
            imp.load_source(mod_str[4:], os.path.join('bin', mod_str[4:]))
            return sys.modules[mod_str[4:]]
        else:
            return importutils.import_module(mod_str)
    except ImportError as ie:
        sys.stderr.write("%s\n" % str(ie))
        return None
    except Exception:
        return None
コード例 #9
0
ファイル: generator.py プロジェクト: AsylumCorp/ironic
def _import_module(mod_str):
    try:
        if mod_str.startswith('bin.'):
            imp.load_source(mod_str[4:], os.path.join('bin', mod_str[4:]))
            return sys.modules[mod_str[4:]]
        else:
            return importutils.import_module(mod_str)
    except ImportError as ie:
        sys.stderr.write("%s\n" % str(ie))
        return None
    except Exception:
        return None
コード例 #10
0
ファイル: api.py プロジェクト: Haomeng/ironic
def _get_drivers():
    """Instantiate, cache, and return drivers based on the CONF."""
    global _drivers
    if _drivers is None:
        _drivers = {}
        for notification_driver in CONF.notification_driver:
            try:
                driver = importutils.import_module(notification_driver)
                _drivers[notification_driver] = driver
            except ImportError:
                LOG.exception(_("Failed to load notifier %s. "
                                "These notifications will not be sent.") %
                              notification_driver)
    return _drivers.values()
コード例 #11
0
def _get_drivers():
    """Instantiate, cache, and return drivers based on the CONF."""
    global _drivers
    if _drivers is None:
        _drivers = {}
        for notification_driver in CONF.notification_driver:
            try:
                driver = importutils.import_module(notification_driver)
                _drivers[notification_driver] = driver
            except ImportError:
                LOG.exception(
                    _("Failed to load notifier %s. "
                      "These notifications will not be sent.") %
                    notification_driver)
    return _drivers.values()
コード例 #12
0
ファイル: api.py プロジェクト: epim/ironic
def add_driver(notification_driver):
    """Add a notification driver at runtime."""
    # Make sure the driver list is initialized.
    _get_drivers()
    if isinstance(notification_driver, basestring):
        # Load and add
        try:
            driver = importutils.import_module(notification_driver)
            _drivers[notification_driver] = driver
        except ImportError:
            LOG.exception(
                _("Failed to load notifier %s. " "These notifications will not be sent.") % notification_driver
            )
    else:
        # Driver is already loaded; just add the object.
        _drivers[notification_driver] = notification_driver
コード例 #13
0
ファイル: api.py プロジェクト: schatt/ironic
def add_driver(notification_driver):
    """Add a notification driver at runtime."""
    # Make sure the driver list is initialized.
    _get_drivers()
    if isinstance(notification_driver, basestring):
        # Load and add
        try:
            driver = importutils.import_module(notification_driver)
            _drivers[notification_driver] = driver
        except ImportError:
            LOG.exception(
                _("Failed to load notifier %s. "
                  "These notifications will not be sent.") %
                notification_driver)
    else:
        # Driver is already loaded; just add the object.
        _drivers[notification_driver] = notification_driver
コード例 #14
0
ファイル: common.py プロジェクト: varunarya10/ironic
def deserialize_remote_exception(conf, data):
    failure = jsonutils.loads(str(data))

    trace = failure.get('tb', [])
    message = failure.get('message', "") + "\n" + "\n".join(trace)
    name = failure.get('class')
    module = failure.get('module')

    # NOTE(ameade): We DO NOT want to allow just any module to be imported, in
    # order to prevent arbitrary code execution.
    if module not in conf.allowed_rpc_exception_modules:
        return RemoteError(name, failure.get('message'), trace)

    try:
        mod = importutils.import_module(module)
        klass = getattr(mod, name)
        if not issubclass(klass, Exception):
            raise TypeError("Can only deserialize Exceptions")

        failure = klass(*failure.get('args', []), **failure.get('kwargs', {}))
    except (AttributeError, TypeError, ImportError):
        return RemoteError(name, failure.get('message'), trace)

    ex_type = type(failure)
    str_override = lambda self: message
    new_ex_type = type(ex_type.__name__ + _REMOTE_POSTFIX, (ex_type, ), {
        '__str__': str_override,
        '__unicode__': str_override
    })
    new_ex_type.__module__ = '%s%s' % (module, _REMOTE_POSTFIX)
    try:
        # NOTE(ameade): Dynamically create a new exception type and swap it in
        # as the new type for the exception. This only works on user defined
        # Exceptions and not core python exceptions. This is important because
        # we cannot necessarily change an exception message so we must override
        # the __str__ method.
        failure.__class__ = new_ex_type
    except TypeError:
        # NOTE(ameade): If a core exception then just add the traceback to the
        # first exception argument.
        failure.args = (message, ) + failure.args[1:]
    return failure
コード例 #15
0
ファイル: common.py プロジェクト: rahulgopan/ironic
def deserialize_remote_exception(conf, data):
    failure = jsonutils.loads(str(data))

    trace = failure.get("tb", [])
    message = failure.get("message", "") + "\n" + "\n".join(trace)
    name = failure.get("class")
    module = failure.get("module")

    # NOTE(ameade): We DO NOT want to allow just any module to be imported, in
    # order to prevent arbitrary code execution.
    if module not in conf.allowed_rpc_exception_modules:
        return RemoteError(name, failure.get("message"), trace)

    try:
        mod = importutils.import_module(module)
        klass = getattr(mod, name)
        if not issubclass(klass, Exception):
            raise TypeError("Can only deserialize Exceptions")

        failure = klass(*failure.get("args", []), **failure.get("kwargs", {}))
    except (AttributeError, TypeError, ImportError):
        return RemoteError(name, failure.get("message"), trace)

    ex_type = type(failure)
    str_override = lambda self: message
    new_ex_type = type(
        ex_type.__name__ + _REMOTE_POSTFIX, (ex_type,), {"__str__": str_override, "__unicode__": str_override}
    )
    new_ex_type.__module__ = "%s%s" % (module, _REMOTE_POSTFIX)
    try:
        # NOTE(ameade): Dynamically create a new exception type and swap it in
        # as the new type for the exception. This only works on user defined
        # Exceptions and not core python exceptions. This is important because
        # we cannot necessarily change an exception message so we must override
        # the __str__ method.
        failure.__class__ = new_ex_type
    except TypeError:
        # NOTE(ameade): If a core exception then just add the traceback to the
        # first exception argument.
        failure.args = (message,) + failure.args[1:]
    return failure
コード例 #16
0
 def __get_backend(self):
     """Get the actual backend.  May be a module or an instance of
     a class.  Doesn't matter to us.  We do this synchronized as it's
     possible multiple greenthreads started very quickly trying to do
     DB calls and eventlet can switch threads before self.__backend gets
     assigned.
     """
     if self.__backend:
         # Another thread assigned it
         return self.__backend
     backend_name = CONF.db_backend
     self.__use_tpool = CONF.dbapi_use_tpool
     if self.__use_tpool:
         from eventlet import tpool
         self.__tpool = tpool
     # Import the untranslated name if we don't have a
     # mapping.
     backend_path = self.__backend_mapping.get(backend_name, backend_name)
     backend_mod = importutils.import_module(backend_path)
     self.__backend = backend_mod.get_backend()
     return self.__backend
コード例 #17
0
ファイル: api.py プロジェクト: anbangr/ironic
 def __get_backend(self):
     """Get the actual backend.  May be a module or an instance of
     a class.  Doesn't matter to us.  We do this synchronized as it's
     possible multiple greenthreads started very quickly trying to do
     DB calls and eventlet can switch threads before self.__backend gets
     assigned.
     """
     if self.__backend:
         # Another thread assigned it
         return self.__backend
     backend_name = CONF.db_backend
     self.__use_tpool = CONF.dbapi_use_tpool
     if self.__use_tpool:
         from eventlet import tpool
         self.__tpool = tpool
     # Import the untranslated name if we don't have a
     # mapping.
     backend_path = self.__backend_mapping.get(backend_name,
                                               backend_name)
     backend_mod = importutils.import_module(backend_path)
     self.__backend = backend_mod.get_backend()
     return self.__backend
コード例 #18
0
def import_versioned_module(version, submodule=None):
    module = 'ironic.common.glance_service.v%s' % version
    if submodule:
        module = '.'.join((module, submodule))
    return importutils.import_module(module)
コード例 #19
0
ファイル: image_service.py プロジェクト: Haomeng/ironic
def import_versioned_module(version, submodule=None):
    module = 'ironic.common.glance_service.v%s' % version
    if submodule:
        module = '.'.join((module, submodule))
    return importutils.import_module(module)
コード例 #20
0
ファイル: service.py プロジェクト: PeterMartini/ironic
def load_manager(manager_modulename, manager_classname, host):
    manager_module = importutils.import_module(manager_modulename)
    manager_class = getattr(manager_module, manager_classname)
    return manager_class(host, manager_module.MANAGER_TOPIC)
コード例 #21
0
def load_manager(manager_modulename, manager_classname, host):
    manager_module = importutils.import_module(manager_modulename)
    manager_class = getattr(manager_module, manager_classname)
    return manager_class(host, manager_module.MANAGER_TOPIC)