How to create a VM using the REST API in RHEV 3.0

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Virtualization 3.0

Issue

Is it possible to create VMs in RHEV using REST API commands?

Requirements :
- VM will be cloned from a existing template in RHEV
- VM will be created from a template with a template ID : 301d59d5-a6c0-42ec-87fb-01f3f087a9de
- disk attached to the template has the following disk ID : d2a734b2-fdca-41cb-88de-a836f4cb2a06
- VM will be created in the cluster with the cluster ID : 8ba5ef90-587c-11e1-8567-5254005ef58b
- Disks are created as RAW disks.

Resolution

Curl commands can be run on any client to create VM using Rest API.

1. Use a command line tool such as wget to download the certificate from the server.

# wget -O rhevm.cer http://[rhev.example.com]:8080/ca.crt

2. Run the command similar to below to create a VM on RHEV.

curl -X POST -H "Accept: application/xml" -H "Content-Type: application/xml" -u admin@internal:password --cacert ~/rhevm.cer  -d "<vm><name>cloned_test</name><template id='301d59d5-a6c0-42ec-87fb-01f3f087a9de'/><cluster id='8ba5ef90-587c-11e1-8567-5254005ef58b'/><disks><clone>true</clone><disk id='d2a734b2-fdca-41cb-88de-a836f4cb2a06'><format>RAW</format></disk></disks></vm>" https://rhev.example.com:8443/api/vms

Relevant UUID's can be found through the RHEV Manager REST API.

https://rhev.example.com:8443/api

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments