Moti Asayag has uploaded a new change for review.

Change subject: engine: Add VmDao.getAllWithoutNetwork
......................................................................

engine: Add VmDao.getAllWithoutNetwork

Added VmDao.getAllWithoutNetwork to retrieve all of the VMs within
the same data-center on which a network is configured, and none of
the VMs has the network attached to it.

Change-Id: I0cb0c6771efb5b55d1acf1f2471b1e2cbd5f92cb
Signed-off-by: Moti Asayag <[email protected]>
---
M backend/manager/dbscripts/vms_sp.sql
M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
4 files changed, 55 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/41/10341/1

diff --git a/backend/manager/dbscripts/vms_sp.sql 
b/backend/manager/dbscripts/vms_sp.sql
index 89f2904..a8694c8 100644
--- a/backend/manager/dbscripts/vms_sp.sql
+++ b/backend/manager/dbscripts/vms_sp.sql
@@ -887,8 +887,25 @@
 Create or replace FUNCTION GetVmsByDataCenterId(v_data_center_id UUID) RETURNS 
SETOF vms
    AS $procedure$
 BEGIN
-   RETURN QUERY SELECT DISTINCT vms.*
+   RETURN QUERY SELECT vms.*
    FROM vms
-   WHERE storage_pool_id = v_data_center_id;
+   WHERE storage_pool_id = v_data_center_id
+   ORDER BY vm_guid;
 END; $procedure$
 LANGUAGE plpgsql;
+
+
+
+Create or replace FUNCTION GetVmsWithoutNetwork(v_network_id UUID) RETURNS 
SETOF vms
+AS $procedure$
+ BEGIN
+    RETURN QUERY SELECT vms.*
+    FROM vms
+    WHERE NOT EXISTS (
+       SELECT 1
+       FROM vm_interface_ext_view
+       WHERE vm_interface_ext_view.network_id = v_network_id
+       AND vm_interface_ext_view.vm_guid = vms.vm_guid
+       AND vm_interface_ext_view.data_center_id = vms.storage_pool_id);
+ END; $procedure$
+LANGUAGE plpgsql;
\ No newline at end of file
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
index 87bfde2..cce6345 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAO.java
@@ -211,4 +211,13 @@
      * @return the list of VMs
      */
     List<VM> getAllForNetwork(Guid networkId);
+
+    /**
+     * Retrieves all VMs that the given Network is not attached to within the 
same data-center
+     *
+     * @param networkId
+     *            the network
+     * @return the list of VMs
+     */
+    List<VM> getAllWithoutNetwork(Guid networkId);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
index 18cb81f..2d97e3d 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDAODbFacadeImpl.java
@@ -182,6 +182,13 @@
     }
 
     @Override
+    public List<VM> getAllWithoutNetwork(Guid networkId) {
+        return getCallsHandler().executeReadList("GetVmsWithoutNetwork",
+                VMRowMapper.instance,
+                getCustomMapSqlParameterSource().addValue("network_id", 
networkId));
+    }
+
+    @Override
     public void save(VM vm) {
         getCallsHandler().executeModification("InsertVm", 
getCustomMapSqlParameterSource()
                 .addValue("description", vm.getDescription())
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
index e8f24a4..dfe7e47 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDAOTest.java
@@ -3,6 +3,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
@@ -10,9 +11,11 @@
 import java.util.Map;
 
 import org.junit.Test;
+import org.ovirt.engine.core.common.businessentities.Network;
 import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
+import org.ovirt.engine.core.common.businessentities.VmNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.VmStatic;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.compat.Guid;
@@ -357,6 +360,23 @@
         }
     }
 
+    @Test
+    public void testGetAllWithoutNetwork() {
+        List<VM> vms = dao.getAllWithoutNetwork(FixturesTool.NETWORK_ENGINE_2);
+        assertNotNull(vms);
+        assertFalse(vms.isEmpty());
+        assertNetworkNotAttachedToVms(vms, 
getDbFacade().getNetworkDao().get(FixturesTool.NETWORK_ENGINE_2));
+    }
+
+    private void assertNetworkNotAttachedToVms(List<VM> vms, Network network) {
+        for (VM vm : vms) {
+            List<VmNetworkInterface> nics = 
getDbFacade().getVmNetworkInterfaceDao().getAllForVm(vm.getId());
+            for (VmNetworkInterface nic : nics) {
+                assertNotSame(nic.getNetworkName(), network.getName());
+            }
+        }
+    }
+
     private static void assertCorrectGetAllResult(List<VM> result) {
         assertNotNull(result);
         assertFalse(result.isEmpty());


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

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