'Deletes group_snapshot.'

def delete_group_snapshot(self, context, group_snapshot):

    caller_context = context
    context = context.elevated()
    project_id = group_snapshot.project_id
    LOG.info('group_snapshot    %s:    deleting', group_snapshot.id)
    snapshots = objects.SnapshotList.get_all_for_group_snapshot(context, group_snapshot.id)
    self._notify_about_group_snapshot_usage(context, group_snapshot, 'delete.start')
    snapshots_model_update = None
    model_update = None
    try:
        utils.require_driver_initialized(self.driver)
        LOG.debug('group_snapshot    %(grp_snap_id)s:    deleting', {'grp_snap_id': group_snapshot.id})
        group_snapshot.context = caller_context
        for snapshot in snapshots:
            snapshot.context = caller_context
        try:
            (model_update, snapshots_model_update) = self.driver.delete_group_snapshot(context, group_snapshot, snapshots)
        except NotImplementedError:
            cgsnap_type = group_types.get_default_cgsnapshot_type()
            if (group_snapshot.group_type_id != cgsnap_type['id']):
                (model_update, snapshots_model_update) = self._delete_group_snapshot_generic(context, group_snapshot, snapshots)
            else:
                (cgsnapshot, snapshots) = self._convert_group_snapshot_to_cgsnapshot(group_snapshot, snapshots, context)
                (model_update, snapshots_model_update) = self.driver.delete_cgsnapshot(context, cgsnapshot, snapshots)
                self._remove_cgsnapshot_id_from_snapshots(snapshots)
        if snapshots_model_update:
            for snap_model in snapshots_model_update:
                snap = next((item for item in snapshots if (item.id == snap_model['id'])), None)
                if snap:
                    snap_model.pop('id')
                    snap.update(snap_model)
                    snap.save()
                if ((snap_model['status'] in [fields.SnapshotStatus.ERROR_DELETING, fields.SnapshotStatus.ERROR]) and (model_update['status'] not in ['error_deleting', 'error'])):
                    model_update['status'] = snap_model['status']
        if model_update:
            if (model_update['status'] in ['error_deleting', 'error']):
                msg = (_('Error    occurred    when    deleting    group_snapshot    %s.') % group_snapshot.id)
                LOG.error(msg)
                raise exception.VolumeDriverException(message=msg)
            else:
                group_snapshot.update(model_update)
                group_snapshot.save()
    except exception.CinderException:
        with excutils.save_and_reraise_exception():
            group_snapshot.status = fields.GroupSnapshotStatus.ERROR
            group_snapshot.save()
            if (not snapshots_model_update):
                self._remove_cgsnapshot_id_from_snapshots(snapshots)
                for snapshot in snapshots:
                    snapshot.status = fields.SnapshotStatus.ERROR
                    snapshot.save()
    for snapshot in snapshots:
        try:
            if CONF.no_snapshot_gb_quota:
                reserve_opts = {'snapshots': (-1)}
            else:
                reserve_opts = {'snapshots': (-1), 'gigabytes': (- snapshot.volume_size)}
            volume_ref = objects.Volume.get_by_id(context, snapshot.volume_id)
            QUOTAS.add_volume_type_opts(context, reserve_opts, volume_ref.volume_type_id)
            reservations = QUOTAS.reserve(context, project_id=project_id, **reserve_opts)
        except Exception:
            reservations = None
            LOG.exception('Failed    to    update    usages    deleting    snapshot')
        self.db.volume_glance_metadata_delete_by_snapshot(context, snapshot.id)
        snapshot.destroy()
        if reservations:
            QUOTAS.commit(context, reservations, project_id=project_id)
    group_snapshot.destroy()
    LOG.info('group_snapshot    %s:    deleted    successfully', group_snapshot.id)
    self._notify_about_group_snapshot_usage(context, group_snapshot, 'delete.end', snapshots)
