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
This commit is contained in:
Masahito Muroi 2017-11-17 18:44:28 +09:00 committed by Pierre Riteau
parent 774b519342
commit 06424f8e07
5 changed files with 63 additions and 9 deletions

51
blazar/api/wsgi_app.py Normal file
View File

@ -0,0 +1,51 @@
# 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

View File

@ -36,19 +36,12 @@ opts = [
help='Port that will be used to listen on'),
]
api_opts = [
cfg.BoolOpt('enable_v1_api',
default=True,
help='Deploy the v1 API.'),
]
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
CONF.register_cli_opts(opts)
CONF.register_opts(api_opts)
CONF.import_opt('host', 'blazar.config')
CONF.import_opt('enable_v1_api', 'blazar.config')
def main():

View File

@ -66,7 +66,14 @@ os_opts = [
help='A domain name the os_admin_project_name belongs to')
]
api_opts = [
cfg.BoolOpt('enable_v1_api',
default=True,
help='Deploy the v1 API.'),
]
CONF = cfg.CONF
CONF.register_cli_opts(cli_opts)
CONF.register_opts(os_opts)
CONF.register_opts(api_opts)
logging.register_options(cfg.CONF)

View File

@ -32,8 +32,8 @@ def list_opts():
('DEFAULT',
itertools.chain(
blazar.api.v2.app.auth_opts,
blazar.cmd.api.api_opts,
blazar.cmd.api.opts,
blazar.config.api_opts,
blazar.config.cli_opts,
blazar.config.os_opts,
blazar.db.base.db_driver_opts,

View File

@ -55,6 +55,9 @@ blazar.api.v2.controllers.extensions =
oslo.config.opts =
blazar = blazar.opts:list_opts
wsgi_scripts =
blazar-api-wsgi = blazar.api.wsgi_app:init_app
[build_sphinx]
all_files = 1
build-dir = doc/build