コード例 #1
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()
コード例 #2
0
ファイル: openstack.py プロジェクト: nkwilson/fuxi
    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()
コード例 #3
0
def get_host_id():
    """Get a value that could represent this server."""
    host_id = None
    volume_connector = cinder_conf.volume_connector
    if volume_connector == OPENSTACK:
        host_id = utils.get_instance_uuid()
    elif volume_connector == OSBRICK:
        host_id = utils.get_hostname().lower()
    return host_id
コード例 #4
0
ファイル: cinder.py プロジェクト: nkwilson/fuxi
def get_host_id():
    """Get a value that could represent this server."""
    host_id = None
    volume_connector = cinder_conf.volume_connector
    if volume_connector == OPENSTACK:
        host_id = utils.get_instance_uuid()
    elif volume_connector == OSBRICK:
        host_id = utils.get_hostname().lower()
    return host_id
コード例 #5
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")
コード例 #6
0
ファイル: openstack.py プロジェクト: nkwilson/fuxi
    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")