Best way to wait for end stop vm task using HA

Sam0x

Member
Mar 1, 2023
8
0
6
Hi !

I would like to be able to perform a stop task on a virtual machine using HA. I need to wait for the end of that task.
I noticed that when I call POST /api2/json/nodes/{node}/qemu/{vmid}/status/stop, I get the id of the ha stop task which does not wait for the end of the subtask that stops the virtual machine.

In your opinion, what would be the best way to get the proper task ?

So far, I was thinking I would wait for the end of ha stop and then get the cluster tasks to find the one and then wait for its end but I'm not sure.
 
that's a bit tricky - for HA guests, such requests only tell the HA stack to queue that action. you need to either poll the VM status itself, or the task list (filtered by vmid) and wait for the task to show up/desired state to be reached.
 
  • Like
Reactions: Sam0x
In the future, will there be a way to get the task id of qmstop id other than requesting the tasks until we get a match ?
For instance, it could be added to the logs of the task.
 
we could probably technically implement such a cross-referencing mechanism, but it would only make sense if tasks had structured return data which they currently also lack. I am not aware of anybody working on either, but feel free to file an issue/feature request for this particular gap!