def delete_snapshot(self, snapshot_id): logger.info("Deleting snapshot with id : {0}".format(snapshot_id)) snapshot_name = self._get_volume_name_by_wwn_if_exists(snapshot_id) if not snapshot_name: raise controller_errors.SnapshotNotFoundError(snapshot_id) cli_volume = self._get_cli_volume_if_exists(snapshot_name) if not cli_volume or not cli_volume.FC_id: raise controller_errors.SnapshotNotFoundError(snapshot_name) self._delete_snapshot(cli_volume) logger.info("Finished snapshot deletion. id : {0}".format(snapshot_id))
def _copy_to_existing_volume_from_snapshot(self, vol, src_snapshot_id, min_vol_size, array_mediator, pool): vol_name = vol.volume_name try: src_snapshot = array_mediator.get_snapshot_by_id(src_snapshot_id) if not src_snapshot: raise controller_errors.SnapshotNotFoundError(src_snapshot_id) src_snapshot_name = src_snapshot.snapshot_name src_snapshot_capacity = src_snapshot.capacity_bytes logger.debug("Copy snapshot {0} data to volume {1}.".format( src_snapshot_id, vol_name)) array_mediator.copy_to_existing_volume_from_snapshot( vol_name, src_snapshot_name, src_snapshot_capacity, min_vol_size, pool) logger.debug("Copy volume from snapshot finished") except controller_errors.VolumeNotFoundError as ex: logger.error( "Volume not found while copying snapshot data to volume") logger.exception(ex) raise ex except Exception as ex: logger.error( "Exception raised while copying snapshot data to volume") self._rollback_create_volume_from_snapshot(array_mediator, vol.id) raise ex return vol
def copy_to_existing_volume_from_snapshot(self, name, src_snap_name, src_snap_capacity_in_bytes, min_vol_size_in_bytes, pool=None): logger.debug( "Copy snapshot {0} data to volume {1}. Snapshot capacity {2}. Minimal requested volume capacity {3}".format( name, src_snap_name, src_snap_capacity_in_bytes, min_vol_size_in_bytes)) try: logger.debug("Formatting volume {0}".format(name)) self.client.cmd.vol_format(vol=name) logger.debug("Copying Snapshot {0} data to volume {1}.".format(name, src_snap_name)) self.client.cmd.vol_copy(vol_src=src_snap_name, vol_trg=name) if min_vol_size_in_bytes > src_snap_capacity_in_bytes: min_vol_size_in_blocks = self._convert_size_bytes_to_blocks(min_vol_size_in_bytes) logger.debug( "Increasing volume {0} size to {1} blocks.".format(name, min_vol_size_in_blocks)) self.client.cmd.vol_resize(vol=name, size_blocks=min_vol_size_in_blocks) except xcli_errors.IllegalNameForObjectError as ex: logger.exception(ex) raise controller_errors.IllegalObjectName(ex.status) except xcli_errors.SourceVolumeBadNameError as ex: logger.exception(ex) raise controller_errors.SnapshotNotFoundError(src_snap_name) except (xcli_errors.VolumeBadNameError, xcli_errors.TargetVolumeBadNameError) as ex: logger.exception(ex) raise controller_errors.VolumeNotFoundError(name) except xcli_errors.OperationForbiddenForUserCategoryError as ex: logger.exception(ex) raise controller_errors.PermissionDeniedError("create vol : {0}".format(name))
def delete_snapshot(self, snapshot_id): logger.info("Deleting snapshot with id : {0}".format(snapshot_id)) try: snapshot_name = self._get_vol_by_wwn(snapshot_id) except controller_errors.VolumeNotFoundError: raise controller_errors.SnapshotNotFoundError(snapshot_id) try: self.client.cmd.snapshot_delete(snapshot=snapshot_name) except xcli_errors.VolumeBadNameError as ex: logger.exception(ex) raise controller_errors.SnapshotNotFoundError(snapshot_name) except xcli_errors.OperationForbiddenForUserCategoryError as ex: logger.exception(ex) raise controller_errors.PermissionDeniedError("delete snapshot : {0}".format(snapshot_name)) logger.info("Finished snapshot deletion. id : {0}".format(snapshot_id))
def _delete_snapshot(self, cli_volume): fcmap_id = cli_volume.FC_id snapshot_name = cli_volume.name if fcmap_id == 'many': self._delete_all_fcmaps_as_source_if_exist(snapshot_name) fcmap = self._get_fcmap_as_target_if_exists(snapshot_name) if not fcmap: raise controller_errors.SnapshotNotFoundError(snapshot_name) self._stop_and_delete_fcmap(fcmap.id) self._delete_volume_by_name(snapshot_name)
def delete_snapshot(self, snapshot_id): logger.info("Deleting snapshot with id : {0}".format(snapshot_id)) volume_id = get_volume_id_from_scsi_identifier(snapshot_id) api_volume = self._get_api_volume_by_id(volume_id, not_exist_err=False) if not api_volume: raise array_errors.SnapshotNotFoundError(snapshot_id) if not api_volume.flashcopy: logger.error( "FlashCopy relationship not found for target volume: {}". format(api_volume.name)) raise array_errors.SnapshotNameBelongsToVolumeError( api_volume.name, self.service_address) self._check_snapshot_use_status(volume_id, api_volume.flashcopy) self.delete_volume(volume_id) logger.info("Finished snapshot deletion. id : {0}".format(snapshot_id))