예제 #1
0
파일: debugger.py 프로젝트: yanyuge/rack
def init():
    from oslo.config import cfg
    CONF = cfg.CONF

    # NOTE(markmc): gracefully handle the CLI options not being registered
    if 'remote_debug' not in CONF:
        return

    if not (CONF.remote_debug.host and CONF.remote_debug.port):
        return

    from rack.openstack.common.gettextutils import _
    from rack.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)

    LOG.warn(
        _('WARNING: Using the remote debug option changes how '
          'Rack 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.'))
예제 #2
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.

        :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: rack.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("rack.%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__)
예제 #3
0
파일: version.py 프로젝트: yanyuge/rack
def _load_config():
    # Don't load in global context, since we can't assume
    # these modules are accessible when distutils uses
    # this module
    import ConfigParser

    from oslo.config import cfg

    from rack.openstack.common import log as logging

    global loaded, RACK_VENDOR, RACK_PRODUCT, RACK_PACKAGE
    if loaded:
        return

    loaded = True

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

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

        RACK_VENDOR = cfg.get("Rack", "vendor")
        if cfg.has_option("Rack", "vendor"):
            RACK_VENDOR = cfg.get("Rack", "vendor")

        RACK_PRODUCT = cfg.get("Rack", "product")
        if cfg.has_option("Rack", "product"):
            RACK_PRODUCT = cfg.get("Rack", "product")

        RACK_PACKAGE = cfg.get("Rack", "package")
        if cfg.has_option("Rack", "package"):
            RACK_PACKAGE = cfg.get("Rack", "package")
    except Exception as ex:
        LOG = logging.getLogger(__name__)
        LOG.error(_("Failed to load %(cfgfile)s: %(ex)s"), {
            'cfgfile': cfgfile,
            'ex': ex
        })
예제 #4
0
파일: version.py 프로젝트: n-nishida/rack
def _load_config():
    # Don't load in global context, since we can't assume
    # these modules are accessible when distutils uses
    # this module
    import ConfigParser

    from oslo.config import cfg

    from rack.openstack.common import log as logging

    global loaded, RACK_VENDOR, RACK_PRODUCT, RACK_PACKAGE
    if loaded:
        return

    loaded = True

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

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

        RACK_VENDOR = cfg.get("Rack", "vendor")
        if cfg.has_option("Rack", "vendor"):
            RACK_VENDOR = cfg.get("Rack", "vendor")

        RACK_PRODUCT = cfg.get("Rack", "product")
        if cfg.has_option("Rack", "product"):
            RACK_PRODUCT = cfg.get("Rack", "product")

        RACK_PACKAGE = cfg.get("Rack", "package")
        if cfg.has_option("Rack", "package"):
            RACK_PACKAGE = cfg.get("Rack", "package")
    except Exception as ex:
        LOG = logging.getLogger(__name__)
        LOG.error(_("Failed to load %(cfgfile)s: %(ex)s"),
                  {'cfgfile': cfgfile, 'ex': ex})
예제 #5
0
파일: debugger.py 프로젝트: n-nishida/rack
def init():
    from oslo.config import cfg

    CONF = cfg.CONF

    # NOTE(markmc): gracefully handle the CLI options not being registered
    if "remote_debug" not in CONF:
        return

    if not (CONF.remote_debug.host and CONF.remote_debug.port):
        return

    from rack.openstack.common.gettextutils import _
    from rack.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
    )

    LOG.warn(
        _(
            "WARNING: Using the remote debug option changes how "
            "Rack 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."
        )
    )
예제 #6
0
import errno
import logging as stdlib_logging
import os
import random
import shlex
import signal

from eventlet.green import subprocess
from eventlet import greenthread
import six

from rack.openstack.common.gettextutils import _
from rack.openstack.common import log as logging


LOG = logging.getLogger(__name__)


class InvalidArgumentError(Exception):
    def __init__(self, message=None):
        super(InvalidArgumentError, self).__init__(message)


class UnknownArgumentError(Exception):
    def __init__(self, message=None):
        super(UnknownArgumentError, self).__init__(message)


class ProcessExecutionError(Exception):
    def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None, description=None):
        self.exit_code = exit_code
예제 #7
0
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
from migrate import ForeignKeyConstraint
from rack.openstack.common.gettextutils import _
from rack.openstack.common import log as logging
from sqlalchemy import MetaData, Table, Column, Integer
from sqlalchemy import String, DateTime, Boolean

LOG = logging.getLogger(__name__)

meta = MetaData()

networks = Table('networks',
                 meta,
                 Column('created_at', DateTime),
                 Column('updated_at', DateTime),
                 Column('deleted_at', DateTime),
                 Column('network_id',
                        String(length=255),
                        primary_key=True,
                        nullable=False),
                 Column('gid', String(length=255), nullable=False),
                 Column('neutron_network_id', String(length=255)),
                 Column('is_admin', Boolean),
예제 #8
0
파일: object.py 프로젝트: n-nishida/rack
import collections
import copy
import functools

from oslo import messaging
import six

from rack import context
from rack import exception
from rack.openstack.common.gettextutils import _
from rack.openstack.common import log as logging
from rack.openstack.common import versionutils

#from nova.objects.base import ObjectListBase

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):
    # NOTE(danms/comstud): Inherit fields from super classes.
    # mro() returns the current class first and returns 'object' last, so
    # those can be skipped.  Also be careful to not overwrite any fields