Alissa Bonas has uploaded a new change for review.

Change subject: restapi: add use_latest_template_version to vm restapi
......................................................................

restapi: add use_latest_template_version to vm restapi

Add the new optional parameter that is relevant for stateless vm creation.
It can be also passed when updating a vm.
By using it, users can select to always create stateless vm based on its
latest version of the used template.

Feature page
http://www.ovirt.org/Features/Template_Versions#REST_API

Change-Id: I38b569f7ef6df4d485dac15b804427c8248ab540
Signed-off-by: Alissa Bonas <[email protected]>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
M 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
4 files changed, 79 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/26/25026/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
index a849751..537d812 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
@@ -2648,6 +2648,7 @@
 
           <xs:element ref="reported_devices" minOccurs="0" maxOccurs="1"/>
           <xs:element ref="watchdogs" minOccurs="0" maxOccurs="1"/>
+          <xs:element name="use_latest_template_version" type="xs:boolean" 
minOccurs="0" maxOccurs="1"/>
         </xs:sequence>
       </xs:extension>
     </xs:complexContent>
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
index dd314bb..62d7b8f 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
@@ -89,6 +89,7 @@
           vm.tunnel_migration: xs:boolean
           vm.migration_downtime: xs:int
           vm.virtio_scsi.enabled: xs:boolean
+          vm.use_latest_template_version: xs:boolean
           vm.payloads.payload--COLLECTION: {payload.type: 'xs:string', 
payload.volume_id: 'xs:string', payload.files.file--COLLECTION: {file.name: 
'xs:string', file.content: 'xs:string'}}
           vm.cpu.cpu_tune.vcpu_pin--COLLECTION: {vcpu_pin.vcpu: 'xs:int', 
vcpu_pin.cpu_set: 'xs:string'}
         description: update the virtual machine in the system for the given 
virtual machine id with the values specified in the request
@@ -167,6 +168,7 @@
           vm.initialization.configuration.type: 'xs:string'
           vm.initialization.configuration.data: 'xs:string'
           vm.cpu.cpu_tune.vcpu_pin--COLLECTION: {vcpu_pin.vcpu: 'xs:int', 
vcpu_pin.cpu_set: 'xs:string'}
+          vm.use_latest_template_version: xs:boolean
         description: add a virtual machine to the system from scratch
       # the following signature is for clone VM from a Snapshot - requires the 
Snapshot ID
       - mandatoryArguments: {vm.name: 'xs:string', vm.template.id|name: 
'xs:string', vm.cluster.id|name: 'xs:string',
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
index c5087a1..0cbdc89 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmsResourceTest.java
@@ -609,7 +609,7 @@
     }
 
     @Test
-    public void testAdd() throws Exception {
+    public void testAddStatelessWithLatestTemplateVersion() throws Exception {
         setUriInfo(setUpBasicUriExpectations());
         setUpGetPayloadExpectations(1, 2);
         setUpGetBallooningExpectations(1, 2);
@@ -627,25 +627,72 @@
                                     new String[] { "Id" },
                                     new Object[] { GUIDS[2] },
                                     getVdsGroupEntity());
+
+        org.ovirt.engine.core.common.businessentities.VM vm = getEntity(2);
+        expect(vm.getVmtGuid()).andReturn(GUIDS[1]).anyTimes();
+        expect(vm.isStateless()).andReturn(true).anyTimes();
+        expect(vm.isUseLatestVersion()).andReturn(true).anyTimes();
+
         setUpCreationExpectations(VdcActionType.AddVm,
-                                  VmManagementParametersBase.class,
-                                  new String[] { "StorageDomainId" },
-                                  new Object[] { GUIDS[0] },
-                                  true,
-                                  true,
-                                  GUIDS[2],
-                                  VdcQueryType.GetVmByVmId,
-                                  IdQueryParameters.class,
-                                  new String[] { "Id" },
-                                  new Object[] { GUIDS[2] },
-                                  getEntity(2));
+                VmManagementParametersBase.class,
+                new String[]{"StorageDomainId"},
+                new Object[]{GUIDS[0]},
+                true,
+                true,
+                GUIDS[2],
+                VdcQueryType.GetVmByVmId,
+                IdQueryParameters.class,
+                new String[]{"Id"},
+                new Object[]{GUIDS[2]},
+                vm);
+
         Response response = collection.add(createModel(null));
         assertEquals(201, response.getStatus());
         assertTrue(response.getEntity() instanceof VM);
-        verifyModel((VM) response.getEntity(), 2);
+        VM returnValueVM = (VM) response.getEntity();
+        verifyModel(returnValueVM, 2);
+        assertTrue(returnValueVM.isStateless());
+        assertTrue(returnValueVM.isUseLatestTemplateVersion());
     }
 
     @Test
+        public void testAdd() throws Exception {
+            setUriInfo(setUpBasicUriExpectations());
+            setUpGetPayloadExpectations(1, 2);
+            setUpGetBallooningExpectations(1, 2);
+            setUpGetCertuficateExpectations(1, 2);
+            setUpGetConsoleExpectations(new int[]{1, 2});
+            setUpGetVirtioScsiExpectations(new int[]{2});
+            setUpGetVmOvfExpectations(new int[]{2});
+            setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate,
+                                         GetVmTemplateParameters.class,
+                                         new String[] { "Id" },
+                                         new Object[] { GUIDS[1] },
+                                         getTemplateEntity(0));
+            setUpEntityQueryExpectations(VdcQueryType.GetVdsGroupByVdsGroupId,
+                                        IdQueryParameters.class,
+                                        new String[] { "Id" },
+                                        new Object[] { GUIDS[2] },
+                                        getVdsGroupEntity());
+            setUpCreationExpectations(VdcActionType.AddVm,
+                                      VmManagementParametersBase.class,
+                                      new String[] { "StorageDomainId" },
+                                      new Object[] { GUIDS[0] },
+                                      true,
+                                      true,
+                                      GUIDS[2],
+                                      VdcQueryType.GetVmByVmId,
+                                      IdQueryParameters.class,
+                                      new String[] { "Id" },
+                                      new Object[] { GUIDS[2] },
+                                      getEntity(2));
+            Response response = collection.add(createModel(null));
+            assertEquals(201, response.getStatus());
+            assertTrue(response.getEntity() instanceof VM);
+            verifyModel((VM) response.getEntity(), 2);
+        }
+
+    @Test
     public void testAddFromConfiguration() throws Exception {
         setUriInfo(setUpBasicUriExpectations());
         setUpGetPayloadExpectations(1, 2);
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
index 1092148..8a16c89 100644
--- 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/VmMapper.java
@@ -145,8 +145,17 @@
           //TODO: Get rid of this logic code when Backend supports default 
memory.
             staticVm.setMemSizeMb(DEFAULT_MEMORY_SIZE);
         }
-        if (vm.isSetTemplate() && vm.getTemplate().getId() != null) {
-            staticVm.setVmtGuid(GuidUtils.asGuid(vm.getTemplate().getId()));
+        if (vm.isSetTemplate()) {
+            if (vm.getTemplate().getId() != null) {
+                
staticVm.setVmtGuid(GuidUtils.asGuid(vm.getTemplate().getId()));
+            }
+            // There is no need to pass this property to backend if
+            // no template was specified.
+            // If user passes this property for a stateful vm which is not 
supported,
+            // it will be handled by the backend.
+            if (vm.isSetUseLatestTemplateVersion()) {
+                staticVm.setUseLatestVersion(vm.isUseLatestTemplateVersion());
+            }
         }
         if (vm.isSetCluster() && vm.getCluster().getId() != null) {
             staticVm.setVdsGroupId(GuidUtils.asGuid(vm.getCluster().getId()));
@@ -346,6 +355,11 @@
         if (entity.getVmtGuid() != null) {
             model.setTemplate(new Template());
             model.getTemplate().setId(entity.getVmtGuid().toString());
+            // display this property only if the vm is stateless
+            // otherwise the value of this property is meaningless and 
misleading
+            if(entity.isStateless()) {
+                model.setUseLatestTemplateVersion(entity.isUseLatestVersion());
+            }
         }
         if (entity.getStatus() != null) {
             model.setStatus(StatusUtils.create(map(entity.getStatus(), null)));


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I38b569f7ef6df4d485dac15b804427c8248ab540
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.4
Gerrit-Owner: Alissa Bonas <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to