XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    REST API create_vm returns task URL that doesn't exist?

    Scheduled Pinned Locked Moved REST API
    6 Posts 4 Posters 55 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      DevFlint
      last edited by

      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!

      florentF MathieuRAM 2 Replies Last reply Reply Quote 0
      • olivierlambertO Online
        olivierlambert Vates πŸͺ Co-Founder CEO
        last edited by

        Hi,

        Let me ask the XO team via @lsouai-vates

        1 Reply Last reply Reply Quote 0
        • florentF Offline
          florent Vates πŸͺ XO Team @DevFlint
          last edited by

          @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 )

          1 Reply Last reply Reply Quote 0
          • MathieuRAM Offline
            MathieuRA Vates πŸͺ XO Team @DevFlint
            last edited by

            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 using sync=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 πŸ™‚

            D 1 Reply Last reply Reply Quote 0
            • D Offline
              DevFlint @MathieuRA
              last edited by

              @MathieuRA I can’t find any documentation of /tasks/ in swagger, I am on the newest Version of XOA

              MathieuRAM 1 Reply Last reply Reply Quote 0
              • MathieuRAM Offline
                MathieuRA Vates πŸͺ XO Team @DevFlint
                last edited by

                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.

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post