This is part 1 of a 2-part article about Advanced Integration with RHEV-M. 

Background

At CloudOpen Europe 2013, in Edinburgh, I presented a talk about advanced integration with the oVirt engine. This technical article is covering the contents of this session.

RHEV-M is a Large scale, centralized management for server and desktop virtualization. It is based on leading performance, scalability and security infrastructure technologies, focusing on KVM for best integration/performance. It provides an alternative to Center/vSphere, providing end-to-end IaaS platform.

rhevm

In this post I'll show you how you can integrate with the RHEV-M engine, covering both new and cool features, as well as some "old" useful features.  Let's start with the REST-based APIs. These APIs allow you to perform different operations on the engine externally. You can do anything using the REST APIs, even operations that aren't exposed through the different UI interfaces.

REST-based APIs

We have several REST-based APIs in the RHEV-M engine:

  • REST API - provides application programming interface for the RHEV-M engine, using basic HTTP operations
  • SDKs (Python, Java) - based on the REST API - provides python based SDK to the RHEV-M engine
  • CLI (based on the Python SDK) - provides command line utility to the RHEV-M engine

So, what should you use?

That depends mostly on who you are, and what you are trying to accomplish:

  • If you're a sysadmin running a virtualized environment, and you would like to troubleshoot some issues without going into the UI, then you should use the CLI.
  • If you're a developer and you would like to integrate with the RHEV-M engine in your application, and your application is Java/Python based, then you should use the proper SDK.
  • If you're a developer using other languages, then you should use the API, using some HTTP library available in your platform.
  • If you just want to automate some tasks, then you should use the Python SDK or the CLI, depending on your preferable scripting language.

Let's dive a little deeper into the API and the SDK. I won't cover the CLI in this post. For more information on that have a look at CLI Wiki page

REST API

The REST API provides application programming interface for the RHEV-M engine, using basic HTTP operations:

  • GET - Requests a resource
  • POST - Creates a new resource. The new resource data is included in the body of the request
  • PUT - Modifies an existing resource. The modified resource data is included in the body of the request
  • DELETE - Deletes a resource

The API URI structure is as follows:

protocol://server_details/entry_point/collection/resource/sub-collection/subresource

For example, the following URL is a representation of the disk sub-resource with ID yyy-yyy in the VM resource with ID xxx-xxx, on our (secured) RHEV-M that's installed on machine rhevm port 8443:

https://rhevm:8443/api/vms/{xxx}/disks/{yyy}

Some basic examples:

  1. To list all collection resources, use HTTP GET
    • GET http(s)://server:port/api/vms
  2. To retrieve a specific resource, use HTTP GET
    • GET http(s)://server:port/api/vms/{xxx}
    • curl -v -u "user@domain:password" -H "Content-type: application/xml" -X GET http(s)://server:port/api/vms/{xxx}
  3. To create a resource, use POST.
    • POST http(s)://server:port/api/vms
      <vm>...</vm>
    • curl -v -u "user@domain:password"
      -H "Content-type: application/xml"
      -d
      '<vm>
      <name>my_new_vm</name>
      <cluster><name>cluster_name</name></cluster>
      <template><name>template_name</name></template>
      </vm>' 'http(s)://server:port/api/vms'
  4. To update the resource, use PUT.
    • PUT http(s)://server:port/api/vms/{xxx}
      <vm><name>aaa</name></vm>
    • echo "<vm><name>new_name</name></vm>" > /tmp/upload.xml
      curl -v -u "user@domain:password"
      -H "Content-type: application/xml"
      -T /tmp/upload.xml
      'http(s)://server:port/api/vms/{xxx}'
  5. To remove the resource, use DELETE.
    • DELETE http(s)://server:port/api/vms/{xxx}
    • curl -v -u "user@domain:password" -X DELETE http(s)://server:port/api/vms/{xxx}

RSDL- RESTful Service Description Language

How do you know what arguments to use when doing different operations?

You can use the RSDL (RESTful Service Description Language) - machine and human readable XML description of HTTP-based web applications (typically REST web services). It models the resource/s provided by a service, the relationship between them, parameters that has to be supplied for the certain operation, specifies if parameter/s has to be mandated, and describes possible overloads as parameters sets.

RSDL is intended to simplify the reuse of web services that are based on the HTTP architecture of the Web. It is platform and language independent and aims to promote reuse of applications beyond the basic use in a web browser, by both humans and machines.

In order to get the RSDL, just follow the basic API URI, followed by "?rsdl":

  • https://rhevm:8080/ovirt-engine/api?rsdl

And then you'll get all the different options for each and every HTTP request you can do on each and every resource.

For example, here you see a partial list of available parameters when adding a new VM using HTTP POST on the VMs collection:

rsdl

SDK

The Python-SDK is auto-generated software development kit for the RHEV-M engine API. Let's show some examples on how to use it.

  1. First, you need to create a proxy to the API
    • api = API(url='http://localhost:8080', username='user@domain', password='password')
  2. Now, you can access the different collections, (api.vms(), api.clusters(), etc...)
  3. Create new resources, for example create a new VM:
    • cluster = api.clusters().get(name='my_cluster') #destination cluster

    • template = api.templates().get(name='my_template') #source template
    • param = params.VM(name='new_vm', cluster=cluster, template=template, memory=1073741824) #setting additional parameters

    • new_vm = api.vms().add(param) #creating the VM
  4. List resources by query (server side query)
    • vms = api.vms().list(query = 'name=my_vm')
  5. List resources by property constraint (client side filtering)
    • vms = api.vms().list(memory=1073741824)
  6. Get a resource by constraint
    • vm = api.vms().get(id='f70d7c72-0232-4859-8fd7-fdaf1fd29d6d')
  7. Access resource methods and properties
    • vm.start()
    • vm.start_time

Depending on your development environment, you'll get auto-completion, and documentation that will ease the development process using the SDK.

In this part you learned how to perform different operations on the engine from the outside using the API/SDK. In the next part you'll learn how you can influence the engine from the inside, using extension APIs.

Find Part 2 of this article here.

Last updated: January 10, 2023