Omer Frenkel has uploaded a new change for review.

Change subject: core: add template version related fields to vm and template
......................................................................

core: add template version related fields to vm and template

for templates, added templateVersionNumber, templateVersionName and 
baseTemplateId
fot VMs, added useLatestVersion
these fields are used for supporting templates versions,
as documented in the Template Versions feature page

http://www.ovirt.org/index.php?title=Features/Template_Versions

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1037478
Change-Id: I08f13eee5609525880a92fc81c9fd3cb1d2ba62d
Signed-off-by: Omer Frenkel <ofren...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmTemplateParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Cloner.java
M packaging/dbscripts/create_views.sql
M packaging/dbscripts/storages_sp.sql
A packaging/dbscripts/upgrade/03_04_0520_add_template_version_to_vm_static.sql
M packaging/dbscripts/vm_templates_sp.sql
M packaging/dbscripts/vms_sp.sql
18 files changed, 472 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/06/23606/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
index 938ee9e..dbc4c45 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
@@ -463,7 +463,9 @@
                         getParameters().getMasterVm().getMigrationSupport(),
                         
getParameters().getMasterVm().isAllowConsoleReconnect(),
                         getParameters().getMasterVm().getIsoPath(),
-                        getParameters().getMasterVm().getMigrationDowntime()));
+                        getParameters().getMasterVm().getMigrationDowntime(),
+                        getVmTemplateId(),
+                        getParameters().getTemplateVersionName()));
         DbFacade.getInstance().getVmTemplateDao().save(getVmTemplate());
         getCompensationContext().snapshotNewEntity(getVmTemplate());
         setActionReturnValue(getVmTemplate().getId());
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmTemplateParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmTemplateParameters.java
index 1042ad8..b0cef67 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmTemplateParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmTemplateParameters.java
@@ -51,6 +51,8 @@
 
     private Boolean virtioScsiEnabled;
 
+    private String templateVersionName;
+
     public AddVmTemplateParameters(VmStatic masterVm, String name, String 
description) {
         this();
         _masterVm = masterVm;
@@ -160,4 +162,12 @@
     public void setTemplateType(VmEntityType templateType) {
         this.templateType = templateType;
     }
+
+    public String getTemplateVersionName() {
+        return templateVersionName;
+    }
+
+    public void setTemplateVersionName(String templateVersionName) {
+        this.templateVersionName = templateVersionName;
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java
index 51d885f..fe8f2b3 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java
@@ -417,6 +417,14 @@
         return vmStatic.getKernelParams();
     }
 
+    public boolean isUseLatestVersion() {
+        return vmStatic.isUseLatestVersion();
+    }
+
+    public void setUseLatestVersion(boolean useLatestVersion) {
+        vmStatic.setUseLatestVersion(useLatestVersion);
+    }
+
     public void setKernelParams(String value) {
         vmStatic.setKernelParams(value);
     }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
index 12a80a4..0c30d3a 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmStatic.java
@@ -51,6 +51,9 @@
     private Guid instanceTypeId;
     private Guid imageTypeId;
 
+    @EditableField
+    private boolean useLatestVersion;
+
     public VmStatic() {
         setNumOfMonitors(1);
         initialized = false;
@@ -67,6 +70,7 @@
         vmtGuid = vmStatic.getVmtGuid();
         setCustomProperties(vmStatic.getCustomProperties());
         setInitialized(vmStatic.isInitialized());
+        setUseLatestVersion(vmStatic.isUseLatestVersion());
     }
 
     public VmStatic(VmBase vmBase) {
@@ -161,6 +165,7 @@
         result = prime * result + ((imageTypeId == null) ? 0 : 
imageTypeId.hashCode());
         result = prime * result + ((originalTemplateGuid == null) ? 0 : 
originalTemplateGuid.hashCode());
         result = prime * result + ((originalTemplateName == null) ? 0 : 
originalTemplateName.hashCode());
+        result = prime * result + (useLatestVersion ? 1249 : 1259);
         return result;
     }
 
@@ -187,6 +192,7 @@
                 && ObjectUtils.objectsEqual(imageTypeId, other.imageTypeId)
                 && ObjectUtils.objectsEqual(originalTemplateGuid, 
other.originalTemplateGuid)
                 && ObjectUtils.objectsEqual(originalTemplateName, 
other.originalTemplateName)
+                && useLatestVersion == other.useLatestVersion
          );
     }
 
@@ -237,4 +243,12 @@
     public void setOriginalTemplateGuid(Guid originalTemplateGuid) {
         this.originalTemplateGuid = originalTemplateGuid;
     }
+
+    public boolean isUseLatestVersion() {
+        return useLatestVersion;
+    }
+
+    public void setUseLatestVersion(boolean useLatestVersion) {
+        this.useLatestVersion = useLatestVersion;
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java
index 3631348..4325f6d 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java
@@ -18,6 +18,7 @@
 
 public class VmTemplate extends VmBase implements 
BusinessEntityWithStatus<Guid, VmTemplateStatus>, InstanceType, ImageType {
     private static final long serialVersionUID = -5238366659716600486L;
+    public static final int BASE_VERSION_NUMBER = 1;
 
     private int childCount;
 
@@ -44,6 +45,13 @@
 
     private ArchitectureType clusterArch;
 
+    private Guid baseTemplateId;
+
+    private int templateVersionNumber;
+
+    @EditableField
+    private String templateVersionName;
+
     public VmTemplate() {
         setNiceLevel(0);
         setCpuShares(0);
@@ -51,6 +59,8 @@
         status = VmTemplateStatus.OK;
         diskImageMap = new HashMap<Guid, DiskImage>();
         templateType = VmEntityType.TEMPLATE;
+        baseTemplateId = Guid.Empty;
+        setTemplateVersionNumber(BASE_VERSION_NUMBER);
     }
 
     @EditableField
@@ -64,7 +74,8 @@
             int minAllocatedMem, boolean stateless, boolean runAndPause, Guid 
createdByUserId, VmEntityType templateType,
             boolean autoStartup, int priority, DisplayType defaultDisplayType, 
String initrdUrl, String kernelUrl,
             String kernelParams, Guid quotaId, Guid dedicatedVmForVds, 
MigrationSupport migrationSupport,
-            boolean allowConsoleReconnect, String isoPath, Integer 
migrationDowntime) {
+            boolean allowConsoleReconnect, String isoPath, Integer 
migrationDowntime,
+            Guid baseTemplateId, String templateVersionName) {
         super(name,
                 vmtGuid,
                 vdsGroupId,
@@ -114,6 +125,9 @@
         this.childCount = childCount;
         this.setStatus(VmTemplateStatus.forValue(status));
         setTemplateType(templateType);
+        setBaseTemplateId(baseTemplateId);
+        setTemplateVersionNumber(BASE_VERSION_NUMBER);
+        setTemplateVersionName(templateVersionName);
     }
 
     public ArchitectureType getClusterArch() {
@@ -259,4 +273,36 @@
     public void setTemplateType(VmEntityType templateType) {
         this.templateType = templateType;
     }
+
+    public Guid getBaseTemplateId() {
+        return baseTemplateId;
+    }
+
+    public void setBaseTemplateId(Guid baseTemplateId) {
+        this.baseTemplateId = baseTemplateId;
+    }
+
+    public int getTemplateVersionNumber() {
+        return templateVersionNumber;
+    }
+
+    public void setTemplateVersionNumber(int templateVersionNumber) {
+        this.templateVersionNumber = templateVersionNumber;
+    }
+
+    public String getTemplateVersionName() {
+        return templateVersionName;
+    }
+
+    public void setTemplateVersionName(String templateVersionName) {
+        this.templateVersionName = templateVersionName;
+    }
+
+    /**
+     * Check if template is base template or version of a template
+     * @return true if template is a base template, and false if its a version 
of a template
+     */
+    public boolean isBaseTemplate() {
+        return getId().equals(getBaseTemplateId());
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
index 15e897f..d1349dc 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
@@ -409,6 +409,9 @@
             entity.setVmPoolSpiceProxy(rs.getString("vm_pool_spice_proxy"));
             
entity.setVdsGroupSpiceProxy(rs.getString("vds_group_spice_proxy"));
             entity.setMigrationDowntime((Integer) 
rs.getObject("migration_downtime"));
+            // if template_version_number is null it means use latest version
+            entity.setUseLatestVersion(rs.getObject("template_version_number") 
==
+                    
VmStaticDAODbFacadeImpl.USE_LATEST_VERSION_NUMBER_INDICATOR);
             return entity;
         }
     }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
index cad46a9..6552eb1 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
@@ -16,6 +16,8 @@
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 
 public class VmStaticDAODbFacadeImpl extends BaseDAODbFacade implements 
VmStaticDAO {
+    public static final Integer USE_LATEST_VERSION_NUMBER_INDICATOR = null;
+    public static final Integer DONT_USE_LATEST_VERSION_NUMBER_INDICATOR = 1;
 
     @Override
     public VmStatic get(Guid id) {
@@ -95,7 +97,9 @@
                 .addValue("image_type_id", vm.getImageTypeId())
                 .addValue("original_template_name", 
vm.getOriginalTemplateName())
                 .addValue("original_template_id", vm.getOriginalTemplateGuid())
-                .addValue("migration_downtime", vm.getMigrationDowntime());
+                .addValue("migration_downtime", vm.getMigrationDowntime())
+                .addValue("template_version_number", vm.isUseLatestVersion() ?
+                        USE_LATEST_VERSION_NUMBER_INDICATOR : 
DONT_USE_LATEST_VERSION_NUMBER_INDICATOR);
     }
 
     @Override
@@ -229,6 +233,8 @@
             
entity.setImageTypeId(Guid.createGuidFromString(rs.getString("image_type_id")));
             
entity.setOriginalTemplateName(rs.getString("original_template_name"));
             entity.setOriginalTemplateGuid(getGuid(rs, 
"original_template_id"));
+            // if template_version_number is null it means use latest version
+            entity.setUseLatestVersion(rs.getObject("template_version_number") 
== USE_LATEST_VERSION_NUMBER_INDICATOR);
 
             return entity;
         }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
index 3f20185..c2b037d 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
@@ -193,7 +193,9 @@
                 .addValue("is_run_and_pause", template.isRunAndPause())
                 .addValue("created_by_user_id", template.getCreatedByUserId())
                 .addValue("template_type", template.getTemplateType().name())
-                .addValue("migration_downtime", 
template.getMigrationDowntime());
+                .addValue("migration_downtime", 
template.getMigrationDowntime())
+                .addValue("base_template_id", template.getBaseTemplateId())
+                .addValue("template_version_name", 
template.getTemplateVersionName());
     }
 
     @Override
@@ -280,6 +282,9 @@
             entity.setTrustedService(rs.getBoolean("trusted_service"));
             
entity.setTemplateType(VmEntityType.valueOf(rs.getString("entity_type")));
             
entity.setClusterArch(ArchitectureType.forValue(rs.getInt("architecture")));
+            entity.setBaseTemplateId(getGuidDefaultEmpty(rs, 
"base_template_id"));
+            
entity.setTemplateVersionNumber(rs.getInt("template_version_number"));
+            
entity.setTemplateVersionName(rs.getString("template_version_name"));
             return entity;
         }
     }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
index 9a96828..287b8eb 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
@@ -214,6 +214,16 @@
     protected static final Guid VM_TEMPLATE_RHEL6_2 = new 
Guid("1b85420c-b84c-4f29-997e-0eb674b40b82");
 
     /**
+     * Predefined template version for testing with the following properties :
+     * <ul>
+     * <li>Vds group: rhel6.iscsi (b399944a-81ab-4ec5-8266-e19ba7c3c9d1)</li>
+     * <li>Base template: VM_TEMPLATE_RHEL5 
(1b85420c-b84c-4f29-997e-0eb674b40b79)</li>
+     * <li>template version: 2</li>
+     * </ul>
+     */
+    public static final Guid VM_TEMPLATE_RHEL5_V2 = new 
Guid("1b85420c-b84c-4f29-997e-0eb674b40b83");
+
+    /**
      * Predefined user for testing with the following properties :
      * <ul>
      * <li>Ad group id : 9bf7c640-b620-456f-a550-0348f366544b</li>
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
index ec7d0ba..85e57e8 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
@@ -28,7 +28,7 @@
     private static final Guid STORAGE_DOMAIN_ID = new 
Guid("72e3a666-89e1-4005-a7ca-f7548004a9ab");
     private static final Guid POOL_ID = new 
Guid("103cfd1d-18b1-4790-8a0c-1e52621b0076");
 
-    private static final int VM_COUNT = 5;
+    private static final int VM_COUNT = 7;
     private VmDAO dao;
     private VM existingVm;
     private VmStatic newVmStatic;
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
index 8044f87..f80ef2a 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
@@ -23,7 +23,7 @@
 
 public class VmTemplateDAOTest extends BaseDAOTestCase {
     private static final int NUMBER_OF_TEMPLATES_FOR_PRIVELEGED_USER = 1;
-    private static final int NUMBER_OF_TEMPLATES_IN_DB = 7;
+    private static final int NUMBER_OF_TEMPLATES_IN_DB = 8;
     private static final Guid EXISTING_TEMPLATE_ID = new 
Guid("1b85420c-b84c-4f29-997e-0eb674b40b79");
     private static final Guid DELETABLE_TEMPLATE_ID = new 
Guid("1b85420c-b84c-4f29-997e-0eb674b40b80");
     private static final Guid STORAGE_DOMAIN_ID = new 
Guid("72e3a666-89e1-4005-a7ca-f7548004a9ab");
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index f0b0ea2..bf4d6d0 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -1526,6 +1526,9 @@
         <column>original_template_id</column>
         <column>original_template_name</column>
         <column>migration_downtime</column>
+        <column>template_version_number</column>
+        <column>template_version_name</column>
+
         <!-- Templates -->
         <row>
             <value>00000000-0000-0000-0000-000000000000</value>
@@ -1578,13 +1581,15 @@
             <null />
             <null />
             <value>123</value>
+            <value>1</value>
+            <null />
         </row>
         <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b79</value>
             <value>TEMPLATE</value>
             <value>1</value>
             <value>512</value>
-            <value>00000000-0000-0000-0000-000000000000</value>
+            <value>1b85420c-b84c-4f29-997e-0eb674b40b79</value>
             <value>1</value>
             <null />
             <value>b399944a-81ab-4ec5-8266-e19ba7c3c9d1</value>
@@ -1630,13 +1635,15 @@
             <null />
             <null />
             <value>0</value>
+            <value>1</value>
+            <value>ver 1</value>
         </row>
         <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b80</value>
             <value>TEMPLATE</value>
             <value>1</value>
             <value>512</value>
-            <value>00000000-0000-0000-0000-000000000000</value>
+            <value>1b85420c-b84c-4f29-997e-0eb674b40b80</value>
             <value>1</value>
             <null />
             <value>b399944a-81ab-4ec5-8266-e19ba7c3c9d1</value>
@@ -1682,13 +1689,15 @@
             <null />
             <null />
             <null />
+            <value>1</value>
+            <null />
         </row>
         <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b81</value>
             <value>TEMPLATE</value>
             <value>1</value>
             <value>512</value>
-            <value>00000000-0000-0000-0000-000000000000</value>
+            <value>1b85420c-b84c-4f29-997e-0eb674b40b81</value>
             <value>1</value>
             <null />
             <value>eba797fb-8e3b-4777-b63c-92e7a5957d7c</value>
@@ -1734,13 +1743,15 @@
             <null />
             <null />
             <value>500</value>
+            <value>1</value>
+            <null />
         </row>
          <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value>
             <value>TEMPLATE</value>
             <value>1</value>
             <value>512</value>
-            <value>00000000-0000-0000-0000-000000000000</value>
+             <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value>
             <value>1</value>
             <null />
             <value>eba797fb-8e3b-4777-b63c-92e7a5957d7c</value>
@@ -1786,13 +1797,15 @@
             <null />
             <null />
             <null />
+            <value>1</value>
+            <null />
         </row>
          <row>
             <value>99408929-82cf-4dc7-a532-9d998063fa95</value>
             <value>INSTANCE_TYPE</value>
             <value>1</value>
             <value>512</value>
-            <value>00000000-0000-0000-0000-000000000000</value>
+             <value>99408929-82cf-4dc7-a532-9d998063fa95</value>
             <value>1</value>
             <null />
             <value>eba797fb-8e3b-4777-b63c-92e7a5957d7c</value>
@@ -1837,6 +1850,8 @@
             <value>none</value>
             <null />
             <null />
+            <null />
+            <value>1</value>
             <null />
         </row>
          <row>
@@ -1844,7 +1859,7 @@
             <value>IMAGE_TYPE</value>
             <value>1</value>
             <value>512</value>
-            <value>00000000-0000-0000-0000-000000000000</value>
+             <value>5849b030-626e-47cb-ad90-3ce782d831b3</value>
             <value>1</value>
             <null />
             <value>eba797fb-8e3b-4777-b63c-92e7a5957d7c</value>
@@ -1890,6 +1905,62 @@
             <null />
             <null />
             <null />
+            <value>1</value>
+            <null />
+        </row>
+        <row>
+            <value>1b85420c-b84c-4f29-997e-0eb674b40b83</value>
+            <value>TEMPLATE</value>
+            <value>1</value>
+            <value>1024</value>
+            <value>1b85420c-b84c-4f29-997e-0eb674b40b79</value>
+            <value>1</value>
+            <null />
+            <value>b399944a-81ab-4ec5-8266-e19ba7c3c9d1</value>
+            <value></value>
+            <value>2010-11-21 16:39:27</value>
+            <value>0</value>
+            <value>1</value>
+            <value>false</value> <!-- allow_console_reconnect -->
+            <null />
+            <value>1</value>
+            <value>1</value>
+            <value>0</value>
+            <value>1</value>
+            <value>GMT standard time</value>
+            <value>0</value>
+            <value>1</value>
+            <null />
+            <null />
+            <null />
+            <value>1</value>
+            <value>0</value>
+            <value>0</value>
+            <value>12</value>
+            <value>0</value>
+            <value>0</value>
+            <value></value>
+            <value>0</value>
+            <value></value>
+            <value></value>
+            <value>0</value>
+            <value>0</value>
+            <null />
+            <null />
+            <null />
+            <value>1</value>
+            <value>false</value>
+            <value>256</value>
+            <value>false</value>
+            <null />
+            <null />
+            <null />
+            <value>none</value>
+            <null />
+            <null />
+            <null />
+            <value>2</value>
+            <value>verver</value>
         </row>
 
         <!-- VMS -->
@@ -1944,6 +2015,8 @@
             <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value>
             <value>someTemplateName</value>
             <value>1234</value>
+            <value>1</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4355</value>
@@ -1995,6 +2068,8 @@
             <value>none</value>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value>
             <value>someTemplateName</value>
+            <null />
+            <null />
             <null />
         </row>
         <row>
@@ -2048,6 +2123,8 @@
             <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value>
             <value>someTemplateName</value>
             <null />
+            <value>1</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4357</value>
@@ -2099,6 +2176,8 @@
             <value>none</value>
             <null />
             <null />
+            <null />
+            <value>1</value>
             <null />
         </row>
         <row>
@@ -2152,6 +2231,8 @@
             <value>1b85420c-b84c-4f29-997e-0eb674b40b81</value>
             <value>otherTemplateName</value>
             <null />
+            <value>1</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4360</value>
@@ -2201,6 +2282,9 @@
             <null />
             <null />
             <value>guest_agent</value>
+            <null />
+            <null />
+            <null />
             <null />
             <null />
         </row>
@@ -2253,6 +2337,117 @@
             <null />
             <value>guest_agent</value>
             <null />
+            <null />
+            <null />
+            <null />
+            <null />
+        </row>
+        <row>
+            <value>77296e00-0cad-4e5a-9299-008a7b6f5002</value>
+            <value>VM</value>
+            <value>rhel5-pool-50</value>
+            <value>1024</value>
+            <value>1b85420c-b84c-4f29-997e-0eb674b40b83</value>
+            <value>0</value>
+            <null />
+            <value>b399944a-81ab-4ec5-8266-e19ba7c3c9d1</value>
+            <value></value>
+            <value>2010-11-18 11:13:24</value>
+            <null />
+            <value>1</value>
+            <value>false</value> <!-- allow_console_reconnect -->
+            <value>1</value>
+            <value>1</value>
+            <value>1</value>
+            <null />
+            <value>1</value>
+            <value></value>
+            <value>0</value>
+            <value>1</value>
+            <value>2010-11-18 11:13:24</value>
+            <null />
+            <value>afce7a39-8e8c-4819-ba9c-796d316592e7</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value></value>
+            <value>0</value>
+            <value></value>
+            <value></value>
+            <value></value>
+            <value>0</value>
+            <null />
+            <null />
+            <value>88296e00-0cad-4e5a-9291-008a7b7f4399</value>
+            <value>1</value>
+            <null />
+            <value>256</value>
+            <value>false</value>
+            <null />
+            <null />
+            <null />
+            <value>guest_agent</value>
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+        </row>
+        <row>
+            <value>77296e00-0cad-4e5a-9299-008a7b6f5003</value>
+            <value>VM</value>
+            <value>rhel5-pool-50</value>
+            <value>1024</value>
+            <value>1b85420c-b84c-4f29-997e-0eb674b40b83</value>
+            <value>0</value>
+            <null />
+            <value>b399944a-81ab-4ec5-8266-e19ba7c3c9d1</value>
+            <value></value>
+            <value>2010-11-18 11:13:24</value>
+            <null />
+            <value>1</value>
+            <value>false</value> <!-- allow_console_reconnect -->
+            <value>1</value>
+            <value>1</value>
+            <value>1</value>
+            <null />
+            <value>1</value>
+            <value></value>
+            <value>0</value>
+            <value>1</value>
+            <value>2010-11-18 11:13:24</value>
+            <null />
+            <value>afce7a39-8e8c-4819-ba9c-796d316592e7</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value></value>
+            <value>0</value>
+            <value></value>
+            <value></value>
+            <value></value>
+            <value>0</value>
+            <null />
+            <null />
+            <value>88296e00-0cad-4e5a-9291-008a7b7f4399</value>
+            <value>1</value>
+            <null />
+            <value>256</value>
+            <value>false</value>
+            <null />
+            <null />
+            <null />
+            <value>guest_agent</value>
+            <null />
+            <null />
+            <null />
+            <value>1</value>
             <null />
         </row>
     </table>
@@ -2888,6 +3083,78 @@
             <null />
             <null />
         </row>
+        <row>
+            <value>77296e00-0cad-4e5a-9299-008a7b6f5002</value>
+            <value>0</value>
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null /> <!-- console_user_id -->
+            <null />
+            <null />
+            <null />
+            <value></value>
+            <value>5900</value>
+            <value>1</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>1</value>
+            <value>-1</value>
+            <value>0</value>
+            <null />
+            <value></value>
+            <null />
+            <null />
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <null />
+            <null />
+        </row>
+        <row>
+            <value>77296e00-0cad-4e5a-9299-008a7b6f5003</value>
+            <value>0</value>
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null /> <!-- console_user_id -->
+            <null />
+            <null />
+            <null />
+            <value></value>
+            <value>5900</value>
+            <value>1</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>1</value>
+            <value>-1</value>
+            <value>0</value>
+            <null />
+            <value></value>
+            <null />
+            <null />
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <null />
+            <null />
+        </row>
     </table>
 
     <table name="vm_statistics">
@@ -2950,6 +3217,26 @@
             <value>17</value>
             <null />
         </row>
+        <row>
+            <value>77296e00-0cad-4e5a-9299-008a7b6f5002</value>
+            <value>17</value>
+            <value>0</value>
+            <value>267308</value>
+            <value>0</value>
+            <value>0</value>
+            <value>17</value>
+            <null />
+        </row>
+        <row>
+            <value>77296e00-0cad-4e5a-9299-008a7b6f5003</value>
+            <value>17</value>
+            <value>0</value>
+            <value>267308</value>
+            <value>0</value>
+            <value>0</value>
+            <value>17</value>
+            <null />
+        </row>
     </table>
 
     <table name="storage_domain_static">
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Cloner.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Cloner.java
index c61b43e..1724f94 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Cloner.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Cloner.java
@@ -213,6 +213,8 @@
         vm.setClusterArch(instance.getClusterArch());
         vm.setOriginalTemplateGuid(instance.getOriginalTemplateGuid());
         vm.setOriginalTemplateName(instance.getOriginalTemplateName());
+        vm.setMigrationDowntime(instance.getMigrationDowntime());
+        vm.setUseLatestVersion(instance.isUseLatestVersion());
 
         return vm;
     }
@@ -425,6 +427,9 @@
         obj.setDiskList(instance.getDiskList());
         obj.setRunAndPause(instance.isRunAndPause());
         obj.setClusterArch(instance.getClusterArch());
+        obj.setTemplateVersionNumber(instance.getTemplateVersionNumber());
+        obj.setBaseTemplateId(instance.getBaseTemplateId());
+        obj.setTemplateVersionName(instance.getTemplateVersionName());
 
         return obj;
     }
@@ -462,6 +467,7 @@
         obj.setId(instance.getId());
         obj.setName(instance.getName());
         obj.setVmtGuid(instance.getVmtGuid());
+        obj.setUseLatestVersion(instance.isUseLatestVersion());
 
         return obj;
     }
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index 3aadaed..a08edf4 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -406,7 +406,10 @@
        vm_templates.created_by_user_id as created_by_user_id,
        vm_templates.entity_type,
        vm_templates.migration_downtime as migration_downtime,
-       vds_groups.architecture as architecture
+       vds_groups.architecture as architecture,
+       vm_templates.template_version_number as template_version_number,
+       vm_templates.vmt_guid as base_template_id,
+       vm_templates.template_version_name as template_version_name
 FROM       vm_static AS vm_templates  INNER JOIN
 vds_groups ON vm_templates.vds_group_id = vds_groups.vds_group_id
 left outer JOIN
@@ -439,7 +442,9 @@
                          vm_templates.kernel_params, 
image_storage_domain_map.storage_domain_id AS storage_id,
                     quota.quota_name as quota_name, vm_templates.is_disabled, 
vm_templates.min_allocated_mem, vm_templates.is_run_and_pause, 
vm_templates.created_by_user_id,
                     vm_templates.migration_downtime,
-                    vm_templates.entity_type, vds_groups.architecture
+                    vm_templates.entity_type, vds_groups.architecture,
+                    vm_templates.template_version_number as 
template_version_number, vm_templates.vmt_guid as base_template_id,
+                    vm_templates.template_version_name as template_version_name
 FROM                  vm_static AS vm_templates INNER JOIN
                          vds_groups ON vm_templates.vds_group_id = 
vds_groups.vds_group_id LEFT OUTER JOIN
                       storage_pool ON storage_pool.id = 
vds_groups.storage_pool_id INNER JOIN
@@ -461,7 +466,9 @@
                       image_storage_domain_map.storage_domain_id AS storage_id,
                       quota.quota_name as quota_name, 
vm_templates_1.is_disabled, vm_templates_1.min_allocated_mem, 
vm_templates_1.is_run_and_pause, vm_templates_1.created_by_user_id,
                       vm_templates_1.migration_downtime,
-                      vm_templates_1.entity_type, vds_groups_1.architecture
+                      vm_templates_1.entity_type, vds_groups_1.architecture,
+                      vm_templates_1.template_version_number as 
template_version_number, vm_templates_1.vmt_guid as base_template_id,
+                      vm_templates_1.template_version_name as 
template_version_name
 FROM                  vm_static AS vm_templates_1 INNER JOIN
                       vds_groups AS vds_groups_1 ON 
vm_templates_1.vds_group_id = vds_groups_1.vds_group_id LEFT OUTER JOIN
                       storage_pool AS storage_pool_1 ON storage_pool_1.id = 
vds_groups_1.storage_pool_id INNER JOIN
@@ -603,7 +610,7 @@
                       vm_static.tunnel_migration as tunnel_migration, 
vm_static.vnc_keyboard_layout as vnc_keyboard_layout, 
vm_static.is_run_and_pause as is_run_and_pause, vm_static.created_by_user_id as 
created_by_user_id,
                       vm_dynamic.last_watchdog_event as last_watchdog_event, 
vm_dynamic.last_watchdog_action as last_watchdog_action, vm_dynamic.is_run_once 
as is_run_once, vm_dynamic.vm_fqdn as vm_fqdn, vm_dynamic.cpu_name as cpu_name,
                       vm_static.instance_type_id as instance_type_id, 
vm_static.image_type_id as image_type_id, vds_groups.architecture as 
architecture, vm_static.original_template_id as original_template_id, 
vm_static.original_template_name as original_template_name, 
vm_dynamic.last_stop_time as last_stop_time,
-                      vm_static.migration_downtime as migration_downtime
+                      vm_static.migration_downtime as migration_downtime, 
vm_static.template_version_number as template_version_number
 FROM         vm_static INNER JOIN
 vm_dynamic ON vm_static.vm_guid = vm_dynamic.vm_guid INNER JOIN
 vm_static AS vm_templates ON vm_static.vmt_guid = vm_templates.vm_guid INNER 
JOIN
@@ -643,7 +650,7 @@
             vms.vnc_keyboard_layout as vnc_keyboard_layout, 
vms.is_run_and_pause as is_run_and_pause, vms.created_by_user_id as 
created_by_user_id, vms.vm_fqdn, vms.cpu_name as cpu_name,
             vms.vm_pool_spice_proxy as vm_pool_spice_proxy, 
vms.vds_group_spice_proxy as vds_group_spice_proxy,
             vms.instance_type_id as instance_type_id, vms.image_type_id as 
image_type_id, vms.architecture as architecture, vms.original_template_id as 
original_template_id, vms.original_template_name as original_template_name,
-            vms.migration_downtime as migration_downtime
+            vms.migration_downtime as migration_downtime, 
vms.template_version_number as template_version_number
 FROM        vms LEFT OUTER JOIN
             tags_vm_map_view ON vms.vm_guid = tags_vm_map_view.vm_id LEFT 
OUTER JOIN
             vm_device ON vm_device.vm_id = vms.vm_guid LEFT OUTER JOIN
diff --git a/packaging/dbscripts/storages_sp.sql 
b/packaging/dbscripts/storages_sp.sql
index 303f8e7..287052d 100644
--- a/packaging/dbscripts/storages_sp.sql
+++ b/packaging/dbscripts/storages_sp.sql
@@ -589,6 +589,12 @@
          where entity_type = 'TEMPLATE' and storage_id = v_storage_domain_id;
    END;
 
+   -- Add also Template Versions based on the selected templates
+   insert into TEMPLATES_IDS_TEMPORARY_TABLE
+     select vm_guid from vm_static
+     where vmt_guid in (select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE)
+     and entity_type = 'TEMPLATE';
+
    BEGIN
      -- Vms which resides on the storage domain
      CREATE GLOBAL TEMPORARY TABLE VM_IDS_TEMPORARY_TABLE AS select 
vm_id,vm_images_view.entity_type as entity_type from vm_images_view
diff --git 
a/packaging/dbscripts/upgrade/03_04_0520_add_template_version_to_vm_static.sql 
b/packaging/dbscripts/upgrade/03_04_0520_add_template_version_to_vm_static.sql
new file mode 100644
index 0000000..424e6eb
--- /dev/null
+++ 
b/packaging/dbscripts/upgrade/03_04_0520_add_template_version_to_vm_static.sql
@@ -0,0 +1,8 @@
+select fn_db_add_column('vm_static', 'template_version_number', 'INTEGER 
DEFAULT NULL');
+select fn_db_add_column('vm_static', 'template_version_name', 'varchar(40) 
DEFAULT NULL');
+-- make all existing vms and templates have version 1
+update vm_static set template_version_number=1;
+-- update base template for all templates
+update vm_static set vmt_guid = vm_guid where entity_type='TEMPLATE';
+-- set default 'base version' as version name
+update vm_static set template_version_name = 'base version' where 
entity_type='TEMPLATE';
diff --git a/packaging/dbscripts/vm_templates_sp.sql 
b/packaging/dbscripts/vm_templates_sp.sql
index ae99c98..9f391e8 100644
--- a/packaging/dbscripts/vm_templates_sp.sql
+++ b/packaging/dbscripts/vm_templates_sp.sql
@@ -52,14 +52,28 @@
  v_is_run_and_pause BOOLEAN,
  v_created_by_user_id UUID,
  v_template_type VARCHAR(40),
- v_migration_downtime INTEGER)
+ v_migration_downtime INTEGER,
+ v_base_template_id UUID,
+ v_template_version_name VARCHAR(40))
 
 RETURNS VOID
    AS $procedure$
+DECLARE
+v_template_version_number INTEGER;
 BEGIN
+  -- get current max version and use next
+  SELECT max(template_version_number) + 1 into v_template_version_number
+  from vm_static
+  where vmt_guid = v_base_template_id
+        and entity_type = 'TEMPLATE';
+
+  -- if no versions exist it might return null, so this is a new base template
+  if v_template_version_number is null then
+    v_template_version_number = 1;
+  end if;
+
 INSERT
 INTO vm_static(
-    vmt_guid,
     child_count,
     creation_date,
     description,
@@ -105,11 +119,11 @@
     min_allocated_mem,
     is_run_and_pause,
     created_by_user_id,
-    migration_downtime)
+    migration_downtime,
+    template_version_number,
+    vmt_guid,
+    template_version_name)
 VALUES(
-    -- This field is meaningless for templates for the time being, however we 
want to keep it not null for VMs.
-    -- Thus, since templates are top level elements they "point" to the 
'Blank' template.
-    '00000000-0000-0000-0000-000000000000',
     v_child_count,
     v_creation_date,
     v_description,
@@ -155,7 +169,10 @@
     v_min_allocated_mem,
     v_is_run_and_pause,
     v_created_by_user_id,
-    v_migration_downtime);
+    v_migration_downtime,
+    v_template_version_number,
+    v_base_template_id,
+    v_template_version_name);
 -- perform deletion from vm_ovf_generations to ensure that no record exists 
when performing insert to avoid PK violation.
 DELETE FROM vm_ovf_generations gen WHERE gen.vm_guid = v_vmt_guid;
 INSERT INTO vm_ovf_generations(vm_guid, storage_pool_id)
@@ -214,7 +231,8 @@
  v_is_run_and_pause BOOLEAN,
  v_created_by_user_id UUID,
  v_template_type VARCHAR(40),
- v_migration_downtime INTEGER)
+ v_migration_downtime INTEGER,
+ v_template_version_name VARCHAR(40))
 RETURNS VOID
 
        --The [vm_templates] table doesn't have a timestamp column. Optimistic 
concurrency logic cannot be generated
@@ -238,7 +256,8 @@
       migration_support = v_migration_support, dedicated_vm_for_vds = 
v_dedicated_vm_for_vds, is_smartcard_enabled = v_is_smartcard_enabled,
       is_delete_protected = v_is_delete_protected, sso_method = v_sso_method, 
is_disabled = v_is_disabled, tunnel_migration = v_tunnel_migration,
       vnc_keyboard_layout = v_vnc_keyboard_layout, min_allocated_mem = 
v_min_allocated_mem, is_run_and_pause = v_is_run_and_pause, created_by_user_id 
= v_created_by_user_id,
-      migration_downtime = v_migration_downtime
+      migration_downtime = v_migration_downtime,
+      template_version_name = v_template_version_name
       WHERE vm_guid = v_vmt_guid
       AND   entity_type = v_template_type;
 END; $procedure$
diff --git a/packaging/dbscripts/vms_sp.sql b/packaging/dbscripts/vms_sp.sql
index 3a3ac67..10bed79 100644
--- a/packaging/dbscripts/vms_sp.sql
+++ b/packaging/dbscripts/vms_sp.sql
@@ -452,12 +452,14 @@
     v_image_type_id UUID,
     v_original_template_id UUID,
     v_original_template_name VARCHAR(255),
-    v_migration_downtime INTEGER)
+    v_migration_downtime INTEGER,
+    v_template_version_number INTEGER)
 RETURNS VOID
    AS $procedure$
 BEGIN
-INSERT INTO vm_static(description, free_text_comment, mem_size_mb, os, 
vds_group_id, vm_guid, VM_NAME, vmt_guid,domain,creation_date,num_of_monitors, 
single_qxl_pci, 
allow_console_reconnect,is_initialized,num_of_sockets,cpu_per_socket,usb_policy,
 time_zone,auto_startup,is_stateless,dedicated_vm_for_vds, fail_back, 
default_boot_sequence, vm_type, nice_level, cpu_shares, default_display_type, 
priority,iso_path,origin,initrd_url,kernel_url,kernel_params,migration_support,predefined_properties,userdefined_properties,min_allocated_mem,
 entity_type, quota_id, cpu_pinning, is_smartcard_enabled,is_delete_protected, 
sso_method, host_cpu_flags, tunnel_migration, vnc_keyboard_layout, 
is_run_and_pause, created_by_user_id, instance_type_id, image_type_id, 
original_template_id, original_template_name, migration_downtime)
-       VALUES(v_description, v_free_text_comment, v_mem_size_mb, v_os, 
v_vds_group_id, v_vm_guid, v_vm_name, v_vmt_guid, v_domain, v_creation_date, 
v_num_of_monitors,v_single_qxl_pci, v_allow_console_reconnect, 
v_is_initialized, v_num_of_sockets, v_cpu_per_socket, v_usb_policy, 
v_time_zone, v_auto_startup,v_is_stateless,v_dedicated_vm_for_vds,v_fail_back, 
v_default_boot_sequence, v_vm_type, v_nice_level, v_cpu_shares, 
v_default_display_type, 
v_priority,v_iso_path,v_origin,v_initrd_url,v_kernel_url,v_kernel_params,v_migration_support,v_predefined_properties,v_userdefined_properties,v_min_allocated_mem,
 'VM', v_quota_id, v_cpu_pinning, v_is_smartcard_enabled,v_is_delete_protected, 
v_sso_method, v_host_cpu_flags, v_tunnel_migration, v_vnc_keyboard_layout, 
v_is_run_and_pause, v_created_by_user_id, v_instance_type_id, v_image_type_id, 
v_original_template_id, v_original_template_name, v_migration_downtime);
+INSERT INTO vm_static(description, free_text_comment, mem_size_mb, os, 
vds_group_id, vm_guid, VM_NAME, vmt_guid,domain,creation_date,num_of_monitors, 
single_qxl_pci, 
allow_console_reconnect,is_initialized,num_of_sockets,cpu_per_socket,usb_policy,
 time_zone,auto_startup,is_stateless,dedicated_vm_for_vds, fail_back, 
default_boot_sequence, vm_type, nice_level, cpu_shares, default_display_type, 
priority,iso_path,origin,initrd_url,kernel_url,kernel_params,migration_support,predefined_properties,userdefined_properties,min_allocated_mem,
 entity_type, quota_id, cpu_pinning, is_smartcard_enabled,is_delete_protected, 
sso_method, host_cpu_flags, tunnel_migration, vnc_keyboard_layout, 
is_run_and_pause, created_by_user_id, instance_type_id, image_type_id, 
original_template_id, original_template_name, migration_downtime, 
template_version_number)
+       VALUES(v_description, v_free_text_comment, v_mem_size_mb, v_os, 
v_vds_group_id, v_vm_guid, v_vm_name, v_vmt_guid, v_domain, v_creation_date, 
v_num_of_monitors,v_single_qxl_pci, v_allow_console_reconnect, 
v_is_initialized, v_num_of_sockets, v_cpu_per_socket, v_usb_policy, 
v_time_zone, v_auto_startup,v_is_stateless,v_dedicated_vm_for_vds,v_fail_back, 
v_default_boot_sequence, v_vm_type, v_nice_level, v_cpu_shares, 
v_default_display_type, 
v_priority,v_iso_path,v_origin,v_initrd_url,v_kernel_url,v_kernel_params,v_migration_support,v_predefined_properties,v_userdefined_properties,v_min_allocated_mem,
 'VM', v_quota_id, v_cpu_pinning, v_is_smartcard_enabled,v_is_delete_protected, 
v_sso_method, v_host_cpu_flags, v_tunnel_migration, v_vnc_keyboard_layout, 
v_is_run_and_pause, v_created_by_user_id, v_instance_type_id, v_image_type_id, 
v_original_template_id, v_original_template_name, v_migration_downtime, 
v_template_version_number);
+
 -- perform deletion from vm_ovf_generations to ensure that no record exists 
when performing insert to avoid PK violation.
 DELETE FROM vm_ovf_generations gen WHERE gen.vm_guid = v_vm_guid;
 INSERT INTO vm_ovf_generations(vm_guid, storage_pool_id) VALUES (v_vm_guid, 
(SELECT storage_pool_id FROM vds_groups vg WHERE vg.vds_group_id = 
v_vds_group_id));
@@ -577,7 +579,9 @@
 v_image_type_id UUID,
 v_original_template_id UUID,
 v_original_template_name VARCHAR(255),
-v_migration_downtime INTEGER)
+v_migration_downtime INTEGER,
+v_template_version_number INTEGER)
+
 RETURNS VOID
 
        --The [vm_static] table doesn't have a timestamp column. Optimistic 
concurrency logic cannot be generated
@@ -606,7 +610,7 @@
       vnc_keyboard_layout = v_vnc_keyboard_layout, is_run_and_pause = 
v_is_run_and_pause, created_by_user_id = v_created_by_user_id,
       instance_type_id = v_instance_type_id, image_type_id = v_image_type_id, 
original_template_id = v_original_template_id,
       original_template_name = v_original_template_name,
-      migration_downtime = v_migration_downtime
+      migration_downtime = v_migration_downtime, template_version_number = 
v_template_version_number
       WHERE vm_guid = v_vm_guid
       AND   entity_type = 'VM';
 END; $procedure$


-- 
To view, visit http://gerrit.ovirt.org/23606
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I08f13eee5609525880a92fc81c9fd3cb1d2ba62d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.4
Gerrit-Owner: Omer Frenkel <ofren...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to