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

    Xen Orchestra API and documentation - Examples

    Scheduled Pinned Locked Moved REST API
    11 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.
    • olivierlambertO Offline
      olivierlambert Vates 🪐 Co-Founder CEO
      last edited by

      Pinging @julien-f

      1 Reply Last reply Reply Quote 0
      • julien-fJ Offline
        julien-f Vates 🪐 Co-Founder XO Team @KPS
        last edited by

        @KPS Both APIs are completely different, the oldest one has never been intended for public consumption, it was developed for XO's internal needs even though we are not preventing anyone from using it 🙂

        The REST API has been created exactly to address the need of a public API, use it if it covers your need.

        Also, feel free to provide feedback and we'lll improve it.

        Regarding the limit issue, it has been fixed 6 weeks ago, please make sure you are up to date.

        K 1 Reply Last reply Reply Quote 0
        • olivierlambertO olivierlambert moved this topic from Xen Orchestra on
        • K Offline
          KPS Top contributor @julien-f
          last edited by

          @julien-f
          I think, there is still a problem, when limit is >100.

          xo-cli rest get vms fields=name_label,uuid limit=150
          

          --> Does also return only 100 entries.

          julien-fJ 1 Reply Last reply Reply Quote 0
          • julien-fJ Offline
            julien-f Vates 🪐 Co-Founder XO Team @KPS
            last edited by

            @KPS It works as expected on my side.

            K 1 Reply Last reply Reply Quote 0
            • K Offline
              KPS Top contributor @julien-f
              last edited by

              @julien-f
              Do you have any idea, what I could do wrong?

              I am getting:

              ...
                  uuid: 'abd06f55-8356-ab9f-1cd1-98a7953672d1'
                },
                ... 22 more items
              ]
              

              no matter, if limit=100 or limit=150.
              Everything above 100 seems to give 100.

              julien-fJ 1 Reply Last reply Reply Quote 0
              • julien-fJ Offline
                julien-f Vates 🪐 Co-Founder XO Team @KPS
                last edited by

                @KPS My bad, you're right, xo-cli rest is indeed limited to 100 entries 😅

                I thought you were talking about the REST API itself, but this one is working fine.

                xo-cli has been primarily developed to test and explore the API by hand, not to automate stuff. For instance the output is not valid JSON and is using colors.

                But still, the situation could be improved, for instance the REST API support a ndjson param to get the result in newline delimited JSON format and xo-cli does not supports it.

                Maybe just adding it and make xo-cli output all the records would be good enough for your use case?

                Example:

                $ xo-cli rest get vms limits=150 ndjson
                {
                  href: 'vms/2d561dc2-7dbc-55f2-c643-9661cb28010a',
                  name_label: 'demo 2',
                  uuid: '2d561dc2-7dbc-55f2-c643-9661cb28010a'
                }
                {
                  href: 'vms/9344c80d-f8e0-25c6-9670-365c4e2b52a6',
                  name_label: 'SVE Windows Server 2019 1809 US UEFI',
                  uuid: '9344c80d-f8e0-25c6-9670-365c4e2b52a6'
                }
                

                What do you think?

                K 1 Reply Last reply Reply Quote 0
                • K Offline
                  KPS Top contributor @julien-f
                  last edited by

                  @julien-f said in Xen Orchestra API and documentation - Examples:

                  xo-cli rest get vms limits=150 ndjson

                  Hi Julien,
                  for me, that would be great, if I would be able to add a higher limit than 100 on the cli - ndjson sounds perfect.

                  julien-fJ 1 Reply Last reply Reply Quote 0
                  • julien-fJ Offline
                    julien-f Vates 🪐 Co-Founder XO Team @KPS
                    last edited by

                    @KPS Published as xo-cli@0.24.0.

                    K 1 Reply Last reply Reply Quote 1
                    • K Offline
                      KPS Top contributor @julien-f
                      last edited by KPS

                      List old snapshots:

                      xo-cli rest get vm-snapshots fields=name_label,parent,snapshot_time ndjson filter="snapshot_time:<$(($(date --date "-8 days" +%s%N)/1000000000))"

                      Or as script:

                      #!/bin/bash
                      
                      IFS=$'\n'
                      
                      export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
                      
                      /usr/local/bin/xo-cli register --alowUnauthorized  --token xxxxxxxxxxx http://xoa
                      
                      echo "age/d;SnapName;SnapshotOf"
                      
                      
                      output=$(for i in $(xo-cli rest get vm-snapshots fields='name_label,uuid,$snapshot_of,snapshot_time' ndjson filter="snapshot_time:<$(($(date --date "-8 days" +%s%N)/1000000000))" | grep uuid | awk '{print $2}' | awk -F "'" '{print $2}')
                      do
                              snapdetails=$(xo-cli rest get vm-snapshots fields='name_label,uuid,$snapshot_of,snapshot_time' ndjson filter="uuid:$i")
                              snapshot_of=$(echo "$snapdetails" | grep snapshot_of | awk -F "'" '{print $4}')
                              name_label=$(echo "$snapdetails" | grep name_label |  awk -F "'" '{print $2}')
                              snapshot_of_name=$(/usr/local/bin/xo-cli rest get vms/$snapshot_of| grep name_label | awk -F "'" '{print $2}')
                              timestamp=$(echo "$snapdetails" | grep snapshot_time | awk -F " " '{print $2}' | awk -F "," '{print $1}')
                              age=$(( ($(($(date +%s%N)/1000000000)) - $timestamp) / 86400 ))
                              echo "$age;$name_label;$snapshot_of_name"
                      done
                      )
                      
                      echo "$output" | sort -k1,1 -n -r
                      
                      1 Reply Last reply Reply Quote 0
                      • olivierlambertO Offline
                        olivierlambert Vates 🪐 Co-Founder CEO
                        last edited by

                        I think it might be easier to do so with the new REST API, what do you think @julien-f ? 🤔

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