Omer Frenkel has uploaded a new change for review.

Change subject: core: add templateVersion field to vm and template
......................................................................

core: add templateVersion field to vm and template

this field is 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/businessentities/VM.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.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/dal/dbbroker/AbstractVmRowMapper.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 packaging/dbscripts/create_views.sql
M packaging/dbscripts/storages_sp.sql
A packaging/dbscripts/upgrade/03_04_0300_add_template_version_to_vm_static.sql
M packaging/dbscripts/vm_templates_sp.sql
M packaging/dbscripts/vms_sp.sql
18 files changed, 379 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/36/22736/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 63be43c..dce8e8d 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
@@ -440,7 +440,8 @@
                         getParameters().getMasterVm().isStateless(),
                         getParameters().getMasterVm().isRunAndPause(),
                         getUserId(),
-                        getParameters().getTemplateType()));
+                        getParameters().getTemplateType(),
+                        VmTemplateHandler.BLANK_VM_TEMPLATE_ID));
         
getVmTemplate().setAutoStartup(getParameters().getMasterVm().isAutoStartup());
         
getVmTemplate().setPriority(getParameters().getMasterVm().getPriority());
         
getVmTemplate().setDefaultDisplayType(getParameters().getMasterVm().getDefaultDisplayType());
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 a11e6e4..68c9790 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 Integer getTemplateVersion() {
+        return vmStatic.getTemplateVersion();
+    }
+
+    public void setTemplateVersion(Integer templateVersion) {
+        vmStatic.setTemplateVersion(templateVersion);
+    }
+
     public void setKernelParams(String value) {
         vmStatic.setKernelParams(value);
     }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
index c0cf842..29717a3 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
@@ -181,6 +181,9 @@
     // not persisted to db
     private Date exportDate;
 
+    @EditableOnVmStatusField
+    private Integer templateVersion;
+
     public VmBase() {
         name = "";
         interfaces = new ArrayList<VmNetworkInterface>();
@@ -278,7 +281,8 @@
             String vncKeyboardLayout,
             int minAllocatedMem,
             boolean runAndPause,
-            Guid createdByUserId) {
+            Guid createdByUserId,
+            Integer templateVersion) {
         this();
         this.id = id;
         this.vdsGroupId = vdsGroupId;
@@ -317,6 +321,7 @@
         this.createdByUserId = createdByUserId;
         defaultDisplayType = DisplayType.qxl;
         setQuotaId(quotaId);
+        this.templateVersion = templateVersion;
     }
 
     public long getDbGeneration() {
@@ -831,4 +836,12 @@
     public void setSsoMethod(SsoMethod ssoMethod) {
         this.ssoMethod = ssoMethod;
     }
+
+    public Integer getTemplateVersion() {
+        return templateVersion;
+    }
+
+    public void setTemplateVersion(Integer templateVersion) {
+        this.templateVersion = templateVersion;
+    }
 }
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 9b873f2..004d87b 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
@@ -98,7 +98,8 @@
                 vmStatic.getVncKeyboardLayout(),
                 vmStatic.getMinAllocatedMem(),
                 vmStatic.isRunAndPause(),
-                vmStatic.getCreatedByUserId());
+                vmStatic.getCreatedByUserId(),
+                vmStatic.getTemplateVersion());
         setName(vmStatic.getName());
         vmtGuid = vmStatic.getVmtGuid();
         setCustomProperties(vmStatic.getCustomProperties());
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 dbe37ec..5e13664 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
@@ -44,6 +44,8 @@
 
     private ArchitectureType clusterArch;
 
+    private Guid baseTemplateId;
+
     public VmTemplate() {
         setNiceLevel(0);
         setCpuShares(0);
@@ -51,6 +53,8 @@
         status = VmTemplateStatus.OK;
         diskImageMap = new HashMap<Guid, DiskImage>();
         templateType = VmEntityType.TEMPLATE;
+        baseTemplateId = Guid.Empty;
+        setTemplateVersion(1);
     }
 
     @EditableField
@@ -61,7 +65,7 @@
             int numOfMonitors, boolean singleQxlPci, int status, int 
usbPolicy, String timeZone, int niceLevel,
             int cpuShares, boolean failBack, BootSequence defaultBootSequence, 
VmType vmType,
             boolean smartcardEnabled, boolean deleteProtected, SsoMethod 
ssoMethod, Boolean tunnelMigration, String vncKeyboardLayout,
-            int minAllocatedMem, boolean stateless, boolean runAndPause, Guid 
createdByUserId, VmEntityType templateType) {
+            int minAllocatedMem, boolean stateless, boolean runAndPause, Guid 
createdByUserId, VmEntityType templateType, Guid baseTemplateId) {
         super(
                 vmtGuid,
                 vdsGroupId,
@@ -98,7 +102,8 @@
                 vncKeyboardLayout,
                 minAllocatedMem,
                 runAndPause,
-                createdByUserId);
+                createdByUserId,
+                1);
 
         diskTemplateMap = new HashMap<Guid, DiskImage>();
         diskImageMap = new HashMap<Guid, DiskImage>();
@@ -108,6 +113,7 @@
         this.setNumOfMonitors(numOfMonitors);
         this.setStatus(VmTemplateStatus.forValue(status));
         setTemplateType(templateType);
+        setBaseTemplateId(baseTemplateId);
     }
 
     public ArchitectureType getClusterArch() {
@@ -253,4 +259,12 @@
     public void setTemplateType(VmEntityType templateType) {
         this.templateType = templateType;
     }
+
+    public Guid getBaseTemplateId() {
+        return baseTemplateId;
+    }
+
+    public void setBaseTemplateId(Guid baseTemplateId) {
+        this.baseTemplateId = baseTemplateId;
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/AbstractVmRowMapper.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/AbstractVmRowMapper.java
index bf110a6..b23904e 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/AbstractVmRowMapper.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/AbstractVmRowMapper.java
@@ -48,6 +48,7 @@
         entity.setVncKeyboardLayout(rs.getString("vnc_keyboard_layout"));
         entity.setRunAndPause(rs.getBoolean("is_run_and_pause"));
         
entity.setCreatedByUserId(Guid.createGuidFromString(rs.getString("created_by_user_id")));
+        entity.setTemplateVersion(rs.getInt("template_version"));
     }
 
 }
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 e0d1d9a..07412a0 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
@@ -392,6 +392,7 @@
             entity.setOriginalTemplateGuid(getGuid(rs, 
"original_template_id"));
             entity.setVmPoolSpiceProxy(rs.getString("vm_pool_spice_proxy"));
             
entity.setVdsGroupSpiceProxy(rs.getString("vds_group_spice_proxy"));
+            entity.setTemplateVersion((Integer) 
rs.getObject("template_version"));
             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 c4779ad..3f3579c 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
@@ -94,7 +94,8 @@
                 .addValue("instance_type_id", vm.getInstanceTypeId())
                 .addValue("image_type_id", vm.getImageTypeId())
                 .addValue("original_template_name", 
vm.getOriginalTemplateName())
-                .addValue("original_template_id", 
vm.getOriginalTemplateGuid());
+                .addValue("original_template_id", vm.getOriginalTemplateGuid())
+                .addValue("template_version", vm.getTemplateVersion());
     }
 
     @Override
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 3904451..3642429 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
@@ -192,7 +192,8 @@
                 .addValue("min_allocated_mem", template.getMinAllocatedMem())
                 .addValue("is_run_and_pause", template.isRunAndPause())
                 .addValue("created_by_user_id", template.getCreatedByUserId())
-                .addValue("template_type", template.getTemplateType().name());
+                .addValue("template_type", template.getTemplateType().name())
+                .addValue("base_template_id", template.getBaseTemplateId());
     }
 
     @Override
@@ -279,6 +280,7 @@
             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"));
             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 781e19c..4dc4940 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
@@ -213,6 +213,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 c71e539..2e54ec2 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 73622a3..0331e97 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -1514,6 +1514,8 @@
         <column>sso_method</column>
         <column>original_template_id</column>
         <column>original_template_name</column>
+        <column>template_version</column>
+
         <!-- Templates -->
         <row>
             <value>00000000-0000-0000-0000-000000000000</value>
@@ -1565,6 +1567,7 @@
             <value>guest_agent</value>
             <null />
             <null />
+            <value>1</value>
         </row>
         <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b79</value>
@@ -1616,6 +1619,7 @@
             <value>none</value>
             <null />
             <null />
+            <value>1</value>
         </row>
         <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b80</value>
@@ -1667,6 +1671,7 @@
             <value>guest_agent</value>
             <null />
             <null />
+            <value>1</value>
         </row>
         <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b81</value>
@@ -1718,6 +1723,7 @@
             <value>none</value>
             <null />
             <null />
+            <value>1</value>
         </row>
          <row>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value>
@@ -1769,6 +1775,7 @@
             <value>guest_agent</value>
             <null />
             <null />
+            <value>1</value>
         </row>
          <row>
             <value>99408929-82cf-4dc7-a532-9d998063fa95</value>
@@ -1820,6 +1827,7 @@
             <value>none</value>
             <null />
             <null />
+            <value>1</value>
         </row>
          <row>
             <value>5849b030-626e-47cb-ad90-3ce782d831b3</value>
@@ -1871,6 +1879,59 @@
             <value>none</value>
             <null />
             <null />
+            <value>1</value>
+        </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 />
+            <value>2</value>
         </row>
 
         <!-- VMS -->
@@ -1924,6 +1985,7 @@
             <value>none</value>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value>
             <value>someTemplateName</value>
+            <value>1</value>
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4355</value>
@@ -1975,6 +2037,7 @@
             <value>none</value>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value>
             <value>someTemplateName</value>
+            <null />
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4356</value>
@@ -2026,6 +2089,7 @@
             <value>guest_agent</value>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value>
             <value>someTemplateName</value>
+            <value>1</value>
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4357</value>
@@ -2077,6 +2141,7 @@
             <value>none</value>
             <null />
             <null />
+            <value>1</value>
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4359</value>
@@ -2128,6 +2193,7 @@
             <value>none</value>
             <value>1b85420c-b84c-4f29-997e-0eb674b40b81</value>
             <value>otherTemplateName</value>
+            <value>1</value>
         </row>
         <row>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4360</value>
@@ -2177,6 +2243,7 @@
             <null />
             <null />
             <value>guest_agent</value>
+            <null />
             <null />
             <null />
         </row>
@@ -2230,6 +2297,111 @@
             <value>guest_agent</value>
             <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 />
+        </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 />
+            <value>2</value>
         </row>
     </table>
 
@@ -2856,6 +3028,76 @@
             <null />
             <null />
         </row>
+        <row>
+            <value>77296e00-0cad-4e5a-9299-008a7b6f5002</value>
+            <value>0</value>
+            <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 /> <!-- 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">
@@ -2918,6 +3160,26 @@
             <value>17</value>
             <null />
         </row>
+        <row>
+            <value>77296e00-0cad-4e5a-9299-008a7b6f5002</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <null />
+        </row>
+        <row>
+            <value>77296e00-0cad-4e5a-9299-008a7b6f5003</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <null />
+        </row>
     </table>
 
     <table name="storage_domain_static">
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index 2d46408..c555777 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -405,7 +405,9 @@
        vm_templates.is_run_and_pause as is_run_and_pause,
        vm_templates.created_by_user_id as created_by_user_id,
        vm_templates.entity_type,
-       vds_groups.architecture as architecture
+       vds_groups.architecture as architecture,
+       vm_templates.template_version as template_version,
+       vm_templates.vmt_guid as base_template_id
 FROM       vm_static AS vm_templates  INNER JOIN
 vds_groups ON vm_templates.vds_group_id = vds_groups.vds_group_id
 left outer JOIN
@@ -437,7 +439,7 @@
                          vm_templates.is_stateless, vm_templates.iso_path, 
vm_templates.origin, vm_templates.initrd_url, vm_templates.kernel_url,
                          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.entity_type, vds_groups.architecture
+                    vm_templates.entity_type, vds_groups.architecture, 
vm_templates.template_version as template_version, vm_templates.vmt_guid as 
base_template_id
 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
@@ -458,7 +460,7 @@
                       vm_templates_1.initrd_url, vm_templates_1.kernel_url, 
vm_templates_1.kernel_params,
                       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.entity_type, vds_groups_1.architecture
+                      vm_templates_1.entity_type, vds_groups_1.architecture, 
vm_templates_1.template_version as template_version, vm_templates_1.vmt_guid as 
base_template_id
 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
@@ -599,7 +601,8 @@
                       vm_static.initrd_url as initrd_url, vm_static.kernel_url 
as kernel_url, vm_static.kernel_params as kernel_params, 
vm_dynamic.pause_status as pause_status, vm_dynamic.exit_message as 
exit_message, vm_dynamic.exit_status as exit_status,vm_static.migration_support 
as migration_support,vm_static.predefined_properties as 
predefined_properties,vm_static.userdefined_properties as 
userdefined_properties,vm_static.min_allocated_mem as min_allocated_mem,  
vm_dynamic.hash as hash, vm_static.cpu_pinning as cpu_pinning, 
vm_static.db_generation as db_generation, vm_static.host_cpu_flags as 
host_cpu_flags,
                       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_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_static.template_version as template_version
 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
@@ -638,7 +641,8 @@
             vms.quota_id as quota_id, vms.quota_name as quota_name, 
vms.tunnel_migration as tunnel_migration,
             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.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.template_version as template_version
 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..c6495ba 100644
--- a/packaging/dbscripts/storages_sp.sql
+++ b/packaging/dbscripts/storages_sp.sql
@@ -587,6 +587,12 @@
          JOIN vm_device ON vm_device.device_id = 
images_storage_domain_view.disk_id
          JOIN STORAGE_DOMAIN_MAP_TABLE ON STORAGE_DOMAIN_MAP_TABLE.image_id = 
images_storage_domain_view.image_guid
          where entity_type = 'TEMPLATE' and storage_id = v_storage_domain_id;
+
+      -- Add also Template Versions based on these 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';
    END;
 
    BEGIN
diff --git 
a/packaging/dbscripts/upgrade/03_04_0300_add_template_version_to_vm_static.sql 
b/packaging/dbscripts/upgrade/03_04_0300_add_template_version_to_vm_static.sql
new file mode 100644
index 0000000..e36a9aa
--- /dev/null
+++ 
b/packaging/dbscripts/upgrade/03_04_0300_add_template_version_to_vm_static.sql
@@ -0,0 +1,3 @@
+select fn_db_add_column('vm_static', 'template_version', 'INTEGER DEFAULT 
NULL');
+-- make all existing vms and templates have version 1
+update vm_static set template_version=1;
diff --git a/packaging/dbscripts/vm_templates_sp.sql 
b/packaging/dbscripts/vm_templates_sp.sql
index 87b555d..bc7d06e 100644
--- a/packaging/dbscripts/vm_templates_sp.sql
+++ b/packaging/dbscripts/vm_templates_sp.sql
@@ -51,14 +51,33 @@
  v_min_allocated_mem INTEGER,
  v_is_run_and_pause BOOLEAN,
  v_created_by_user_id UUID,
- v_template_type VARCHAR(40))
+ v_template_type VARCHAR(40),
+  v_base_template_id UUID)
 
 RETURNS VOID
    AS $procedure$
+DECLARE
+v_template_version INTEGER;
 BEGIN
+  -- assign correct template version:
+  --  if base is blank, this is a base template, use version 1
+  --  other, get current max version and use next
+  if v_base_template_id = '00000000-0000-0000-0000-000000000000' then
+    v_template_version = 1;
+  else
+    SELECT max(template_version) + 1 into v_template_version
+    from vm_static
+    where vmt_guid = v_base_template_id
+    and entity_type = 'TEMPLATE';
+
+    -- if no versions exist it might return null, means version should be 2
+    if v_template_version is null then
+      v_template_version = 2;
+    end if;
+  end if;
+
 INSERT
 INTO vm_static(
-    vmt_guid,
     child_count,
     creation_date,
     description,
@@ -103,11 +122,10 @@
     vnc_keyboard_layout,
     min_allocated_mem,
     is_run_and_pause,
-    created_by_user_id)
+    created_by_user_id,
+    template_version,
+    vmt_guid)
 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,
@@ -152,7 +170,9 @@
     v_vnc_keyboard_layout,
     v_min_allocated_mem,
     v_is_run_and_pause,
-    v_created_by_user_id);
+    v_created_by_user_id,
+    v_template_version,
+    v_base_template_id);
 -- 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)
@@ -210,7 +230,8 @@
  v_min_allocated_mem INTEGER,
  v_is_run_and_pause BOOLEAN,
  v_created_by_user_id UUID,
- v_template_type VARCHAR(40))
+ v_template_type VARCHAR(40),
+ v_base_template_id UUID)
 RETURNS VOID
 
        --The [vm_templates] table doesn't have a timestamp column. Optimistic 
concurrency logic cannot be generated
@@ -233,7 +254,8 @@
       kernel_url = v_kernel_url,kernel_params = v_kernel_params, _update_date 
= CURRENT_TIMESTAMP, quota_id = v_quota_id,
       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
+      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,
+      vmt_guid = v_base_template_id
       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 bda16da..9cd7b30 100644
--- a/packaging/dbscripts/vms_sp.sql
+++ b/packaging/dbscripts/vms_sp.sql
@@ -448,12 +448,13 @@
     v_instance_type_id UUID,
     v_image_type_id UUID,
     v_original_template_id UUID,
-    v_original_template_name VARCHAR(255))
+    v_original_template_name VARCHAR(255),
+  v_template_version 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)
-       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);
+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, template_version)
+       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_template_version);
 -- 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));
@@ -572,7 +573,8 @@
 v_instance_type_id UUID,
 v_image_type_id UUID,
 v_original_template_id UUID,
-v_original_template_name VARCHAR(255))
+v_original_template_name VARCHAR(255),
+v_template_version INTEGER)
 
 RETURNS VOID
 
@@ -601,7 +603,7 @@
       is_delete_protected = v_is_delete_protected, sso_method = v_sso_method, 
host_cpu_flags = v_host_cpu_flags, tunnel_migration = v_tunnel_migration,
       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
+      original_template_name = v_original_template_name, template_version = 
v_template_version
       WHERE vm_guid = v_vm_guid
       AND   entity_type = 'VM';
 END; $procedure$


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I08f13eee5609525880a92fc81c9fd3cb1d2ba62d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
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