Get VMs assigned to user via API
I'm currently evaluating RHEV solution, and I would like to write some script for the user. Part of this script - is to get info about VMs assigned to him.
How could it be possibly done? I'm able to get full list of VMs - but only when usnig API with admin permissions. Is it possible to run API with user permissions?
Responses
I am somewhat familiar with 2 options available via the RESTapi - Curl and Python. I found curl to be a much easier option for me personally as I am not very proficient with python. The RESTapi guide has not yet been updated to 3.1 (that I have seen) so, check for the doc under 3.0 - the doc is actually very helpful in providing the foundation to get started quickly.
Check out section 2.1 on how to retrieve the cert from your RHEV manager.
Here is their example
curl -X GET -H "Accept: application/xml" -u [USER:PASS]
--cacert [CERT]
https://[RHEVM Host]
:8443/api
and this is what I typically run and then parse out:
curl -k -X GET -u "${USERNAME}@${DOMAIN}:${PASSWORD}"--cacert rhevm.cer -H "Accept: application/xml" https://${RHEVM}/api/vm
curl -k -X GET -u "${USERNAME}@${DOMAIN}:${PASSWORD}" -H "Accept: application/xml" https://${RHEVM}/api/vms?search=servername
Dmitry,
This curl command should return a list of VMs assigned to a non-admin user:
curl --cacert $CACERT -u "$USER:$PASSWORD" -H "Accept: application/xml" -H "Filter: true" -X GET https://$RHEVM_HOST/api/vms
Also, the API documentation for 3.1 is in the Developer Guide:
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Virtualization/3.1/html/Developer_Guide/index.html