Beispiel #1
0
    def restore_backup(self, sg_client, backup, restore_volume, device):
        driver_data = jsonutils.loads(backup.driver_data)
        vol_id = driver_data['volume_id']
        vol_size = backup['size']
        backup_id = driver_data['backup_id']
        # backup_type: local, remote
        backup_type = backup['destination']
        # new volume id
        new_vol_id = restore_volume.id
        new_vol_size = restore_volume.size * GB_SIZE
        new_device = device

        try:
            res = self.backup_ctrl(sg_client).RestoreBackup(
                backup_id, backup_type, vol_id, vol_size, new_vol_id,
                new_vol_size, new_device)
        except Exception as exc:
            msg = (_LE('restore backup failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('restore backup failed, err_no: %s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #2
0
    def disable_sg(self, sg_client, volume):
        try:
            res = self.volume_ctrl(sg_client).DisableSG(volume.id)
        except Exception as exc:
            msg = (_LE('disable sg failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('disable sg failed, err_no: %s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #3
0
    def detach_volume(self, sg_client, volume):
        try:
            res = self.volume_ctrl(sg_client).DetachVolume(volume.id)
        except Exception as exc:
            msg = (_LE('detach volume failed, err:%s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('detach volume failed, err_no:%s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #4
0
    def list_devices(self, sg_client):
        try:
            res = self.volume_ctrl(sg_client).ListDevices()
        except Exception as exc:
            msg = (_LE('list devices failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('list devices failed, err_no: %s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
        return res.devices
Beispiel #5
0
    def create_volume_from_snapshot(self, sg_client, snapshot, new_volume_id,
                                    device):
        try:
            res = self.snap_ctrl(sg_client).CreateVolumeFromSnap(
                snapshot.volume_id, snapshot.id, new_volume_id, device)
        except Exception as exc:
            msg = (_LE('create volume from snapshot failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.header.status != 0:
            msg = (_LE('create volume from snapshot failed, '
                       'err_noe: %s'), res.header.status)
            raise exception.SGDriverError(reason=msg)
Beispiel #6
0
    def query_volume_from_snapshot(self, sg_client, new_volume_id):
        try:
            res = self.snap_ctrl(sg_client).QueryVolumeFromSnap(new_volume_id)
        except Exception as exc:
            msg = (_LE('query volume from snapshot failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.header.status != 0:
            msg = (_LE('query volume from snapshot failed, '
                       'err_noe: %s'), res.header.status)
            raise exception.SGDriverError(reason=msg)
        return {'id': new_volume_id,
                'status': VOLUME_STATUS_MAPPING[res.vol_status]}
Beispiel #7
0
    def enable_sg(self, sg_client, volume, device):
        vol_size = volume.size * GB_SIZE
        try:
            res = self.volume_ctrl(sg_client).EnableSG(
                volume.id, vol_size, device)
        except Exception as exc:
            msg = (_LE('enable sg failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('enable sg failed, err_no: %s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #8
0
    def terminate_connection(self, sg_client, volume, mode, device=None):
        mode = CLIENT_MODE_MAPPING.get(mode, common_pb2.ISCSI_MODE)
        try:
            res = self.volume_ctrl(sg_client).TerminateConnection(
                volume.id, mode, device)
        except Exception as exc:
            msg = (_LE('terminate connection failed, err:%s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('terminate connection failed, err_no:%s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #9
0
    def reverse_replicate(self, sg_client, volume):
        vol_id = volume.id
        role = REPLICATE_ROLE_MAPPING[volume.replicate_mode]
        try:
            res = self.replicate_ctrl(sg_client).ReverseReplication(
                vol_id, role)
        except Exception as exc:
            msg = (_LE('reverse replicate failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('reverse replicate failed, err_no: %s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #10
0
    def delete_backup(self, sg_client, backup):
        vol_id = backup.volume_id
        backup_id = backup.id

        try:
            res = self.backup_ctrl(sg_client).DeleteBackup(backup_id, vol_id)
        except Exception as exc:
            msg = (_LE('delete backup failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('delete backup failed, err_no: %s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #11
0
    def failover_replicate(self, sg_client, volume, checkpoint_id,
                           snapshot_id):
        vol_id = volume.id
        role = REPLICATE_ROLE_MAPPING[volume.replicate_mode]
        try:
            res = self.replicate_ctrl(sg_client).FailoverReplication(
                vol_id, role, checkpoint_id=checkpoint_id,
                snapshot_id=snapshot_id)
        except Exception as exc:
            msg = (_LE('failover replicate failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('failover replicate failed, err_no: %s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #12
0
    def create_replicate(self, sg_client, volume):
        rep_uuid = volume.replication_id
        role = REPLICATE_ROLE_MAPPING[volume.replicate_mode]
        local_volume = volume.id
        peer_volumes = [volume.peer_volume]
        try:
            res = self.replicate_ctrl(sg_client).CreateReplication(
                rep_uuid, local_volume, role, peer_volumes)
        except Exception as exc:
            msg = (_LE('create replicate failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('create replicate failed, err_no: %s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #13
0
    def create_backup(self, sg_client, backup):
        # backup_mode: full, incremental
        backup_mode = backup.type
        # backup_type: local, remote
        backup_type = backup.destination
        vol_id = backup.volume_id
        vol_size = backup.size * GB_SIZE
        backup_id = backup.id

        try:
            res = self.backup_ctrl(sg_client).CreateBackup(
                backup_mode, backup_type, vol_id, vol_size, backup_id)
        except Exception as exc:
            msg = (_LE('create backup failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('create backup failed, err_no: %s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #14
0
    def rollback_snapshot(self, sg_client, snapshot):
        vol_id = snapshot.volume_id
        snap_id = snapshot.id
        snap_type = snapshot.destination
        if snapshot.checkpoint_id:
            checkpoint_uuid = snapshot.checkpoint_id
        else:
            checkpoint_uuid = None

        try:
            res = self.snap_ctrl(sg_client).RollbackSnapshot(
                snap_type, vol_id, snap_id, checkpoint_uuid)
        except Exception as exc:
            msg = (_LE('rollback snapshot failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.header.status != 0:
            msg = (_LE('rollback snapshot failed, err_no: %s'),
                   res.header.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
Beispiel #15
0
    def get_backup(self, sg_client, backup):
        vol_id = backup.volume_id
        backup_id = backup.id

        try:
            res = self.backup_ctrl(sg_client).GetBackup(backup_id, vol_id)
        except Exception as exc:
            msg = (_LE('get backup failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            if res.status == common_pb2.sBackupNotExist:
                backup = {'id': backup.id,
                          'status': fields.BackupStatus.DELETED}
            else:
                msg = (_LE('get backup failed, err_no: %s'), res.status)
                LOG.error(msg)
                raise exception.SGDriverError(reason=msg)
        else:
            backup = {'id': backup.id,
                      'status': BACKUP_STATUS_MAPPING[res.backup_status]}
        return backup
Beispiel #16
0
    def get_snapshot(self, sg_client, snapshot):
        vol_id = snapshot.volume_id
        snap_id = snapshot.id

        try:
            res = self.snap_ctrl(sg_client).GetSnapshot(vol_id, snap_id)
        except Exception as exc:
            msg = (_LE('get snapshot failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.header.status != 0:
            if res.header.status == common_pb2.sSnapNotExist:
                snapshot = {'id': snapshot.id,
                            'status': fields.SnapshotStatus.DELETED}
            else:
                msg = (_LE('get snapshot failed, err_no: %s'),
                       res.header.status)
                LOG.error(msg)
                raise exception.SGDriverError(reason=msg)
        else:
            snapshot = {'id': snapshot.id,
                        'status': SNAPSHOT_STATUS_MAPPING[res.snap_status]}
        return snapshot
Beispiel #17
0
    def initialize_connection(self, sg_client, volume, mode):
        mode = CLIENT_MODE_MAPPING.get(mode, common_pb2.ISCSI_MODE)
        try:
            res = self.volume_ctrl(sg_client).InitializeConnection(
                volume.id, mode)
        except Exception as exc:
            msg = (_LE('initialize connection failed, err:%s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            msg = (_LE('initialize connection failed, err_no:%s'), res.status)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)
        if mode == common_pb2.ISCSI_MODE:
            target_portal = "%s:3260" % sg_client.host
            target_iqn = res.connection_info['target_iqn']
            target_lun = int(res.connection_info['target_lun'])
            connection_info = {
                'target_portal': target_portal,
                'target_iqn': target_iqn,
                'target_lun': target_lun,
            }
            return connection_info
Beispiel #18
0
    def get_volume(self, sg_client, volume):
        try:
            res = self.volume_ctrl(sg_client).GetVolume(volume.id)
        except Exception as exc:
            msg = (_LE('get volume  failed, err: %s'), exc)
            LOG.error(msg)
            raise exception.SGDriverError(reason=msg)

        if res.status != 0:
            volume = {'id': volume.id,
                      'status': fields.VolumeStatus.DELETED,
                      'replicate_status': fields.ReplicateStatus.DELETED}
            return volume

        status = VOLUME_STATUS_MAPPING[res.volume.vol_status]
        replicate_status = REPLICATE_STATUS_MAPPING[res.volume.rep_status]

        volume = {
            'id': volume.id,
            'status': status,
            'replicate_status': replicate_status,
            'replicate_mode': ROLE_REPLICATE_MAPPING.get(res.volume.role,
                                                         None)}
        return volume