Exemple #1
0
 def _run(self, application, socket):
     """Start a WSGI server in a new green thread."""
     logger = logging.getLogger('eventlet.wsgi')
     eventlet.wsgi.server(socket,
                          application,
                          custom_pool=self.tg.pool,
                          log=logging.WritableLogger(logger))
Exemple #2
0
def main():
    # Pase config file and command line options, then start logging
    example_service.prepare_service(sys.argv)

    # Build and start the WSGI app
    host = CONF.example_api_bind_ip
    port = CONF.example_api_port
    wsgi = simple_server.make_server(host, port,
                                     app.VersionSelectorApplication())

    LOG = log.getLogger(__name__)
    LOG.info("Serving on http://%s:%s" % (host, port))
    LOG.info("Configuration:")
    CONF.log_opt_values(LOG, logging.INFO)

    try:
        wsgi.serve_forever()
    except KeyboardInterrupt:
        pass
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
import flask
from stevedore import extension
from werkzeug import exceptions as wexceptions
from werkzeug import wrappers


from example.openstack.common import jsonutils as json
from example.openstack.common import log as logging
from example import exceptions

LOG = logging.getLogger(__name__)


class Request(flask.Request, wrappers.AcceptMixin,
              wrappers.CommonRequestDescriptorsMixin):
    def __init__(self, *args, **kwargs):
        super(Request, self).__init__(*args, **kwargs)

        self._validate_content_type()
        self._validate_accept()

    def _validate_content_type(self):
        if (self.method in ['POST', 'PUT', 'PATCH']
                and self.mimetype != 'application/json'):

            msg = 'Unsupported Content-Type: %s' % self.mimetype
            raise exceptions.UnsupportedContentType(msg)
Exemple #4
0
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#

from example import storage
from example.openstack.common import log as logging
from example.openstack.common import excutils
LOG = logging.getLogger(__name__)


class StorageAPI(object):
    """ Storage API """
    def __init__(self):
        self.storage = storage.get_storage()

    # message
    def create_message(self, context, *args, **kwargs):
        try:
            return self.storage.create_message(context, *args, **kwargs)
        except Exception as exc:
            LOG.error("Create message failed due to %s" % exc)
            with excutils.save_and_reraise_exception():
                pass