VM info by name


#1

Hey folks, for now I am looking at ManageIQ simply for VM inventory of around 20 Vsphere vcenters. I am currently testing one and trying to wrap my head around the API. I notice the API mostly revolves around VM IDs. So how can I easily get the ID of a VM by name, or cut out the step and get basic information on the VM (power state, CPU, memory, vcenter) by VM name?


#2

@cwb124 have you reviewed: http://manageiq.org/docs/reference/latest/api/overview/query
There are few examples that might be exactly what you’re asking about.


#3

I have and I’m not sure that does what I need. According to the doc, this is how I might query by name:

/api/vms?filter[]=“name=‘myvm’”

But I get the following error:
{
“error”: {
“kind”: “bad_request”,
“message”: "attribute “name does not exist”,
“klass”: “ApiController::BadRequestError”
}
}

Name is most certainly an attribute on a VM.

Why is everything so easy as long as you have a VM ID, but how are you supposed to obtain the ID for the VM you want info about?


#4

The syntax is a little different in the downstream CloudForms docs.

Try adding “expand=resources&attributes=name” and dropping the quotes around the filter parameter. Something like this:

/api/vms?expand=resources&attributes=name&filter[]=name="myvm"

I was able to get that to work on CFME 4.2, but I didn’t test it on the upstream.


#5

I got that working, thanks krain.

When I am able to retrieve VM information via the API, I notice the cpu and memory count and some other pieces of info are missing. I see the info in the GUI so the data is available. Where can I find the documents or list of attributes available to return for a VM? Seems like basic info is missing from the simple API call of /api/vms/102


#6

I think you need to add attributes=hardware, i.e.

/api/vms?expand=resources&attributes=hardware&filter[]=name="myvm"

pemcg


#7

There are tons of these attributes so we don’t return them by default, all these other attributes are available via virtual attributes, you can see what’s available for the vms collection by doing an HTTP OPTIONS /api/vms

virtual_attributes and relationships can be queried in addition to the base attributes via the attributes parameter:

GET /api/vms/102?attributes=cpu_total_cores,...

hope this helps,
Alberto