def _gc_delete(self, vname): """Delete volume and its hidden parents Deletes volume by going recursively to the first active parent and cals recursive deletion on storage side """ vol = None try: vol = self.ra.get_lun(vname) except jexc.JDSSResourceNotFoundException: LOG.debug('volume %s does not exist, it was already ' 'deleted.', vname) return except jexc.JDSSException as jerr: raise exception.VolumeBackendAPIException(jerr) if vol['is_clone']: self._delete_back_recursively(jcom.origin_volume(vol['origin']), jcom.origin_snapshot(vol['origin'])) else: try: self.ra.delete_lun(vname, force_umount=True) except jexc.JDSSRESTException as jerr: LOG.debug( "Unable to delete physical volume %(volume)s " "with error %(err)s.", { "volume": vname, "err": jerr }) raise exception.VolumeIsBusy(jerr)
def delete_volume(self, volume): """Destroy a volume. :param volume: volume reference """ volume_name = volume['id'] volume_info = {} try: volume_info = self.ra.get_lun(self.pool, volume_name) except exception.JDSSException as err: if 'unable to get volume' in err.args[0]: LOG.debug( 'Volume %s does not exist, it seems it was already ' 'deleted.', volume_name) return # TODO([email protected]): implement rising of exceptions # VolumeIsBusy, VolumeDriverException and VolumeBackendAPIException try: self.ra.delete_lun(self.pool, volume_name) except exception.JDSSRESTException as err: if "volume is busy" == err.args[0]: LOG.error('Failed to delete volume %(id)', {"id": volume['id']}) raise exception.VolumeIsBusy( data=('Failed to delete volume %s', volume['id'])) raise exception.VolumeBackendAPIException( "Fail during volume deletion.") LOG.debug("JovianDSS: volume info is %s.", volume_info) if 'origin' in volume_info and 'replication_driver_data' in volume: if (volume_info["origin"] is not None) and\ (volume['replication_driver_data'] is not None): rdd_data = volume['replication_driver_data'] rdd_snapshots = self.re_tmp_snapshot.match(rdd_data).group(1) origin_volume = jcom.origin_volume(self.pool, volume_info["origin"]) origin_snapshot = jcom.origin_snapshot(volume_info["origin"]) LOG.debug( "JovianDSS: Original vol %(orig_vol)s" "original snap %(orig_snap)s " "replication_driver_data %(rdd)s", { "orig_vol": jcom.origin_volume(self.pool, volume_info["origin"]), "orig_snap": jcom.origin_snapshot(volume_info["origin"]), "rdd": rdd_snapshots }) if origin_snapshot == rdd_snapshots: try: self.ra.delete_snapshot(self.pool, origin_volume, origin_snapshot) except exception.JDSSRESTException as err: LOG.debug( "Unable to delete temporal snapshot %(snapshot)s" " of volume %(volume) with error %(err).", { "snapshot": origin_snapshot, "volume": volume, "err": err }) raise exception.SnapshotIsBusy(err) return return
def _delete_back_recursively(self, opvname, opsname): """Deletes snapshot by removing its oldest removable parent Checks if source volume for this snapshot is hidden: If it is hidden and have no other descenents, it calls itself on its source snapshot if such exists, or deletes it If it is not hidden, trigers delete for snapshot :param opvname: origin physical volume name :param opsname: origin physical snapshot name """ if jcom.is_hidden(opvname): # Resource is hidden snaps = [] try: snaps = self.ra.get_snapshots(opvname) except jexc.JDSSResourceNotFoundException: LOG.debug( 'Unable to get physical snapshots related to' ' physical volume %s, volume do not exist', opvname) return except jexc.JDSSException as jerr: raise exception.VolumeBackendAPIException(jerr) snaps = self._clean_garbage_snapshots(opvname, snaps) if len(snaps) > 1: # opvname has active snapshots and cant be deleted # that is why we delete branch related to opsname try: self.ra.delete_snapshot(opvname, opsname, recursively_children=True, recursively_dependents=True, force_umount=True) except jexc.JDSSException as jerr: raise exception.VolumeBackendAPIException(jerr) else: vol = None try: vol = self.ra.get_lun(opvname) except jexc.JDSSResourceNotFoundException: LOG.debug( 'volume %s does not exist, it was already ' 'deleted.', opvname) return except jexc.JDSSException as jerr: raise exception.VolumeBackendAPIException(jerr) if vol['is_clone']: self._delete_back_recursively( jcom.origin_volume(vol['origin']), jcom.origin_snapshot(vol['origin'])) else: try: self.ra.delete_lun(opvname, recursively_children=True, recursively_dependents=True, force_umount=True) except jexc.JDSSResourceNotFoundException: LOG.debug( 'volume %s does not exist, it was already ' 'deleted.', opvname) return except jexc.JDSSException as jerr: raise exception.VolumeBackendAPIException(jerr) else: # Resource is active try: self.ra.delete_snapshot(opvname, opsname, recursively_children=True, recursively_dependents=True, force_umount=True) except jexc.JDSSException as jerr: raise exception.VolumeBackendAPIException(jerr) from jerr