Fetch VMS and there current hosts
-
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
-
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
-
@olivierlambert i will open a support ticket right away!
-
@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
-
@KPS thank you, i will share this with our developer! so they can use it in there development!
-
@KPS Nice script! FYI, I fixed a small typo where one of the "L"s was missing in "allowUnauthorized" .
-
thanks we found this info! all is working!
-
@julien-f don't we have the info in the REST API somehow?
-
@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 forusers/<id>/groups
. -
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>
.