Muli Salem has uploaded a new change for review.

Change subject: core: Validate Network is in Host for HotPlug (#850854)
......................................................................

core: Validate Network is in Host for HotPlug (#850854)

https://bugzilla.redhat.com/850854

This patch makes sure the Network that is being added
to the VM and activated, is in the VM's current Host.

Change-Id: Ie1ef34503e5232280c506cf6a909fd703e99acb3
Signed-off-by: Muli Salem <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmInterfaceCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/PlugUnplugVmNicCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/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
8 files changed, 36 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/50/7550/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmInterfaceCommand.java
index 5329031..ecddfb6 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmInterfaceCommand.java
@@ -112,6 +112,7 @@
             getReturnValue().getExecuteFailedMessages().add("Failed 
hot-plugging nic to VM");
             
getReturnValue().getCanDoActionMessages().addAll(plugVmNicReturnValue.getCanDoActionMessages());
             
getReturnValue().getCanDoActionMessages().remove(VdcBllMessages.VAR__ACTION__ADD);
+            getReturnValue().setCanDoAction(false);
         }
         return plugVmNicReturnValue.getSucceeded();
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/PlugUnplugVmNicCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/PlugUnplugVmNicCommand.java
index e2cf00d..21c9477 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/PlugUnplugVmNicCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/PlugUnplugVmNicCommand.java
@@ -1,12 +1,16 @@
 package org.ovirt.engine.core.bll;
 
+import java.util.List;
+
 import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
 import org.ovirt.engine.core.common.action.PlugAction;
 import org.ovirt.engine.core.common.action.PlugUnplugVmNicParameters;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
+import org.ovirt.engine.core.common.businessentities.VdsNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.vdscommands.HotPlugUnplgNicVDSParameters;
+import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.VdcBllMessages;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
@@ -35,6 +39,10 @@
             if (VmHandler.isHotPlugNicAllowedForVmStatus(getVm().getstatus())) 
{
                 setVdsId(getVm().getrun_on_vds().getValue());
                 returnValue = canPerformHotPlug();
+                if (returnValue && !networkAttachedToVds(getNetworkName(), 
getVdsId())) {
+                    
addCanDoActionMessage(VdcBllMessages.PLUG_UNPLUG_NETWORK_NOT_IN_VDS);
+                    returnValue = false;
+                }
             }
         } else {
             
addCanDoActionMessage(VdcBllMessages.PLUG_UNPLUG_NIC_VM_STATUS_ILLEGAL);
@@ -50,6 +58,10 @@
         }
 
         return returnValue;
+    }
+
+    private String getNetworkName() {
+        return 
getVmNetworkInterfaceDAO().get(getParameters().getNicId()).getNetworkName();
     }
 
     @Override
@@ -91,4 +103,15 @@
         return vmStatus == VMStatus.Up || vmStatus == VMStatus.Down;
     }
 
+    private boolean networkAttachedToVds(String networkName, Guid vdsId) {
+        if (networkName != null) {
+            List<VdsNetworkInterface> listOfInterfaces = 
getInterfaceDAO().getAllInterfacesForVds(vdsId);
+            for (VdsNetworkInterface vdsNetworkInterface : listOfInterfaces) {
+                if (networkName.equals(vdsNetworkInterface.getNetworkName())) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
index a4a123a..83c273f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
@@ -44,6 +44,7 @@
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dao.DiskDao;
 import org.ovirt.engine.core.dao.DiskImageDAO;
+import org.ovirt.engine.core.dao.InterfaceDAO;
 import org.ovirt.engine.core.dao.TagDAO;
 import org.ovirt.engine.core.dao.VmDeviceDAO;
 import org.ovirt.engine.core.dao.VmDynamicDAO;
@@ -506,6 +507,10 @@
         return getDbFacade().getDiskImageDAO();
     }
 
+    protected InterfaceDAO getInterfaceDAO() {
+        return getDbFacade().getInterfaceDAO();
+    }
+
     protected boolean checkPayload(VmPayload payload, String isoPath) {
         boolean returnValue = true;
         if (payload.getType() != VmDeviceType.CDROM && payload.getType() != 
VmDeviceType.FLOPPY) {
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
index 11cc65a..9fa115f 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
@@ -584,6 +584,7 @@
     HOT_PLUG_DISK_IS_NOT_UNPLUGGED,
     HOT_UNPLUG_DISK_IS_NOT_PLUGGED,
     PLUG_UNPLUG_NIC_VM_STATUS_ILLEGAL,
+    PLUG_UNPLUG_NETWORK_NOT_IN_VDS,
     SHAREABLE_DISK_IS_NOT_SUPPORTED_FOR_DISK,
     SHAREABLE_DISK_IS_NOT_SUPPORTED_BY_VOLUME_FORMAT,
     ERROR_CANNOT_DETACH_DISK_WITH_SNAPSHOT,
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 0380a9c..0bb44ee 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -695,6 +695,7 @@
 HOT_PLUG_DISK_IS_NOT_UNPLUGGED=Disk is already activated.
 HOT_UNPLUG_DISK_IS_NOT_PLUGGED=Disk is already deactivated.
 PLUG_UNPLUG_NIC_VM_STATUS_ILLEGAL=Cannot activate/deactivate VM Network 
Interface due to VM status. The VM status must be Down or Up.
+PLUG_UNPLUG_NETWORK_NOT_IN_VDS=The Network does not exist on the host the VM 
is running on.\n Either add the Network to the Host, uncheck the 'Activate' 
checkbox or migrate the VM to a Host that has this Network.
 VM_CANNOT_RUN_FROM_DISK_WITHOUT_PLUGGED_DISK=Cannot ${action} ${type} without 
at least one active disk.\nPlease activate a disk and rerun the VM.
 SHAREABLE_DISK_IS_NOT_SUPPORTED_FOR_DISK=Cannot ${action} ${type}. Disk cannot 
be shareable if it depends on a snapshot. In order to share it, remove the 
disk's snapshots.
 SHAREABLE_DISK_IS_NOT_SUPPORTED_BY_VOLUME_FORMAT=Cannot ${action} ${type}. 
Disk's volume format is not supported for shareable disk.
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 0424973..59e51ae 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
@@ -1861,6 +1861,9 @@
     @DefaultStringValue("Cannot activate/deactivate interface due to VM 
status. The VM status must be Down or Up.")
     String PLUG_UNPLUG_NIC_VM_STATUS_ILLEGAL();
 
+    @DefaultStringValue("The Network does not exist on the host the VM is 
running on.\n Either add the Network to the Host, uncheck the 'Activate' 
checkbox or migrate the VM to a Host that has this Network.")
+    String PLUG_UNPLUG_NETWORK_NOT_IN_VDS();
+
     @DefaultStringValue("Disk is already deactivated.")
     String HOT_UNPLUG_DISK_IS_NOT_PLUGGED();
 
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 1b9385c..848b457 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
@@ -689,6 +689,7 @@
 HOT_PLUG_DISK_IS_NOT_UNPLUGGED=Disk is already activated.
 HOT_UNPLUG_DISK_IS_NOT_PLUGGED=Disk is already deactivated.
 PLUG_UNPLUG_NIC_VM_STATUS_ILLEGAL=Cannot activate/deactivate VM Network 
Interface due to VM status. The VM status must be Down or Up.
+PLUG_UNPLUG_NETWORK_NOT_IN_VDS=The Network does not exist on the host the VM 
is running on.\n Either add the Network to the Host, uncheck the 'Activate' 
checkbox or migrate the VM to a Host that has this Network.
 VM_CANNOT_RUN_FROM_DISK_WITHOUT_PLUGGED_DISK=Cannot ${action} ${type} without 
at least one active disk.\nPlease activate a disk and rerun the VM.
 SHAREABLE_DISK_IS_NOT_SUPPORTED_FOR_DISK=Cannot ${action} ${type}. Disk cannot 
be shareable if it depends on a snapshot. In order to share it, remove the 
disk's snapshots.
 SHAREABLE_DISK_IS_NOT_SUPPORTED_BY_VOLUME_FORMAT=Cannot ${action} ${type}. 
Disk's volume format is not supported for shareable disk.
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 bd49959..a65cec6 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
@@ -689,6 +689,7 @@
 HOT_PLUG_DISK_IS_NOT_UNPLUGGED=Disk is already activated.
 HOT_UNPLUG_DISK_IS_NOT_PLUGGED=Disk is already deactivated.
 PLUG_UNPLUG_NIC_VM_STATUS_ILLEGAL=Cannot activate/deactivate VM Network 
Interface due to VM status. The VM status must be Down or Up.
+PLUG_UNPLUG_NETWORK_NOT_IN_VDS=The Network does not exist on the host the VM 
is running on.\n Either add the Network to the Host, uncheck the 'Activate' 
checkbox or migrate the VM to a Host that has this Network.
 VM_CANNOT_RUN_FROM_DISK_WITHOUT_PLUGGED_DISK=Cannot ${action} ${type} without 
at least one active disk.\nPlease activate a disk and rerun the VM.
 SHAREABLE_DISK_IS_NOT_SUPPORTED_FOR_DISK=Cannot ${action} ${type}. Disk cannot 
be shareable if it depends on a snapshot. In order to share it, remove the 
disk's snapshots.
 SHAREABLE_DISK_IS_NOT_SUPPORTED_BY_VOLUME_FORMAT=Cannot ${action} ${type}. 
Disk's volume format is not supported for shareable disk.


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1ef34503e5232280c506cf6a909fd703e99acb3
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Muli Salem <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to