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

    How to revert VM to snapshot

    Scheduled Pinned Locked Moved Solved REST API
    13 Posts 3 Posters 1.7k Views 3 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.
    • S Offline
      slavavrn
      last edited by

      Re: Automation script to revert and save snapshot

      Thanks.

      Can I be sure that all API capabilities are reflected in Swagger?

      So far, I've only found one method: creating a scheduled job, which can be launched via the API.
      curl -k -X POST -b 'authenticationToken=<my-token-from-user-authentication-tokens>' 'https://<xen-local>/rest/v0/schedules/<schedule-id>/actions/run'
      But that's a bit of a complicated process.

      1 Reply Last reply Reply Quote 1
      • olivierlambertO Online
        olivierlambert Vates 🪐 Co-Founder CEO
        last edited by

        Swagger is auto generated from the API, so the doc cannot lag. That's the point of the Swagger doc/API.

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          slavavrn @olivierlambert
          last edited by

          @olivierlambert
          But, for example, for VMS, there are the following actions:
          curl -k -X GET -H "Content-Type: application/json" -b authenticationToken=<my-token-from-user-authentication-tokens> 'https://<xen-local>/rest/v0/vms/<vm_id>/actions'
          [
          "/rest/v0/vms/<vm_id>/actions/clean_reboot",
          "/rest/v0/vms/<vm_id>/actions/clean_shutdown",
          "/rest/v0/vms/<vm_id>/actions/hard_reboot",
          "/rest/v0/vms/<vm_id>/actions/hard_shutdown",
          "/rest/v0/vms/<vm_id>/actions/snapshot",
          "/rest/v0/vms/<vm_id>/actions/start"
          ]
          but in swagger you can see only one action - start
          So, not everything available through the API is reflected in Swagger?Screenshot 2025-10-14 181918.png

          S 1 Reply Last reply Reply Quote 0
          • olivierlambertO Online
            olivierlambert Vates 🪐 Co-Founder CEO
            last edited by olivierlambert

            Because some endpoints aren't migrated to swagger yet (it needs to be correctly typed etc.). Each month we migrate more and more endpoint to it (it's almost done).

            Adding @mathieuRA in the convo

            1 Reply Last reply Reply Quote 0
            • S Offline
              slavavrn @slavavrn
              last edited by

              So, Swagger isn't 100% API compliant. That's what I was saying 🙂
              Can I see the API endpoints myself? Is the code open source?
              https://github.com/vatesfr/xen-orchestra/blob/master/packages/xo-server/src/api/vm.mjs#L1088
              Did I find the correct entry point?
              Maybe I should use xo-cli to perform the revert operation? Or does the cli also access the API and can't provide more functionality?

              1 Reply Last reply Reply Quote 0
              • olivierlambertO Online
                olivierlambert Vates 🪐 Co-Founder CEO
                last edited by

                I will let @mathieuRA to answer

                S 1 Reply Last reply Reply Quote 0
                • S Offline
                  slavavrn @olivierlambert
                  last edited by

                  @olivierlambert There is no information on this issue yet?

                  MathieuRAM 2 Replies Last reply Reply Quote 0
                  • MathieuRAM Offline
                    MathieuRA Vates 🪐 XO Team @slavavrn
                    last edited by MathieuRA

                    Hi @slavavrn
                    FYI, all endpoints are now documented in Swagger.

                    The REST API code is available here.

                    The revert snapshot action is not yet accessible via the REST API, but you can use it with xo-cli.

                    See
                    xo-cli vm.revert snapshot=<snapshot-id>

                    1 Reply Last reply Reply Quote 1
                    • olivierlambertO Online
                      olivierlambert Vates 🪐 Co-Founder CEO
                      last edited by

                      Thanks @MathieuRA !

                      1 Reply Last reply Reply Quote 0
                      • MathieuRAM Offline
                        MathieuRA Vates 🪐 XO Team @slavavrn
                        last edited by

                        Hi @slavavrn,
                        FYI, its now possible to revert a snapshot via the REST API.
                        POST /vms/:id/actions/revert_snapshot
                        And the body of the endpoint:

                        {
                          "snapshotId": <snapshot-id>
                          "snapshotBefore": boolean (optional)
                        }
                        
                        1 Reply Last reply Reply Quote 1
                        • MathieuRAM MathieuRA marked this topic as a question
                        • MathieuRAM MathieuRA has marked this topic as solved

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • First post
                          Last post