def _clone_object(self, oname, coname): """Creates a clone of specified object :param: oname: name of an object to clone :param: coname: name of a new clone """ LOG.debug('cloning %(oname)s to %(coname)s', { "oname": oname, "coname": coname }) try: self.ra.create_snapshot(oname, coname) except jexc.JDSSSnapshotExistsException: try: self.ra.delete_snapshot(oname, coname) except jexc.JDSSSnapshotIsBusyException as jerrisbusy: raise exception.Duplicate() from jerrisbusy except jexc.JDSSException as jerr: raise exception.VolumeBackendAPIException( (_("Unable to create volume %s.") % coname)) from jerr except jexc.JDSSResourceNotFoundException as jerrnotfound: if jcom.is_volume(oname): raise exception.VolumeNotFound( volume_id=jcom.idname(oname)) from jerrnotfound raise exception.SnapshotNotFound( snapshot_id=jcom.idname(oname)) from jerrnotfound except jexc.JDSSException as jerr: args = {'snapshot': coname, 'object': oname, 'err': jerr} msg = (_('Failed to create tmp snapshot %(snapshot)s ' 'for object %(object)s: %(err)s') % args) raise exception.VolumeBackendAPIException(msg) try: self.ra.create_volume_from_snapshot(coname, coname, oname, sparse=self.jovian_sparse) except jexc.JDSSResourceExistsException as jerr: raise exception.Duplicate() from jerr except jexc.JDSSException as jerr: try: self.ra.delete_snapshot(oname, coname, recursively_children=True, recursively_dependents=True, force_umount=True) except jexc.JDSSException as jerrd: LOG.warning( "Because of %s physical snapshot %s of volume" " %s have to be removed manually", jerrd, coname, oname) raise exception.VolumeBackendAPIException( _("Unable to create volume %(vol)s because of %(err)s.") % { 'vol': coname, 'err': jerr }) from jerr
def _clean_garbage_snapshots(self, vname, snapshots): """Delete physical snapshots that have no descendents""" garbage = [] for snap in snapshots: if snap['clones'] == '': try: self.ra.delete_snapshot(vname, snap['name']) except jexc.JDSSException as jerr: args = {'obj': jcom.idname(vname), 'err': jerr} msg = (_("Unable to clean garbage for " "%(obj)s: %(err)s") % args) raise exception.VolumeBackendAPIException(msg) garbage.append(snap) for snap in garbage: snapshots.remove(snap) return snapshots