Exemplo n.º 1
0
 def _run(self, application, asocket):
     """Start a WSGI server in a new green thread."""
     logger = logging.getLogger('eventlet.wsgi')
     eventlet.wsgi.server(
         asocket,
         application,
         custom_pool=self.tg.pool,
         log=logger
     )
Exemplo n.º 2
0
import webob.exc
import eventlet
from chef_validator.common.utils import JSONSerializer, JSONDeserializer

eventlet.patcher.monkey_patch(all=False, socket=True)
import eventlet.wsgi
from eventlet.green import socket
from oslo_service import service
from oslo_service import sslutils
from chef_validator.common import log as logging
from oslo_utils import importutils
from oslo_config import cfg
from chef_validator.common import exception
from chef_validator.common.i18n import _, _LW

LOG = logging.getLogger(__name__)
CONF = cfg.CONF


class Service(service.Service):
    """Provides a Service API for wsgi servers.

    This gives us the ability to launch wsgi servers with the
    Launcher classes in oslo_service.service.py.
    """

    def __init__(self, application, port, host='0.0.0.0', backlog=4096,
                 threads=1000):
        self.application = application
        self._port = port
        self._host = host
# so that it will override what happens to be installed in
# /usr/(local/)lib/python...
root = os.path.abspath(
    os.path.join(os.path.abspath(__file__), os.pardir, os.pardir, os.pardir)
)
if os.path.exists(os.path.join(root, 'chef_validator', '__init__.py')):
    sys.path.insert(0, root)

from chef_validator.common import log as logging
from chef_validator.common.i18n import _LI
from chef_validator.common import config
from chef_validator.common import wsgi

i18n.enable_lazy()

LOG = logging.getLogger()
CONF = config.CONF


def main():
    """Launch validator API """
    try:
        config.parse_args()
        logging.setup(CONF, 'chef_validator_api')
        app = config.load_paste_app("chef_validator_api")
        port, host = (CONF.bind_port, CONF.bind_host)
        LOG.info(_LI('Starting Chef Validator ReST API on %(host)s:%(port)s'),
                 {'host': host, 'port': port})
        server = wsgi.Service(app, port, host)
        server.start()
        server.wait()