Пример #1
0
    def __init__(self, name, app, host='0.0.0.0', port=0, pool_size=None,
                       protocol=eventlet.wsgi.HttpProtocol, backlog=128,
                       use_ssl=False, max_url_len=None):
        """
        Initialize, but do not start, a WSGI server.
        初始化但并不启动一个WSGI服务;
        """
        # 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("xdrs.%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__)
Пример #2
0
def _load_config():
    import ConfigParser

    from oslo.config import cfg

    from xdrs.openstack.common import log as logging

    global loaded, XDRS_LD, XDRS_PRODUCT, XDRS_PACKAGE
    if loaded:
        return

    loaded = True

    cfgfile = cfg.CONF.find_file("release")
    if cfgfile is None:
        return

    try:
        cfg = ConfigParser.RawConfigParser()
        cfg.read(cfgfile)

        XDRS_LD = cfg.get("Xdrs", "vendor")
        if cfg.has_option("Xdrs", "vendor"):
            XDRS_LD = cfg.get("Xdrs", "vendor")

        XDRS_PRODUCT = cfg.get("Xdrs", "product")
        if cfg.has_option("Xdrs", "product"):
            XDRS_PRODUCT = cfg.get("Xdrs", "product")

        XDRS_PACKAGE = cfg.get("Xdrs", "package")
        if cfg.has_option("Xdrs", "package"):
            XDRS_PACKAGE = cfg.get("Xdrs", "package")
    except Exception as ex:
        LOG = logging.getLogger(__name__)
        LOG.error(_("Failed to load %(cfgfile)s: %(ex)s"), {
            'cfgfile': cfgfile,
            'ex': ex
        })
Пример #3
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 xdrs.openstack.common.gettextutils import _
    from xdrs.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=False,
                    stderrToServer=False)
Пример #4
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 xdrs.openstack.common.gettextutils import _
    from xdrs.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=False,
                    stderrToServer=False)
Пример #5
0
"""
Handles all requests relating to compute resources (e.g. guest VMs,
networking and storage of VMs, and compute hosts on which they run).
"""

import functools

from oslo.config import cfg
from xdrs.controller import rpcapi as controller_rpcapi
from xdrs.controller import manager as manager
from xdrs.db import base
from xdrs import exception
from xdrs.openstack.common import log as logging
from xdrs import rpc

LOG = logging.getLogger(__name__)

get_notifier = functools.partial(rpc.get_notifier, service='global')
wrap_exception = functools.partial(exception.wrap_exception,
                                   get_notifier=get_notifier)

CONF = cfg.CONF
CONF.import_opt('controller', 'xdrs.service')


class API(base.Base):
    """
    API for interacting with the host manager.
    """
    def __init__(self, **kwargs):
        self.controller_rpcapi = controller_rpcapi.ControllerRPCAPI()
Пример #6
0
Xdrs项目中的异常处理;
"""

import functools
import sys

from oslo.config import cfg
import webob.exc
from eventlet import Timeout

from xdrs.openstack.common import excutils
from xdrs.openstack.common.gettextutils import _
from xdrs.openstack.common import log as logging
from xdrs import safe_utils

LOG = logging.getLogger(__name__)

CONF = cfg.CONF
CONF.import_opt('fatal_exception_format_errors', 'xdrs.service')

class ConvertedException(webob.exc.WSGIHTTPException):
    def __init__(self, code=0, title="", explanation=""):
        self.code = code
        self.title = title
        self.explanation = explanation
        super(ConvertedException, self).__init__()

class MessageTimeout(Timeout):

    def __init__(self, seconds=None, msg=None):
        Timeout.__init__(self, seconds=seconds)
Пример #7
0
"""Xdrs common internal object model"""

import collections
import functools

import netaddr
from oslo import messaging
import six

from xdrs import exception
from xdrs.objects import fields
from xdrs.openstack.common.gettextutils import _
from xdrs.openstack.common import log as logging


LOG = logging.getLogger('object')


class NotSpecifiedSentinel:
    pass


def get_attrname(name):
    """
    Return the mangled name of the attribute's underlying storage.
    """
    return '_%s' % name


def make_class_properties(cls):
    cls.fields = dict(cls.fields)