Any better way to start a dom0 script whenever a qube starts other then polling admin.vm.CurrentState? (note: could allow static IPs in disposable sys-net qubes)

Even though sys-net is not my actual issue, I’ll put this in the context of disposable network VMs that need static addresses as a more understandable example:

After a disposable sys-net starts, we can go to dom0 and do
qvm-run --user=root sys-net "netmanager blah blah blah"
to set the static ip address. We can make a script that we run each time from dom0.

Is there a way to say that whenever sys-net starts, dom0 should run the script after sys-net finishes starting?

we could just write a daemon that polls admin.vm.CurrentState of the qube every 60 seconds or something.

typing:
qrexec-client-vm work admin.vm.CurrentState < /dev/null
at just the right moments shows that possiblities for states include:
power_state=Transient
power_state=Running

But before doing that, I’d like to verify that there isn’t a better way.

You can use events with the adminapi

#!/usr/bin/env python3

import asyncio
import subprocess
import qubesadmin
import qubesadmin.events

def startup(vm, event, **kwargs):
	print(f'Starting VM: {vm.name}')

app = qubesadmin.Qubes()
dispatcher = qubesadmin.events.EventsDispatcher(app)
dispatcher.add_handler('domain-start', startup)
asyncio.run(dispatcher.listen_for_events())

Thanks. I’ll look into that.