Example #1
0
    def attach_volume(self, name, device, mount_device, static=True):
        try:
            s = os.stat(device)
            if not stat.S_ISBLK(s.st_mode):
                raise exception.InvalidInput(reason='"%s" is not block device'%device)
            maj, min = os.major(s.st_rdev), os.minor(s.st_rdev)
            if not static:
                # ignore mount_device now
                self._dynamic_attach_or_detach_volume(name, device, maj, min, attach=True)
            else:
                conf_path = lxc_device_conf_file(name, device)
                with open(conf_path, 'w') as f:
                    for i in range(16):
                        f.write('lxc.cgroup.devices.allow = '
                                 'b %(maj)s:%(min)s rwm\n'%{'maj':maj, 'min':min+i})

                LOG.info(_("new config path %(path)s for %(device)s"),
                        {'path': conf_path, 'device': device})
                # autodev hook:
                #  add the partitions of this device into the container when it starts
                with open(lxc_autodev_hook_script(name, device), 'w') as f, \
                      open('/proc/partitions', 'r') as p:
                    for line in p:
                        fields = line.split()
                        if fields and fields[-1].startswith(os.path.basename(device)):
                            f.write("mknod --mode=0660 $LXC_ROOTFS_MOUNT/dev/%(device)s "
                                    "b %(maj)s %(min)s\n" % {
                                    "device": fields[-1], "maj":fields[0], "min":fields[1]})


        except Exception as ex:
            with excutils.save_and_reraise_exception():
                LOG.error(_('Failed to attach device %(device)s '
                              ' for %(name)s: %(ex)s'),
                          {'name': name, 'ex': ex.message, 'device': device})
Example #2
0
    def __init__(self, name, loader=None, use_ssl=False, max_url_len=None):
        """Initialize, but do not start the WSGI server.

        :param name: The name of the WSGI server given to the loader.
        :param loader: Loads the WSGI application using the given name.
        :returns: None

        """
        self.name = name
        self.manager = self._get_manager()
        self.loader = loader or wsgi.Loader()
        self.app = self.loader.load_app(name)
        self.host = '0.0.0.0'
        self.port = CONF.get('port', 7127)
        self.workers = 1
        if self.workers and self.workers < 1:
            worker_name = '%s_workers' % name
            msg = (_("%(worker_name)s value of %(workers)s is invalid, "
                     "must be greater than 0") %
                   {'worker_name': worker_name,
                    'workers': str(self.workers)})
            raise exception.InvalidInput(msg)
        self.use_ssl = use_ssl
        self.server = wsgi.Server(name,
                                  self.app,
                                  host=self.host,
                                  port=self.port,
                                  use_ssl=self.use_ssl,
                                  max_url_len=max_url_len)
        # Pull back actual port used
        self.port = self.server.port
        self.backdoor_port = None
Example #3
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: wormhole.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_size = pool_size or self.default_pool_size
        self._pool = eventlet.GreenPool(self.pool_size)
        self._logger = logging.getLogger("wormhole.%s.wsgi.server" % self.name)
        self._wsgi_logger = logging.WritableLogger(self._logger)
        self._use_ssl = use_ssl
        self._max_url_len = max_url_len
        self.client_socket_timeout = CONF.client_socket_timeout or None

        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"),
                 {'name': self.name, 'host': self.host, 'port': self.port})
Example #4
0
 def detach_volume(self, name, device, mount_device, static=True):
     try:
         s = os.stat(device)
         if not stat.S_ISBLK(s.st_mode):
             raise exception.InvalidInput(reason='"%s" is not block device'%device)
         maj, min = os.major(s.st_rdev), os.minor(s.st_rdev)
         if not static:
             self._dynamic_attach_or_detach_volume(name, device, maj, min, attach=False)
         for cb in  [lxc_device_conf_file, lxc_autodev_hook_script]:
             path = cb(name, device)
             if path and os.isfile(path):
                 os.remove(path)
                 LOG.info(_("delete path %(path)s for %(device)s"),
                         {'path': path, 'device': device})
     except Exception as ex:
         with excutils.save_and_reraise_exception():
             LOG.error(_('Failed to detach device %(device)s '
                           ' for %(name)s: %(ex)s'),
                       {'name': name, 'ex': ex.message, 'device': device})