Filter storage volumes list by "used_by"

Is it possible to filter for volumes that are not attached to any instance and list them? For example, if I have a volume that looks like this:

config:
  size: 5GiB
description: ""
name: testing-disk01
type: custom
used_by: []
location: none
content_type: block
project: default
created_at: 2023-11-25T00:34:45.159711339Z

I can see this volume when filtering on fields like content_type and type.

$ incus storage volume list default -fcompact 'content_type=block' 'type=custom'
   TYPE        NAME       DESCRIPTION  CONTENT-TYPE  USED BY
  custom  testing-disk01               block         0
  custom  testing-disk02               block         1
  custom  testing-disk03               block         1

But trying to filter by the used_by field doesn’t appear to be supported.

$ incus storage volume list default -fcompact used_by=0
Error: Invalid type "slice" for field "used_by"

Which makes sense since the values for used_by in the volume’s config is indeed a slice/array. It looks like the filter (here) simply doesn’t allow matching on slices. Only strings, integers, and booleans.

What I’m trying to achieve is to get just the names of volumes that are not attached to an instance (something like used_by == []). I can get what I want with awk:

$ incus storage volume list default -cnu -fcsv 'content_type=block' 'type=custom' | awk 'BEGIN { FS="," } $2==0 { print $1 }'
testing-disk01

But it would be nice if I can just add something like used_by=? in the same incus command instead. Or if there’s another subcommand that can do this with instead I’d really appreciate any tips.

Thanks!

Hmm, yeah, this is server-side filtering but we should be able to make the used_by=[] syntax work with a small server-side change.

Can you file that feature request at Issues · lxc/incus · GitHub ?

I should be able to take a stab at it shortly.

So sorry for the late reply. The weekend got away from me and couldn’t create that issue right away. Looks like you already implemented that feature by now though. Really appreciate the fast turnaround and looking forward to upgrading and taking advantage of that.

Thanks!

Yep, Incus 0.3 should have what you need!

1 Like