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;
</pre>
#

#            Automate Method

#

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

#

#            Method Code Goes here

#

#!/usr/bin/ruby

require 'rubygems'

require 'rest_client'

vm = $evm.root['vm']

ext_management_system = vm.ext_management_system

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

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

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

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

rhevadmin = 'admin@internal'

rhevadminpass = 'monster'

resource = RestClient::Resource.new(rhevm, :user => rhevadmin, :password => rhevadminpass)

deleteTemplate = resource.delete

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

#

#

#

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

exit MIQ_OK
<pre>

And the method code you can get here….https://github.com/jonnyfiveiq/CloudFORMSNOW/blob/master/RHEV/Templates/deleteTemplate.rb

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.

Credit

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s