zun/higgins/api/app.py
Hongbin Lu 0dad325f56 Add a config to tune the number of api workers
The default number of workers is the number of CPU cores, which
might be too much for development setup.

Change-Id: I9495bcc83e40ff1b522c7f1c21e70d2afbdcbee6
2016-05-29 10:41:35 -05:00

72 lines
2.4 KiB
Python

# 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.
from oslo_config import cfg
from oslo_log import log
import pecan
from higgins.api import config as api_config
from higgins.api import middleware
from higgins.common.i18n import _
# Register options for the service
API_SERVICE_OPTS = [
cfg.PortOpt('port',
default=9512,
help='The port for the higgins API server.'),
cfg.IPOpt('host',
default='127.0.0.1',
help='The listen IP for the higgins API server.'),
cfg.BoolOpt('enable_ssl_api',
default=False,
help=_("Enable the integrated stand-alone API to service "
"requests via HTTPS instead of HTTP. If there is a "
"front-end service performing HTTPS offloading from "
"the service, this option should be False; note, you "
"will want to change public API endpoint to represent "
"SSL termination URL with 'public_endpoint' option.")),
cfg.IntOpt('workers',
help=_("Number of workers for higgins-api service. "
"The default will be the number of CPUs available.")),
]
CONF = cfg.CONF
opt_group = cfg.OptGroup(name='api',
title='Options for the higgins-api service')
CONF.register_group(opt_group)
CONF.register_opts(API_SERVICE_OPTS, opt_group)
LOG = log.getLogger(__name__)
def get_pecan_config():
# Set up the pecan configuration
filename = api_config.__file__.replace('.pyc', '.py')
return pecan.configuration.conf_from_file(filename)
def setup_app(config=None):
if not config:
config = get_pecan_config()
app_conf = dict(config.app)
app = pecan.make_app(
app_conf.pop('root'),
logging=getattr(config, 'logging', {}),
wrap_app=middleware.ParsableErrorMiddleware,
**app_conf
)
return app