From 0b6fff12bafed4b9c4bcb274cb51f4d003ed8603 Mon Sep 17 00:00:00 2001 From: Anand Shanmugam Date: Fri, 19 Jun 2015 04:09:49 -0700 Subject: [PATCH] Adding commond module for invoking cloudpulse Change-Id: I10f5b83f8bb8b451338a5c7f25c912a87032924d --- cloudpulse/api/app.py | 8 ++++++ cloudpulse/cmd/__init__.py | 0 cloudpulse/cmd/api.py | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 cloudpulse/cmd/__init__.py create mode 100644 cloudpulse/cmd/api.py diff --git a/cloudpulse/api/app.py b/cloudpulse/api/app.py index 924ca32..450a64c 100644 --- a/cloudpulse/api/app.py +++ b/cloudpulse/api/app.py @@ -18,6 +18,13 @@ from cloudpulse.api import config as api_config from cloudpulse.api import middleware # Register options for the service +bind_opts = [ + cfg.StrOpt('host', default='0.0.0.0', + help=('Address to bind the server. Useful when ' + 'selecting a particular network interface.')), + cfg.IntOpt('port', default='9999', + help=('The port on which the server will listen.')), +] API_SERVICE_OPTS = [ cfg.IntOpt('port', default=9511, @@ -35,6 +42,7 @@ CONF = cfg.CONF opt_group = cfg.OptGroup(name='api', title='Options for the cloudpulse-api service') CONF.register_group(opt_group) +CONF.register_opts(bind_opts) CONF.register_opts(API_SERVICE_OPTS, opt_group) diff --git a/cloudpulse/cmd/__init__.py b/cloudpulse/cmd/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cloudpulse/cmd/api.py b/cloudpulse/cmd/api.py new file mode 100644 index 0000000..36ff30c --- /dev/null +++ b/cloudpulse/cmd/api.py @@ -0,0 +1,54 @@ +# Copyright 2013 - Red Hat, 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. + +"""Starter script for the Cloudpulse API service.""" + +import logging as std_logging +import os +import sys +from wsgiref import simple_server + +from oslo_config import cfg + +from cloudpulse.api import app as api_app +from cloudpulse.common import service +from cloudpulse.openstack.common._i18n import _LI +from cloudpulse.openstack.common import log as logging + + +LOG = logging.getLogger(__name__) + + +def main(): + service.prepare_service(sys.argv) + + app = api_app.setup_app() + + # Create the WSGI server and start it + host, port = cfg.CONF.host, cfg.CONF.port + srv = simple_server.make_server(host, port, app) + + LOG.info(_LI('Starting server in PID %s') % os.getpid()) + LOG.debug("Configuration:") + cfg.CONF.log_opt_values(LOG, std_logging.DEBUG) + + if host == '0.0.0.0': + LOG.info(_LI('serving on 0.0.0.0:%(port)s, ' + 'view at http://127.0.0.1:%(port)s') % + dict(port=port)) + else: + LOG.info(_LI('serving on http://%(host)s:%(port)s') % + dict(host=host, port=port)) + + srv.serve_forever()