Пример #1
0
class TricircleException(Exception):
    """Base Tricircle Exception.

    To correctly use this class, inherit from it and define
    a 'message' property. That message will get printf'd
    with the keyword arguments provided to the constructor.
    """
    message = _("An unknown exception occurred.")

    def __init__(self, **kwargs):
        try:
            super(TricircleException, self).__init__(self.message % kwargs)
            self.msg = self.message % kwargs
        except Exception:
            with excutils.save_and_reraise_exception() as ctxt:
                if not self.use_fatal_exceptions():
                    ctxt.reraise = False
                    # at least get the core message out if something happened
                    super(TricircleException, self).__init__(self.message)

    if six.PY2:

        def __unicode__(self):
            return unicode(self.msg)

    def use_fatal_exceptions(self):
        return False
Пример #2
0
def load_paste_app(app_name):
    """Builds and returns a WSGI app from a paste config file.

    :param app_name: Name of the application to load
    :raises ConfigFilesNotFoundError when config file cannot be located
    :raises RuntimeError when application cannot be loaded from config file
    """

    config_path = cfg.CONF.find_file(cfg.CONF.api_paste_config)
    if not config_path:
        raise cfg.ConfigFilesNotFoundError(
            config_files=[cfg.CONF.api_paste_config])
    config_path = os.path.abspath(config_path)
    LOG.info(_LI("Config paste file: %s"), config_path)

    try:
        app = deploy.loadapp("config:%s" % config_path, name=app_name)
    except (LookupError, ImportError):
        msg = (_("Unable to load %(app_name)s from "
                 "configuration file %(config_path)s.") % {
                     'app_name': app_name,
                     'config_path': config_path
                 })
        LOG.exception(msg)
        raise RuntimeError(msg)
    return app
Пример #3
0
def load_paste_app(app_name):
    """Builds and returns a WSGI app from a paste config file.

    :param app_name: Name of the application to load
    :raises ConfigFilesNotFoundError when config file cannot be located
    :raises RuntimeError when application cannot be loaded from config file
    """

    config_path = cfg.CONF.find_file(cfg.CONF.api_paste_config)
    if not config_path:
        raise cfg.ConfigFilesNotFoundError(
            config_files=[cfg.CONF.api_paste_config])
    config_path = os.path.abspath(config_path)
    LOG.info(_LI("Config paste file: %s"), config_path)

    try:
        app = deploy.loadapp("config:%s" % config_path, name=app_name)
    except (LookupError, ImportError):
        msg = (_("Unable to load %(app_name)s from "
                 "configuration file %(config_path)s.") %
               {'app_name': app_name,
                'config_path': config_path})
        LOG.exception(msg)
        raise RuntimeError(msg)
    return app
Пример #4
0
from oslo_config import cfg
from oslo_log import log as logging
from paste import deploy

from tricircle.i18n import _
from tricircle.i18n import _LI

# from tricircle import policy
from tricircle import version

LOG = logging.getLogger(__name__)

common_opts = [
    cfg.StrOpt('bind_host',
               default='0.0.0.0',
               help=_("The host IP to bind to")),
    cfg.IntOpt('bind_port', default=19999, help=_("The port to bind to")),
    cfg.IntOpt('api_workers', default=1, help=_("number of api workers")),
    cfg.StrOpt('api_paste_config',
               default="api-paste.ini",
               help=_("The API paste config file to use")),
    cfg.StrOpt('api_extensions_path',
               default="",
               help=_("The path for API extensions")),
    cfg.StrOpt('auth_strategy',
               default='keystone',
               help=_("The type of authentication to use")),
    cfg.BoolOpt('allow_bulk',
                default=True,
                help=_("Allow the usage of the bulk API")),
    cfg.BoolOpt('allow_pagination',
Пример #5
0
from oslo_config import cfg
from oslo_log import log as logging
from paste import deploy

from tricircle.i18n import _
from tricircle.i18n import _LI

# from tricircle import policy
from tricircle import version


LOG = logging.getLogger(__name__)

common_opts = [
    cfg.StrOpt('bind_host', default='0.0.0.0',
               help=_("The host IP to bind to")),
    cfg.IntOpt('bind_port', default=19999,
               help=_("The port to bind to")),
    cfg.IntOpt('api_workers', default=1,
               help=_("number of api workers")),
    cfg.StrOpt('api_paste_config', default="api-paste.ini",
               help=_("The API paste config file to use")),
    cfg.StrOpt('api_extensions_path', default="",
               help=_("The path for API extensions")),
    cfg.StrOpt('auth_strategy', default='keystone',
               help=_("The type of authentication to use")),
    cfg.BoolOpt('allow_bulk', default=True,
                help=_("Allow the usage of the bulk API")),
    cfg.BoolOpt('allow_pagination', default=False,
                help=_("Allow the usage of the pagination")),
    cfg.BoolOpt('allow_sorting', default=False,
Пример #6
0
class InvalidConfigurationOption(TricircleException):
    message = _("An invalid value was provided for %(opt_name)s: "
                "%(opt_value)s")
Пример #7
0
class InUse(TricircleException):
    message = _("The resource is inuse")
Пример #8
0
class AdminRequired(NotAuthorized):
    message = _("User does not have admin privileges: %(reason)s")
Пример #9
0
class ServiceUnavailable(TricircleException):
    message = _("The service is unavailable")
Пример #10
0
class NotAuthorized(TricircleException):
    message = _("Not authorized.")
Пример #11
0
class BadRequest(TricircleException):
    message = _('Bad %(resource)s request: %(msg)s')