@locked_snapshot_operation
def delete_snapshot(self, context, snapshot, unmanage_only=False):
    'Deletes and unexports snapshot.'
    context = context.elevated()
    snapshot._context = context
    project_id = snapshot.project_id
    self._notify_about_snapshot_usage(context, snapshot, 'delete.start')
    try:
        utils.require_driver_initialized(self.driver)
        snapshot.context = context
        snapshot.save()
        if unmanage_only:
            self.driver.unmanage_snapshot(snapshot)
        else:
            self.driver.delete_snapshot(snapshot)
    except exception.SnapshotIsBusy:
        LOG.error(_LE('Delete snapshot failed, due to snapshot busy.'), resource=snapshot)
        snapshot.status = fields.SnapshotStatus.AVAILABLE
        snapshot.save()
        return
    except Exception:
        with excutils.save_and_reraise_exception():
            snapshot.status = fields.SnapshotStatus.ERROR_DELETING
            snapshot.save()
    try:
        if CONF.no_snapshot_gb_quota:
            reserve_opts = {'snapshots': (- 1)}
        else:
            reserve_opts = {'snapshots': (- 1), 'gigabytes': (- snapshot.volume_size)}
        volume_ref = self.db.volume_get(context, snapshot.volume_id)
        QUOTAS.add_volume_type_opts(context, reserve_opts, volume_ref.get('volume_type_id'))
        reservations = QUOTAS.reserve(context, project_id=project_id, **reserve_opts)
    except Exception:
        reservations = None
        LOG.exception(_LE('Update snapshot usages failed.'), resource=snapshot)
    self.db.volume_glance_metadata_delete_by_snapshot(context, snapshot.id)
    snapshot.destroy()
    self._notify_about_snapshot_usage(context, snapshot, 'delete.end')
    if reservations:
        QUOTAS.commit(context, reservations, project_id=project_id)
    LOG.info(_LI('Delete snapshot completed successfully'), resource=snapshot)
Deletes and unexports snapshot.
@locked_snapshot_operation
def delete_snapshot(self, context, snapshot, unmanage_only=False):
    
    context = context.elevated()
    snapshot._context = context
    project_id = snapshot.project_id
    self._notify_about_snapshot_usage(context, snapshot, 'delete.start')
    try:
        utils.require_driver_initialized(self.driver)
        snapshot.context = context
        snapshot.save()
        if unmanage_only:
            self.driver.unmanage_snapshot(snapshot)
        else:
            self.driver.delete_snapshot(snapshot)
    except exception.SnapshotIsBusy:
        LOG.error(_LE('Delete snapshot failed, due to snapshot busy.'), resource=snapshot)
        snapshot.status = fields.SnapshotStatus.AVAILABLE
        snapshot.save()
        return
    except Exception:
        with excutils.save_and_reraise_exception():
            snapshot.status = fields.SnapshotStatus.ERROR_DELETING
            snapshot.save()
    try:
        if CONF.no_snapshot_gb_quota:
            reserve_opts = {'snapshots': (- 1)}
        else:
            reserve_opts = {'snapshots': (- 1), 'gigabytes': (- snapshot.volume_size)}
        volume_ref = self.db.volume_get(context, snapshot.volume_id)
        QUOTAS.add_volume_type_opts(context, reserve_opts, volume_ref.get('volume_type_id'))
        reservations = QUOTAS.reserve(context, project_id=project_id, **reserve_opts)
    except Exception:
        reservations = None
        LOG.exception(_LE('Update snapshot usages failed.'), resource=snapshot)
    self.db.volume_glance_metadata_delete_by_snapshot(context, snapshot.id)
    snapshot.destroy()
    self._notify_about_snapshot_usage(context, snapshot, 'delete.end')
    if reservations:
        QUOTAS.commit(context, reservations, project_id=project_id)
    LOG.info(_LI('Delete snapshot completed successfully'), resource=snapshot)