~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/wsgi.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
"""Utility methods for working with WSGI servers."""
21
21
 
 
22
import os.path
22
23
import sys
23
24
 
24
25
import eventlet
61
62
        self.host = host or "0.0.0.0"
62
63
        self.port = port or 0
63
64
        self._server = None
64
 
        self._tcp_server = None
65
65
        self._socket = None
66
66
        self._protocol = protocol
67
67
        self._pool = eventlet.GreenPool(pool_size or self.default_pool_size)
85
85
 
86
86
        :param backlog: Maximum number of queued connections.
87
87
        :returns: None
 
88
        :raises: nova.exception.InvalidInput
88
89
 
89
90
        """
 
91
        if backlog < 1:
 
92
            raise exception.InvalidInput(
 
93
                    reason='The backlog must be more than 1')
90
94
        self._socket = eventlet.listen((self.host, self.port), backlog=backlog)
91
95
        self._server = eventlet.spawn(self._start)
92
96
        (self.host, self.port) = self._socket.getsockname()
96
100
        """Stop this server.
97
101
 
98
102
        This is not a very nice action, as currently the method by which a
99
 
        server is stopped is by killing it's eventlet.
 
103
        server is stopped is by killing its eventlet.
100
104
 
101
105
        :returns: None
102
106
 
103
107
        """
104
108
        LOG.info(_("Stopping WSGI server."))
105
109
        self._server.kill()
106
 
        if self._tcp_server is not None:
107
 
            LOG.info(_("Stopping raw TCP server."))
108
 
            self._tcp_server.kill()
109
 
 
110
 
    def start_tcp(self, listener, port, host='0.0.0.0', key=None, backlog=128):
111
 
        """Run a raw TCP server with the given application."""
112
 
        arg0 = sys.argv[0]
113
 
        LOG.info(_('Starting TCP server %(arg0)s on %(host)s:%(port)s')
114
 
                 % locals())
115
 
        socket = eventlet.listen((host, port), backlog=backlog)
116
 
        self._tcp_server = self._pool.spawn_n(self._run_tcp, listener, socket)
117
110
 
118
111
    def wait(self):
119
112
        """Block, until the server has stopped.
128
121
        except greenlet.GreenletExit:
129
122
            LOG.info(_("WSGI server has stopped."))
130
123
 
131
 
    def _run_tcp(self, listener, socket):
132
 
        """Start a raw TCP server in a new green thread."""
133
 
        while True:
134
 
            try:
135
 
                new_sock, address = socket.accept()
136
 
                self._pool.spawn_n(listener, new_sock)
137
 
            except (SystemExit, KeyboardInterrupt):
138
 
                pass
139
 
 
140
124
 
141
125
class Request(webob.Request):
142
126
    pass
374
358
 
375
359
        """
376
360
        config_path = config_path or FLAGS.api_paste_config
377
 
        self.config_path = utils.find_config(config_path)
 
361
        if os.path.exists(config_path):
 
362
            self.config_path = config_path
 
363
        else:
 
364
            self.config_path = FLAGS.find_file(config_path)
 
365
        if not self.config_path:
 
366
            raise exception.ConfigNotFound(path=config_path)
378
367
 
379
368
    def load_app(self, name):
380
369
        """Return the paste URLMap wrapped WSGI application.
385
374
 
386
375
        """
387
376
        try:
 
377
            LOG.debug(_("Loading app %(name)s from %(path)s") %
 
378
                      {'name': name, 'path': self.config_path})
388
379
            return deploy.loadapp("config:%s" % self.config_path, name=name)
389
380
        except LookupError as err:
390
381
            LOG.error(err)