Moti Asayag has uploaded a new change for review.

Change subject: engine: Add remove vnic profile command
......................................................................

engine: Add remove vnic profile command

The patch adds a new command for removing a vnic profile
which is no longer in use by vm or templates.

Change-Id: I53d8803f78838cea6c8423cb95b6d12ce6d3bea0
Signed-off-by: Moti Asayag <[email protected]>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/RemoveVnicProfileCommand.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, 78 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/76/16676/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/RemoveVnicProfileCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/RemoveVnicProfileCommand.java
new file mode 100644
index 0000000..2a62491
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/RemoveVnicProfileCommand.java
@@ -0,0 +1,73 @@
+package org.ovirt.engine.core.bll.network.vm;
+
+import java.util.List;
+
+import org.ovirt.engine.core.common.AuditLogType;
+import org.ovirt.engine.core.common.action.VnicProfileParameters;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VmTemplate;
+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.RemoveEntity;
+import org.ovirt.engine.core.utils.ReplacementUtils;
+
+public class RemoveVnicProfileCommand<T extends VnicProfileParameters> extends 
VnicProfileCommon<T> {
+
+    public RemoveVnicProfileCommand(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;
+        }
+
+        List<VM> vms = 
getVmDAO().getAllForVnicProfile(getVnicProfile().getId());
+        if (!vms.isEmpty()) {
+            // TODO: Add CDA message 'cannot modify vnic profiles network if 
there are VMs using the vnic profile
+            ReplacementUtils.replaceWithNameable("VMS_USING_VNIC_PROFILE", 
vms);
+            return false;
+        }
+
+        List<VmTemplate> templates = 
getVmTemplateDAO().getAllForVnicProfile(getVnicProfile().getId());
+        if (!templates.isEmpty()) {
+            // TODO: Add CDA message 'cannot modify vnic profiles network if 
there are templates using the vnic profile
+            
ReplacementUtils.replaceWithNameable("TEMPLATES_USING_VNIC_PROFILE", templates);
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    protected void executeCommand() {
+        getVnicProfileDao().remove(getVnicProfile().getId());
+        setSucceeded(true);
+    }
+
+    @Override
+    protected List<Class<?>> getValidationGroups() {
+        addValidationGroup(RemoveEntity.class);
+        return super.getValidationGroups();
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        super.setActionMessageParameters();
+        addCanDoActionMessage(VdcBllMessages.VAR__ACTION__REMOVE);
+    }
+
+    @Override
+    public AuditLogType getAuditLogTypeValue() {
+        return getSucceeded() ? AuditLogType.REMOVE_VNIC_PROFILE
+                : AuditLogType.REMOVE_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 73b4f22..c1da977 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
@@ -578,6 +578,8 @@
     ADD_VNIC_PROFILE_FAILED(1122),
     UPDATE_VNIC_PROFILE(1123),
     UPDATE_VNIC_PROFILE_FAILED(1124),
+    REMOVE_VNIC_PROFILE(1125),
+    REMOVE_VNIC_PROFILE_FAILED(1126),
 
     // 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 75fefedc..de84e91 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
@@ -87,6 +87,7 @@
     // VnicProfile Commands
     AddVnicProfile(160, ActionGroup.CREATE_NETWORK_VNIC_PROFILE, false, 
QuotaDependency.NONE),
     UpdateVnicProfile(161, ActionGroup.CONFIGURE_NETWORK_VNIC_PROFILE, false, 
QuotaDependency.NONE),
+    RemoveVnicProfile(162, ActionGroup.DELETE_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 e145885..3a92a0e 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
@@ -748,6 +748,8 @@
         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);
+        severities.put(AuditLogType.REMOVE_VNIC_PROFILE, 
AuditLogSeverity.NORMAL);
+        severities.put(AuditLogType.REMOVE_VNIC_PROFILE_FAILED, 
AuditLogSeverity.ERROR);
 
         // External Events/Alerts
         severities.put(AuditLogType.EXTERNAL_EVENT_NORMAL, 
AuditLogSeverity.NORMAL);


-- 
To view, visit http://gerrit.ovirt.org/16676
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I53d8803f78838cea6c8423cb95b6d12ce6d3bea0
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

Reply via email to