Moti Asayag has uploaded a new change for review. Change subject: engine: Refactor resolution of vnic profile for a vnic ......................................................................
engine: Refactor resolution of vnic profile for a vnic The patch refactors the logic of updating a vnic's profile id so the code could be extracted into the VmInterfaceManager for the sake of sharing it between ImportVmCommand and ImportVmTemplateCommand. Change-Id: I26f1764db23555f5a284c427d36639d4ef4f6f5f Signed-off-by: Moti Asayag <masa...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java 1 file changed, 60 insertions(+), 37 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/42/17442/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java index 1adee36..ea5332a 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java @@ -81,6 +81,7 @@ import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.NotImplementedException; +import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector; import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase; import org.ovirt.engine.core.utils.GuidUtils; @@ -1061,43 +1062,71 @@ for (VmNetworkInterface iface : getVm().getInterfaces()) { initInterface(iface); - - if (iface.getNetworkName() == null) { - if (FeatureSupported.networkLinking(getVdsGroup().getcompatibility_version())) { - iface.setVnicProfileId(null); - } else { - markNicHasNoProfile(invalidNetworkNames, invalidIfaceNames, iface); - } - - addVnic(vmInterfaceManager, iface); - continue; - } - - Network network = networksInClusterByName.get(iface.getNetworkName()); - if (network == null || !network.isVmNetwork()) { + if (!updateNicWithVnicProfile(iface, + iface.getNetworkName(), + iface.getVnicProfileName(), + getVdsGroup().getcompatibility_version(), + networksInClusterByName, + vnicProfilesInDc)) { markNicHasNoProfile(invalidNetworkNames, invalidIfaceNames, iface); - addVnic(vmInterfaceManager, iface); - continue; } - VnicProfile vnicProfile = getVnicProfileForNetwork(vnicProfilesInDc, network, iface.getVnicProfileName()); - if (vnicProfile == null) { - vnicProfile = findVnicProfileForUser(getCurrentUser().getUserId(), network); - if (vnicProfile == null) { - markNicHasNoProfile(invalidNetworkNames, invalidIfaceNames, iface); - } else { - iface.setVnicProfileId(vnicProfile.getId()); - } - - addVnic(vmInterfaceManager, iface); - continue; - } - - iface.setVnicProfileId(vnicProfile.getId()); - addVnic(vmInterfaceManager, iface); + vmInterfaceManager.add(iface, getCompensationContext(), getParameters().isImportAsNewEntity(), + getVdsGroup().getcompatibility_version()); + macsAdded.add(iface.getMacAddress()); } auditInvalidInterfaces(invalidNetworkNames, invalidIfaceNames); + } + + /** + * Updates the vnic profile id of a given {@link VmNic} by a network name and vnic profile name. + * + * @param iface + * The vm network interface to be updated + * @param networkName + * The network name which the vnic profile is associated with + * @param vnicProfileName + * The vnic profile name + * @param compatibilityVersion + * The compatibility version of the cluster in which the VM exists + * @param networksInClusterByName + * The networks which are assigned to the cluster + * @param vnicProfilesInDc + * The vnic profiles for the data-center in which the VM exists + * @return {@code true} if the vnic profile id is updated, else {@code false} + */ + public boolean updateNicWithVnicProfile(VmNic iface, + String networkName, + String vnicProfileName, + Version compatibilityVersion, + Map<String, Network> networksInClusterByName, + List<VnicProfileView> vnicProfilesInDc) { + + if (networkName == null) { + if (FeatureSupported.networkLinking(getVdsGroup().getcompatibility_version())) { + iface.setVnicProfileId(null); + return true; + } else { + return false; + } + } + + Network network = networksInClusterByName.get(networkName); + if (network == null || !network.isVmNetwork()) { + return false; + } + + VnicProfile vnicProfile = getVnicProfileForNetwork(vnicProfilesInDc, network, vnicProfileName); + if (vnicProfile == null) { + vnicProfile = findVnicProfileForUser(getCurrentUser().getUserId(), network); + if (vnicProfile == null) { + return false; + } + } + + iface.setVnicProfileId(vnicProfile.getId()); + return true; } private VnicProfile findVnicProfileForUser(Guid userId, Network network) { @@ -1123,12 +1152,6 @@ actionGroup, profile.getId(), VdcObjectType.VnicProfile) != null; - } - - private void addVnic(VmInterfaceManager vmInterfaceManager, VmNetworkInterface iface) { - vmInterfaceManager.add(iface, getCompensationContext(), getParameters().isImportAsNewEntity(), - getVdsGroup().getcompatibility_version()); - macsAdded.add(iface.getMacAddress()); } private void markNicHasNoProfile(List<String> invalidNetworkNames, -- To view, visit http://gerrit.ovirt.org/17442 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I26f1764db23555f5a284c427d36639d4ef4f6f5f Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <masa...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches