Alissa Bonas has uploaded a new change for review. Change subject: restapi: add use_latest_template_version to vm creation ......................................................................
restapi: add use_latest_template_version to vm creation Add the new optional parameter that is relevant for stateless vm creation. 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, 74 insertions(+), 13 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/60/23560/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 86809df..16c2fad 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 @@ -2641,6 +2641,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 b1e68d1..217a806 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 @@ -87,6 +87,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 @@ -165,6 +166,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 9b4602d..649148e 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 @@ -601,7 +601,7 @@ } @Test - public void testAdd() throws Exception { + public void testAddStatelessWithLatestTemplateVersion() throws Exception { setUriInfo(setUpBasicUriExpectations()); setUpGetPayloadExpectations(1, 2); setUpGetBallooningExpectations(1, 2); @@ -618,25 +618,71 @@ 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}); + 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 67bbd74..42ca9ea 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 @@ -147,6 +147,13 @@ } if (vm.isSetTemplate() && 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())); @@ -335,6 +342,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/23560 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I38b569f7ef6df4d485dac15b804427c8248ab540 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alissa Bonas <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
