7.3. Collections
7.3.1. Collections
hosts collection which contains all virtualization hosts in the environment. An example of a sub-collection is the host.nics collection which contains resources for all network interface cards attached to a host resource.
7.3.2. Listing All Resources in a Collection
GET request on the collection URI obtained from the entry point.
Accept HTTP header to define the MIME type for the response format.
GET /ovirt-engine/api/[collection] HTTP/1.1 Accept: [MIME type]
7.3.3. Listing Extended Resource Sub-Collections
Accept header includes the detail parameter.
GET /ovirt-engine/api/collection HTTP/1.1 Accept: application/xml; detail=subcollection
detail parameters:
GET /ovirt-engine/api/collection HTTP/1.1 Accept: application/xml; detail=subcollection1; detail=subcollection2
detail parameter that separates the sub-collection with the + operator:
GET /ovirt-engine/api/collection HTTP/1.1 Accept: application/xml; detail=subcollection1+subcollection2+subcollection3
Table 7.4. Collections that use extended sub-collections
| Collection | Extended Sub-Collection Support |
|---|---|
hosts | statistics |
vms | statistics, nics, disks |
Example 7.1. A request for extended statistics, NICs and disks sub-collections in the vms collection
GET /ovirt-engine/api/vms HTTP/1.1 Accept: application/xml; detail=statistics+nics+disks
7.3.4. Searching Collections with Queries
GET request on a "collection/search" link results in a search query of that collection. The API only returns resources within the collection that satisfy the search query constraints.
GET /ovirt-engine/api/collection?search={query} HTTP/1.1
Accept: application/xml
HTTP/1.1 200 OK
Content-Type: application/xml
<collection>
<resource id="resource_id" href="/ovirt-engine/api/collection/resource_id">
...
</resource>
...
</collection>
7.3.5. Maximum Results Parameter
max URL parameter to limit the list of results. An API search query without specifying the max parameter will return all values. Specifying the max parameter is recommended to prevent API search queries from slowing UI performance.
GET /ovirt-engine/api/collection;max=1 HTTP/1.1
Accept: application/xml
HTTP/1.1 200 OK
Content-Type: application/xml
<collection>
<resource id="resource_id" href="/ovirt-engine/api/collection/resource_id">
<name>Resource-Name</name>
<description>A description of the resource</description>
...
</resource>
</collection>
7.3.6. Case Sensitivity
Example 7.2. Case insensitive search query
GET /ovirt-engine/api/collection;case-sensitive=false?search={query} HTTP/1.1
Accept: application/xml
7.3.7. Query Syntax
query with a GET request:
GET /ovirt-engine/api/collection?search={query} HTTP/1.1
Accept: application/xml
query template value refers to the search query the API directs to the collection. This query uses the same format as Red Hat Virtualization Query Language:
(criteria) [sortby (element) asc|desc]
sortby clause is optional and only needed when ordering results.
Table 7.5. Example search queries
| Collection | Criteria | Result |
|---|---|---|
hosts | vms.status=up | Displays a list of all hosts running virtual machines that are up. |
vms | domain=qa.company.com | Displays a list of all virtual machines running on the specified domain. |
vms | users.name=mary | Displays a list of all virtual machines belonging to users with the user name mary. |
events | severity>normal sortby time | Displays the list of all events with severity higher than normal and sorted by the time element values. |
events | severity>normal sortby time desc | Displays the list of all events with severity higher than normal and sorted by the time element values in descending order. |
query template to be URL-encoded to translate reserved characters, such as operators and spaces.
Example 7.3. URL-encoded search query
GET /ovirt-engine/api/vms?search=name%3Dvm1 HTTP/1.1 Accept: application/xml
7.3.8. Wildcards
Example 7.4. Wildcard search query for name=vm*
GET /ovirt-engine/api/vms?search=name%3Dvm* HTTP/1.1 Accept: application/xml
vm, such as vm1, vm2, vma or vm-webserver.
Example 7.5. Wildcard search query for name=v*1
GET /ovirt-engine/api/vms?search=name%3Dv*1 HTTP/1.1 Accept: application/xml
v and ending with 1, such as vm1, vr1 or virtualmachine1.
7.3.9. Pagination
page command.
Example 7.6. Paginating resources
GET /ovirt-engine/api/collection?search=page%201 HTTP/1.1 Accept: application/xml
page value to view the next page of results:
GET /ovirt-engine/api/collection?search=page%202 HTTP/1.1 Accept: application/xml
page command in conjunction with other commands in a search query. For example:
GET /ovirt-engine/api/collection?search=sortby%20element%20asc%20page%202 HTTP/1.1 Accept: application/xml
Important
7.3.10. Creating a Resource in a Collection
POST request to the collection URI containing a representation of the new resource.
POST request requires a Content-Type header. This informs the API of the representation MIME type in the body content as part of the request.
Accept HTTP header to define the MIME type for the response format.
POST /ovirt-engine/api/[collection] HTTP/1.1 Accept: [MIME type] Content-Type: [MIME type] [body]
7.3.11. Asynchronous Requests
POST requests unless the user overrides them with an Expect: 201-created header.
202 Accepted status. The initial document structure for a 202 Accepted resource also contains a creation_status element and link for creation status updates. For example:
POST /ovirt-engine/api/collection HTTP/1.1
Accept: application/xml
Content-Type: application/xml
<resource>
<name>Resource-Name</name>
</resource>
HTTP/1.1 202 Accepted
Content-Type: application/xml
<resource id="resource_id" href="/ovirt-engine/api/collection/resource_id">
<name>Resource-Name</name>
<creation_status>
<state>pending</state>
</creation status>
<link rel="creation_status"
href="/ovirt-engine/api/collection/resource_id/creation_status/creation_status_id"/>
...
</resource>
GET request to the creation_status link provides a creation status update:
GET /ovirt-engine/api/collection/resource_id/creation_status/creation_status_id HTTP/1.1
Accept: application/xml
HTTP/1.1 200 OK
Content-Type: application/xml
<creation id="creation_status_id"
href="/ovirt-engine/api/collection/resource_id/creation_status/creation_status_id">
<status>
<state>complete</state>
</status>
</creation>
Expect: 201-created header:
POST /ovirt-engine/api/collection HTTP/1.1
Accept: application/xml
Content-Type: application/xml
Expect: 201-created
<resource>
<name>Resource-Name</name>
</resource>

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.