Maor Lipchuk has uploaded a new change for review.

Change subject: core: Add audit log when removing networks from iSCSI bond.
......................................................................

core: Add audit log when removing networks from iSCSI bond.

Adding an audit log to indicate the user that the removed networks
from the iSCSI bond, will only take affect, after the Hosts will be moved
to maintenance and activated again.

Change-Id: I087818bb48cc9243e76b2cb850e6262104537f3c
Bug-Url: https://bugzilla.redhat.com/BZ1094144
Signed-off-by: Maor Lipchuk <mlipc...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/EditIscsiBondCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
M 
backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
3 files changed, 22 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/88/30988/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/EditIscsiBondCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/EditIscsiBondCommand.java
index a1089b1..2b52289 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/EditIscsiBondCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/EditIscsiBondCommand.java
@@ -11,9 +11,11 @@
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.EditIscsiBondParameters;
 import org.ovirt.engine.core.common.businessentities.IscsiBond;
+import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.validation.group.UpdateEntity;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
 
@@ -24,6 +26,7 @@
 
     private List<String> addedConnections = new ArrayList<>();
     private List<Guid> addedNetworks = new ArrayList<>();
+    private Set<Guid> removedNetworks = new HashSet<>();
 
     public EditIscsiBondCommand(T parameters) {
         super(parameters);
@@ -60,7 +63,7 @@
                     getDbFacade().getIscsiBondDao().update(getIscsiBond());
                 }
 
-                updateNetworksIds();
+                removedNetworks = updateNetworksIds();
                 updateConnectionsIds();
 
                 return null;
@@ -71,10 +74,24 @@
             connectAllHostsToStorage(getIscsiBond().getStorageConnectionIds());
         }
 
+        if (!removedNetworks.isEmpty()) {
+            addAuditLogForRemovedNetowrks(removedNetworks);
+        }
         setSucceeded(true);
     }
 
-    private void updateNetworksIds() {
+    private void addAuditLogForRemovedNetowrks(Set<Guid> removedNetworks) {
+        List<String> networkrNames = new ArrayList<>();
+        for (Guid networkId : removedNetworks) {
+            Network network = getDbFacade().getNetworkDao().get(networkId);
+            networkrNames.add(network.getName());
+        }
+        addCustomValue("NetowrkNames", StringUtils.join(networkrNames, ","));
+        addCustomValue("IscsiBondName", getIscsiBond().getName());
+        AuditLogDirector.log(this, AuditLogType.USER_FAILED_HOTPLUG_DISK);
+    }
+
+    private Set<Guid> updateNetworksIds() {
         Set<Guid> beforeChangeNetworkIds = new 
HashSet<>(getExistingIscsiBond().getNetworkIds());
 
         for (Guid networkId : getIscsiBond().getNetworkIds()) {
@@ -87,6 +104,7 @@
         for (Guid networkId : beforeChangeNetworkIds) {
             
getDbFacade().getIscsiBondDao().removeNetworkFromIscsiBond(getExistingIscsiBond().getId(),
 networkId);
         }
+        return beforeChangeNetworkIds;
     }
 
     private void updateConnectionsIds() {
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 0127bf1..dbb2dc6 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
@@ -253,6 +253,7 @@
     USER_EXPORT_IMAGE_FINISHED_FAILURE(2032, AuditLogSeverity.ERROR),
     HOT_SET_NUMBER_OF_CPUS(2033),
     FAILED_HOT_SET_NUMBER_OF_CPUS(2034, AuditLogSeverity.ERROR),
+    USER_ISCSI_BOND_HOST_RESTART_WARNING(2035, AuditLogSeverity.WARNING),
 
     // Used only from SQL script, therefor should not have severity & message
     USER_RUN_UNLOCK_ENTITY_SCRIPT(2024),
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
index 57cdaf4..d8135fd 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -99,6 +99,7 @@
 USER_EXPORT_IMAGE_FINISHED_FAILURE=User ${UserName} failed to export image 
${RepoImageName} to domain ${DestinationStorageDomainName}.
 HOT_SET_NUMBER_OF_CPUS=Hotplug CPU: changed the number of CPUs on VM ${vmName} 
from ${previousNumberOfCpus} to ${numberOfCpus}
 FAILED_HOT_SET_NUMBER_OF_CPUS= Failed to hot set number of CPUS to VM 
${vmName}. Underlying error message: ${ErrorMessage}
+USER_ISCSI_BOND_HOST_RESTART_WARNING=The following Networks has been removed 
from the iSCSI bond ${IscsiBondName}: ${NetworkNames}. for those changes to 
take affect, the hosts must be moved to maintenance and activated again.
 USER_MOVE_IMAGE_GROUP_FAILED_TO_DELETE_SRC_IMAGE=Possible failure while 
deleting ${DiskAlias} from the source Storage Domain ${StorageDomainName} 
during the move operation. The Storage Domain may be manually cleaned-up from 
possible leftovers (User:${UserName}).
 USER_MOVE_IMAGE_GROUP_FAILED_TO_DELETE_DST_IMAGE=Possible failure while 
clearing possible leftovers of ${DiskAlias} from the target Storage Domain 
${StorageDomainName} after the move operation failed to copy the image to it 
properly. The Storage Domain may be manually cleaned-up from possible leftovers 
(User:${UserName}).
 USER_REMOVE_DISK_FROM_VM=Disk was removed from VM ${VmName} by ${UserName}.


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I087818bb48cc9243e76b2cb850e6262104537f3c
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Maor Lipchuk <mlipc...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to