Beispiel #1
0
    def create_volume_from_snapshot(self, volume, snapshot):
        """Create a volume from a snapshot."""
        context = req_context.RequestContext(is_admin=True,
                                             project_id=volume.project_id)
        try:
            provider_snap = self._get_provider_snapshot_id(
                context, snapshot.id)
            vol = self._create_volume(volume, context, snapshot=provider_snap)
        except Exception as ex:
            LOG.error(
                _LE('create_volume_from_snapshot failed,'
                    'snapshot:%(id)s,ex:%(ex)s'), {
                        'id': snapshot.id,
                        'ex': ex
                    })
            msg = (_("create_volume_from_snapshot failed! volume:%s") %
                   volume.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        # create local volume mapper
        try:
            values = {'provider_volume_id': vol['VolumeId']}
            self.caa_db_api.volume_mapper_create(context, volume.id,
                                                 context.project_id, values)
        except Exception as ex:
            LOG.error(_LE("volume_mapper_create failed! ex = %s"), ex)
            self._aws_client.get_aws_client(context).\
                delete_volume(VolumeId=vol['VolumeId'])
            msg = (_("create_volume_from_snapshot failed! volume:%s") %
                   volume.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        LOG.debug('create volume %s success.' % volume.id)
Beispiel #2
0
 def test_create_backup_failed(self, mock_create):
     msg = (_("create provider snapshot failed vol:%s") % 'fake')
     mock_create.side_effect = cinder_ex.VolumeBackendAPIException(data=msg)
     self.assertRaises(cinder_ex.BackupOperationError,
                       self.driver.backup,
                       self.backup,
                       'fake')
Beispiel #3
0
 def validate_connector(self, connector):
     # iSCSI drivers require the initiator information
     if 'initiator' not in connector:
         err_msg = _('The volume driver requires the iSCSI initiator '
                     'name in the connector.')
         LOG.error(err_msg)
         raise exception.VolumeBackendAPIException(data=err_msg)
     self.initiator_iqn = connector['initiator']
Beispiel #4
0
    def create_cloned_volume(self, volume, src_vref):
        """Create a clone of the specified volume."""
        context = req_context.RequestContext(is_admin=True,
                                             project_id=volume.project_id)
        snapshot = None
        try:
            src_vol = self._get_provider_volume_id(context, src_vref)
            snapshot = self._aws_client.get_aws_client(context).\
                create_snapshot(VolumeId=src_vol)
            provider_vol = self._create_volume(volume,
                                               context,
                                               snapshot=snapshot['SnapshotId'])
        except Exception as ex:
            LOG.error(
                _LE("create_cloned_volume failed! volume:%(id)s,"
                    "ex: %(ex)s"), {
                        'id': volume.id,
                        'ex': ex
                    })
            msg = (_("create_cloned_volume failed! volume:%s") % volume.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)
        finally:
            if snapshot:
                self._aws_client.get_aws_client(context).\
                    delete_snapshot(
                    SnapshotId=snapshot['SnapshotId']
                )
        # create local volume mapper
        try:
            values = {'provider_volume_id': provider_vol['VolumeId']}
            self.caa_db_api.volume_mapper_create(context, volume.id,
                                                 context.project_id, values)
        except Exception as ex:
            LOG.error(
                _LE("volume_mapper_create failed! vol:%(id)s,"
                    " ex = %(ex)s"), {
                        'id': volume.id,
                        'ex': ex
                    })
            self._aws_client.get_aws_client(context).\
                delete_volume(VolumeId=provider_vol['VolumeId'])
            msg = (_("volume_mapper_create failed! volume:%s") % volume.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        LOG.debug('create volume %s success.' % volume.id)
Beispiel #5
0
 def retype(self, context, volume, new_type, diff, host):
     try:
         self._modify_volume(volume, new_type=new_type)
     except Exception as e:
         LOG.error(_LE("retype failed! volume:%(id)s,ex: %(ex)s"), {
             'id': volume.id,
             'ex': e
         })
         msg = (_("retype failed! volume:%s") % volume.id)
         raise cinder_ex.VolumeBackendAPIException(data=msg)
     return True, None
Beispiel #6
0
 def extend_volume(self, volume, new_size):
     """Extend a volume."""
     try:
         self._modify_volume(volume, new_size=new_size)
     except Exception as e:
         LOG.error(_LE("extend failed! volume:%(id)s,ex: %(ex)s"), {
             'id': volume.id,
             'ex': e
         })
         msg = (_("extend_volume failed! volume:%s") % volume.id)
         raise cinder_ex.VolumeBackendAPIException(data=msg)
Beispiel #7
0
    def delete_snapshot(self, snapshot):
        """Delete a snapshot."""
        context = req_context.RequestContext(is_admin=True,
                                             project_id=snapshot.project_id)

        try:
            provider_snap = self._get_provider_snapshot_id(
                context, snapshot.id)
            if provider_snap:
                self._aws_client.get_aws_client(context).\
                    delete_snapshot(SnapshotId=provider_snap)
            else:
                snapshots = self._get_provider_snapshot(context, snapshot.id)
                for snap in snapshots:
                    self._aws_client.get_aws_client(context).\
                        delete_snapshot(SnapshotId=snap)
        except Exception as ex:
            LOG.error(
                _LE("delete snapshot failed! snapshot:%(id)s,"
                    "ex = %(ex)s"), {
                        'id': snapshot.id,
                        'ex': ex
                    })
            msg = (_("delete_snapshot failed! snapshot:%s") % snapshot.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        # delete snapshot mapper
        try:
            self.caa_db_api.volume_snapshot_mapper_delete(
                context, snapshot.id, context.project_id)
        except Exception as ex:
            LOG.error(
                _LE("delete snapshot mapper failed! snapshot:%(id)s,"
                    "ex = %(ex)s"), {
                        'id': snapshot.id,
                        'ex': ex
                    })
            msg = (_("delete_snapshot failed! snapshot:%s") % snapshot.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        LOG.info(_LI("delete snapshot(%s) success!"), snapshot.id)
Beispiel #8
0
    def _create_volume(self,
                       volume,
                       context,
                       new_size=None,
                       new_type=None,
                       snapshot=None):
        provider_type = self._get_provider_type_name(
            context, new_type or volume.volume_type_id)
        provider_az = self._get_provider_az(context, volume.availability_zone)
        if not provider_az:
            msg = (_("create provider volume failed,no provider_az vol:%s") %
                   volume.id)
            LOG.error(msg)
            raise cinder_ex.VolumeBackendAPIException(data=msg)
        volume_args = {
            'AvailabilityZone': provider_az,
            'VolumeType': provider_type or 'standard',
            'Size': new_size or volume.size
        }
        if snapshot:
            volume_args['SnapshotId'] = snapshot

        try:
            provider_vol = self._aws_client.get_aws_client(context).\
                create_volume(**volume_args)
            # create remote volume mapper
            tags = [{'Key': 'caa_volume_id', 'Value': volume.id}]
            self._aws_client.get_aws_client(context).\
                create_tags(Resources=[provider_vol['VolumeId']],
                            Tags=tags)
        except Exception as ex:
            LOG.error(
                _LE("create provider volume failed! vol:%(id)s,"
                    " ex = %(ex)s"), {
                        'id': volume.id,
                        'ex': ex
                    })
            msg = (_("create provider volume failed vol:%s") % volume.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        return provider_vol
Beispiel #9
0
    def delete_volume(self, volume):
        context = req_context.RequestContext(is_admin=True,
                                             project_id=volume.project_id)
        try:
            vol_id = self._get_provider_volume_id(context, volume)
            if not vol_id:
                volumes = self._get_provider_volume(context, volume.id)
                # if len(volumes) > 1,there must have been an error,we should
                # delete all volumes
                for vol in volumes:
                    self._aws_client.get_aws_client(context).\
                        delete_volume(VolumeId=vol)
            else:
                self._aws_client.get_aws_client(context).\
                    delete_volume(VolumeId=vol_id)
        except Exception as ex:
            LOG.error(_LE("delete volume failed! vol:%(id)s,ex = %(ex)s"), {
                'id': volume.id,
                'ex': ex
            })
            msg = (_("delete_volume failed! volume:%s") % volume.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        # delete volume mapper
        try:
            self.caa_db_api.volume_mapper_delete(context, volume.id,
                                                 context.project_id)
        except Exception as ex:
            LOG.error(
                _LE("delete volume mapper failed! vol: %(id)s,"
                    "ex = %(ex)s"), {
                        'id': volume.id,
                        'ex': ex
                    })
            msg = (_("volume_mapper_delete failed! vol: %(id)s,ex: %(ex)s"), {
                'id': volume.id,
                'ex': ex
            })
            raise cinder_ex.VolumeBackendAPIException(data=msg)
Beispiel #10
0
    def create_snapshot(self, snapshot):
        context = req_context.RequestContext(is_admin=True,
                                             project_id=snapshot.project_id)
        volume = snapshot.volume
        try:
            provider_vol = self._get_provider_volume_id(context, volume)
            provider_snap = self._create_snapshot(context, provider_vol,
                                                  snapshot.id)
        except Exception as ex:
            LOG.error(_LE("create snapshot %(id)s failed! ex = %(ex)s"), {
                'id': snapshot.id,
                'ex': ex
            })
            msg = (_("create_snapshot failed! volume:%s") % snapshot.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        # create volume snapshot mapper
        try:
            values = {"provider_snapshot_id": provider_snap['SnapshotId']}
            self.caa_db_api.volume_snapshot_mapper_create(
                context, snapshot.id, context.project_id, values)
        except Exception as ex:
            LOG.error(
                _LE("create snapshot mapper failed! snapshot:%(id)s,"
                    "ex = %(ex)s"), {
                        'id': snapshot.id,
                        'ex': ex
                    })
            self._aws_client.get_aws_client(context).\
                delete_snapshot(
                SnapshotId=provider_snap['SnapshotId']
            )
            msg = (_("create_snapshot failed! snapshot:%s") % snapshot.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        LOG.info(_LI("create snapshot:%s success!"), snapshot.id)
Beispiel #11
0
    def create_volume(self, volume):
        context = req_context.RequestContext(is_admin=True,
                                             project_id=volume.project_id)
        try:
            provider_vol = self._create_volume(volume, context)
        except Exception:
            msg = (_("create_volume failed! volume:%s") % volume.id)
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        # create local volume mapper
        try:
            values = {'provider_volume_id': provider_vol['VolumeId']}
            self.caa_db_api.volume_mapper_create(context, volume.id,
                                                 context.project_id, values)
        except Exception as ex:
            msg = (_("volume_mapper_create failed! vol: %(id)s,ex: %(ex)s"), {
                'id': volume.id,
                'ex': ex
            })
            self._aws_client.get_aws_client(context).\
                delete_volume(VolumeId=provider_vol['VolumeId'])
            raise cinder_ex.VolumeBackendAPIException(data=msg)

        LOG.debug('create volume %s success.' % volume.id)
Beispiel #12
0
def check_qemu_img_version(minimum_version):
    qemu_version = get_qemu_img_version()
    if (qemu_version is None
            or qemu_version < _get_version_from_string(minimum_version)):
        if qemu_version:
            current_version = '.'.join(
                (str(element) for element in qemu_version))
        else:
            current_version = None

        _msg = _('qemu-img %(minimum_version)s or later is required by '
                 'this volume driver. Current qemu-img version: '
                 '%(current_version)s') % {
                     'minimum_version': minimum_version,
                     'current_version': current_version
                 }
        raise exception.VolumeBackendAPIException(data=_msg)
Beispiel #13
0
 def _create_snapshot(self, context, provider_vol, os_id):
     try:
         snapshot_args = {'VolumeId': provider_vol}
         provider_snap = self._aws_client.get_aws_client(context).\
             create_snapshot(**snapshot_args)
         # create remote volume mapper
         tags = [{'Key': 'caa_snapshot_id', 'Value': os_id}]
         self._aws_client.get_aws_client(context).\
             create_tags(
             Resources=[provider_snap['SnapshotId']],
             Tags=tags
         )
     except Exception as ex:
         LOG.error(
             _LE("create provider snapshot failed! os_id:%(os_id)s,"
                 " ex = %(ex)s"), {
                     'os_id': os_id,
                     'ex': ex
                 })
         msg = (_("create provider snapshot failed os_id:%s") % os_id)
         raise cinder_ex.VolumeBackendAPIException(data=msg)
     return provider_snap
Beispiel #14
0
    def _modify_volume(self, volume, new_size=None, new_type=None):
        context = req_context.RequestContext(is_admin=True,
                                             project_id=volume.project_id)
        snapshot = None
        try:
            old_vol = self._get_provider_volume_id(context, volume)
            snapshot = self._aws_client.get_aws_client(context).\
                create_snapshot(VolumeId=old_vol)
            provider_vol = self._create_volume(volume,
                                               context,
                                               snapshot=snapshot['SnapshotId'],
                                               new_type=new_type,
                                               new_size=new_size)
        except Exception as ex:
            msg = _("Modify Volume failed! Result: %s.") % ex
            raise cinder_ex.VolumeBackendAPIException(data=msg)
        finally:
            if snapshot:
                self._aws_client.get_aws_client(context).\
                    delete_snapshot(
                    SnapshotId=snapshot['SnapshotId']
                )

        # update local volume mapper
        try:
            values = {'provider_volume_id': provider_vol['VolumeId']}
            self.caa_db_api.volume_mapper_update(context, volume.id,
                                                 context.project_id, values)
        except Exception as ex:
            LOG.error(_LE("volume_mapper_create failed! ex = %s"), ex)
            self._aws_client.get_aws_client(context).\
                delete_volume(VolumeId=provider_vol['VolumeId'])
            raise
        self._aws_client.get_aws_client(context).\
            delete_volume(VolumeId=old_vol)
        LOG.debug('create volume %s success.' % volume.id)