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)
- Instance for button to call.
- Button instance link to your automate instance (system/request/buttoninstance –> sample/methods/delete_template)
- create your delete_template instance and method.
- 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!