Efficiet way to get all tags of all qubes

I searching for a efficient and general way to get all tags of all Qubes. The best thing I came up which is this ugly for loop.

for vm in $(qvm-ls --raw-list); do
   TAGS+=$'\n'
   TAGS+=$"$(qvm-tags "${vm}")"
done
TAGS=$"$(printf '%s' "${TAGS}" | sort -u)"

Furthermore I noticed that qvm-ls --raw-data -O=tags produces unreadable output. So this falls flat for now too.

My current loop solution unfortunately takes rather log to compute. Is there a more efficient and general way to do this?

Using python and the admin API is probably more efficient

https://dev.qubes-os.org/projects/core-admin/en/latest/

Something like this:

#!/usr/bin/python3

import qubesadmin

app = qubesadmin.Qubes()
for vm in app.domains:
    for tag in vm.tags:
        print(f"VM: {vm} TAG: {tag}")
1 Like

Thanks I will look into that.

Since this bigfix is in stable now. There is no need for a workaround any longer

qvm-ls --raw-data --field=tags | sed 's/,/\n/g' | sort -u

works perfectly well now and finishes in about 0.2s.