예제 #1
0
파일: rpc.py 프로젝트: docstack/glance
    def do_request(self, method, **kwargs):
        """
        Simple do_request override. This method serializes
        the outgoing body and builds the command that will
        be sent.

        :params method: The remote python method to call
        :params kwargs: Dynamic parameters that will be
            passed to the remote method.
        """
        content = self.bulk_request([{'command': method,
                                      'kwargs': kwargs}])

        # NOTE(flaper87): Return the first result if
        # a single command was executed.
        content = content[0]

        # NOTE(flaper87): Check if content is an error
        # and re-raise it if raise_exc is True. Before
        # checking if content contains the '_error' key,
        # verify if it is an instance of dict - since the
        # RPC call may have returned something different.
        if self.raise_exc and (isinstance(content, dict)
                               and '_error' in content):
            error = content['_error']
            try:
                exc_cls = imp.import_class(error['cls'])
                raise exc_cls(error['val'])
            except ImportError:
                # NOTE(flaper87): The exception
                # class couldn't be imported, using
                # a generic exception.
                raise exception.RPCError(**error)
        return content
예제 #2
0
파일: rpc.py 프로젝트: onodes/glance
    def do_request(self, method, **kwargs):
        """
        Simple do_request override. This method serializes
        the outgoing body and builds the command that will
        be sent.

        :params method: The remote python method to call
        :params kwargs: Dynamic parameters that will be
            passed to the remote method.
        """
        content = self.bulk_request([{'command': method, 'kwargs': kwargs}])

        # NOTE(flaper87): Return the first result if
        # a single command was executed.
        content = content[0]

        # NOTE(flaper87): Check if content is an error
        # and re-raise it if raise_exc is True. Before
        # checking if content contains the '_error' key,
        # verify if it is an instance of dict - since the
        # RPC call may have returned something different.
        if self.raise_exc and (isinstance(content, dict)
                               and '_error' in content):
            error = content['_error']
            try:
                exc_cls = imp.import_class(error['cls'])
                raise exc_cls(error['val'])
            except ImportError:
                # NOTE(flaper87): The exception
                # class couldn't be imported, using
                # a generic exception.
                raise exception.RPCError(**error)
        return content
예제 #3
0
파일: rpc.py 프로젝트: brandon-adams/glance
    def do_request(self, method, **kwargs):
        """
        Simple do_request override. This method serializes
        the outgoing body and builds the command that will
        be sent.

        :params method: The remote python method to call
        :params kwargs: Dynamic parameters that will be
            passed to the remote method.
        """
        content = self.bulk_request([{'command': method,
                                      'kwargs': kwargs}])

        # NOTE(flaper87): Return the first result if
        # a single command was executed.
        content = content[0]
        if self.raise_exc and (content and '_error' in content):
            error = content['_error']
            try:
                exc_cls = imp.import_class(error['cls'])
                raise exc_cls(error['val'])
            except ImportError:
                # NOTE(flaper87): The exception
                # class couldn't be imported, using
                # a generic exception.
                raise exception.RPCError(**error)
        return content
예제 #4
0
    def do_request(self, method, **kwargs):
        """
        Simple do_request override. This method serializes
        the outgoing body and builds the command that will
        be sent.

        :params method: The remote python method to call
        :params kwargs: Dynamic parameters that will be
            passed to the remote method.
        """
        content = self.bulk_request([{'command': method,
                                      'kwargs': kwargs}])

        # NOTE(flaper87): Return the first result if
        # a single command was executed.
        content = content[0]
        if self.raise_exc and (content and '_error' in content):
            error = content['_error']
            try:
                exc_cls = imp.import_class(error['cls'])
                raise exc_cls(error['val'])
            except ImportError:
                # NOTE(flaper87): The exception
                # class couldn't be imported, using
                # a generic exception.
                raise exception.RPCError(**error)
        return content
예제 #5
0
파일: __init__.py 프로젝트: brk3/glance
def _get_store_class(store_entry):
    store_cls = None
    try:
        LOG.debug("Attempting to import store %s", store_entry)
        store_cls = importutils.import_class(store_entry)
    except exception.NotFound:
        raise BackendException("Unable to load store. " "Could not find a class named %s." % store_entry)
    return store_cls
예제 #6
0
    def init_driver(self):
        """
        Create the driver for the cache
        """
        driver_name = CONF.image_cache_driver
        driver_module = __name__ + ".drivers." + driver_name + ".Driver"
        try:
            self.driver_class = importutils.import_class(driver_module)
            LOG.info(_("Image cache loaded driver '%s'.") % driver_name)
        except ImportError, import_err:
            LOG.warn(
                _("Image cache driver " "'%(driver_name)s' failed to load. " "Got error: '%(import_err)s.") % locals()
            )

            driver_module = __name__ + ".drivers.sqlite.Driver"
            LOG.info(_("Defaulting to SQLite driver."))
            self.driver_class = importutils.import_class(driver_module)
예제 #7
0
파일: base.py 프로젝트: home-dog/glance
 def get_store_location_class(self):
     """
     Returns the store location class that is used by this store.
     """
     if not self.store_location_class:
         class_name = "%s.StoreLocation" % (self.__module__)
         LOG.debug("Late loading location class %s", class_name)
         self.store_location_class = importutils.import_class(class_name)
     return self.store_location_class
예제 #8
0
 def get_store_location_class(self):
     """
     Returns the store location class that is used by this store.
     """
     if not self.store_location_class:
         class_name = "%s.StoreLocation" % (self.__module__)
         LOG.debug("Late loading location class %s", class_name)
         self.store_location_class = importutils.import_class(class_name)
     return self.store_location_class
예제 #9
0
파일: __init__.py 프로젝트: mindpool/glance
    def init_driver(self):
        """
        Create the driver for the cache
        """
        driver_name = CONF.image_cache_driver
        driver_module = (__name__ + '.drivers.' + driver_name + '.Driver')
        try:
            self.driver_class = importutils.import_class(driver_module)
            LOG.info(_("Image cache loaded driver '%s'.") % driver_name)
        except ImportError, import_err:
            LOG.warn(
                _("Image cache driver "
                  "'%(driver_name)s' failed to load. "
                  "Got error: '%(import_err)s.") % locals())

            driver_module = __name__ + '.drivers.sqlite.Driver'
            LOG.info(_("Defaulting to SQLite driver."))
            self.driver_class = importutils.import_class(driver_module)
예제 #10
0
def _get_store_class(store_entry):
    store_cls = None
    try:
        LOG.debug("Attempting to import store %s", store_entry)
        store_cls = importutils.import_class(store_entry)
    except exception.NotFound:
        raise BackendException('Unable to load store. '
                               'Could not find a class named %s.' %
                               store_entry)
    return store_cls
예제 #11
0
파일: __init__.py 프로젝트: cloudbau/glance
    def init_driver(self):
        """
        Create the driver for the cache
        """
        driver_name = CONF.image_cache_driver
        driver_module = (__name__ + '.drivers.' + driver_name + '.Driver')
        try:
            self.driver_class = importutils.import_class(driver_module)
            LOG.info(_("Image cache loaded driver '%s'.") %
                     driver_name)
        except ImportError as import_err:
            LOG.warn(_("Image cache driver "
                       "'%(driver_name)s' failed to load. "
                       "Got error: '%(import_err)s."),
                     {'driver_name': driver_name,
                      'import_err': import_err})

            driver_module = __name__ + '.drivers.sqlite.Driver'
            LOG.info(_("Defaulting to SQLite driver."))
            self.driver_class = importutils.import_class(driver_module)
        self.configure_driver()
예제 #12
0
파일: __init__.py 프로젝트: onodes/glance
 def new_task_executor(self, context):
     try:
         executor_cls = ('glance.async.%s_executor.'
                         'TaskExecutor' % CONF.task.task_executor)
         LOG.debug("Loading %s executor" % CONF.task.task_executor)
         executor = importutils.import_class(executor_cls)
         return executor(context,
                         self.task_repo,
                         self.image_repo,
                         self.image_factory)
     except ImportError:
         with excutils.save_and_reraise_exception():
             LOG.exception(_LE("Failed to load the %s executor provided "
                               "in the config.") % CONF.task.task_executor)
예제 #13
0
파일: __init__.py 프로젝트: markwash/glance
    def __init__(self, strategy=None):
        _strategy = CONF.notifier_strategy
        try:
            strategy = _STRATEGY_ALIASES[_strategy]
            msg = _('Converted strategy alias %s to %s')
            LOG.debug(msg % (_strategy, strategy))
        except KeyError:
            strategy = _strategy
            LOG.debug(_('No strategy alias found for %s') % strategy)

        try:
            strategy_class = importutils.import_class(strategy)
        except ImportError:
            raise exception.InvalidNotifierStrategy(strategy=strategy)
        else:
            self.strategy = strategy_class()
예제 #14
0
    def __init__(self, strategy=None):
        _strategy = CONF.notifier_strategy
        try:
            strategy = _STRATEGY_ALIASES[_strategy]
            msg = _('Converted strategy alias %s to %s')
            LOG.debug(msg % (_strategy, strategy))
        except KeyError:
            strategy = _strategy
            LOG.debug(_('No strategy alias found for %s') % strategy)

        try:
            strategy_class = importutils.import_class(strategy)
        except ImportError:
            raise exception.InvalidNotifierStrategy(strategy=strategy)
        else:
            self.strategy = strategy_class()
예제 #15
0
 def configure_driver(self):
     """
     Configure the driver for the cache and, if it fails to configure,
     fall back to using the SQLite driver which has no odd dependencies
     """
     try:
         self.driver = self.driver_class()
         self.driver.configure()
     except exception.BadDriverConfiguration, config_err:
         driver_module = self.driver_class.__module__
         LOG.warn(_("Image cache driver "
                    "'%(driver_module)s' failed to configure. "
                    "Got error: '%(config_err)s") % locals())
         LOG.info(_("Defaulting to SQLite driver."))
         default_module = __name__ + '.drivers.sqlite.Driver'
         self.driver_class = importutils.import_class(default_module)
         self.driver = self.driver_class()
         self.driver.configure()
예제 #16
0
 def configure_driver(self):
     """
     Configure the driver for the cache and, if it fails to configure,
     fall back to using the SQLite driver which has no odd dependencies
     """
     try:
         self.driver = self.driver_class()
         self.driver.configure()
     except exception.BadDriverConfiguration, config_err:
         driver_module = self.driver_class.__module__
         LOG.warn(_("Image cache driver "
                    "'%(driver_module)s' failed to configure. "
                    "Got error: '%(config_err)s") % locals())
         LOG.info(_("Defaulting to SQLite driver."))
         default_module = __name__ + '.drivers.sqlite.Driver'
         self.driver_class = importutils.import_class(default_module)
         self.driver = self.driver_class()
         self.driver.configure()