Get VMs assigned to user via API

Latest response

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.

https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Virtualization/3.0/html-single/REST_API_Guide/index.html

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

 

James, thank you for your comment. I'm familiar with RESTful API and the way of using curl with it. The actual problem I faced - is that I cannot run API request where username has just UserRole permission assigned. In this case I get responce 

"query execution failed due to insufficient permissions"

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<fault>
    <reason>Operation Failed</reason>
    <detail>query execution failed due to insufficient permissions.</detail>
</fault>

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<fault>
    <reason>Operation Failed</reason>
    <detail>query execution failed due to insufficient permissions.</detail>
</fault>

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

Thank you very much! This was exactly what I was looking for - your advice worked. 

My fault, I didn't notice the functionality of "Filter" header in request.

Thanks Anthony!  I see the word Developer and I automatically look the other way ;-)  I figured either the API hadn't changed for 3.1, or the RESTapi doc would be released later.  I'm glad you pointed out it's now in the Developer Guide.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.