Delete Template from Disk (RHEV)

You want to delete a Template in RHEV from the CloudFORMS UI, but how?

This is easy, because the ReST API’s are so lovely in RHEV. Here is how;

Create a custom button that will execute your method, remember this is for VM Template and not just VM.

Now create the Automate parts, (if you need assistance on the general wiring of automate, try here first)

  1. Instance for button to call.
  2. Button instance link to your automate instance (system/request/buttoninstance –> sample/methods/delete_template)
  3. create your delete_template instance and method.
  4. The method code is as follows;

#            Automate Method


$evm.log("info", "Automate Method Started")


#            Method Code Goes here



require 'rubygems'

require 'rest_client'

vm = $evm.root['vm']

ext_management_system = vm.ext_management_system

$evm.log("info", "Template Name - #{}")

$evm.log("info", "Template UID - #{vm.uid_ems}")

$evm.log("info", "RHEVM Name - #{}")

rhevm = "https://#{ext_management_system.ipaddress}/api/templates"

rhevadmin = 'admin@internal'

rhevadminpass = 'monster'

resource =, :user => rhevadmin, :password => rhevadminpass)

deleteTemplate = resource.delete

$evm.log("info", "Result - #{deleteTemplate}")




$evm.log("info", "Automate Method Ended")

exit MIQ_OK

And the method code you can get here….

You may want to add a dialog to confirm the action, for this POC it was not required though I think its a good idea, even get the administrator to confirm there name so we have some trace to the action.


Matteo Bernacchi – We do like these ReST API’s for RHEV!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s