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

    Fetch VMS and there current hosts

    Scheduled Pinned Locked Moved REST API
    10 Posts 5 Posters 1.1k 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.
    • R Offline
      rtjdamen
      last edited by

      Hi All,

      Question regarding the REST-API, for our licensing reporting we need to see what vms are running on what hosts on a specific time. this info is then stored for microsoft licensing audits in the future. I found we can fetch information on vms and there status but it seems the current host is not displayed, or i do not understand how to get this field. Anyone can tell me how i can get this info over the api?

      Cheers Robin

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

        Hi!

        If you can open a support ticket, that would be more efficient to be sure we'll prioritize to answer 🙂 Otherwise, you'll have to wait a bit for @julien-f here 🙂

        R 1 Reply Last reply Reply Quote 0
        • R Offline
          rtjdamen @olivierlambert
          last edited by

          @olivierlambert i will open a support ticket right away!

          K 1 Reply Last reply Reply Quote 1
          • K Offline
            KPS Top contributor @rtjdamen
            last edited by Danp

            @rtjdamen
            That is VERY funny: I did write a small script for that, today morning...

            #!/bin/bash
            
            export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
            
            /usr/local/bin/xo-cli --register --allowUnauthorized  --token xxxxxxx http://xxxxxxx
            
            
            for hostuuid in $(xo-cli rest get hosts | grep hosts | awk -F "/" '{print $2}' | awk -F "'" '{print $1}');
                    do
                            hostnamelabel=$(xo-cli rest get hosts fields=name_label filter="uuid:$hostuuid" | grep name_label | awk  -F "'" '{print $2}')
                            echo VMs on $hostnamelabel $hostuuid:
                            /usr/local/bin/xo-cli xo.getAllObjects filter="/^VM$/ \$container:$hostuuid"  | grep name_label | awk -F "'" '{print "    " $2}'
                    done
            
            

            And a Cron-Job:

            0 * * * *       root    /bin/bash /root/scripts/ShowVMsOnHost.bash > /tmp/vm-host-list.$(date '+\%Y-\%m-\%d'_\%H-\%M-\%S).txt 2>&1
            
            R DanpD 2 Replies Last reply Reply Quote 1
            • R Offline
              rtjdamen @KPS
              last edited by

              @KPS thank you, i will share this with our developer! so they can use it in there development!

              1 Reply Last reply Reply Quote 0
              • DanpD Online
                Danp Pro Support Team @KPS
                last edited by

                @KPS Nice script! FYI, I fixed a small typo where one of the "L"s was missing in "allowUnauthorized" .

                R 1 Reply Last reply Reply Quote 0
                • R Offline
                  rtjdamen @Danp
                  last edited by

                  thanks we found this info! all is working!

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

                    @julien-f don't we have the info in the REST API somehow?

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

                      @olivierlambert Yes, you can see which VMs are on host with its residentVms field.

                      It's also possible to see where the VM resides by looking at the $container field (it will be a host or a pool).

                      I will add a hosts/<id>/residentVms route to resolve the VMs, just like I did for users/<id>/groups.

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

                        After reflection I don't think I will implement /hosts/<host id>/residentVms, you can do it very easily with filter: /vms?filter=$container:<host id>.

                        1 Reply Last reply Reply Quote 1

                        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