Exemple #1
0
def init():
    from oslo.config import cfg
    CONF = cfg.CONF
    if 'remote_debug' not in CONF:
        return
    if not(CONF.remote_debug.host and CONF.remote_debug.port):
        return 
    
    from mvpn.openstack.common.gettextutils import _
    from mvpn.openstack.common import log as logging
    LOG = logging.getLogger(__name__)
    LOG.debug(_('Listening on %(host)s:%(port)s for debug connection'),
              {'host': CONF.remote_debug.host,
               'port': CONF.remote_debug.port})
               
    from pydev import pydevd
    pydevd.settrace(host=CONF.remote_debug.host,
                    port=CONF.remote_debug.port,
                    stdoutToServer=True,
                    stderrToServer=True)
    
    LOG.warn(_('WARNING: Using the remote debug option changes how '
               'Nova uses the eventlet library to support async IO. This '
               'could result in failures that do not occur under normal '
               'operation. Use at your own risk.'))
Exemple #2
0
    def __init__(
        self,
        name,
        app,
        host="0.0.0.0",
        port=9000,
        pool_size=None,
        protocol=eventlet.wsgi.HttpProtocol,
        backlog=128,
        use_ssl=False,
        max_url_len=None,
    ):
        """Initialize, but do not start, a WSGI server.

        :param name: Pretty name for logging.
        :param app: The WSGI application to serve.
        :param host: IP address to serve the application.
        :param port: Port number to server the application.
        :param pool_size: Maximum number of eventlets to spawn concurrently.
        :param backlog: Maximum number of queued connections.
        :param max_url_len: Maximum length of permitted URLs.
        :returns: None
        :raises: nova.exception.InvalidInput     
        """
        # Allow operators to customize http requests max header line size.
        eventlet.wsgi.MAX_HEADER_LINE = CONF.max_header_line
        self.name = name
        self.app = app
        self._server = None
        self._protocol = protocol
        self._pool = eventlet.GreenPool(pool_size or self.default_pool_size)
        self._logger = logging.getLogger("mvpn.%s.wsgi.server" % self.name)
        self._wsgi_logger = logging.WritableLogger(self._logger)
        self._use_ssl = use_ssl
        self._max_url_len = max_url_len

        if backlog < 1:
            raise exception.InvalidInput(reason="The backlog must be more than 1")

        bind_addr = (host, port)
        # TODO(dims): eventlet's green dns/socket module does not actually
        # support IPv6 in getaddrinfo(). We need to get around this in the
        # future or monitor upstream for a fix
        try:
            info = socket.getaddrinfo(bind_addr[0], bind_addr[1], socket.AF_UNSPEC, socket.SOCK_STREAM)[0]
            family = info[0]
            bind_addr = info[-1]
        except Exception:
            family = socket.AF_INET

        try:
            self._socket = eventlet.listen(bind_addr, family, backlog=backlog)
        except EnvironmentError:
            LOG.error(_("Could not bind to %(host)s:%(port)s"), {"host": host, "port": port})
            raise

        (self.host, self.port) = self._socket.getsockname()[0:2]
        LOG.info(_("%(name)s listening on %(host)s:%(port)s") % self.__dict__)
Exemple #3
0
from eventlet import greenpool
from eventlet import greenthread

from mvpn.openstack.common import loopingcall 
from mvpn.openstack.common import log as logging

LOG = logging.getLogger(__name__)

def _thread_done(gt, *args, **kwargs):
    """Callback function"""
    kwargs['group'].thread_done(kwargs['thread'])

class Thread(object):
    def __init__(self, thread, group):
        self.thread = thread
        self.thread.link(_thread_done, group=group, thread=self)

    def stop(self):
        self.thread.kill()

    def wait(self):
        return self.thread.wait()


class ThreadGroup(object):
    """The point of the ThreadGroup classis to:

    * keep track of timers and greenthreads (making it easier to stop them
    when need be).
    * provide an easy API to add timers.