Beispiel #1
0
    def disconnect_volume(self, volume, **disconnect_opts):
        try:
            volume = self.cinderclient.volumes.get(volume.id)
        except cinder_exception.ClientException as e:
            msg = _LE("Get Volume {0} from Cinder failed").format(volume.id)
            LOG.error(msg)
            raise

        try:
            link_path = self.get_device_path(volume)
            utils.execute('rm', '-f', link_path, run_as_root=True)
        except processutils.ProcessExecutionError as e:
            msg = _LE("Error happened when remove docker volume "
                      "mountpoint directory. Error: {0}").format(e)
            LOG.warn(msg)

        try:
            self.novaclient.volumes.delete_server_volume(
                utils.get_instance_uuid(),
                volume.id)
        except nova_exception.ClientException as e:
            msg = _LE("Detaching volume {0} failed. "
                      "Err: {1}").format(volume.id, e)
            LOG.error(msg)
            raise

        volume_monitor = state_monitor.StateMonitor(self.cinderclient,
                                                    volume,
                                                    'available',
                                                    ('in-use', 'detaching',))
        return volume_monitor.monitor_cinder_volume()
Beispiel #2
0
def init_app_conf():
    # Init volume providers.
    volume_providers = CONF.volume_providers
    if not volume_providers:
        raise Exception("Must define volume providers in configuration file")

    app.volume_providers = collections.OrderedDict()
    for provider in volume_providers:
        if provider in volume_providers_conf:
            app.volume_providers[provider] = importutils\
                .import_class(volume_providers_conf[provider])()
            app.logger.info(_LI("Load volume provider: {0}").format(provider))
        else:
            msg = _LW("Could not find volume provider: {0}").format(provider)
            app.logger.warn(msg)
    if not app.volume_providers:
        raise Exception("Not provide at least one effective volume provider")

    # Init volume store directory.
    try:
        volume_dir = CONF.volume_dir
        if not os.path.exists(volume_dir) or not os.path.isdir(volume_dir):
            utils.execute('mkdir', '-p', '-m=700', volume_dir,
                          run_as_root=True)
    except processutils.ProcessExecutionError:
        raise
Beispiel #3
0
def init_app_conf():
    # Init volume providers.
    volume_providers = CONF.volume_providers
    if not volume_providers:
        raise Exception(
            _("Must define volume providers in "
              "configuration file"))

    app.volume_providers = collections.OrderedDict()
    for provider in volume_providers:
        if provider in volume_providers_conf:
            app.volume_providers[provider] = importutils\
                .import_class(volume_providers_conf[provider])()
            LOG.info("Load volume provider: %s", provider)
        else:
            LOG.warning("Could not find volume provider: %s", provider)
    if not app.volume_providers:
        raise Exception(
            _("Not provide at least one effective "
              "volume provider"))

    # Init volume store directory.
    try:
        volume_dir = CONF.volume_dir
        if not os.path.exists(volume_dir) or not os.path.isdir(volume_dir):
            utils.execute('mkdir',
                          '-p',
                          '-m=700',
                          volume_dir,
                          run_as_root=True)
    except processutils.ProcessExecutionError:
        raise
Beispiel #4
0
    def disconnect_volume(self, volume, **disconnect_opts):
        try:
            volume = self.cinderclient.volumes.get(volume.id)
        except cinder_exception.ClientException as e:
            LOG.error("Get Volume %s from Cinder failed", volume.id)
            raise

        try:
            link_path = self.get_device_path(volume)
            utils.execute('rm', '-f', link_path, run_as_root=True)
        except processutils.ProcessExecutionError as e:
            LOG.warning(
                "Error happened when remove docker volume"
                " mountpoint directory. Error: %s", e)

        try:
            self.novaclient.volumes.delete_server_volume(
                utils.get_instance_uuid(), volume.id)
        except nova_exception.ClientException as e:
            LOG.error("Detaching volume %(vol)s failed. Err: %(err)s", {
                'vol': volume.id,
                'err': e
            })
            raise

        volume_monitor = state_monitor.StateMonitor(self.cinderclient, volume,
                                                    'available', (
                                                        'in-use',
                                                        'detaching',
                                                    ))
        return volume_monitor.monitor_cinder_volume()
Beispiel #5
0
def init_app_conf():
    # Init volume providers.
    volume_providers = CONF.volume_providers
    if not volume_providers:
        raise Exception("Must define volume providers in configuration file")

    app.volume_providers = collections.OrderedDict()
    for provider in volume_providers:
        if provider in volume_providers_conf:
            app.volume_providers[provider] = importutils\
                .import_class(volume_providers_conf[provider])()
            app.logger.info(_LI("Load volume provider: {0}").format(provider))
        else:
            msg = _LW("Could not find volume provider: {0}").format(provider)
            app.logger.warn(msg)
    if not app.volume_providers:
        raise Exception("Not provide at least one effective volume provider")

    # Init volume store directory.
    try:
        volume_dir = CONF.volume_dir
        if not os.path.exists(volume_dir) or not os.path.isdir(volume_dir):
            utils.execute('mkdir', '-p', '-m=700', volume_dir,
                          run_as_root=True)
    except processutils.ProcessExecutionError:
        raise
Beispiel #6
0
 def unmount(self, mountpoint):
     try:
         utils.execute('umount', mountpoint, run_as_root=True)
     except processutils.ProcessExecutionError as e:
         msg = _("Unexpected err while unmount block device. "
                 "Mountpoint: {0}, "
                 "Error: {1}").format(mountpoint, e)
         raise exceptions.UnmountException(msg)
Beispiel #7
0
 def unmount(self, mountpoint):
     try:
         utils.execute('umount', mountpoint, run_as_root=True)
     except processutils.ProcessExecutionError as e:
         msg = _("Unexpected err while unmount block device. "
                 "Mountpoint: {0}, "
                 "Error: {1}").format(mountpoint, e)
         raise exceptions.UnmountException(msg)
Beispiel #8
0
 def make_filesystem(self, devpath, fstype):
     try:
         utils.execute('mkfs', '-t', fstype, '-F', devpath,
                       run_as_root=True)
     except processutils.ProcessExecutionError as e:
         msg = _("Unexpected error while make filesystem. "
                 "Devpath: {0}, "
                 "Fstype: {1}"
                 "Error: {2}").format(devpath, fstype, e)
         raise exceptions.MakeFileSystemException(msg)
Beispiel #9
0
 def make_filesystem(self, devpath, fstype):
     try:
         utils.execute('mkfs', '-t', fstype, '-F', devpath,
                       run_as_root=True)
     except processutils.ProcessExecutionError as e:
         msg = _("Unexpected error while make filesystem. "
                 "Devpath: {0}, "
                 "Fstype: {1}"
                 "Error: {2}").format(devpath, fstype, e)
         raise exceptions.MakeFileSystemException(msg)
Beispiel #10
0
    def _clear_mountpoint(self, mountpoint):
        """Clear mount point directory if it wouldn't used any more.

        :param mountpoint: The path of Docker volume.
        """
        if os.path.exists(mountpoint) and os.path.isdir(mountpoint):
            try:
                utils.execute('rm', '-r', mountpoint, run_as_root=True)
                LOG.info(_LI("Clear mountpoint %s successfully"), mountpoint)
            except processutils.ProcessExecutionError as e:
                LOG.error(_LE("Error happened when clear mountpoint {0}"), e)
                raise
Beispiel #11
0
    def _disconnect_volume(self, volume):
        try:
            link_path = self.get_device_path(volume)
            utils.execute('rm', '-f', link_path, run_as_root=True)
        except processutils.ProcessExecutionError as e:
            msg = _LE("Error happened when remove docker volume "
                      "mountpoint directory. Error: {0}").format(e)
            LOG.warn(msg)

        conn_info = self._get_connection_info(volume.id)

        protocol = conn_info['driver_volume_type']
        brick_get_connector(protocol).disconnect_volume(conn_info['data'],
                                                        None)
Beispiel #12
0
 def mount(self, devpath, mountpoint, fstype=None):
     try:
         if fstype:
             utils.execute('mount', '-t', fstype, devpath, mountpoint,
                           run_as_root=True)
         else:
             utils.execute('mount', devpath, mountpoint,
                           run_as_root=True)
     except processutils.ProcessExecutionError as e:
         msg = _("Unexpected error while mount block device. "
                 "Devpath: {0}, "
                 "Mountpoint: {1} "
                 "Error: {2}").format(devpath, mountpoint, e)
         raise exceptions.MountException(msg)
    def _disconnect_volume(self, volume):
        try:
            link_path = self.get_device_path(volume)
            utils.execute('rm', '-f', link_path, run_as_root=True)
        except processutils.ProcessExecutionError as e:
            msg = _LE("Error happened when remove docker volume "
                      "mountpoint directory. Error: {0}").format(e)
            LOG.warning(msg)

        conn_info = self._get_connection_info(volume.id)

        protocol = conn_info['driver_volume_type']
        brick_get_connector(protocol).disconnect_volume(conn_info['data'],
                                                        None)
Beispiel #14
0
    def _create_mountpoint(self, mountpoint):
        """Create mount point directory for Docker volume.

        :param mountpoint: The path of Docker volume.
        """
        try:
            if not os.path.exists(mountpoint) or not os.path.isdir(mountpoint):
                utils.execute('mkdir', '-p', '-m=755', mountpoint,
                              run_as_root=True)
                LOG.info(_LI("Create mountpoint %s successfully"), mountpoint)
        except processutils.ProcessExecutionError as e:
            LOG.error(_LE("Error happened when create volume "
                          "directory. Error: %s"), e)
            raise
Beispiel #15
0
 def mount(self, devpath, mountpoint, fstype=None):
     try:
         if fstype:
             utils.execute('mount', '-t', fstype, devpath, mountpoint,
                           run_as_root=True)
         else:
             utils.execute('mount', devpath, mountpoint,
                           run_as_root=True)
     except processutils.ProcessExecutionError as e:
         msg = _("Unexpected error while mount block device. "
                 "Devpath: {0}, "
                 "Mountpoint: {1} "
                 "Error: {2}").format(devpath, mountpoint, e)
         raise exceptions.MountException(msg)
    def _connect_volume(self, volume):
        conn_info = self._get_connection_info(volume.id)

        protocol = conn_info['driver_volume_type']
        brick_connector = brick_get_connector(protocol)
        device_info = brick_connector.connect_volume(conn_info['data'])
        LOG.info(_LI("Get device_info after connect to "
                     "volume %s") % device_info)
        try:
            link_path = os.path.join(consts.VOLUME_LINK_DIR, volume.id)
            utils.execute('ln', '-s', os.path.realpath(device_info['path']),
                          link_path,
                          run_as_root=True)
        except processutils.ProcessExecutionError as e:
            LOG.error(_LE("Failed to create link for device. %s"), e)
            raise
        return {'path': link_path}
Beispiel #17
0
    def _connect_volume(self, volume):
        conn_info = self._get_connection_info(volume.id)

        protocol = conn_info['driver_volume_type']
        brick_connector = brick_get_connector(protocol)
        device_info = brick_connector.connect_volume(conn_info['data'])
        LOG.info(_LI("Get device_info after connect to "
                     "volume %s") % device_info)
        try:
            link_path = os.path.join(consts.VOLUME_LINK_DIR, volume.id)
            utils.execute('ln', '-s', os.path.realpath(device_info['path']),
                          link_path,
                          run_as_root=True)
        except processutils.ProcessExecutionError as e:
            LOG.error(_LE("Failed to create link for device. %s"), e)
            raise
        return {'path': link_path, 'iscsi_path': device_info['path']}
Beispiel #18
0
    def connect_volume(self, volume, **connect_opts):
        bdm = blockdevice.BlockerDeviceManager()
        ori_devices = bdm.device_scan()

        # Do volume-attach
        try:
            server_id = connect_opts.get('server_id', None)
            if not server_id:
                server_id = utils.get_instance_uuid()

            LOG.info("Start to connect to volume %s", volume)
            nova_volume = self.novaclient.volumes.create_server_volume(
                server_id=server_id, volume_id=volume.id, device=None)

            volume_monitor = state_monitor.StateMonitor(
                self.cinderclient, nova_volume, 'in-use', (
                    'available',
                    'attaching',
                ))
            attached_volume = volume_monitor.monitor_cinder_volume()
        except nova_exception.ClientException as ex:
            LOG.error(
                "Attaching volume %(vol)s to server %(s)s "
                "failed. Error: %(err)s", {
                    'vol': volume.id,
                    's': server_id,
                    'err': ex
                })
            raise

        # Get all devices on host after do volume-attach,
        # and then find attached device.
        LOG.info("After connected to volume, scan the added "
                 "block device on host")
        curr_devices = bdm.device_scan()
        start_time = time.time()
        delta_devices = list(set(curr_devices) - set(ori_devices))
        while not delta_devices:
            time.sleep(consts.DEVICE_SCAN_TIME_DELAY)
            curr_devices = bdm.device_scan()
            delta_devices = list(set(curr_devices) - set(ori_devices))
            if time.time() - start_time > consts.DEVICE_SCAN_TIMEOUT:
                msg = _("Could not detect added device with " "limited time")
                raise exceptions.FuxiException(msg)
        LOG.info("Get extra added block device %s", delta_devices)

        for device in delta_devices:
            if bdm.get_device_size(device) == volume.size:
                device = device.replace('/sys/block', '/dev')
                LOG.info(
                    "Find attached device %(dev)s"
                    " for volume %(at)s %(vol)s", {
                        'dev': device,
                        'at': attached_volume.name,
                        'vol': volume
                    })

                link_path = os.path.join(consts.VOLUME_LINK_DIR, volume.id)
                try:
                    utils.execute('ln',
                                  '-s',
                                  device,
                                  link_path,
                                  run_as_root=True)
                except processutils.ProcessExecutionError as e:
                    LOG.error(
                        "Error happened when create link file for"
                        " block device attached by Nova."
                        " Error: %s", e)
                    raise
                return {'path': link_path}

        LOG.warning("Could not find matched device")
        raise exceptions.NotFound("Not Found Matched Device")
Beispiel #19
0
    def connect_volume(self, volume, **connect_opts):
        bdm = blockdevice.BlockerDeviceManager()
        ori_devices = bdm.device_scan()

        # Do volume-attach
        try:
            server_id = connect_opts.get('server_id', None)
            if not server_id:
                server_id = utils.get_instance_uuid()

            LOG.info(_LI("Start to connect to volume {0}").format(volume))
            nova_volume = self.novaclient.volumes.create_server_volume(
                server_id=server_id,
                volume_id=volume.id,
                device=None)

            volume_monitor = state_monitor.StateMonitor(
                self.cinderclient,
                nova_volume,
                'in-use',
                ('available', 'attaching',))
            attached_volume = volume_monitor.monitor_cinder_volume()
        except nova_exception.ClientException as ex:
            LOG.error(_LE("Attaching volume {0} to server {1} "
                          "failed. Error: {2}").format(volume.id,
                                                       server_id, ex))
            raise

        # Get all devices on host after do volume-attach,
        # and then find attached device.
        LOG.info(_LI("After connected to volume, scan the added "
                     "block device on host"))
        curr_devices = bdm.device_scan()
        start_time = time.time()
        delta_devices = list(set(curr_devices) - set(ori_devices))
        while not delta_devices:
            time.sleep(consts.DEVICE_SCAN_TIME_DELAY)
            curr_devices = bdm.device_scan()
            delta_devices = list(set(curr_devices) - set(ori_devices))
            if time.time() - start_time > consts.DEVICE_SCAN_TIMEOUT:
                msg = _("Could not detect added device with "
                        "limited time")
                raise exceptions.FuxiException(msg)
        LOG.info(_LI("Get extra added block device {0}"
                     "").format(delta_devices))

        for device in delta_devices:
            if bdm.get_device_size(device) == volume.size:
                device = device.replace('/sys/block', '/dev')
                msg = _LI("Find attached device {0} for volume {1} "
                          "{2}").format(device,
                                        attached_volume.name,
                                        volume)
                LOG.info(msg)

                link_path = os.path.join(consts.VOLUME_LINK_DIR, volume.id)
                try:
                    utils.execute('ln', '-s', device,
                                  link_path,
                                  run_as_root=True)
                except processutils.ProcessExecutionError as e:
                    msg = _LE("Error happened when create link file for "
                              "block device attached by Nova. "
                              "Error: {0}").format(e)
                    LOG.error(msg)
                    raise
                return {'path': link_path}

        LOG.warm(_LW("Could not find matched device"))
        raise exceptions.NotFound("Not Found Matched Device")