Muli Salem has uploaded a new change for review.

Change subject: core: Allow Non-Required Networks Not On Host (Do not submit)
......................................................................

core: Allow Non-Required Networks Not On Host (Do not submit)

This patch adds the ConfigValue
OnlyRequiredNetworksMandatoryForVdsSelection. When set
to true, it allows selecting a Vds for running a VM, even if
a Non-Required Network that is on an active vNic of the VM,
is not attached to any Host Nic. When set to false, does not
change behaviour.

Signed-off-by: Muli Salem <msa...@redhat.com>
Change-Id: I4909a658bf729d839c9f01268f1295e43391a2c3
---
M backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsSelector.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
3 files changed, 39 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/92/7992/1

diff --git a/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql 
b/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
index 37b0b8e..1fe0e89 100644
--- a/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
+++ b/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
@@ -49,6 +49,7 @@
 select 
fn_db_add_config_value('AsyncTaskZombieTaskLifeInMinutes','300','general');
 select fn_db_add_config_value('AuditLogAgingThreashold','30','general');
 select fn_db_add_config_value('AuditLogCleanupTime','03:35:35','general');
+select 
fn_db_add_config_value('OnlyRequiredNetworksMandatoryForVdsSelection','false','general');
 --Handling Authentication Method
 select fn_db_add_config_value('AuthenticationMethod','LDAP','general');
 select fn_db_add_config_value('AutoMode','PerServer','general');
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsSelector.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsSelector.java
index f1adef0..de0be5c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsSelector.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsSelector.java
@@ -3,10 +3,12 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.common.businessentities.Entities;
 import org.ovirt.engine.core.common.businessentities.MigrationSupport;
+import org.ovirt.engine.core.common.businessentities.Network;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.VDSType;
@@ -22,7 +24,9 @@
 import org.ovirt.engine.core.dal.VdcBllMessages;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dao.InterfaceDAO;
+import org.ovirt.engine.core.dao.NetworkDAO;
 import org.ovirt.engine.core.dao.VmNetworkInterfaceDAO;
+import org.ovirt.engine.core.utils.NetworkUtils;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 
@@ -260,7 +264,7 @@
             sb.append("swap value is illegal");
             return new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_VDS_VM_SWAP);
         }
-        else if (!areRequiredNetworksAvailable(vds.getId())) {
+        else if (!areRequiredNetworksAvailable(vds)) {
             sb.append("is missing networks required by VM nics 
").append(Entities.interfacesByNetworkName(getVmNICs())
                     .keySet());
             return new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_VDS_VM_NETWORKS);
@@ -331,19 +335,25 @@
     }
 
     /**
-     * Determine whether all required Networks are attached to the Host's 
Nics. Required Networks are the Networks that
-     * are defined on active vNics of the VM.
-     *
+     * Determine whether all required Networks are attached to the Host's 
Nics. A required Network is defined as:
+     * Depending on ConfigValue.OnlyRequiredNetworksMandatoryForVdsSelection: 
1. false: any network that is defined on
+     * an Active vNic of the VM. 2. true: a Cluster-Required Network that is 
defined on an Active vNic of the VM.
      * @param vdsId
      *            The Host id.
      * @return <code>true</code> if all required Networks are attached to a 
Host Nic, otherwise, <code>false</code>.
      */
-    boolean areRequiredNetworksAvailable(Guid vdsId) {
-        final List<VdsNetworkInterface> allInterfacesForVds = 
getInterfaceDAO().getAllInterfacesForVds(vdsId);
+    boolean areRequiredNetworksAvailable(VDS vds) {
+        final List<VdsNetworkInterface> allInterfacesForVds = 
getInterfaceDAO().getAllInterfacesForVds(vds.getId());
+        final List<Network> clusterNetworks = 
getNetworkDAO().getAllForCluster(vds.getvds_group_id());
+        final Map<String, Network> networksByName = 
NetworkUtils.networksByName(clusterNetworks);
+
+        boolean onlyRequiredNetworks =
+                Config.<Boolean> 
GetValue(ConfigValues.OnlyRequiredNetworksMandatoryForVdsSelection);
         for (final VmNetworkInterface vmIf : getVmNICs()) {
             boolean found = false;
             for (final VdsNetworkInterface vdsIf : allInterfacesForVds) {
-                if (!vmIf.isActive() || 
StringUtils.equals(vmIf.getNetworkName(), vdsIf.getNetworkName())) {
+                if (!networkRequiredOnVds(vmIf, networksByName, 
onlyRequiredNetworks)
+                        || StringUtils.equals(vmIf.getNetworkName(), 
vdsIf.getNetworkName())) {
                     found = true;
                     break;
                 }
@@ -355,6 +365,22 @@
         return true;
     }
 
+    private NetworkDAO getNetworkDAO() {
+        return DbFacade.getInstance().getNetworkDAO();
+    }
+
+    private boolean networkRequiredOnVds(VmNetworkInterface vmIf,
+            Map<String, Network> networksByName,
+            boolean onlyRequiredNetworks) {
+        boolean networkRequiredOnVds = true;
+        if (!vmIf.isActive()) {
+            networkRequiredOnVds = false;
+        } else if (onlyRequiredNetworks) {
+            networkRequiredOnVds = 
networksByName.get(vmIf.getNetworkName()).getCluster().isRequired();
+        }
+        return networkRequiredOnVds;
+    }
+
     VmNetworkInterfaceDAO getVmNetworkInterfaceDAO() {
         return DbFacade.getInstance().getVmNetworkInterfaceDAO();
     }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
index d2c1a66..64c1695 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
@@ -1508,6 +1508,11 @@
     @TypeConverterAttribute(String.class)
     @DefaultValueAttribute("")
     IPTablesConfigForGluster(388),
+    
+    @Reloadable
+    @TypeConverterAttribute(Boolean.class)
+    @DefaultValueAttribute("false")
+    OnlyRequiredNetworksMandatoryForVdsSelection(384),
 
     Invalid(65535);
 


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

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

Reply via email to