<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[CloudForms Now]]></provider_name><provider_url><![CDATA[http://cloudformsblog.redhat.com]]></provider_url><author_name><![CDATA[johnhardy36]]></author_name><author_url><![CDATA[https://cloudformsblog.redhat.com/author/johnhardy36/]]></author_url><title><![CDATA[Clone from Template&nbsp;(RHEV)]]></title><type><![CDATA[link]]></type><html><![CDATA[<p>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&#8230;. this is how&#8230;<!--more--></p>
<p>Point to take note on,</p>
<ul>
<li>This is a quick and dirty example.</li>
<li>I would in a real implementation take the normal VM_Provision statemachine and amend the process that calls Provision to be replaced with this process, thus retaining all the approval and quota bits that make lifecycle management possible.</li>
</ul>
<p>You will need a dialog looking something like this&#8230;</p>
<p><a href="http://cloudformsnow.files.wordpress.com/2013/05/screen-shot-2013-05-09-at-12-17-34.png"><img data-attachment-id="95" data-permalink="https://cloudformsblog.redhat.com/screen-shot-2013-05-09-at-12-17-34/" data-orig-file="https://cloudformsredhat.files.wordpress.com/2013/05/screen-shot-2013-05-09-at-12-17-34.png" data-orig-size="1328,162" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Screen Shot 2013-05-09 at 12.17.34" data-image-description="" data-medium-file="https://cloudformsredhat.files.wordpress.com/2013/05/screen-shot-2013-05-09-at-12-17-34.png?w=300&#038;h=37" data-large-file="https://cloudformsredhat.files.wordpress.com/2013/05/screen-shot-2013-05-09-at-12-17-34.png?w=1024" class="alignnone wp-image-95 size-medium" src="https://cloudformsredhat.files.wordpress.com/2013/05/screen-shot-2013-05-09-at-12-17-34.png?w=300&#038;h=37" alt="Screen Shot 2013-05-09 at 12.17.34" width="300" height="37" srcset="https://cloudformsredhat.files.wordpress.com/2013/05/screen-shot-2013-05-09-at-12-17-34.png?w=300&amp;h=37 300w, https://cloudformsredhat.files.wordpress.com/2013/05/screen-shot-2013-05-09-at-12-17-34.png?w=600&amp;h=74 600w, https://cloudformsredhat.files.wordpress.com/2013/05/screen-shot-2013-05-09-at-12-17-34.png?w=150&amp;h=18 150w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>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;</p>
<ul>
<li>dialog_vm_count</li>
<li>dialog_vm_prefix</li>
</ul>
<p>You will need to create a custom button for Templates, link the button to this dialog and to a system/request called cloneTemplate</p>
<p>Create the usual bits as follows;</p>
<p>/system/request/cloneTemplate instance.</p>
<p>/Sample/Methods/cloneTemplate instance.</p>
<p>/Sample/Methods/cloneTemplate method.</p>
<p>Place the following into your method.</p>
<pre class="brush: ruby; title: ; notranslate" title="">&lt;/pre&gt;
#

#            Automate Method

#

$evm.log(&quot;info&quot;, &quot;cloneTemplate -- Automate Method Started&quot;)

#

#            Method Code Goes here

#

&amp;nbsp;

#!/usr/bin/ruby

require 'rubygems'

require 'rest_client'

&amp;nbsp;

vm = $evm.root['vm']

ext_management_system = vm.ext_management_system

ems_cluster = vm.ems_cluster

$evm.log(&quot;info&quot;, &quot;VM Name - #{vm.name}&quot;)

$evm.log(&quot;info&quot;, &quot;RHEVM Name - #{ext_management_system.name}&quot;)

$evm.log(&quot;info&quot;, &quot;Cluster Name - #{ems_cluster.name}&quot;)

$dialog_vm_count = ' '

$dialog_vm_prefix = ' '

$evm.root.attributes.sort.each { |k, v|

$evm.log(&quot;info&quot;,&quot;#{k}---#{v}&quot;)

if &quot;#{k}&quot; == &quot;dialog_vm_count&quot;

$dialog_vm_count = &quot;#{v}&quot;

$evm.log(&quot;info&quot;, &quot;Found #{$dialog_vm_count}&quot;)

end

if &quot;#{k}&quot; == &quot;dialog_vm_prefix&quot;

$dialog_vm_prefix = &quot;#{v}&quot;

$evm.log(&quot;info&quot;, &quot;Found #{$dialog_vm_prefix}&quot;)

end

}

rhevm = &quot;https://#{ext_management_system.ipaddress}/api/vms&quot;

rhevadmin = 'admin@internal'

rhevadminpass = 'monster'

resource = RestClient::Resource.new(rhevm, :user =&gt; rhevadmin, :password =&gt; rhevadminpass)

$i = 1

while $i &lt; ($dialog_vm_count.to_i + 1)  do

$evm.log(&quot;info&quot;, &quot;******** &lt;vm&gt;&lt;name&gt;#{$dialog_vm_prefix}#{$i}&lt;/name&gt;&lt;cluster&gt;&lt;name&gt;#{ems_cluster.name}&lt;/name&gt;&lt;/cluster&gt;&lt;template&gt;&lt;name&gt;#{vm.name}&lt;/name&gt;&lt;/template&gt;&lt;memory&gt;4294967296&lt;/memory&gt;&lt;os&gt;&lt;boot dev='hd'/&gt;&lt;/os&gt;&lt;/vm&gt;****&quot;)

cloneTemplate = resource.post &quot;&lt;vm&gt;&lt;name&gt;#{$dialog_vm_prefix}#{$i}&lt;/name&gt;&lt;cluster&gt;&lt;name&gt;#{ems_cluster.name}&lt;/name&gt;&lt;/cluster&gt;&lt;template&gt;&lt;name&gt;#{vm.name}&lt;/name&gt;&lt;/template&gt;&lt;memory&gt;4294967296&lt;/memory&gt;&lt;os&gt;&lt;boot dev='hd'/&gt;&lt;/os&gt;&lt;/vm&gt;&quot;, :content_type =&gt; 'application/xml', :accept =&gt; 'application/xml'

$evm.log(&quot;info&quot;, &quot;Result - #{cloneTemplate}&quot;)

$i +=1

end

#

#

#

$evm.log(&quot;info&quot;, &quot;Automate Method Ended&quot;)

exit MIQ_OK
&lt;pre&gt;</pre>
<p>You can download the methods code from here&#8230;<a href="https://github.com/jonnyfiveiq/CloudFORMSNOW/blob/master/RHEV/Templates/cloneTemplate.rb" target="_blank" rel="noopener">https://github.com/jonnyfiveiq/CloudFORMSNOW/blob/master/RHEV/Templates/cloneTemplate.rb</a></p>
]]></html><thumbnail_url><![CDATA[https://cloudformsredhat.files.wordpress.com/2013/05/screen-shot-2013-05-09-at-12-17-34.png?w=300&fit=440%2C330]]></thumbnail_url><thumbnail_width><![CDATA[300]]></thumbnail_width><thumbnail_height><![CDATA[37]]></thumbnail_height></oembed>