Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
# Copyright 2018 TrilioData Inc.
# All Rights Reserved.

"""WSGI application initialization for Nova APIs."""

import os

from oslo_config import cfg
from oslo_log import log as logging
from oslo_service import _options as service_opts
from paste import deploy

from dmapi import config
from dmapi import context
from dmapi import exception
from dmapi import objects
from dmapi import service
from dmapi import utils

CONF = cfg.CONF

CONFIG_FILES = ['api-paste.ini', 'triliovault-datamover-api.conf']

utils.monkey_patch()
objects.register_all()


def _get_config_files(env=None):
    if env is None:
        env = os.environ
    dirname = env.get('OS_DMAPI_CONFIG_DIR', '/etc/triliovault-datamover').strip()
    return [os.path.join(dirname, config_file)
            for config_file in CONFIG_FILES]


def error_application(exc, name):
    # TODO(cdent): make this something other than a stub
    def application(environ, start_response):
        start_response('500 Internal Server Error', [
            ('Content-Type', 'text/plain; charset=UTF-8')])
        return ['Out of date %s service %s\n' % (name, exc)]
    return application


def init_application(name):
    conf_files = _get_config_files()
    config.parse_args([], default_config_files=conf_files)

    logging.setup(CONF, "dmapi")

    service.setup_profiler(name, CONF.host)

    # dump conf at debug (log_options option comes from oslo.service)
    # FIXME(mriedem): This is gross but we don't have a public hook into
    # oslo.service to register these options, so we are doing it manually for
    # now; remove this when we have a hook method into oslo.service.
    CONF.register_opts(service_opts.service_opts)
    if CONF.log_options:
        CONF.log_opt_values(
            logging.getLogger(__name__),
            logging.DEBUG)

    conf = conf_files[0]

    return deploy.loadapp('config:%s' % conf, name=name)