Moti Asayag has uploaded a new change for review. Change subject: engine: Support vnic api by network name for backward compatibility ......................................................................
engine: Support vnic api by network name for backward compatibility The patch designed for backward compatibility, for providing the network name instead of the vnic profile id, since this api is still support via the rest. The engine will attempt to find the best matching of a profile according to the provided network. Change-Id: I70843c967981567fa83613d3e9576640bcd8b7d5 Signed-off-by: Moti Asayag <masa...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/VmInterfaceManager.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AbstractVmInterfaceCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 9 files changed, 73 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/15/17615/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/VmInterfaceManager.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/VmInterfaceManager.java index 47730ff..a5442fe 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/VmInterfaceManager.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/VmInterfaceManager.java @@ -5,12 +5,14 @@ import java.util.Map; import org.apache.commons.lang.ObjectUtils; +import org.ovirt.engine.core.bll.ValidationResult; import org.ovirt.engine.core.bll.context.CompensationContext; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.FeatureSupported; import org.ovirt.engine.core.common.VdcObjectType; import org.ovirt.engine.core.common.businessentities.ActionGroup; import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.businessentities.VmBase; import org.ovirt.engine.core.common.businessentities.network.Network; import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.common.businessentities.network.VmNic; @@ -18,6 +20,7 @@ import org.ovirt.engine.core.common.businessentities.network.VnicProfileView; import org.ovirt.engine.core.common.errors.VdcBLLException; import org.ovirt.engine.core.common.errors.VdcBllErrors; +import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.dal.dbbroker.DbFacade; @@ -25,6 +28,7 @@ import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase; import org.ovirt.engine.core.dao.PermissionDAO; import org.ovirt.engine.core.dao.VmDAO; +import org.ovirt.engine.core.dao.network.NetworkDao; import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao; import org.ovirt.engine.core.dao.network.VmNetworkStatisticsDao; import org.ovirt.engine.core.dao.network.VmNicDao; @@ -212,18 +216,42 @@ return true; } + public ValidationResult updateParametersForBackwardCompatibility(VmNetworkInterface nic, VmBase vm, Guid userId) { + if (nic.getVnicProfileId() != null) { + return ValidationResult.VALID; + } + + if (nic.getNetworkName() == null) { + if (nic.isPortMirroring()) { + return new ValidationResult(VdcBllMessages.PORT_MIRRORING_REQUIRES_NETWORK); + } else { + return ValidationResult.VALID; + } + } + + Network network = getNetworkDao().getByNameAndCluster(nic.getNetworkName(), vm.getVdsGroupId()); + + if (network == null) { + return new ValidationResult(VdcBllMessages.NETWORK_NOT_EXISTS_IN_CLUSTER); + } + + List<VnicProfile> vnicProfiles = getVnicProfileDao().getAllForNetwork(network.getId()); + for (VnicProfile profile : vnicProfiles) { + if (isVnicProfilePermitted(userId, profile, nic.isPortMirroring())) { + nic.setVnicProfileId(profile.getId()); + return ValidationResult.VALID; + } + } + + return new ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_CANNOT_FIND_VNIC_PROFILE_FOR_NETWORK); + } + private VnicProfile findVnicProfileForUser(Guid userId, Network network) { List<VnicProfile> networkProfiles = getVnicProfileDao().getAllForNetwork(network.getId()); for (VnicProfile profile : networkProfiles) { - if (profile.isPortMirroring()) { - if (isVnicProfilePermitted(userId, profile, ActionGroup.PORT_MIRRORING)) { - return profile; - } - } else { - if (isVnicProfilePermitted(userId, profile, ActionGroup.CONFIGURE_VM_NETWORK)) { - return profile; - } + if (isVnicProfilePermitted(userId, profile, profile.isPortMirroring())) { + return profile; } } @@ -248,9 +276,9 @@ return null; } - private boolean isVnicProfilePermitted(Guid userId, VnicProfile profile, ActionGroup actionGroup) { + private boolean isVnicProfilePermitted(Guid userId, VnicProfile profile, boolean portMirroring) { return getPermissionDAO().getEntityPermissions(userId, - actionGroup, + portMirroring ? ActionGroup.PORT_MIRRORING : ActionGroup.CONFIGURE_VM_NETWORK, profile.getId(), VdcObjectType.VnicProfile) != null; } @@ -293,6 +321,10 @@ return DbFacade.getInstance().getPermissionDao(); } + private NetworkDao getNetworkDao() { + return DbFacade.getInstance().getNetworkDao(); + } + private AuditLogableBase createAuditLog(final VmNic iface) { AuditLogableBase logable = new AuditLogableBase(); logable.setVmId(iface.getVmId()); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AbstractVmInterfaceCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AbstractVmInterfaceCommand.java index 2a69ab7..2832171 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AbstractVmInterfaceCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AbstractVmInterfaceCommand.java @@ -7,6 +7,7 @@ import org.ovirt.engine.core.bll.VmCommand; import org.ovirt.engine.core.bll.VmHandler; import org.ovirt.engine.core.bll.network.MacPoolManager; +import org.ovirt.engine.core.bll.network.VmInterfaceManager; import org.ovirt.engine.core.common.action.ActivateDeactivateVmNicParameters; import org.ovirt.engine.core.common.action.AddVmInterfaceParameters; import org.ovirt.engine.core.common.action.PlugAction; @@ -99,6 +100,17 @@ : ValidationResult.VALID; } + protected boolean updateVnicForBackwardCompatibility() { + VmInterfaceManager nicManager = new VmInterfaceManager(); + if (!validate(nicManager.updateParametersForBackwardCompatibility(getParameters().getInterface(), + getVm().getStaticData(), + getCurrentUser().getUserId()))) { + return false; + } + + return true; + } + protected String getMacAddress() { return getInterface().getMacAddress(); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java index cfd3597..b3d1c0b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java @@ -104,6 +104,10 @@ return false; } + if (!updateVnicForBackwardCompatibility()) { + return false; + } + switch (getVmDynamicDao().get(getParameters().getVmId()).getStatus()) { case Up: case Down: diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java index 3f1176a..1d8c600 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java @@ -140,6 +140,14 @@ @Override protected boolean canDoAction() { + if (getVm() == null) { + addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_VM_NOT_FOUND); + return false; + } + + if (!updateVnicForBackwardCompatibility()) { + return false; + } if (!updateVmNicAllowed(getVm().getStatus())) { addCanDoActionMessage(VdcBllMessages.NETWORK_CANNOT_CHANGE_STATUS_WHEN_NOT_DOWN_UP); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java index 66c7053..51042e6 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java @@ -430,6 +430,7 @@ VNIC_PROFILE_NOT_EXISTS(ErrorType.BAD_PARAMETERS), VNIC_PROFILE_NAME_IN_USE(ErrorType.CONFLICT), VNIC_PROFILE_IN_USE(ErrorType.CONFLICT), + ACTION_TYPE_FAILED_CANNOT_FIND_VNIC_PROFILE_FOR_NETWORK(ErrorType.BAD_PARAMETERS), CANNOT_CHANGE_VNIC_PROFILE_NETWORK(ErrorType.BAD_PARAMETERS), CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_MIGRATION_NETWORK_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED), diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index 6f6e72f..db74f32 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -364,6 +364,7 @@ VNIC_PROFILE_IN_USE=Cannot ${action} ${type}. Several ${entities} (${ENTITIES_USING_VNIC_PROFILE_COUNTER}) are using this VM network interface profile:\n${ENTITIES_USING_VNIC_PROFILE}\n - Please remove it from all ${entities} that are using it and try again. CANNOT_CHANGE_VNIC_PROFILE_NETWORK=Cannot ${action} ${type}. VM network interface profile's network cannot be changed. CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK=Cannot ${action} ${type}. VM network interface profiles can be added to a VM network only. +ACTION_TYPE_FAILED_CANNOT_FIND_VNIC_PROFILE_FOR_NETWORK=Cannot ${action} ${type}. There is no VM network interface's profile for the network the user can use.\n\-Please use VM network interface profile instead of network name. ACTION_TYPE_FAILED_NAME_ALREADY_USED=Cannot ${action} ${type}. The ${type} name is already in use, please choose a unique name and try again. ACTION_TYPE_FAILED_URL_INVALID=Cannot ${action} ${type}. The URL is not valid, please enter a valid URL and try again. ACTION_TYPE_FAILED_STORAGE_CONNECTION_NOT_EXIST=Cannot ${action} ${type}. Storage connection doesn't exist. diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java index aa41a8a..12ccda1 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java @@ -1156,6 +1156,9 @@ @DefaultStringValue("Cannot ${action} ${type}. VM network interface profiles can be added to a VM network only.") String CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK(); + @DefaultStringValue("Cannot ${action} ${type}. There is no VM network interface's profile for the network the user can use.\n\-Please use VM network interface profile instead of network name.") + String ACTION_TYPE_FAILED_CANNOT_FIND_VNIC_PROFILE_FOR_NETWORK(); + @DefaultStringValue("The specified external network cannot be configured on the host's interface.") String EXTERNAL_NETWORK_CANNOT_BE_PROVISIONED(); diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index aa20269..2a87c73 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -406,6 +406,7 @@ VNIC_PROFILE_IN_USE=Cannot ${action} ${type}. Several ${entities} (${ENTITIES_USING_VNIC_PROFILE_COUNTER}) are using this VM network interface profile:\n${ENTITIES_USING_VNIC_PROFILE}\n - Please remove it from all ${entities} that are using it and try again. CANNOT_CHANGE_VNIC_PROFILE_NETWORK=Cannot ${action} ${type}. VM network interface profile's network cannot be changed. CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK=Cannot ${action} ${type}. VM network interface profiles can be added to a VM network only. +ACTION_TYPE_FAILED_CANNOT_FIND_VNIC_PROFILE_FOR_NETWORK=Cannot ${action} ${type}. There is no VM network interface's profile for the network the user can use.\n\-Please use VM network interface profile instead of network name. EXTERNAL_NETWORK_CANNOT_BE_PROVISIONED=The specified external network cannot be configured on the host's interface. ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover Data Center with active Data Storage Domain in Data Center. ERROR_CANNOT_RECOVERY_STORAGE_POOL_STORAGE_TYPE_MISSMATCH=Cannot recover Data Center. Mismatch between Storage Domain type and Data Center type. diff --git a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 6813e06..d75536d 100644 --- a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -368,6 +368,7 @@ VNIC_PROFILE_IN_USE=Cannot ${action} ${type}. Several ${entities} (${ENTITIES_USING_VNIC_PROFILE_COUNTER}) are using this VM network interface profile:\n${ENTITIES_USING_VNIC_PROFILE}\n - Please remove it from all ${entities} that are using it and try again. CANNOT_CHANGE_VNIC_PROFILE_NETWORK=Cannot ${action} ${type}. VM network interface profile's network cannot be changed. CANNOT_ADD_VNIC_PROFILE_TO_NON_VM_NETWORK=Cannot ${action} ${type}. VM network interface profiles can be added to a VM network only. +ACTION_TYPE_FAILED_CANNOT_FIND_VNIC_PROFILE_FOR_NETWORK=Cannot ${action} ${type}. There is no VM network interface's profile for the network the user can use.\n\-Please use VM network interface profile instead of network name. ACTION_TYPE_FAILED_NAME_ALREADY_USED=Cannot ${action} ${type}. The ${type} name is already in use, please choose a unique name and try again. VALIDATION_VDS_CONSOLEADDRESSS_HOSTNAME_OR_IP=Console address must be a FQDN or a valid IP address ACTION_TYPE_FAILED_URL_INVALID=Cannot ${action} ${type}. The URL is not valid, please enter a valid URL and try again. -- To view, visit http://gerrit.ovirt.org/17615 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I70843c967981567fa83613d3e9576640bcd8b7d5 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