예제 #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')