def delete_consistencygroup(self, context, group):
    'Deletes consistency group and the volumes in the 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 = self.db.volume_get_all_by_group(context, group.id)
    for volume_ref in volumes:
        if (volume_ref['attach_status'] == 'attached'):
            raise exception.VolumeAttached(volume_id=volume_ref['id'])
        if volume_ref['host']:
            new_host = vol_utils.extract_host(volume_ref['host'])
            if (new_host != self.host):
                raise exception.InvalidVolume(reason=_('Volume is not local to this node'))
    self._notify_about_consistencygroup_usage(context, group, 'delete.start')
    volumes_model_update = None
    model_update = None
    try:
        utils.require_driver_initialized(self.driver)
        (model_update, volumes_model_update) = self.driver.delete_consistencygroup(context, group, volumes)
        if volumes_model_update:
            for volume in volumes_model_update:
                update = {'status': volume['status']}
                self.db.volume_update(context, volume['id'], update)
                if ((volume['status'] in ['error_deleting', 'error']) and (model_update['status'] not in ['error_deleting', 'error'])):
                    model_update['status'] = volume['status']
        if model_update:
            if (model_update['status'] in ['error_deleting', 'error']):
                msg = _('Delete consistency group failed.')
                LOG.error(msg, resource={'type': 'consistency_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 = 'error'
            group.save()
            if (not volumes_model_update):
                for vol in volumes:
                    self.db.volume_update(context, vol['id'], {'status': 'error'})
    try:
        reserve_opts = {'consistencygroups': (- 1)}
        cgreservations = CGQUOTAS.reserve(context, project_id=project_id, **reserve_opts)
    except Exception:
        cgreservations = None
        LOG.exception(_LE('Delete consistency group failed to update usages.'), resource={'type': 'consistency_group', 'id': group.id})
    for volume_ref in volumes:
        try:
            volume_id = volume_ref['id']
            reserve_opts = {'volumes': (- 1), 'gigabytes': (- volume_ref['size'])}
            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('Delete consistency group failed to update usages.'), resource={'type': 'consistency_group', 'id': group.id})
        self.db.volume_glance_metadata_delete_by_volume(context, volume_id)
        self.db.volume_destroy(context, volume_id)
        if reservations:
            QUOTAS.commit(context, reservations, project_id=project_id)
        self.stats['allocated_capacity_gb'] -= volume_ref['size']
    if cgreservations:
        CGQUOTAS.commit(context, cgreservations, project_id=project_id)
    group.destroy()
    self._notify_about_consistencygroup_usage(context, group, 'delete.end', volumes)
    self.publish_service_capabilities(context)
    LOG.info(_LI('Delete consistency group completed successfully.'), resource={'type': 'consistency_group', 'id': group.id})
Deletes consistency group and the volumes in the group.
def delete_consistencygroup(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 = self.db.volume_get_all_by_group(context, group.id)
    for volume_ref in volumes:
        if (volume_ref['attach_status'] == 'attached'):
            raise exception.VolumeAttached(volume_id=volume_ref['id'])
        if volume_ref['host']:
            new_host = vol_utils.extract_host(volume_ref['host'])
            if (new_host != self.host):
                raise exception.InvalidVolume(reason=_('Volume is not local to this node'))
    self._notify_about_consistencygroup_usage(context, group, 'delete.start')
    volumes_model_update = None
    model_update = None
    try:
        utils.require_driver_initialized(self.driver)
        (model_update, volumes_model_update) = self.driver.delete_consistencygroup(context, group, volumes)
        if volumes_model_update:
            for volume in volumes_model_update:
                update = {'status': volume['status']}
                self.db.volume_update(context, volume['id'], update)
                if ((volume['status'] in ['error_deleting', 'error']) and (model_update['status'] not in ['error_deleting', 'error'])):
                    model_update['status'] = volume['status']
        if model_update:
            if (model_update['status'] in ['error_deleting', 'error']):
                msg = _('Delete consistency group failed.')
                LOG.error(msg, resource={'type': 'consistency_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 = 'error'
            group.save()
            if (not volumes_model_update):
                for vol in volumes:
                    self.db.volume_update(context, vol['id'], {'status': 'error'})
    try:
        reserve_opts = {'consistencygroups': (- 1)}
        cgreservations = CGQUOTAS.reserve(context, project_id=project_id, **reserve_opts)
    except Exception:
        cgreservations = None
        LOG.exception(_LE('Delete consistency group failed to update usages.'), resource={'type': 'consistency_group', 'id': group.id})
    for volume_ref in volumes:
        try:
            volume_id = volume_ref['id']
            reserve_opts = {'volumes': (- 1), 'gigabytes': (- volume_ref['size'])}
            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('Delete consistency group failed to update usages.'), resource={'type': 'consistency_group', 'id': group.id})
        self.db.volume_glance_metadata_delete_by_volume(context, volume_id)
        self.db.volume_destroy(context, volume_id)
        if reservations:
            QUOTAS.commit(context, reservations, project_id=project_id)
        self.stats['allocated_capacity_gb'] -= volume_ref['size']
    if cgreservations:
        CGQUOTAS.commit(context, cgreservations, project_id=project_id)
    group.destroy()
    self._notify_about_consistencygroup_usage(context, group, 'delete.end', volumes)
    self.publish_service_capabilities(context)
    LOG.info(_LI('Delete consistency group completed successfully.'), resource={'type': 'consistency_group', 'id': group.id})