blazar/blazar/api/wsgi_app.py
Masahito Muroi 06424f8e07 Enable uWSGI deployment of the blazar-api service
This patch adds a WSGI entry point to setup.cfg and enables users to
deploy the blazar-api service as a uWSGI service.

If operators want to deploy blazar-api under their own servers that
support WSGI applications, they can get the WSGI app by calling
blazar.api.wsgi_app.init_app().

If you need more details about WSGI itself, please see the following
link: https://www.python.org/dev/peps/pep-3333/

Patially Implements: blueprint deploy-api-in-wsgi
Change-Id: I1fb02c403c6e588e49fa455969895731b88e5dd7
2017-12-13 12:30:17 +00:00

52 lines
1.4 KiB
Python

# Copyright (c) 2017 NTT Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from oslo_config import cfg
from oslo_log import log as logging
from blazar.api import app as wsgi_app
from blazar.api.v2 import app as v2_app
from blazar.utils import service as service_utils
CONF = cfg.CONF
CONF.import_opt('enable_v1_api', 'blazar.config')
logging.register_options(CONF)
CONFIG_FILES = ['blazar.conf']
def _get_config_files(env=None):
if env is None:
env = os.environ
dirname = env.get('OS_BLAZAR_CONFIG_DIR', '/etc/blazar').strip()
return [os.path.join(dirname, config_file)
for config_file in CONFIG_FILES]
def init_app():
config_files = _get_config_files()
CONF([], project='blazar', prog='blazar-api',
default_config_files=config_files)
service_utils.prepare_service()
if not CONF.enable_v1_api:
app = v2_app.make_app()
else:
app = wsgi_app.VersionSelectorApplication()
return app