Vitor de Lima has uploaded a new change for review. Change subject: restapi: Fix VM creation with blank template in other archs ......................................................................
restapi: Fix VM creation with blank template in other archs This change changes how the OS is selected when a VM is created from the REST API. If the API user does not select a OS and the blank template is chosen, the OS with the lowest ID for the selected architecture is attributed to the newly created VM. This change avoids the selection of the x86_64 specific "Other OS" when creating a VM of another architecture. Change-Id: I880e5940c7244476e477e098445a47210ea08b5d Signed-off-by: Vitor de Lima <vitor.l...@eldorado.org.br> --- M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java 1 file changed, 31 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/67/20667/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 8304f79..b3ad050 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 @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -39,6 +40,7 @@ import org.ovirt.engine.core.common.action.RemoveVmParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VmManagementParametersBase; +import org.ovirt.engine.core.common.businessentities.ArchitectureType; import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSGroup; @@ -46,6 +48,7 @@ import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.businessentities.VmTemplate; 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.GetVmTemplateParameters; import org.ovirt.engine.core.common.queries.IdQueryParameters; @@ -53,6 +56,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 @@ -101,8 +105,14 @@ staticVm.setVdsGroupId(getClusterId(vm)); } + VDSGroup cluster = lookupCluster(staticVm.getVdsGroupId()); + + if (Guid.Empty.equals(templateId) && !vm.isSetOs()) { + replaceDefaultOs(staticVm, cluster); + } + staticVm.setUsbPolicy(VmMapper.getUsbPolicyOnCreate(vm.getUsb(), - lookupCluster(staticVm.getVdsGroupId()))); + cluster)); if (!isFiltered()) { // if the user set the host-name within placement-policy, rather than the host-id (legal) - @@ -131,6 +141,26 @@ return removeRestrictedInfoFromResponse(response); } + private void replaceDefaultOs(VmStatic vm, VDSGroup cluster) + { + // Choose the proper default OS for each VM architecture + OsRepository osRepository = SimpleDependecyInjector.getInstance().get(OsRepository.class); + + HashMap<Integer, ArchitectureType> osArchitectures = osRepository.getOsArchitectures(); + + ArrayList<Integer> allOSesForArch = new ArrayList<Integer>(); + + for (Map.Entry<Integer, ArchitectureType> entry : osArchitectures.entrySet()) { + if (entry.getValue().equals(cluster.getArchitecture())) { + allOSesForArch.add(entry.getKey()); + } + } + + Integer defaultOs = Collections.min(allOSesForArch); + + vm.setOsId(defaultOs); + } + private boolean shouldMakeCreatorExplicitOwner() { // In the user level API we should make the creator the owner of the new created machine return isFiltered(); -- To view, visit http://gerrit.ovirt.org/20667 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I880e5940c7244476e477e098445a47210ea08b5d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Vitor de Lima <vitor.l...@eldorado.org.br> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches