Chapter 3. REST API Quick Start Example
Chapter 3. REST API Quick Start Example This chapter provides an example to demonstrate the REST API's ability to setup a basic Red Hat Virtualization environment and create a virtual machine. In addition to the standard prerequisites, this example requires the following: A networked and configured Red Hat Virtualization Host; An ISO file containing a desired virtual machine operating system to install. This chapter uses Red Hat Enterprise Linux Server 6 for our installation ISO example; and Red Hat Virtualization's engine-iso-uploader tool to upload your chosen operating system ISO file. This example uses cURL to demonstrate REST requests with a client application. Note that any application capable of HTTP requests can substitute for cURL . Important For simplicity, the HTTP request headers in this example omit the Host: and Authorization: fields. However, these fields are mandatory and require data specific to your installation of Red Hat Virtualization Manager. Important All cURL examples include placeholders for authentication details ( USER:PASS ) and certificate location ( CERT ). Ensure all requests performed with cURL fulfill certification and authentication requirements. Note Red Hat Virtualization Manager generates a globally unique identifier (GUID) for the id attribute for each resource. Identifier codes in this example might appear different to the identifier codes in your Red Hat Virtualization environment. 3.1. Example: Access API Entry Point The following request retrieves a representation of the main entry point for version 3 of the API. Example 3.1. Access the API v3 entry point Request (with header): Request (without header): cURL command: Result: Important When neither the header nor the URL prefix are used, the server will automatically select a version. The default is version 4 . You can change the default version using the ENGINE_API_DEFAULT_VERSION parameter: Changing this parameter affects all users of the Manager that don't specify the version explicitly. The entry point provides a user with links to the collections in a virtualization environment. The rel= attribute of each collection link provides a reference point for each link. The step in this example examines the datacenter collection, which is available through the rel="datacenter" link. The entry point also contains other data such as product_info , special_objects and summary . This data is covered in chapters outside this example.
GET /ovirt-engine/api HTTP/1.1 Version: 3 Accept: application/xml GET /ovirt-engine/api/v3 HTTP/1.1 Accept: application/xml curl -X GET -H "Accept: application/xml" -u [USER:PASS] --cacert [CERT] https:// [RHEVM Host] :443/ovirt-engine/api HTTP/1.1 200 OK Content-Type: application/xml <api> <link rel="capabilities" href="/ovirt-engine/api/capabilities"/> <link rel="clusters" href="/ovirt-engine/api/clusters"/> <link rel="clusters/search" href="/ovirt-engine/api/clusters?search={query}"/> <link rel="datacenters" href="/ovirt-engine/api/datacenters"/> <link rel="datacenters/search" href="/ovirt-engine/api/datacenters?search={query}"/> <link rel="events" href="/ovirt-engine/api/events"/> <link rel="events/search" href="/ovirt-engine/api/events?search={query}"/> <link rel="hosts" href="/ovirt-engine/api/hosts"/> <link rel="hosts/search" href="/ovirt-engine/api/hosts?search={query}"/> <link rel="networks" href="/ovirt-engine/api/networks"/> <link rel="roles" href="/ovirt-engine/api/roles"/> <link rel="storagedomains" href="/ovirt-engine/api/storagedomains"/> <link rel="storagedomains/search" href="/ovirt-engine/api/storagedomains?search={query}"/> <link rel="tags" href="/ovirt-engine/api/tags"/> <link rel="templates" href="/ovirt-engine/api/templates"/> <link rel="templates/search" href="/ovirt-engine/api/templates?search={query}"/> <link rel="users" href="/ovirt-engine/api/users"/> <link rel="groups" href="/ovirt-engine/api/groups"/> <link rel="domains" href="/ovirt-engine/api/domains"/> <link rel="vmpools" href="/ovirt-engine/api/vmpools"/> <link rel="vmpools/search" href="/ovirt-engine/api/vmpools?search={query}"/> <link rel="vms" href="/ovirt-engine/api/vms"/> <link rel="vms/search" href="/ovirt-engine/api/vms?search={query}"/> <special_objects> <link rel="templates/blank" href="/ovirt-engine/api/templates/00000000-0000-0000-0000-000000000000"/> <link rel="tags/root" href="/ovirt-engine/api/tags/00000000-0000-0000-0000-000000000000"/> </special_objects> <product_info> <name>Red Hat Virtualization</name> <vendor>Red Hat</vendor> <version revision="0" build="0" minor="0" major="4"/> </product_info> <summary> <vms> <total>5</total> <active>0</active> </vms> <hosts> <total>1</total> <active>1</active> </hosts> <users> <total>1</total> <active>1</active> </users> <storage_domains> <total>2</total> <active>2</active> </storage_domains> </summary> </ovirt-engine/api> echo "ENGINE_API_DEFAULT_VERSION=3" > /etc/ovirt-engine/engine.conf.d/99-set-default-version.conf systemctl restart ovirt-engine