From d957bfb9f137610d6f28ec3f63d85a5584a2ba62 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Tue, 30 Aug 2016 21:05:06 -0400 Subject: [PATCH] create placement API wsgi entry point We want a wsgi_script as the entry point for our placement API actually getting run, this is wrapping in the smooth and mellow pbr patterns that make it sensible to also run just by starting it on the command line. This also actually initializes the logging subsystem for the placement API, and does the standard pattern of dumping the configuration if DEBUG is enabled. Pieces of this were cribbed/inspired by equivalent keystone code. The config directory is now setable via environment, which may be be needed by folks with venvs. Change-Id: I00d032554de273d7493cfb467f81687c08fd5389 --- nova/api/openstack/placement/wsgi.py | 65 ++++++++++++++++++++++++++++ setup.cfg | 2 + 2 files changed, 67 insertions(+) create mode 100644 nova/api/openstack/placement/wsgi.py diff --git a/nova/api/openstack/placement/wsgi.py b/nova/api/openstack/placement/wsgi.py new file mode 100644 index 000000000000..7593831e1fcd --- /dev/null +++ b/nova/api/openstack/placement/wsgi.py @@ -0,0 +1,65 @@ +# 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. +"""WSGI script for Placement API + +WSGI handler for running Placement API under Apache2, nginx, gunicorn etc. +""" + +import logging as py_logging +import os +import os.path + +from nova.api.openstack.placement import deploy +from nova import conf +from nova import config + +from oslo_log import log as logging + +CONFIG_FILE = 'nova.conf' + + +def setup_logging(config): + # Any dependent libraries that have unhelp debug levels should be + # pinned to a higher default. + extra_log_level_defaults = [ + 'routes=INFO', + ] + logging.set_defaults(default_log_levels=logging.get_default_log_levels() + + extra_log_level_defaults) + logging.setup(config, 'nova') + py_logging.captureWarnings(True) + + +def _get_config_file(env=None): + if env is None: + env = os.environ + + dirname = env.get('OS_PLACEMENT_CONFIG_DIR', '/etc/nova').strip() + return os.path.join(dirname, CONFIG_FILE) + + +def init_application(): + # initialize the config system + conffile = _get_config_file() + config.parse_args([], default_config_files=[conffile]) + + # initialize the logging system + setup_logging(conf.CONF) + + # dump conf if we're at debug + if conf.CONF.debug: + conf.CONF.log_opt_values( + logging.getLogger(__name__), + logging.DEBUG) + + # build our paste app and return it for wsgi goodness + return deploy.loadapp(conf.CONF) diff --git a/setup.cfg b/setup.cfg index 17c1304faf90..129956730d7d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -68,6 +68,8 @@ console_scripts = nova-serialproxy = nova.cmd.serialproxy:main nova-spicehtml5proxy = nova.cmd.spicehtml5proxy:main nova-xvpvncproxy = nova.cmd.xvpvncproxy:main +wsgi_scripts = + nova-placement-api = nova.api.openstack.placement.wsgi:init_application nova.api.v21.extensions = admin_actions = nova.api.openstack.compute.admin_actions:AdminActions