Moti Asayag has uploaded a new change for review. Change subject: engine: Add update vnic profile command ......................................................................
engine: Add update vnic profile command The patch adds support to update an existing vnic profile command. It will allow the user to modify the vnic profile name, custom properties and set it as port-mirroring. Change-Id: I1a666ccc4fc259c28e56e1c0c455fdd9b0ad14b7 Signed-off-by: Moti Asayag <[email protected]> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVnicProfileCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java 4 files changed, 97 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/75/16675/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVnicProfileCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVnicProfileCommand.java new file mode 100644 index 0000000..6d91130 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVnicProfileCommand.java @@ -0,0 +1,92 @@ +package org.ovirt.engine.core.bll.network.vm; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.ObjectUtils; +import org.ovirt.engine.core.common.AuditLogType; +import org.ovirt.engine.core.common.action.VnicProfileParameters; +import org.ovirt.engine.core.common.businessentities.Entities; +import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.businessentities.VMStatus; +import org.ovirt.engine.core.common.businessentities.network.Network; +import org.ovirt.engine.core.common.businessentities.network.VnicProfile; +import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.common.validation.group.UpdateEntity; +import org.ovirt.engine.core.utils.ReplacementUtils; + +public class UpdateVnicProfileCommand<T extends VnicProfileParameters> extends VnicProfileCommon<T> { + + public UpdateVnicProfileCommand(T parameters) { + super(parameters); + } + + @Override + protected boolean canDoAction() { + if (getVnicProfile() == null) { + // TODO: Add CDA message 'profile not found' + return false; + } + + VnicProfile profile = getVnicProfileDao().get(getVnicProfile().getId()); + if (profile == null) { + // TODO: Add CDA message 'profile not found' + return false; + } + + Network network = getNetworkDAO().get(getVnicProfile().getNetworkId()); + if (network == null) { + // TODO: Add CDA message 'network not found' + return false; + } + + if (!ObjectUtils.equals(getVnicProfile().getNetworkId(), network.getId())) { + List<VM> vms = getVmDAO().getAllForVnicProfile(getVnicProfile().getId()); + List<VM> vmUsingProfile = new ArrayList<>(); + for (VM vm : vms) { + if (vm.getStatus() != VMStatus.Down) { + vmUsingProfile.add(vm); + } + } + + if (!vmUsingProfile.isEmpty()) { + // TODO: Add CDA message 'cannot modify vnic profiles network if there are VMs with status other than + // 'Down' + ReplacementUtils.replaceWithNameable("VMS_USING_VNIC_PROFILE", vmUsingProfile); + return false; + } + } + + List<VnicProfile> profiles = getVnicProfileDao().getAllForNetwork(getVnicProfile().getNetworkId()); + if (Entities.entitiesByName(profiles).containsKey(getVnicProfile().getName())) { + // Add CDA message 'vnic profile name already in use' + return false; + } + + return true; + } + + @Override + protected void executeCommand() { + getVnicProfileDao().update(getVnicProfile()); + setSucceeded(true); + } + + @Override + protected List<Class<?>> getValidationGroups() { + addValidationGroup(UpdateEntity.class); + return super.getValidationGroups(); + } + + @Override + protected void setActionMessageParameters() { + super.setActionMessageParameters(); + addCanDoActionMessage(VdcBllMessages.VAR__ACTION__UPDATE); + } + + @Override + public AuditLogType getAuditLogTypeValue() { + return getSucceeded() ? AuditLogType.UPDATE_VNIC_PROFILE + : AuditLogType.UPDATE_VNIC_PROFILE_FAILED; + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java index 0434741..73b4f22 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java @@ -576,6 +576,8 @@ PERSIST_NETWORK_FAILED_FOR_MANAGEMENT_NETWORK(1121), ADD_VNIC_PROFILE(1121), ADD_VNIC_PROFILE_FAILED(1122), + UPDATE_VNIC_PROFILE(1123), + UPDATE_VNIC_PROFILE_FAILED(1124), // Import/Export IMPORTEXPORT_STARTING_EXPORT_VM(1162), diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java index 77a2c42..75fefedc 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java @@ -86,6 +86,7 @@ // VnicProfile Commands AddVnicProfile(160, ActionGroup.CREATE_NETWORK_VNIC_PROFILE, false, QuotaDependency.NONE), + UpdateVnicProfile(161, ActionGroup.CONFIGURE_NETWORK_VNIC_PROFILE, false, QuotaDependency.NONE), // VmTemplatesCommand AddVmTemplate(201, ActionGroup.CREATE_TEMPLATE, QuotaDependency.BOTH), diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java index 4f75d27..e145885 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java @@ -746,6 +746,8 @@ severities.put(AuditLogType.PERSIST_NETWORK_FAILED_FOR_MANAGEMENT_NETWORK, AuditLogSeverity.WARNING); severities.put(AuditLogType.ADD_VNIC_PROFILE, AuditLogSeverity.NORMAL); severities.put(AuditLogType.ADD_VNIC_PROFILE_FAILED, AuditLogSeverity.ERROR); + severities.put(AuditLogType.UPDATE_VNIC_PROFILE, AuditLogSeverity.NORMAL); + severities.put(AuditLogType.UPDATE_VNIC_PROFILE_FAILED, AuditLogSeverity.ERROR); // External Events/Alerts severities.put(AuditLogType.EXTERNAL_EVENT_NORMAL, AuditLogSeverity.NORMAL); -- To view, visit http://gerrit.ovirt.org/16675 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1a666ccc4fc259c28e56e1c0c455fdd9b0ad14b7 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
