Este contenido no está disponible en el idioma seleccionado.
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 /api/[collection] HTTP/1.1 Accept: [MIME type]
GET /api/[collection] HTTP/1.1
Accept: [MIME type]7.3.3. Listing Extended Resource Sub-Collections
Accept header includes the detail parameter.
	GET /api/collection HTTP/1.1 Accept: application/xml; detail=subcollection
GET /api/collection HTTP/1.1
Accept: application/xml; detail=subcollection
detail parameters:
	GET /api/collection HTTP/1.1 Accept: application/xml; detail=subcollection1; detail=subcollection2
GET /api/collection HTTP/1.1
Accept: application/xml; detail=subcollection1; detail=subcollection2
detail parameter that separates the sub-collection with the + operator:
	GET /api/collection HTTP/1.1 Accept: application/xml; detail=subcollection1+subcollection2+subcollection3
GET /api/collection HTTP/1.1
Accept: application/xml; detail=subcollection1+subcollection2+subcollection3
| 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 /api/vms HTTP/1.1 Accept: application/xml; detail=statistics+nics+disks
GET /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.
	7.3.5. Maximum Results Parameter
max URL parameter to limit the list of results. Previous to Red Hat Enterprise Virtualization 3.4, the default size of the result was limited by the SearchResultsLimit parameter. From Red Hat Enterprise Virtualization 3.4, this parameter does not affect the REST API and 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.
	7.3.6. Case Sensitivity
Example 7.2. Case insensitive search query
GET /api/collection;case-sensitive=false?search={query} HTTP/1.1
Accept: application/xml
GET /api/collection;case-sensitive=false?search={query} HTTP/1.1
Accept: application/xml
7.3.7. Query Syntax
query with a GET request:
	GET /api/collection?search={query} HTTP/1.1
Accept: application/xml
GET /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 Enterprise Virtualization Query Language:
	 (criteria) [sortby (element) asc|desc]
	sortby clause is optional and only needed when ordering results.
	| 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 eventswith severity higher thannormaland sorted by thetimeelement values. | 
| events | severity>normal sortby time desc | Displays the list of all eventswith severity higher thannormaland sorted by thetimeelement 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 /api/vms?search=name%3Dvm1 HTTP/1.1 Accept: application/xml
GET /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 /api/vms?search=name%3Dvm* HTTP/1.1 Accept: application/xml
GET /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 /api/vms?search=name%3Dv*1 HTTP/1.1 Accept: application/xml
GET /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 /api/collection?search=page%201 HTTP/1.1 Accept: application/xml
GET /api/collection?search=page%201 HTTP/1.1
Accept: application/xml
page value to view the next page of results:
		GET /api/collection?search=page%202 HTTP/1.1 Accept: application/xml
GET /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 /api/collection?search=sortby%20element%20asc%20page%202 HTTP/1.1 Accept: application/xml
GET /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 /api/[collection] HTTP/1.1 Accept: [MIME type] Content-Type: [MIME type] [body]
POST /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:
	GET request to the creation_status link provides a creation status update:
	Expect: 201-created header: