CloudForms Now

Clone from Template (RHEV)

Enable CloudFORMS to clone a template, and retaining the disk layout. So CloudFORMS currently deploys new virtual machines in RHEV either by PXE or ISO. It does this by cloning a BLANK template and attaching new disks, where a PXE or ISO process will install an operating system. Those from the VMware world and those in Windows land will want to deploy directly from a template a clone, without having to install an operating system, because the template already has it installed in its disk. Reasonable request…. this is how…

Point to take note on,

You will need a dialog looking something like this…

Include a Submit and Cancel button, my dropdown list is numbered 1-5, you can choose what ever you wish. the only important thing here is to name the two controls;

You will need to create a custom button for Templates, link the button to this dialog and to a system/request called cloneTemplate

Create the usual bits as follows;

/system/request/cloneTemplate instance.

/Sample/Methods/cloneTemplate instance.

/Sample/Methods/cloneTemplate method.

Place the following into your method.

</pre>
#

#            Automate Method

#

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

#

#            Method Code Goes here

#

&nbsp;

#!/usr/bin/ruby

require 'rubygems'

require 'rest_client'

&nbsp;

vm = $evm.root['vm']

ext_management_system = vm.ext_management_system

ems_cluster = vm.ems_cluster

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

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

$evm.log("info", "Cluster Name - #{ems_cluster.name}")

$dialog_vm_count = ' '

$dialog_vm_prefix = ' '

$evm.root.attributes.sort.each { |k, v|

$evm.log("info","#{k}---#{v}")

if "#{k}" == "dialog_vm_count"

$dialog_vm_count = "#{v}"

$evm.log("info", "Found #{$dialog_vm_count}")

end

if "#{k}" == "dialog_vm_prefix"

$dialog_vm_prefix = "#{v}"

$evm.log("info", "Found #{$dialog_vm_prefix}")

end

}

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

rhevadmin = 'admin@internal'

rhevadminpass = 'monster'

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

$i = 1

while $i < ($dialog_vm_count.to_i + 1)  do

$evm.log("info", "******** <vm><name>#{$dialog_vm_prefix}#{$i}</name><cluster><name>#{ems_cluster.name}</name></cluster><template><name>#{vm.name}</name></template><memory>4294967296</memory><os><boot dev='hd'/></os></vm>****")

cloneTemplate = resource.post "<vm><name>#{$dialog_vm_prefix}#{$i}</name><cluster><name>#{ems_cluster.name}</name></cluster><template><name>#{vm.name}</name></template><memory>4294967296</memory><os><boot dev='hd'/></os></vm>", :content_type => 'application/xml', :accept => 'application/xml'

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

$i +=1

end

#

#

#

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

exit MIQ_OK
<pre>

You can download the methods code from here…https://github.com/jonnyfiveiq/CloudFORMSNOW/blob/master/RHEV/Templates/cloneTemplate.rb