How to clone VM (not template) via REST api?



I am trying to trigger a provision_request via REST api to clone an existing VM (not template) to another VM. Similar to what the Lifecycle menu “Clone this VM” can do. I have the guid of my source VM in template_fields:

“template_fields” : {
“guid” : “c9e4740e-c392-11e5-8c35-2cc2603d7015”

But it always failed with error

“kind”: “internal_server_error”,
“message”: “No source template was found from input data:<{:guid=>“c9e4740e-c392-11e5-8c35-2cc2603d7015”}>”,
“klass”: “RuntimeError”

It works when I use the guid of an actual template. What is the proper format to clone an existing VM?


Below is the whole body of the REST call

“version” : “1.1”,
“template_fields” : {
“guid” : “c9e4740e-c392-11e5-8c35-2cc2603d7015”
“vm_fields” : {
“number_of_cpus” : 1,
“vm_name” : “eric_rest_vm1”,
“vm_memory” : “1024”,
“vlan” : “VM Network”
“requester” : {
“user_name” : “admin”,
“owner_first_name” : “Eric”,
“owner_last_name” : “Chong”,
“owner_email” : "",
“auto_approve” : true
“tags” : {
“additional_values” : {
“ems_custom_attributes” : { },
“miq_custom_attributes” : { }


Get a little further when I specify the request type as follow

“template_fields” : {
“request_type” : “clone_to_vm”,
“guid” : “c9e4740e-c392-11e5-8c35-2cc2603d7015”

Now I got a different error in response

“kind”: “internal_server_error”,
“message”: “undefined method `datacenter_name’ for #ManageIQ::Providers::Vmware::InfraManager::Vm:0x000000044a10d8”,
“klass”: “NoMethodError”


I’m very interested in this to.

In the template field does this work:

“template_fields” : {
“name” : “VMname”

I use this when deploying from template, as GUID is just ugly.


I ran a simular request in my enviorment and got the same error. Guess cloning VM isn’t available yet. Ironic that I keep reading that the REST API has met paritiy with the SOAP API of yesteryear.


I opened a case with Red Hat on this feature on CloudForms and the support got the same error. They are opening a bug report. Will post update once I get a response.


Thanks for the update


Just an update. Support said it is fixed in ManageIQ upstream release. CloudForms fix will be coming in future patch release.


@ecchong, do u have any tutorial for how to work with rest API of manageIQ? Also how to get these parameters and everything?



I am no expert, but you can find info in the REST API doc for CloudForms

Also, I use DHC REST client plug-in for Chrome to make it easier to troubleshoot.


Hi @adlinix, @ecchong,

There is a tool in the tools directory of manageiq called rebuild_provision_request.rb. It could possibly help in troubleshooting your REST api calls into Automate.

The Pull Request is here: #9957.

The description in the PR covers how the help menu works and includes some simple examples.

If you have any other questions about it I’d be glad to help.



Can you give the full example for clone vm from template via rest api?


Hi @oguzy,

There is a tool called rebuild_provision_request.rb in the tools directory.

If you run it with the last last_requests flag it will pull up a list of the last 5 provision requests:

rails runner tools/rebuild_provision_request.rb --last-requests

You can re-run any of those requests passing in the id:

rails runner tools/rebuild_provision_request.rb --request-id=<request id>

Including the console flag will allow you to see output that you can run in the rails console.

Using that output will re-run the request using the Rest API (via RestClient.)

As an aside, sometimes you have to require rest_client in the console before running the command.

rails runner tools/rebuild_provision_request.rb --request-id=<request id> --console

The output using the console flag is probably the best way to work through issues cloning a vm from a template via the rest api.

Here is a sampling of the --console output: 'http://user:pass@localhost:3000/api/provision_requests', '{"version":"1.1","template_fields":{"guid":"bbbb-ccc-ddd-12345","name":"test1","request_type":"template"},"vm_fields":{"sysprep_server_license_mode":"perServer","sysprep_identification":"domain","sysprep_per_server_max_connections":"5","sysprep_workgroup_name":"WORKGROUP","addr_mode":"dhcp","sysprep_change_sid":true,"sysprep_auto_logon":true,"sysprep_enabled":"disabled","sysprep_auto_logon_count":1,"placement_auto":true,"number_of_vms":1,"vm_name":"test-run","provision_type":"vmware","vm_auto_start":true,"retirement":0,"retirement_warn":604800,"vlan":"VM Network","disk_format":"unchanged","cpu_limit":-1,"memory_limit":-1,"number_of_sockets":1,"cores_per_socket":1,"cpu_reserve":0,"vm_memory":"1024","memory_reserve":0,"network_adapters":1},"requester":{"owner_first_name":"d","owner_last_name":"b","owner_email":""},"tags":{},"additional_values":null,"ems_custom_attributes":null,"miq_custom_attributes":null}'

For further help with the tool you can run rails runner tools/rebuild_provision_request.rb -- --help

Service catalog with instance type