def delete_group_snapshot(self, context, group_snapshot, force=False): check_policy(context, 'delete_group_snapshot') values = {'status': 'deleting'} expected = {'status': ('available', 'error')} filters = [ ~db.group_creating_from_src(group_snapshot_id=group_snapshot.id) ] res = group_snapshot.conditional_update(values, expected, filters) if not res: msg = _('GroupSnapshot status must be available or error, and no ' 'Group can be currently using it as source for its ' 'creation.') raise exception.InvalidGroupSnapshot(reason=msg) snapshots = objects.SnapshotList.get_all_for_group_snapshot( context, group_snapshot.id) # TODO(xyang): Add a new db API to update all snapshots statuses # in one db API call. for snap in snapshots: snap.status = c_fields.SnapshotStatus.DELETING snap.save() self.volume_rpcapi.delete_group_snapshot(context.elevated(), group_snapshot)
def delete_group_snapshot(self, context, group_snapshot, force=False): check_policy(context, 'delete_group_snapshot') values = {'status': 'deleting'} expected = {'status': ('available', 'error')} filters = [~db.group_creating_from_src( group_snapshot_id=group_snapshot.id)] res = group_snapshot.conditional_update(values, expected, filters) if not res: msg = _('GroupSnapshot status must be available or error, and no ' 'Group can be currently using it as source for its ' 'creation.') raise exception.InvalidGroupSnapshot(reason=msg) snapshots = objects.SnapshotList.get_all_for_group_snapshot( context, group_snapshot.id) # TODO(xyang): Add a new db API to update all snapshots statuses # in one db API call. for snap in snapshots: snap.status = c_fields.SnapshotStatus.DELETING snap.save() self.volume_rpcapi.delete_group_snapshot(context.elevated(), group_snapshot)