REST API create_vm returns task URL that doesn't exist?
-
Hi everyone,
I'm currently creating VMs via the REST API endpoint:
POST /rest/v0/pools/${poolId}/actions/create_vm
Everything works great so far, but since I'm managing VMs externally via my own panel, I need the UUID of the newly created VM as part of the response.
Right now, my workaround is to cache all existing VMs beforehand, use a very unique name (including a timestamp) when creating the VM, and then scan all VMs afterward to find the new one by matching the name β from which I can extract the UUID. This works, but it's far from efficient, especially since I have to query every single VM individually to get the name_label.
However, I noticed that the API call returns something like this:
XOA success response: "/rest/v0/tasks/0mcmb9kba"
But as far as I can tell, there is no /rest/v0/tasks endpoint available in the REST API. So... why does create_vm return a reference to a resource that doesn't exist?
I was quite excited at first, thinking this would let me track the task and maybe get the VM UUID without extra API calls β but it seems like a dead end.
@devs β Is there any timeline on when this /tasks route will be available? And in the meantime, could you consider not returning references to non-existent endpoints? It's a bit misleading and made me waste some time debugging something that doesn't exist (yet?).
Thanks in advance!
-
Hi,
Let me ask the XO team via @lsouai-vates
-
@DevFlint the https://XOA_URL/rest/v0/tasks endpoint exists, but it's not yet documented through swagger
you should be able to add ?sync=true to the url to get the immediate result, but it can fail with a timeout if the creation takes too much time ( for example : migrating a big template )
-
Hello @DevFlint.
/rest/v0/tasks/:id
exists. It's not yet documented in Swagger, but it does exist.FYI, "actions" endpoint are specific.
They can be executed asynchronously (which is what you're currently doing). In this case, a task is returned and needs to be monitored. Use/rest/v0/tasks/:id
for this.
You can also execute your action synchronously by usingsync=true
as a query parameter. In this case, the VM ID will be returned in response.This should normally be documented in Swagger. If it's not clear in the documentation, we can improve it
-
@MathieuRA I canβt find any documentation of /tasks/ in swagger, I am on the newest Version of XOA
-
This is normal, as the
tasks
endpoints are in the old REST API (undocumented by Swagger).
We are gradually migrating to the new REST API to document all endpoints.