Tomas Jelinek has uploaded a new change for review. Change subject: restapi: copy instance type fields to the VM ......................................................................
restapi: copy instance type fields to the VM As a sonsequence of the https://bugzilla.redhat.com/1149663 the instance type fields are not copyed to the VM on server anymore and the frontends (WA/UP/REST) need to take care of it. More specifically it works like this: If only the instance type is selected, it has to copy it's properties to the newly created VM (on VM level this can be overridden) If both the template and the instance type is selected, the instance type overrides the template. When copying the parameters from instance type to the VM, only the ones which are supported on the target cluster/OS are taken into account. Change-Id: Id8ff7a39fe74c73d8984fb34169b69649dab7c15 Bug-Url: https://bugzilla.redhat.com/1149663 Signed-off-by: Tomas Jelinek <tjeli...@redhat.com> --- M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/util/VmHelper.java 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, 220 insertions(+), 123 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/27/35427/1 diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java index 87cb57a..cfcbaa8 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java @@ -35,10 +35,12 @@ import org.ovirt.engine.api.resource.VmResource; import org.ovirt.engine.api.resource.VmsResource; import org.ovirt.engine.api.restapi.types.DiskMapper; +import org.ovirt.engine.api.restapi.types.Mapper; import org.ovirt.engine.api.restapi.types.RngDeviceMapper; import org.ovirt.engine.api.restapi.types.VmMapper; import org.ovirt.engine.api.restapi.util.VmHelper; import org.ovirt.engine.core.common.action.AddVmFromScratchParameters; +import org.ovirt.engine.core.common.FeatureSupported; import org.ovirt.engine.core.common.action.AddVmFromSnapshotParameters; import org.ovirt.engine.core.common.action.AddVmFromTemplateParameters; import org.ovirt.engine.core.common.action.ImportVmParameters; @@ -47,6 +49,7 @@ import org.ovirt.engine.core.common.action.VmManagementParametersBase; import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.Entities; +import org.ovirt.engine.core.common.businessentities.InstanceType; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VdsStatic; import org.ovirt.engine.core.common.businessentities.VmDevice; @@ -67,6 +70,7 @@ import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; import org.ovirt.engine.core.compat.Guid; public class BackendVmsResource extends @@ -109,8 +113,20 @@ } else { validateParameters(vm, "template.id|name"); Guid templateId = getTemplateId(vm.getTemplate()); - VmStatic staticVm = getMapper(VM.class, VmStatic.class).map(vm, - getMapper(VmTemplate.class, VmStatic.class).map(lookupTemplate(templateId), null)); + + VmTemplate templateEntity = lookupTemplate(templateId); + VmStatic builtFromTemplate = getMapper(VmTemplate.class, VmStatic.class).map(templateEntity, null); + + VmStatic builtFromInstanceType = null; + org.ovirt.engine.core.common.businessentities.InstanceType instanceTypeEntity = null; + if (vm.isSetInstanceType() && (vm.getInstanceType().isSetId() || vm.getInstanceType().isSetName())) { + Mapper<org.ovirt.engine.core.common.businessentities.InstanceType, VmStatic> instanceTypeMapper = getMapper(org.ovirt.engine.core.common.businessentities.InstanceType.class, VmStatic.class); + instanceTypeEntity = lookupInstanceType(getTemplateId(vm.getInstanceType())); + builtFromInstanceType = instanceTypeMapper.map(instanceTypeEntity, builtFromTemplate); + builtFromInstanceType.setInstanceTypeId(getTemplateId(vm.getInstanceType())); + } + + VmStatic staticVm = getMapper(VM.class, VmStatic.class).map(vm, builtFromInstanceType != null ? builtFromInstanceType : builtFromTemplate); if (namedCluster(vm)) { staticVm.setVdsGroupId(getClusterId(vm)); } @@ -152,16 +168,12 @@ .getId()) : Guid.Empty; - if (vm.isSetInstanceType() && (vm.getInstanceType().isSetId() || vm.getInstanceType().isSetName())) { - staticVm.setInstanceTypeId(getTemplateId(vm.getInstanceType())); - } - if (vm.isSetDisks() && vm.getDisks().isSetClone() && vm.getDisks().isClone()) { - response = cloneVmFromTemplate(staticVm, vm, templateId); + response = cloneVmFromTemplate(staticVm, vm, templateEntity, instanceTypeEntity, cluster); } else if (Guid.Empty.equals(templateId)) { - response = addVmFromScratch(staticVm, vm, storageDomainId); + response = addVmFromScratch(staticVm, vm, storageDomainId, instanceTypeEntity, cluster); } else { - response = addVm(staticVm, vm, storageDomainId, templateId); + response = addVm(staticVm, vm, storageDomainId, templateEntity, instanceTypeEntity, cluster); } } } @@ -193,9 +205,9 @@ prepareImagesForCloneFromSnapshotParams(vm.getDisks(), diskImagesByImageId); } return cloneVmFromSnapshot(vmConfiguration, - vm, - snapshotId, - diskImagesByImageId); + vm, + snapshotId, + diskImagesByImageId); } private Response removeRestrictedInfoFromResponse(Response response) { @@ -318,34 +330,87 @@ new QueryIdResolver<Guid>(VdcQueryType.GetVmByVmId, IdQueryParameters.class)); } - private Response cloneVmFromTemplate(VmStatic staticVm, VM vm, Guid templateId) { - AddVmFromTemplateParameters params = new AddVmFromTemplateParameters(staticVm, getDisksToClone(vm.getDisks(), templateId), Guid.Empty); + private Response cloneVmFromTemplate(VmStatic staticVm, VM vm, VmTemplate template, InstanceType instanceType, VDSGroup cluster) { + AddVmFromTemplateParameters params = new AddVmFromTemplateParameters(staticVm, getDisksToClone(vm.getDisks(), template.getId()), Guid.Empty); params.setVmPayload(getPayload(vm)); - params.setVirtioScsiEnabled(vm.isSetVirtioScsi() && vm.getVirtioScsi().isSetEnabled() ? - vm.getVirtioScsi().isEnabled() : null); - if(vm.isSetSoundcardEnabled()) { - params.setSoundDeviceEnabled(vm.isSoundcardEnabled()); - } else { - params.setSoundDeviceEnabled(!VmHelper.getInstance().getSoundDevicesForEntity(templateId).isEmpty()); - } - params.setBalloonEnabled(vm.isSetMemoryPolicy() && vm.getMemoryPolicy().isSetBallooning() ? - vm.getMemoryPolicy().isBallooning() : null); - - params.setConsoleEnabled(vm.isSetConsole() && vm.getConsole().isSetEnabled() - ? vm.getConsole().isEnabled() - : !getConsoleDevicesForEntity(templateId).isEmpty()); - - if (vm.isSetRngDevice()) { - params.setUpdateRngDevice(true); - params.setRngDevice(RngDeviceMapper.map(vm.getRngDevice(), null)); - } + addDevicesToParams(params, vm, template, instanceType, staticVm.getOsId(), cluster); params.setMakeCreatorExplicitOwner(shouldMakeCreatorExplicitOwner()); setupCloneTemplatePermissions(vm, params); return performCreate(VdcActionType.AddVmFromTemplate, - params, - new QueryIdResolver<Guid>(VdcQueryType.GetVmByVmId, IdQueryParameters.class)); + params, + new QueryIdResolver<Guid>(VdcQueryType.GetVmByVmId, IdQueryParameters.class)); + } + + private void addDevicesToParams(VmManagementParametersBase params, VM vm, VmTemplate template, InstanceType instanceType, int osId, VDSGroup cluster) { + Guid templateId = template != null ? template.getId() : null; + Guid instanceTypeId = instanceType != null ? instanceType.getId() : null; + + if (vm.isSetVirtioScsi()) { + params.setVirtioScsiEnabled(vm.getVirtioScsi().isEnabled()); + } else { + // it is not defined on the template + params.setVirtioScsiEnabled(instanceTypeId != null ? !VmHelper.getInstance().getVirtioScsiControllersForEntity(instanceTypeId).isEmpty() : null); + } + + if(vm.isSetSoundcardEnabled()) { + params.setSoundDeviceEnabled(vm.isSoundcardEnabled()); + } else if (instanceTypeId != null || templateId != null) { + params.setSoundDeviceEnabled(!VmHelper.getInstance().getSoundDevicesForEntity(instanceTypeId != null ? instanceTypeId : templateId).isEmpty()); + } + + if (vm.isSetMemoryPolicy()) { + params.setBalloonEnabled(vm.getMemoryPolicy().isBallooning()); + } else if (shouldCopyDevice(SimpleDependecyInjector.getInstance().get(OsRepository.class).isBalloonEnabled(osId, cluster.getcompatibility_version()), templateId, instanceTypeId)) { + // it is not defined on the template + params.setBalloonEnabled(instanceTypeId != null ? !VmHelper.getInstance().isMemoryBalloonEnabledForEntity(instanceTypeId) : null); + } + + if (vm.isSetConsole()) { + params.setConsoleEnabled(vm.getConsole().isEnabled()); + } else if (instanceTypeId != null || templateId != null) { + params.setConsoleEnabled(instanceTypeId != null ? !getConsoleDevicesForEntity(instanceTypeId).isEmpty() : null); + } + + if (vm.isSetRngDevice()) { + params.setUpdateRngDevice(true); + params.setRngDevice(RngDeviceMapper.map(vm.getRngDevice(), null)); + } else if (instanceTypeId != null || templateId != null) { + List<VmRngDevice> devices = VmHelper.getInstance().getRngDevicesForEntity(instanceTypeId != null ? instanceTypeId : templateId); + if (devices != null && !devices.isEmpty()) { + boolean supported = cluster.getRequiredRngSources().contains(devices.get(0).getSource()) && FeatureSupported.virtIoRngSupported(cluster.getcompatibility_version()); + if (shouldCopyDevice(supported, templateId, instanceTypeId)) { + params.setUpdateRngDevice(true); + params.setRngDevice(!devices.isEmpty() ? devices.iterator().next() : null); + } + } + } + } + + /** + * Returns true if the device should be copied from the template or instance type + * If the instance type is selected, than the device will be copied from the instance type only if the device is compatible with the cluster and os + * If the instance type is not set and the template is set, than it is copied from the template (e.g. the cluster compatibility is not checked since the template lives in a cluster) + */ + private boolean shouldCopyDevice(boolean isCompatibleWithCluster, Guid templateId, Guid instanceTypeId) { + if (instanceTypeId == null && templateId == null) { + // nothing to copy from + return false; + } + + if (instanceTypeId == null && templateId != null) { + // template is set and is not overridden by instance type, copy device config + return true; + } + + if (instanceTypeId != null && isCompatibleWithCluster) { + // copy from instance type and the device is compatible with cluster, copy + return true; + } + + // not compatible with the cluster, do not copy from instance type + return false; } private HashMap<Guid, DiskImage> getDisksToClone(Disks disks, Guid templateId) { @@ -381,33 +446,14 @@ return (DiskImage)getMapper(Disk.class, org.ovirt.engine.core.common.businessentities.Disk.class).map(entity, template); } - protected Response addVm(VmStatic staticVm, VM vm, Guid storageDomainId, Guid templateId) { + protected Response addVm(VmStatic staticVm, VM vm, Guid storageDomainId, VmTemplate template, InstanceType instanceType, VDSGroup cluster) { VmManagementParametersBase params = new VmManagementParametersBase(staticVm); params.setVmPayload(getPayload(vm)); - if (vm.isSetMemoryPolicy() && vm.getMemoryPolicy().isSetBallooning()) { - params.setBalloonEnabled(vm.getMemoryPolicy().isBallooning()); - } params.setStorageDomainId(storageDomainId); - params.setDiskInfoDestinationMap(getDisksToClone(vm.getDisks(), templateId)); + params.setDiskInfoDestinationMap(getDisksToClone(vm.getDisks(), template.getId())); params.setMakeCreatorExplicitOwner(shouldMakeCreatorExplicitOwner()); setupCloneTemplatePermissions(vm, params); - - params.setConsoleEnabled(vm.isSetConsole() && vm.getConsole().isSetEnabled() - ? vm.getConsole().isEnabled() - : !getConsoleDevicesForEntity(templateId).isEmpty()); - - params.setVirtioScsiEnabled(vm.isSetVirtioScsi() && vm.getVirtioScsi().isSetEnabled() ? - vm.getVirtioScsi().isEnabled() : null); - if(vm.isSetSoundcardEnabled()) { - params.setSoundDeviceEnabled(vm.isSoundcardEnabled()); - } else { - params.setSoundDeviceEnabled(!VmHelper.getInstance().getSoundDevicesForEntity(templateId).isEmpty()); - } - - if (vm.isSetRngDevice()) { - params.setUpdateRngDevice(true); - params.setRngDevice(RngDeviceMapper.map(vm.getRngDevice(), null)); - } + addDevicesToParams(params, vm, template, instanceType, staticVm.getOsId(), cluster); return performCreate(VdcActionType.AddVm, params, @@ -420,28 +466,12 @@ } } - protected Response addVmFromScratch(VmStatic staticVm, VM vm, Guid storageDomainId) { + protected Response addVmFromScratch(VmStatic staticVm, VM vm, Guid storageDomainId, InstanceType instanceType, VDSGroup cluster) { AddVmFromScratchParameters params = new AddVmFromScratchParameters(staticVm, mapDisks(vm.getDisks()), Guid.Empty); params.setVmPayload(getPayload(vm)); - if (vm.isSetMemoryPolicy() && vm.getMemoryPolicy().isSetBallooning()) { - params.setBalloonEnabled(vm.getMemoryPolicy().isBallooning()); - } params.setMakeCreatorExplicitOwner(shouldMakeCreatorExplicitOwner()); params.setStorageDomainId(storageDomainId); - params.setVirtioScsiEnabled(vm.isSetVirtioScsi() && vm.getVirtioScsi().isSetEnabled() ? - vm.getVirtioScsi().isEnabled() : null); - if(vm.isSetSoundcardEnabled()) { - params.setSoundDeviceEnabled(vm.isSoundcardEnabled()); - } - - if (vm.isSetConsole() && vm.getConsole().isSetEnabled()) { - params.setConsoleEnabled(vm.getConsole().isEnabled()); - } - - if (vm.isSetRngDevice()) { - params.setUpdateRngDevice(true); - params.setRngDevice(RngDeviceMapper.map(vm.getRngDevice(), null)); - } + addDevicesToParams(params, vm, null, instanceType, staticVm.getOsId(), cluster); return performCreate(VdcActionType.AddVmFromScratch, params, @@ -591,6 +621,10 @@ return getEntity(VmTemplate.class, VdcQueryType.GetVmTemplate, new GetVmTemplateParameters(id), "GetVmTemplate"); } + public org.ovirt.engine.core.common.businessentities.InstanceType lookupInstanceType(Guid id) { + return getEntity(org.ovirt.engine.core.common.businessentities.InstanceType.class, VdcQueryType.GetVmTemplate, new GetVmTemplateParameters(id), "GetVmTemplate"); + } + private VDSGroup lookupCluster(Guid id) { return getEntity(VDSGroup.class, VdcQueryType.GetVdsGroupByVdsGroupId, new IdQueryParameters(id), "GetVdsGroupByVdsGroupId"); } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/util/VmHelper.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/util/VmHelper.java index 1f3242a..8c66041 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/util/VmHelper.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/util/VmHelper.java @@ -1,5 +1,6 @@ package org.ovirt.engine.api.restapi.util; +import org.ovirt.engine.core.common.businessentities.VmRngDevice; import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.compat.Guid; @@ -31,4 +32,18 @@ new IdQueryParameters(id), "GetSoundDevices", true); } + + public Boolean isMemoryBalloonEnabledForEntity(Guid id) { + return getEntity(Boolean.class, + VdcQueryType.IsBalloonEnabled, + new IdQueryParameters(id), + "IsBalloonEnabled", true); + } + + public List<VmRngDevice> getRngDevicesForEntity(Guid id) { + return getEntity(List.class, + VdcQueryType.GetRngDevice, + new IdQueryParameters(id), + "GetRngDevice", true); + } } 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 d69590c..1de1739 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 @@ -1,5 +1,7 @@ package org.ovirt.engine.api.restapi.resource; +import static org.easymock.EasyMock.anyInt; +import static org.easymock.EasyMock.anyObject; import static org.easymock.EasyMock.expect; import java.util.ArrayList; @@ -53,6 +55,7 @@ import org.ovirt.engine.core.common.businessentities.VmStatistics; import org.ovirt.engine.core.common.businessentities.VmType; import org.ovirt.engine.core.common.interfaces.SearchType; +import org.ovirt.engine.core.common.osinfo.OsRepository; import org.ovirt.engine.core.common.queries.GetVmFromConfigurationQueryParameters; import org.ovirt.engine.core.common.queries.GetVmOvfByVmIdParameters; import org.ovirt.engine.core.common.queries.GetVmTemplateParameters; @@ -60,8 +63,10 @@ import org.ovirt.engine.core.common.queries.IdsQueryParameters; import org.ovirt.engine.core.common.queries.NameQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; import org.ovirt.engine.core.common.utils.VmDeviceType; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.compat.Version; public class BackendVmsResourceTest extends AbstractBackendCollectionResourceTest<VM, org.ovirt.engine.core.common.businessentities.VM, BackendVmsResource> { @@ -70,7 +75,10 @@ private static final String PAYLOAD_COMTENT = "payload"; public static final String CERTIFICATE = "O=Redhat,CN=X.Y.Z.Q"; + protected VmHelper vmHelper = VmHelper.getInstance(); + + private OsRepository osRepository; public BackendVmsResourceTest() { super(new BackendVmsResource(), SearchType.VM, "VMs : "); @@ -80,7 +88,11 @@ public void init() { super.init(); OsTypeMockUtils.mockOsTypes(); + initBackendResource(vmHelper); + + osRepository = control.createMock(OsRepository.class); + SimpleDependecyInjector.getInstance().bind(OsRepository.class, osRepository); } @Test @@ -120,6 +132,7 @@ @Test public void testRemove() throws Exception { setUriInfo(setUpBasicUriExpectations()); + mockUniqueOsNames(); setUpGetEntityExpectations(); setUpGetPayloadExpectations(1, 0); setUpGetBallooningExpectations(1); @@ -131,6 +144,7 @@ @Test public void testRemoveForced() throws Exception { setUriInfo(setUpBasicUriExpectations()); + mockUniqueOsNames(); setUpGetEntityExpectations(); setUpGetPayloadExpectations(1, 0); setUpGetBallooningExpectations(1); @@ -141,6 +155,7 @@ @Test public void testRemoveDetachOnly() throws Exception { + mockUniqueOsNames(); setUriInfo(setUpBasicUriExpectations()); setUpGetEntityExpectations(); setUpGetPayloadExpectations(1, 0); @@ -155,9 +170,16 @@ verifyRemove(collection.remove(GUIDS[0].toString(), action)); } + private void mockUniqueOsNames() { + HashMap<Integer, String> uniqueOsNames = new HashMap<>(); + expect(osRepository.getUniqueOsNames()).andReturn(uniqueOsNames); + uniqueOsNames.put(0, "Fedora20"); + } + @Test public void testRemoveForcedIncomplete() throws Exception { setUriInfo(setUpBasicUriExpectations()); + mockUniqueOsNames(); setUpGetEntityExpectations(); setUpGetPayloadExpectations(1, 0); setUpGetBallooningExpectations(1); @@ -204,6 +226,7 @@ protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { setUpGetEntityExpectations(); + mockUniqueOsNames(); setUpGetPayloadExpectations(1, 0); setUpGetBallooningExpectations(1); setUriInfo(setUpActionExpectations(VdcActionType.RemoveVm, @@ -475,10 +498,14 @@ new String[] { "Id" }, new Object[] { GUIDS[0] }, getTemplateEntity(0)); + + + expect(osRepository.isBalloonEnabled(anyInt(), anyObject(Version.class))).andReturn(false).anyTimes(); + setUpEntityQueryExpectations(VdcQueryType.GetVdsGroupByVdsGroupId, IdQueryParameters.class, - new String[] { "Id" }, - new Object[] { GUIDS[1] }, + new String[]{"Id"}, + new Object[]{GUIDS[1]}, getVdsGroupEntity()); setUriInfo(setUpActionExpectations(VdcActionType.AddVmFromScratch, AddVmFromScratchParameters.class, @@ -503,15 +530,15 @@ @Test public void testCloneWithDisk() throws Exception { setUriInfo(setUpBasicUriExpectations()); - setUpTemplateDisksExpectations(GUIDS[1]); + setUpTemplateDisksExpectations(GUIDS[0]); setUriInfo(setUpBasicUriExpectations()); setUpGetPayloadExpectations(1, 2); setUpGetBallooningExpectations(1, 2); - setUpGetConsoleExpectations(new int[]{1, 2}); + setUpGetConsoleExpectations(new int[]{2}); setUpGetVmOvfExpectations(new int[]{2}); setUpGetVirtioScsiExpectations(new int[]{2}); - setUpGetSoundcardExpectations(new int[]{2, 1}); - setUpGetRngDeviceExpectations(new int[]{2}); + setUpGetSoundcardExpectations(new int[]{0, 2}); + setUpGetRngDeviceExpectations(new int[]{0, 2}); setUpGetCertuficateExpectations(1, 2); setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate, GetVmTemplateParameters.class, @@ -595,11 +622,19 @@ setUriInfo(setUpBasicUriExpectations()); setUpGetPayloadExpectations(1, 2); setUpGetBallooningExpectations(1, 2); - setUpGetConsoleExpectations(new int[]{1, 2}); - setUpGetVmOvfExpectations(new int[]{2}); - setUpGetVirtioScsiExpectations(new int[]{2}); - setUpGetRngDeviceExpectations(new int[]{2}); - setUpGetSoundcardExpectations(new int[]{2, 1}); + +// setUpGetConsoleExpectations(new int[]{1, 2}); +// setUpGetVmOvfExpectations(new int[]{2}); +// setUpGetVirtioScsiExpectations(new int[]{2}); +// setUpGetRngDeviceExpectations(new int[]{2}); +// setUpGetSoundcardExpectations(new int[]{2, 1}); + + setUpGetConsoleExpectations(2); + setUpGetVmOvfExpectations(2); + setUpGetVirtioScsiExpectations(2); + setUpGetSoundcardExpectations(0, 2); + setUpGetRngDeviceExpectations(0, 2); + setUpGetCertuficateExpectations(1, 2); setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate, GetVmTemplateParameters.class, @@ -636,11 +671,11 @@ setUpGetPayloadExpectations(1, 2); setUpGetBallooningExpectations(1, 2); setUpGetCertuficateExpectations(1, 2); - setUpGetConsoleExpectations(new int[]{1, 2}); + setUpGetConsoleExpectations(new int[]{2}); setUpGetVmOvfExpectations(new int[]{2}); setUpGetVirtioScsiExpectations(new int[]{2}); - setUpGetSoundcardExpectations(new int[]{2, 1}); - setUpGetRngDeviceExpectations(new int[]{2}); + setUpGetSoundcardExpectations(new int[]{0, 2}); + setUpGetRngDeviceExpectations(new int[]{2, 0}); setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, @@ -685,10 +720,10 @@ setUpGetPayloadExpectations(1, 2); setUpGetBallooningExpectations(1, 2); setUpGetCertuficateExpectations(1, 2); - setUpGetConsoleExpectations(new int[] { 1, 2 }); + setUpGetConsoleExpectations(new int[] { 2 }); setUpGetVirtioScsiExpectations(new int[] { 2 }); - setUpGetSoundcardExpectations(new int[] { 2, 1 }); - setUpGetRngDeviceExpectations(new int[]{2}); + setUpGetSoundcardExpectations(new int[] {0, 2}); + setUpGetRngDeviceExpectations(new int[]{0, 2}); setUpGetVmOvfExpectations(new int[] { 2 }); setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate, GetVmTemplateParameters.class, @@ -908,11 +943,11 @@ setUriInfo(setUpBasicUriExpectations()); setUpGetPayloadExpectations(1, 2); setUpGetBallooningExpectations(1, 2); - setUpGetConsoleExpectations(new int[]{1, 2}); + setUpGetConsoleExpectations(new int[]{2}); setUpGetVmOvfExpectations(new int[]{2}); setUpGetVirtioScsiExpectations(new int[]{2}); - setUpGetSoundcardExpectations(new int[]{2, 1}); - setUpGetRngDeviceExpectations(new int[]{2}); + setUpGetSoundcardExpectations(new int[]{0, 2}); + setUpGetRngDeviceExpectations(new int[]{0, 2}); setUpGetCertuficateExpectations(1, 2); setUpEntityQueryExpectations(VdcQueryType.GetVdsStaticByName, NameQueryParameters.class, @@ -964,11 +999,11 @@ setUriInfo(setUpBasicUriExpectations()); setUpGetPayloadExpectations(1, 2); setUpGetBallooningExpectations(1, 2); - setUpGetConsoleExpectations(new int[]{1, 2}); + setUpGetConsoleExpectations(new int[]{2}); setUpGetVmOvfExpectations(new int[]{2}); setUpGetVirtioScsiExpectations(new int[]{2}); - setUpGetSoundcardExpectations(new int[]{2, 1}); - setUpGetRngDeviceExpectations(new int[]{2}); + setUpGetSoundcardExpectations(new int[]{0, 2}); + setUpGetRngDeviceExpectations(new int[]{0, 2}); setUpGetCertuficateExpectations(1, 2); setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate, GetVmTemplateParameters.class, @@ -1007,11 +1042,11 @@ setUriInfo(setUpBasicUriExpectations()); setUpGetPayloadExpectations(1, 2); setUpGetBallooningExpectations(1, 2); - setUpGetConsoleExpectations(new int[]{1, 2}); + setUpGetConsoleExpectations(new int[]{2}); setUpGetVmOvfExpectations(new int[]{2}); setUpGetVirtioScsiExpectations(new int[]{2}); - setUpGetSoundcardExpectations(new int[]{2, 1}); - setUpGetRngDeviceExpectations(new int[]{2}); + setUpGetSoundcardExpectations(new int[]{0, 2}); + setUpGetRngDeviceExpectations(new int[]{0, 2}); setUpGetCertuficateExpectations(1, 2); setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate, GetVmTemplateParameters.class, @@ -1073,11 +1108,11 @@ setUpGetPayloadExpectations(1, 2); setUpGetBallooningExpectations(1, 2); setUpGetCertuficateExpectations(1, 2); - setUpGetConsoleExpectations(new int[]{1, 2}); + setUpGetConsoleExpectations(new int[]{2}); setUpGetVmOvfExpectations(new int[]{2}); setUpGetVirtioScsiExpectations(new int[]{2}); - setUpGetSoundcardExpectations(new int[]{2, 1}); - setUpGetRngDeviceExpectations(new int[]{2}); + setUpGetSoundcardExpectations(new int[]{0, 2}); + setUpGetRngDeviceExpectations(new int[]{0, 2}); setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, @@ -1121,17 +1156,17 @@ private void doTestCloneFromTemplateWithClonePermissions(VM model, boolean copy) throws Exception { setUriInfo(setUpBasicUriExpectations()); - setUpTemplateDisksExpectations(GUIDS[1]); + setUpTemplateDisksExpectations(GUIDS[0]); setUriInfo(setUpBasicUriExpectations()); setUpGetPayloadExpectations(1, 2); setUpGetBallooningExpectations(1, 2); setUpGetCertuficateExpectations(1, 2); - setUpGetConsoleExpectations(new int[]{1, 2}); + setUpGetConsoleExpectations(new int[]{2}); setUpGetVmOvfExpectations(new int[]{2}); setUpGetVirtioScsiExpectations(new int[]{2}); - setUpGetSoundcardExpectations(new int[]{2, 1}); - setUpGetRngDeviceExpectations(new int[]{2}); + setUpGetSoundcardExpectations(new int[]{0, 2}); + setUpGetRngDeviceExpectations(new int[]{0, 2}); setUpEntityQueryExpectations(VdcQueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[]{"Id"}, @@ -1276,8 +1311,9 @@ new String[] { "Id" }, new Object[] { GUIDS[1] }, getTemplateEntity(0)); - setUpGetConsoleExpectations(new int[]{1}); - setUpGetSoundcardExpectations(new int[]{1}); + setUpGetSoundcardExpectations(new int[]{0}); + setUpGetRngDeviceExpectations(new int[]{0}); + setUpEntityQueryExpectations(VdcQueryType.GetVdsGroupByVdsGroupId, IdQueryParameters.class, new String[] { "Id" }, 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 92bdb51..37c70af 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 @@ -71,6 +71,7 @@ import org.ovirt.engine.core.common.businessentities.OriginType; import org.ovirt.engine.core.common.businessentities.UsbPolicy; import org.ovirt.engine.core.common.businessentities.VMStatus; +import org.ovirt.engine.core.common.businessentities.VmBase; import org.ovirt.engine.core.common.businessentities.VmInit; import org.ovirt.engine.core.common.businessentities.VmInitNetwork; import org.ovirt.engine.core.common.businessentities.VmPayload; @@ -95,44 +96,55 @@ @Mapping(from = VmTemplate.class, to = VmStatic.class) public static VmStatic map(VmTemplate entity, VmStatic template) { VmStatic staticVm = template != null ? template : new VmStatic(); + staticVm.setId(Guid.Empty); staticVm.setVmtGuid(entity.getId()); staticVm.setVdsGroupId(entity.getVdsGroupId()); - staticVm.setMemSizeMb(entity.getMemSizeMb()); staticVm.setOsId(entity.getOsId()); staticVm.setNiceLevel(entity.getNiceLevel()); staticVm.setCpuShares(entity.getCpuShares()); staticVm.setFailBack(entity.isFailBack()); - staticVm.setAutoStartup(entity.isAutoStartup()); staticVm.setStateless(entity.isStateless()); staticVm.setDeleteProtected(entity.isDeleteProtected()); staticVm.setSsoMethod(entity.getSsoMethod()); - staticVm.setSmartcardEnabled(entity.isSmartcardEnabled()); - staticVm.setAutoStartup(entity.isAutoStartup()); - staticVm.setDefaultBootSequence(entity.getDefaultBootSequence()); staticVm.setVmType(entity.getVmType()); - staticVm.setDefaultDisplayType(entity.getDefaultDisplayType()); staticVm.setIsoPath(entity.getIsoPath()); - staticVm.setNumOfSockets(entity.getNumOfSockets()); - staticVm.setCpuPerSocket(entity.getCpuPerSocket()); staticVm.setKernelUrl(entity.getKernelUrl()); staticVm.setKernelParams(entity.getKernelParams()); staticVm.setInitrdUrl(entity.getInitrdUrl()); staticVm.setTimeZone(entity.getTimeZone()); - staticVm.setNumOfMonitors(entity.getNumOfMonitors()); - staticVm.setSingleQxlPci(entity.getSingleQxlPci()); staticVm.setAllowConsoleReconnect(entity.isAllowConsoleReconnect()); - staticVm.setPriority(entity.getPriority()); - staticVm.setUsbPolicy(entity.getUsbPolicy()); - staticVm.setTunnelMigration(entity.getTunnelMigration()); staticVm.setVncKeyboardLayout(entity.getVncKeyboardLayout()); - staticVm.setMigrationDowntime(entity.getMigrationDowntime()); staticVm.setVmInit(entity.getVmInit()); staticVm.setSerialNumberPolicy(entity.getSerialNumberPolicy()); staticVm.setCustomSerialNumber(entity.getCustomSerialNumber()); staticVm.setSpiceFileTransferEnabled(entity.isSpiceFileTransferEnabled()); staticVm.setSpiceCopyPasteEnabled(entity.isSpiceCopyPasteEnabled()); staticVm.setCpuProfileId(entity.getCpuProfileId()); + return doMapVmBaseHwPartToVmStatic(entity, staticVm); + } + + @Mapping(from = org.ovirt.engine.core.common.businessentities.InstanceType.class, to = VmStatic.class) + public static VmStatic map(org.ovirt.engine.core.common.businessentities.InstanceType entity, VmStatic vmStatic) { + return doMapVmBaseHwPartToVmStatic((VmBase) entity, vmStatic != null ? vmStatic : new VmStatic()); + } + + private static VmStatic doMapVmBaseHwPartToVmStatic(VmBase entity, VmStatic staticVm) { + staticVm.setMemSizeMb(entity.getMemSizeMb()); + staticVm.setAutoStartup(entity.isAutoStartup()); + staticVm.setSmartcardEnabled(entity.isSmartcardEnabled()); + staticVm.setDefaultBootSequence(entity.getDefaultBootSequence()); + staticVm.setDefaultDisplayType(entity.getDefaultDisplayType()); + staticVm.setNumOfSockets(entity.getNumOfSockets()); + staticVm.setCpuPerSocket(entity.getCpuPerSocket()); + staticVm.setNumOfMonitors(entity.getNumOfMonitors()); + staticVm.setSingleQxlPci(entity.getSingleQxlPci()); + staticVm.setPriority(entity.getPriority()); + staticVm.setUsbPolicy(entity.getUsbPolicy()); + staticVm.setTunnelMigration(entity.getTunnelMigration()); + staticVm.setMigrationSupport(entity.getMigrationSupport()); + staticVm.setMigrationDowntime(entity.getMigrationDowntime()); + staticVm.setMinAllocatedMem(entity.getMinAllocatedMem()); return staticVm; } -- To view, visit http://gerrit.ovirt.org/35427 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id8ff7a39fe74c73d8984fb34169b69649dab7c15 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Tomas Jelinek <tjeli...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches