'Deletes group and the volumes in the group.'

def delete_group(self, context, group):

    context = context.elevated()
    project_id = group.project_id
    if (context.project_id != group.project_id):
        project_id = group.project_id
    else:
        project_id = context.project_id
    volumes = objects.VolumeList.get_all_by_generic_group(context, group.id)
    for vol_obj in volumes:
        if (vol_obj.attach_status == 'attached'):
            raise exception.VolumeAttached(volume_id=vol_obj.id)
        self._check_is_our_resource(vol_obj)
    self._notify_about_group_usage(context, group, 'delete.start')
    volumes_model_update = None
    model_update = None
    try:
        utils.require_driver_initialized(self.driver)
        try:
            (model_update, volumes_model_update) = self.driver.delete_group(context, group, volumes)
        except NotImplementedError:
            cgsnap_type = group_types.get_default_cgsnapshot_type()
            if (group.group_type_id != cgsnap_type['id']):
                (model_update, volumes_model_update) = self._delete_group_generic(context, group, volumes)
            else:
                (cg, volumes) = self._convert_group_to_cg(group, volumes)
                (model_update, volumes_model_update) = self.driver.delete_consistencygroup(context, cg, volumes)
                self._remove_consistencygroup_id_from_volumes(volumes)
        if volumes_model_update:
            for update in volumes_model_update:
                if ((update['status'] in ['error_deleting', 'error']) and (model_update['status'] not in ['error_deleting', 'error'])):
                    model_update['status'] = update['status']
            self.db.volumes_update(context, volumes_model_update)
        if model_update:
            if (model_update['status'] in ['error_deleting', 'error']):
                msg = _('Delete    group    failed.')
                LOG.error(msg, resource={'type': 'group', 'id': group.id})
                raise exception.VolumeDriverException(message=msg)
            else:
                group.update(model_update)
                group.save()
    except Exception:
        with excutils.save_and_reraise_exception():
            group.status = fields.GroupStatus.ERROR
            group.save()
            if (not volumes_model_update):
                self._remove_consistencygroup_id_from_volumes(volumes)
                for vol_obj in volumes:
                    vol_obj.status = 'error'
                    vol_obj.save()
    try:
        reserve_opts = {'groups': (-1)}
        grpreservations = GROUP_QUOTAS.reserve(context, project_id=project_id, **reserve_opts)
    except Exception:
        grpreservations = None
        LOG.exception('Delete    group    failed    to    update    usages.', resource={'type': 'group', 'id': group.id})
    for vol in volumes:
        try:
            reserve_opts = {'volumes': (-1), 'gigabytes': (- vol.size)}
            QUOTAS.add_volume_type_opts(context, reserve_opts, vol.volume_type_id)
            reservations = QUOTAS.reserve(context, project_id=project_id, **reserve_opts)
        except Exception:
            reservations = None
            LOG.exception('Delete    group    failed    to    update    usages.', resource={'type': 'group', 'id': group.id})
        self.db.volume_glance_metadata_delete_by_volume(context, vol.id)
        vol.destroy()
        if reservations:
            QUOTAS.commit(context, reservations, project_id=project_id)
        self.stats['allocated_capacity_gb'] -= vol.size
    if grpreservations:
        GROUP_QUOTAS.commit(context, grpreservations, project_id=project_id)
    group.destroy()
    self._notify_about_group_usage(context, group, 'delete.end')
    self.publish_service_capabilities(context)
    LOG.info('Delete    group    completed    successfully.', resource={'type': 'group', 'id': group.id})
