Lior Vernia has uploaded a new change for review. Change subject: webadmin: Set default vNIC type according to OsInfo ......................................................................
webadmin: Set default vNIC type according to OsInfo Only set the vNIC type to VirtIO by default if it exists in the OsInfo vNIC types; if not, pick the first one among the existing values. This had to be changed for both the vNIC dialog and the VM dialog (where the vNIC type can't be edited by the user but it is implicitly set when adding a new vNIC). Change-Id: I4f09986e661d820b3c10301fa35c840fd9cfe0d8 Bug-Url: https://bugzilla.redhat.com/996044 Signed-off-by: Lior Vernia <lver...@redhat.com> --- M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/BaseEditVmInterfaceModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmInterfaceModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModelNetworkAsyncCallback.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceCreatingManager.java 5 files changed, 35 insertions(+), 12 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/26948/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java index 6f9ceee..f42e9f4 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java @@ -3039,9 +3039,15 @@ asyncQuery); } - public static VmInterfaceType getDefaultNicType() + public static VmInterfaceType getDefaultNicType(Collection<VmInterfaceType> items) { - return VmInterfaceType.pv; + if (items == null || items.isEmpty()) { + return null; + } else if (items.contains(VmInterfaceType.pv)) { + return VmInterfaceType.pv; + } else { + return items.iterator().next(); + } } public static boolean isVersionMatchStorageType(Version version, boolean isLocalType) { diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/BaseEditVmInterfaceModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/BaseEditVmInterfaceModel.java index 08a8f42..b484b3d 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/BaseEditVmInterfaceModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/BaseEditVmInterfaceModel.java @@ -101,16 +101,16 @@ @Override protected void initSelectedType() { - Integer selectedNicType = getNic().getType(); + VmInterfaceType selectedNicType = VmInterfaceType.forValue(getNic().getType()); ArrayList<VmInterfaceType> nicTypes = (ArrayList<VmInterfaceType>) getNicType().getItems(); nicTypes = nicTypes == null ? new ArrayList<VmInterfaceType>() : nicTypes; - if (selectedNicType == null || !nicTypes.contains(VmInterfaceType.forValue(selectedNicType))) + if (selectedNicType == null || !nicTypes.contains(selectedNicType)) { - selectedNicType = AsyncDataProvider.getDefaultNicType().getValue(); + selectedNicType = AsyncDataProvider.getDefaultNicType(nicTypes); } - getNicType().setSelectedItem(VmInterfaceType.forValue(selectedNicType)); + getNicType().setSelectedItem(selectedNicType); } @Override diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmInterfaceModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmInterfaceModel.java index df21086..ad35fa0 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmInterfaceModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmInterfaceModel.java @@ -102,7 +102,7 @@ @Override protected void initSelectedType() { - getNicType().setSelectedItem(AsyncDataProvider.getDefaultNicType()); + getNicType().setSelectedItem(AsyncDataProvider.getDefaultNicType(getNicType().getItems())); } @Override diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModelNetworkAsyncCallback.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModelNetworkAsyncCallback.java index c07c5a9..62bfea0 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModelNetworkAsyncCallback.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModelNetworkAsyncCallback.java @@ -31,7 +31,7 @@ VdcReturnValueBase returnValue = result.getReturnValue(); if (returnValue != null && returnValue.getSucceeded()) { networkCreatingManager.updateVnics((idToUpdate == null) ? (Guid) returnValue.getActionReturnValue() - : idToUpdate, unitVmModel.getNicsWithLogicalNetworks().getItems(), unitVmModel.getIsNew()); + : idToUpdate, unitVmModel.getNicsWithLogicalNetworks().getItems(), unitVmModel); } else { networkCreatingManager.getCallback().queryFailed(); } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceCreatingManager.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceCreatingManager.java index 33a89c1..ade11ad 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceCreatingManager.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceCreatingManager.java @@ -1,6 +1,7 @@ package org.ovirt.engine.ui.uicommonweb.models.vms; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -11,6 +12,7 @@ import org.ovirt.engine.core.common.action.VdcActionParametersBase; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VmOperationParameterBase; +import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType; import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.ui.frontend.AsyncQuery; @@ -22,6 +24,7 @@ public class VmInterfaceCreatingManager { + private VmInterfaceType defaultType; private PostVnicCreatedCallback callback; public VmInterfaceCreatingManager(PostVnicCreatedCallback callback) { @@ -38,8 +41,11 @@ void queryFailed(); } - public void updateVnics(final Guid vmId, final Iterable<VnicInstanceType> vnicsWithProfiles, final boolean isAddingNewVm) { - AsyncQuery getVmNicsQuery = new AsyncQuery(); + public void updateVnics(final Guid vmId, + final Iterable<VnicInstanceType> vnicsWithProfiles, + final UnitVmModel unitVmModel) { + + final AsyncQuery getVmNicsQuery = new AsyncQuery(); getVmNicsQuery.asyncCallback = new INewAsyncCallback() { @Override public void onSuccess(Object model, Object result) { @@ -67,6 +73,7 @@ String vnicName = editedVnic.getName(); VmNetworkInterface existingVnic = existingVnicForName.get(vnicName); if (existingVnic == null) { + editedVnic.setType(defaultType == null ? null : defaultType.getValue()); createVnicParameters.add(new AddVmInterfaceParameters(vmId, editedVnic)); } else { vnicsEncountered.add(vnicName); @@ -106,7 +113,7 @@ @Override public void executed(FrontendActionAsyncResult result) { - if (isAddingNewVm) { + if (unitVmModel.getIsNew()) { VmOperationParameterBase reorderParams = new VmOperationParameterBase(vmId); Frontend.getInstance().runAction(VdcActionType.ReorderVmNics, reorderParams, new IFrontendActionAsyncCallback() { public void executed(FrontendActionAsyncResult result) { @@ -124,7 +131,17 @@ }, this); } }; - AsyncDataProvider.getVmNicList(getVmNicsQuery, vmId); + + AsyncQuery osInfoQuery = new AsyncQuery(new INewAsyncCallback() { + @Override + public void onSuccess(Object model, Object returnValue) { + defaultType = AsyncDataProvider.getDefaultNicType((Collection<VmInterfaceType>) returnValue); + AsyncDataProvider.getVmNicList(getVmNicsQuery, vmId); + } + }); + AsyncDataProvider.getNicTypeList(unitVmModel.getOSType().getSelectedItem(), + unitVmModel.getDataCenterWithClustersList().getSelectedItem().getCluster().getcompatibility_version(), + osInfoQuery); } } -- To view, visit http://gerrit.ovirt.org/26948 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4f09986e661d820b3c10301fa35c840fd9cfe0d8 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.4 Gerrit-Owner: Lior Vernia <lver...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches