Use console scripts for ceilometer-api

Blueprint: setuptools-console-scripts

Change-Id: Ia64319ba2ea5fdd2778c7faea76478272bb237a6
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-05-29 13:34:20 +02:00
parent 7183fd5970
commit cc0fc91200
6 changed files with 36 additions and 68 deletions

View File

@ -1,63 +0,0 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Copyright © 2012 New Dream Network, LLC (DreamHost)
#
# Author: Doug Hellmann <doug.hellmann@dreamhost.com>
#
# 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.
"""Set up the development API server.
"""
import logging
import os
import sys
from wsgiref import simple_server
from oslo.config import cfg
from ceilometer.openstack.common import gettextutils
gettextutils.install('ceilometer')
from ceilometer.api import app
from ceilometer.openstack.common import log
from ceilometer import service
if __name__ == '__main__':
# Parse OpenStack config file and command line options, then
# configure logging.
service.prepare_service(sys.argv)
# Build the WSGI app
root = app.VersionSelectorApplication()
# Create the WSGI server and start it
host, port = cfg.CONF.api.host, cfg.CONF.api.port
srv = simple_server.make_server(host, port, root)
LOG = log.getLogger(__name__)
LOG.info('Starting server in PID %s' % os.getpid())
LOG.info("Configuration:")
cfg.CONF.log_opt_values(LOG, logging.INFO)
if host == '0.0.0.0':
LOG.info('serving on 0.0.0.0:%s, view at http://127.0.0.1:%s' %
(port, port))
else:
LOG.info("serving on http://%s:%s" % (host, port))
try:
srv.serve_forever()
except KeyboardInterrupt:
# allow CTRL+C to shutdown without an error
pass

View File

@ -16,14 +16,22 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
from oslo.config import cfg
import pecan
import sys
from ceilometer.api import acl
from ceilometer.api import config as api_config
from ceilometer.api import hooks
from ceilometer.api import middleware
from ceilometer import service
from ceilometer.openstack.common import log
from wsgiref import simple_server
from ceilometer.openstack.common import gettextutils
LOG = log.getLogger(__name__)
auth_opts = [
cfg.StrOpt('auth_strategy',
@ -91,3 +99,27 @@ class VersionSelectorApplication(object):
if environ['PATH_INFO'].startswith('/v1/'):
return self.v1(environ, start_response)
return self.v2(environ, start_response)
def start():
gettextutils.install('ceilometer')
service.prepare_service(sys.argv)
# Build the WSGI app
root = VersionSelectorApplication()
# Create the WSGI server and start it
host, port = cfg.CONF.api.host, cfg.CONF.api.port
srv = simple_server.make_server(host, port, root)
LOG.info('Starting server in PID %s' % os.getpid())
LOG.info("Configuration:")
cfg.CONF.log_opt_values(LOG, logging.INFO)
if host == '0.0.0.0':
LOG.info('serving on 0.0.0.0:%s, view at http://127.0.0.1:%s' %
(port, port))
else:
LOG.info("serving on http://%s:%s" % (host, port))
srv.serve_forever()

View File

@ -334,7 +334,7 @@ Installing the API Server
::
$ ./bin/ceilometer-api
$ ceilometer-api
.. note::

View File

@ -26,8 +26,6 @@ setup-hooks =
[files]
packages =
ceilometer
scripts =
bin/ceilometer-api
[entry_points]
ceilometer.collector =
@ -86,6 +84,7 @@ paste.filter_factory =
swift = ceilometer.objectstore.swift_middleware:filter_factory
console_scripts =
ceilometer-api = ceilometer.api.app:start
ceilometer-agent-central = ceilometer.central.manager:agent_central
ceilometer-agent-compute = ceilometer.compute.manager:agent_compute
ceilometer-dbsync = ceilometer.storage:dbsync

View File

@ -87,7 +87,7 @@ class BinApiTestCase(base.TestCase):
"port=%s\n" % self.api_port)
tmp.write("[database]\n")
tmp.write("connection=log://localhost\n")
self.subp = subprocess.Popen([self.path_get('bin/ceilometer-api'),
self.subp = subprocess.Popen(['ceilometer-api',
"--config-file=%s" % self.tempfile])
def tearDown(self):

View File

@ -24,7 +24,7 @@ deps = pep8==1.4.5
flake8==2.0
hacking>=0.5.3,<0.6
commands =
flake8 ceilometer setup.py bin/ceilometer-api tests
flake8 ceilometer setup.py tests
[testenv:docs]
deps = -r{toxinidir}/requirements.txt