Getting the restart state of running VMs via a script

Hi folks,

I’m currently using a script that is essentially an awk wrapper around qvm-ls that formats the output for use by conky (creating a list of the running qubes on my desktop).

I would like to extend the script to include an indication of the “restart status” (don’t know if that’s what it is actually called). What I mean replicating the green and gray arrows that show up in the Qubes Manager state column, the ones indicating the AppVM needs a restart due to template VM updates.

I have been searching, reading documentation, and can’t figure out where that information comes from, or how to replicate that information on the command line. It doesn’t appear to be in the FLAGS for qvm-ls, and no other qvm-* seems to be the command I’m looking for.

Does anyone know where I can pull that information via a script?

Have you checked the source code of the qube manager widget? There might be some info around there…

I think you can use qvm-volume, and use the is_outdated property.

e.g. qvm-volume info home:root will give you info of the root volume of the home vm.

1 Like

Thanks @renehoj. Using the is_outdated property of qvm-volume does indeed get me the information I needed to get this working.

I noticed that running qvm-volume on all of the running VMs created a CPU spike that was too high for a script that runs every 15 seconds. I ended up rewriting the script to cache that information for 15 minutes, to limit resource usage. This gives me the behavior I want with a simple enough mechanism to force a refresh (rm the cache file).

You can probably use the AdminAPI to get notified when a qube is closing.

You can see the implementation of qui-widget:

And it’s also using volume outdate info as renehoj said.

This is one way to detect a vm shutdown, and get a list of all appvms using it as their template.


import asyncio
import subprocess
import qubesadmin

def stop_event(vm, event, **kwargs):
    vm =[str(vm)] 
    print(f"VM: {} shutdown")
    for appvm in vm.appvms:
        print(f"APPVM: {}")
app = qubesadmin.Qubes()
dispatcher =
dispatcher.add_handler('domain-shutdown', stop_event)
1 Like

Thanks again @renehoj, the Python snippet above definitely pointed me in a better direction where I do not have to use qvm-volume to get that information.

I now have a Python script that watches for shutdowns as you suggested. When I have time to figure out qubesadmin a little more, I suspect I can rewrite the whole thing in Python and skip using qvm-ls as well.

1 Like