Gilad Chaplik has uploaded a new change for review.

Change subject: db: aggregate profiles in db and dal
......................................................................

db: aggregate profiles in db and dal

DB and DAL changes: extend vnic_profiles, rename it to profiles, have a type 
field (ProfileType),
all other limits wil be added there (as sparse matrix).

Current vnicProfile dal flows are reused to benefit all future profile types.

For more information see: http://www.ovirt.org/Features/aggregate_QoS

Change-Id: I229af59277b5055453188f002f19046cdd51d63b
Signed-off-by: Gilad Chaplik <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/VnicProfileHelper.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VnicProfileValidatorTest.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java
D 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileDaoDbFacadeImpl.java
D 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoDbFacadeImpl.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/BaseProfilesDaoFacadeImpl.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/BaseVnicProfileDaoDbFacadeImpl.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/ProfilesDao.java
R 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileDao.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileDaoDbFacadeImpl.java
R 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDao.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDaoDbFacadeImpl.java
M backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
R 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/profiles/VnicProfileDaoTest.java
R 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDaoTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
M packaging/dbscripts/create_dwh_views.sql
M packaging/dbscripts/create_functions.sql
M packaging/dbscripts/create_views.sql
M packaging/dbscripts/network_sp.sql
A packaging/dbscripts/profiles_sp.sql
A packaging/dbscripts/upgrade/03_05_0340_aggregate_profiles.sql
M packaging/dbscripts/vm_templates_sp.sql
M packaging/dbscripts/vms_sp.sql
26 files changed, 453 insertions(+), 351 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/99/27099/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/VnicProfileHelper.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/VnicProfileHelper.java
index 415de64..bfffb86 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/VnicProfileHelper.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/VnicProfileHelper.java
@@ -30,8 +30,8 @@
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
 import org.ovirt.engine.core.dao.PermissionDAO;
 import org.ovirt.engine.core.dao.network.NetworkDao;
-import org.ovirt.engine.core.dao.network.VnicProfileDao;
-import org.ovirt.engine.core.dao.network.VnicProfileViewDao;
+import org.ovirt.engine.core.dao.profiles.VnicProfileDao;
+import org.ovirt.engine.core.dao.profiles.VnicProfileViewDao;
 
 public class VnicProfileHelper {
     private Set<String> invalidNetworkNames = new HashSet<>();
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
index c5a0800..f167823 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
@@ -34,7 +34,7 @@
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
-import org.ovirt.engine.core.dao.network.VnicProfileDao;
+import org.ovirt.engine.core.dao.profiles.VnicProfileDao;
 import org.ovirt.engine.core.dao.qos.NetworkQosDao;
 import org.ovirt.engine.core.utils.MockConfigRule;
 
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VnicProfileValidatorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VnicProfileValidatorTest.java
index b1fec7f..a7441b5 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VnicProfileValidatorTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VnicProfileValidatorTest.java
@@ -31,7 +31,7 @@
 import org.ovirt.engine.core.dao.VmDAO;
 import org.ovirt.engine.core.dao.VmTemplateDAO;
 import org.ovirt.engine.core.dao.network.NetworkDao;
-import org.ovirt.engine.core.dao.network.VnicProfileDao;
+import org.ovirt.engine.core.dao.profiles.VnicProfileDao;
 import org.ovirt.engine.core.dao.qos.NetworkQosDao;
 
 @RunWith(MockitoJUnitRunner.class)
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
index 78a70be..5279cb3 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
@@ -119,8 +119,8 @@
 import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
 import org.ovirt.engine.core.dao.network.VmNetworkStatisticsDao;
 import org.ovirt.engine.core.dao.network.VmNicDao;
-import org.ovirt.engine.core.dao.network.VnicProfileDao;
-import org.ovirt.engine.core.dao.network.VnicProfileViewDao;
+import org.ovirt.engine.core.dao.profiles.VnicProfileDao;
+import org.ovirt.engine.core.dao.profiles.VnicProfileViewDao;
 import org.ovirt.engine.core.dao.provider.ProviderDao;
 import org.ovirt.engine.core.dao.qos.NetworkQosDao;
 import org.ovirt.engine.core.dao.scheduling.AffinityGroupDao;
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java
index ce0b246..fb2d43b 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java
@@ -47,7 +47,7 @@
 import org.ovirt.engine.core.dao.network.NetworkDao;
 import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
 import org.ovirt.engine.core.dao.network.VmNicDao;
-import org.ovirt.engine.core.dao.network.VnicProfileDao;
+import org.ovirt.engine.core.dao.profiles.VnicProfileDao;
 import org.ovirt.engine.core.dao.provider.ProviderDao;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileDaoDbFacadeImpl.java
deleted file mode 100644
index bc4a9d0..0000000
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileDaoDbFacadeImpl.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package org.ovirt.engine.core.dao.network;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.LinkedHashMap;
-import java.util.List;
-
-import org.ovirt.engine.core.common.businessentities.profiles.VnicProfile;
-import org.ovirt.engine.core.compat.Guid;
-import org.ovirt.engine.core.dao.DefaultGenericDaoDbFacade;
-import org.ovirt.engine.core.utils.SerializationFactory;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-
-public class VnicProfileDaoDbFacadeImpl extends 
DefaultGenericDaoDbFacade<VnicProfile, Guid> implements VnicProfileDao {
-
-    public VnicProfileDaoDbFacadeImpl() {
-        super("VnicProfile");
-    }
-
-    @Override
-    public List<VnicProfile> getAllForNetwork(Guid networkId) {
-        return getCallsHandler().executeReadList("GetVnicProfilesByNetworkId",
-                VnicProfileRowMapper.INSTANCE,
-                getCustomMapSqlParameterSource().addValue("network_id", 
networkId));
-    }
-
-    @Override
-    protected MapSqlParameterSource createFullParametersMapper(VnicProfile 
profile) {
-        return createIdParameterMapper(profile.getId())
-                .addValue("name", profile.getName())
-                .addValue("network_id", profile.getNetworkId())
-                .addValue("network_qos_id", profile.getQosId())
-                .addValue("port_mirroring", profile.isPortMirroring())
-                .addValue("description", profile.getDescription())
-                .addValue("custom_properties",
-                        
SerializationFactory.getSerializer().serialize(profile.getCustomProperties()));
-    }
-
-    @Override
-    protected MapSqlParameterSource createIdParameterMapper(Guid id) {
-        return getCustomMapSqlParameterSource().addValue("id", id);
-    }
-
-    @Override
-    protected RowMapper<VnicProfile> createEntityRowMapper() {
-        return VnicProfileRowMapper.INSTANCE;
-    }
-
-    static abstract class VnicProfileRowMapperBase<T extends VnicProfile> 
implements RowMapper<T> {
-
-        @Override
-        @SuppressWarnings("unchecked")
-        public T mapRow(ResultSet rs, int rowNum) throws SQLException {
-            T entity = createVnicProfileEntity();
-            entity.setId(getGuid(rs, "id"));
-            entity.setName(rs.getString("name"));
-            entity.setNetworkId(getGuid(rs, "network_id"));
-            entity.setQosId(getGuid(rs, "network_qos_id"));
-            entity.setCustomProperties(SerializationFactory.getDeserializer()
-                    .deserializeOrCreateNew(rs.getString("custom_properties"), 
LinkedHashMap.class));
-            entity.setPortMirroring(rs.getBoolean("port_mirroring"));
-            entity.setDescription(rs.getString("description"));
-            return entity;
-        }
-
-        abstract protected T createVnicProfileEntity();
-    }
-
-    private static class VnicProfileRowMapper extends 
VnicProfileRowMapperBase<VnicProfile> {
-
-        public static final VnicProfileRowMapper INSTANCE = new 
VnicProfileRowMapper();
-
-        @Override
-        protected VnicProfile createVnicProfileEntity() {
-            return new VnicProfile();
-        }
-    }
-}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoDbFacadeImpl.java
deleted file mode 100644
index 5ee03a9..0000000
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoDbFacadeImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.ovirt.engine.core.dao.network;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-import org.ovirt.engine.core.common.businessentities.profiles.VnicProfileView;
-import org.ovirt.engine.core.compat.Guid;
-import org.ovirt.engine.core.compat.Version;
-import org.ovirt.engine.core.dao.DefaultReadDaoDbFacade;
-import 
org.ovirt.engine.core.dao.network.VnicProfileDaoDbFacadeImpl.VnicProfileRowMapperBase;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-
-public class VnicProfileViewDaoDbFacadeImpl extends 
DefaultReadDaoDbFacade<VnicProfileView, Guid> implements VnicProfileViewDao {
-
-    public VnicProfileViewDaoDbFacadeImpl() {
-        super("VnicProfileView");
-
-    }
-
-    @Override
-    public VnicProfileView get(Guid id) {
-        return get(id, null, false);
-    }
-
-    @Override
-    public VnicProfileView get(Guid id, Guid userId, boolean filtered) {
-        return getCallsHandler().executeRead(getProcedureNameForGet(),
-                VnicProfileViewRowMapper.INSTANCE,
-                createIdParameterMapper(id).addValue("user_id", 
userId).addValue("is_filtered", filtered));
-    }
-
-    @Override
-    public List<VnicProfileView> getAll() {
-        return getAll(null, false);
-    }
-
-    @Override
-    public List<VnicProfileView> getAll(Guid userId, boolean filtered) {
-        return getCallsHandler().executeReadList(getProcedureNameForGetAll(),
-                VnicProfileViewRowMapper.INSTANCE,
-                getCustomMapSqlParameterSource().addValue("user_id", 
userId).addValue("is_filtered", filtered));
-    }
-
-    @Override
-    public List<VnicProfileView> getAllForNetwork(Guid networkId) {
-        return getAllForNetwork(networkId, null, false);
-    }
-
-    @Override
-    public List<VnicProfileView> getAllForNetwork(Guid networkId, Guid userId, 
boolean filtered) {
-        return 
getCallsHandler().executeReadList("GetVnicProfileViewsByNetworkId",
-                VnicProfileViewRowMapper.INSTANCE,
-                getCustomMapSqlParameterSource().addValue("network_id", 
networkId)
-                        .addValue("user_id", userId)
-                        .addValue("is_filtered", filtered));
-    }
-
-    @Override
-    public List<VnicProfileView> getAllForDataCenter(Guid id) {
-        return getAllForDataCenter(id, null, false);
-    }
-
-    @Override
-    public List<VnicProfileView> getAllForDataCenter(Guid id, Guid userId, 
boolean filtered) {
-        return 
getCallsHandler().executeReadList("GetVnicProfileViewsByDataCenterId",
-                VnicProfileViewRowMapper.INSTANCE,
-                getCustomMapSqlParameterSource().addValue("id", id)
-                        .addValue("user_id", userId)
-                        .addValue("is_filtered", filtered));
-    }
-
-    @Override
-    protected VnicProfileViewRowMapper createEntityRowMapper() {
-        return VnicProfileViewRowMapper.INSTANCE;
-    }
-
-    @Override
-    protected MapSqlParameterSource createIdParameterMapper(Guid id) {
-        return getCustomMapSqlParameterSource().addValue("id", id);
-    }
-
-    private static class VnicProfileViewRowMapper extends 
VnicProfileRowMapperBase<VnicProfileView> {
-
-        public static final VnicProfileViewRowMapper INSTANCE = new 
VnicProfileViewRowMapper();
-
-        @Override
-        public VnicProfileView mapRow(ResultSet rs, int rowNum) throws 
SQLException {
-            VnicProfileView entity = super.mapRow(rs, rowNum);
-            entity.setNetworkName(rs.getString("network_name"));
-            entity.setNetworkQosName(rs.getString("network_qos_name"));
-            entity.setDataCenterName(rs.getString("data_center_name"));
-            entity.setCompatibilityVersion(new 
Version(rs.getString("compatibility_version")));
-            return entity;
-        }
-
-        @Override
-        protected VnicProfileView createVnicProfileEntity() {
-            return new VnicProfileView();
-        }
-    }
-
-    @Override
-    public List<VnicProfileView> getAllForNetworkQos(Guid qosId) {
-        return 
getCallsHandler().executeReadList("GetVnicProfileViewsByNetworkQosId",
-                VnicProfileViewRowMapper.INSTANCE,
-                getCustomMapSqlParameterSource().addValue("network_qos_id", 
qosId));
-    }
-}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/BaseProfilesDaoFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/BaseProfilesDaoFacadeImpl.java
new file mode 100644
index 0000000..4a2b892
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/BaseProfilesDaoFacadeImpl.java
@@ -0,0 +1,77 @@
+package org.ovirt.engine.core.dao.profiles;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.ovirt.engine.core.common.businessentities.profiles.BaseProfile;
+import org.ovirt.engine.core.common.businessentities.profiles.ProfileType;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.DefaultGenericDaoDbFacade;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+
+public abstract class BaseProfilesDaoFacadeImpl<T extends BaseProfile> extends 
DefaultGenericDaoDbFacade<T, Guid> implements ProfilesDao<T> {
+    protected final RowMapper<T> mapper = createEntityRowMapper();
+    private final ProfileType profileType;
+
+    public BaseProfilesDaoFacadeImpl(ProfileType profileType, String 
entityStoredProcedureName) {
+        super(entityStoredProcedureName);
+        this.profileType = profileType;
+    }
+
+    /**
+     * @param rs
+     * @return specific mapper for derived profile dao
+     * @throws SQLException
+     */
+    protected abstract T createPartialProfileEntity(ResultSet rs) throws 
SQLException;
+
+    /**
+     * @param map
+     * @param obj
+     * @return parameters mapper for derived profile dao
+     */
+    protected abstract void 
updatePartialParametersMapper(MapSqlParameterSource map, T obj);
+
+    /**
+     * @return Profile type for derived Profile dao object
+     */
+    protected ProfileType getProfileType() {
+        return profileType;
+    }
+
+    @Override
+    protected RowMapper<T> createEntityRowMapper() {
+        return new RowMapper<T>() {
+            @Override
+            public T mapRow(ResultSet rs, int rowNum)
+                    throws SQLException {
+                T entity = createPartialProfileEntity(rs);
+                entity.setId(getGuid(rs, "id"));
+                entity.setName(rs.getString("name"));
+                entity.setQosId(getGuid(rs, "qos_id"));
+                entity.setProfileType(profileType);
+                return entity;
+            }
+        };
+    }
+
+    @Override
+    protected MapSqlParameterSource createFullParametersMapper(T obj) {
+        MapSqlParameterSource map = createIdParameterMapper(
+                obj.getId())
+                .addValue("name", obj.getName())
+                .addValue("profile_type", obj.getProfileType())
+                .addValue("qos_id", obj.getQosId())
+                .addValue("description", obj.getDescription());
+        updatePartialParametersMapper(map, obj);
+        return map;
+    }
+
+    @Override
+    protected MapSqlParameterSource createIdParameterMapper(Guid guid) {
+        return getCustomMapSqlParameterSource()
+                .addValue("id", guid);
+    }
+
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/BaseVnicProfileDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/BaseVnicProfileDaoDbFacadeImpl.java
new file mode 100644
index 0000000..75f5edc
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/BaseVnicProfileDaoDbFacadeImpl.java
@@ -0,0 +1,44 @@
+package org.ovirt.engine.core.dao.profiles;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.LinkedHashMap;
+
+import org.ovirt.engine.core.common.businessentities.profiles.ProfileType;
+import org.ovirt.engine.core.common.businessentities.profiles.VnicProfile;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.utils.SerializationFactory;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+
+public abstract class BaseVnicProfileDaoDbFacadeImpl<T extends VnicProfile> 
extends BaseProfilesDaoFacadeImpl<T> {
+    public BaseVnicProfileDaoDbFacadeImpl(String entityStoredProcedureName) {
+        super(ProfileType.VNIC, entityStoredProcedureName);
+    }
+
+    @Override
+    protected MapSqlParameterSource createIdParameterMapper(Guid id) {
+        return getCustomMapSqlParameterSource().addValue("id", id);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    protected T createPartialProfileEntity(ResultSet rs) throws SQLException {
+        T entity = createVnicProfile();
+        entity.setNetworkId(getGuid(rs, "network_id"));
+        entity.setCustomProperties(SerializationFactory.getDeserializer()
+                .deserializeOrCreateNew(rs.getString("custom_properties"), 
LinkedHashMap.class));
+        entity.setPortMirroring(rs.getBoolean("port_mirroring"));
+        return entity;
+    }
+
+    protected abstract T createVnicProfile();
+
+    @Override
+    protected void updatePartialParametersMapper(MapSqlParameterSource map, 
VnicProfile obj) {
+        map.addValue("network_id", obj.getNetworkId())
+                .addValue("port_mirroring", obj.isPortMirroring())
+                .addValue("custom_properties",
+                        
SerializationFactory.getSerializer().serialize(obj.getCustomProperties()));
+    }
+
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/ProfilesDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/ProfilesDao.java
new file mode 100644
index 0000000..a25cdb0
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/ProfilesDao.java
@@ -0,0 +1,5 @@
+package org.ovirt.engine.core.dao.profiles;
+
+public interface ProfilesDao<T> {
+
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileDao.java
similarity index 91%
rename from 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileDao.java
rename to 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileDao.java
index bed2e20..67e5a4d 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileDao.java
@@ -1,4 +1,4 @@
-package org.ovirt.engine.core.dao.network;
+package org.ovirt.engine.core.dao.profiles;
 
 import java.util.List;
 
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileDaoDbFacadeImpl.java
new file mode 100644
index 0000000..572fce3
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileDaoDbFacadeImpl.java
@@ -0,0 +1,25 @@
+package org.ovirt.engine.core.dao.profiles;
+
+import java.util.List;
+
+import org.ovirt.engine.core.common.businessentities.profiles.VnicProfile;
+import org.ovirt.engine.core.compat.Guid;
+
+public class VnicProfileDaoDbFacadeImpl extends 
BaseVnicProfileDaoDbFacadeImpl<VnicProfile> implements VnicProfileDao {
+
+    public VnicProfileDaoDbFacadeImpl() {
+        super("profile");
+    }
+
+    @Override
+    protected VnicProfile createVnicProfile() {
+        return new VnicProfile();
+    }
+
+    @Override
+    public List<VnicProfile> getAllForNetwork(Guid networkId) {
+        return getCallsHandler().executeReadList("GetVnicProfilesByNetworkId",
+                mapper,
+                getCustomMapSqlParameterSource().addValue("network_id", 
networkId));
+    }
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDao.java
similarity index 98%
rename from 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDao.java
rename to 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDao.java
index 7f8afb9..6a056e6 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDao.java
@@ -1,4 +1,4 @@
-package org.ovirt.engine.core.dao.network;
+package org.ovirt.engine.core.dao.profiles;
 
 import java.util.List;
 
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDaoDbFacadeImpl.java
new file mode 100644
index 0000000..4167370
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDaoDbFacadeImpl.java
@@ -0,0 +1,90 @@
+package org.ovirt.engine.core.dao.profiles;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.ovirt.engine.core.common.businessentities.profiles.VnicProfileView;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.compat.Version;
+
+public class VnicProfileViewDaoDbFacadeImpl extends 
BaseVnicProfileDaoDbFacadeImpl<VnicProfileView> implements VnicProfileViewDao {
+
+    public VnicProfileViewDaoDbFacadeImpl() {
+        super("VnicProfileView");
+    }
+
+    @Override
+    public VnicProfileView get(Guid id) {
+        return get(id, null, false);
+    }
+
+    @Override
+    public VnicProfileView get(Guid id, Guid userId, boolean filtered) {
+        return getCallsHandler().executeRead(getProcedureNameForGet(),
+                mapper,
+                createIdParameterMapper(id).addValue("user_id", 
userId).addValue("is_filtered", filtered));
+    }
+
+    @Override
+    public List<VnicProfileView> getAll() {
+        return getAll(null, false);
+    }
+
+    @Override
+    public List<VnicProfileView> getAll(Guid userId, boolean filtered) {
+        return getCallsHandler().executeReadList(getProcedureNameForGetAll(),
+                mapper,
+                getCustomMapSqlParameterSource().addValue("user_id", 
userId).addValue("is_filtered", filtered));
+    }
+
+    @Override
+    public List<VnicProfileView> getAllForNetwork(Guid networkId) {
+        return getAllForNetwork(networkId, null, false);
+    }
+
+    @Override
+    public List<VnicProfileView> getAllForNetwork(Guid networkId, Guid userId, 
boolean filtered) {
+        return 
getCallsHandler().executeReadList("GetVnicProfileViewsByNetworkId",
+                mapper,
+                getCustomMapSqlParameterSource().addValue("network_id", 
networkId)
+                        .addValue("user_id", userId)
+                        .addValue("is_filtered", filtered));
+    }
+
+    @Override
+    public List<VnicProfileView> getAllForDataCenter(Guid id) {
+        return getAllForDataCenter(id, null, false);
+    }
+
+    @Override
+    public List<VnicProfileView> getAllForDataCenter(Guid id, Guid userId, 
boolean filtered) {
+        return 
getCallsHandler().executeReadList("GetVnicProfileViewsByDataCenterId",
+                mapper,
+                getCustomMapSqlParameterSource().addValue("id", id)
+                        .addValue("user_id", userId)
+                        .addValue("is_filtered", filtered));
+    }
+
+    @Override
+    public List<VnicProfileView> getAllForNetworkQos(Guid qosId) {
+        return 
getCallsHandler().executeReadList("GetVnicProfileViewsByNetworkQosId",
+                mapper,
+                getCustomMapSqlParameterSource().addValue("qos_id", qosId));
+    }
+
+    @Override
+    protected VnicProfileView createVnicProfile() {
+        return new VnicProfileView();
+    }
+
+    @Override
+    protected VnicProfileView createPartialProfileEntity(ResultSet rs) throws 
SQLException {
+        VnicProfileView entity = super.createPartialProfileEntity(rs);
+        entity.setNetworkName(rs.getString("network_name"));
+        entity.setNetworkQosName(rs.getString("network_qos_name"));
+        entity.setDataCenterName(rs.getString("data_center_name"));
+        entity.setCompatibilityVersion(new 
Version(rs.getString("compatibility_version")));
+        return entity;
+    }
+}
diff --git 
a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties 
b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
index e8ee8f6..a81d4c8 100644
--- a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
+++ b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
@@ -8,9 +8,9 @@
 AuditLogDAO=org.ovirt.engine.core.dao.AuditLogDAODbFacadeImpl
 InterfaceDao=org.ovirt.engine.core.dao.network.InterfaceDaoDbFacadeImpl
 
VmNetworkInterfaceDao=org.ovirt.engine.core.dao.network.VmNetworkInterfaceDaoDbFacadeImpl
-VnicProfileDao=org.ovirt.engine.core.dao.network.VnicProfileDaoDbFacadeImpl
+VnicProfileDao=org.ovirt.engine.core.dao.profiles.VnicProfileDaoDbFacadeImpl
 VmNicDao=org.ovirt.engine.core.dao.network.VmNicDaoDbFacadeImpl
-VnicProfileViewDao=org.ovirt.engine.core.dao.network.VnicProfileViewDaoDbFacadeImpl
+VnicProfileViewDao=org.ovirt.engine.core.dao.profiles.VnicProfileViewDaoDbFacadeImpl
 
VmNetworkStatisticsDao=org.ovirt.engine.core.dao.network.VmNetworkStatisticsDaoDbFacadeImpl
 LunDAO=org.ovirt.engine.core.dao.LunDAODbFacadeImpl
 RoleGroupMapDAO=org.ovirt.engine.core.dao.RoleGroupMapDAODbFacadeImpl
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VnicProfileDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/profiles/VnicProfileDaoTest.java
similarity index 98%
rename from 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VnicProfileDaoTest.java
rename to 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/profiles/VnicProfileDaoTest.java
index b4cb628..71c8a37 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VnicProfileDaoTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/profiles/VnicProfileDaoTest.java
@@ -1,4 +1,4 @@
-package org.ovirt.engine.core.dao.network;
+package org.ovirt.engine.core.dao.profiles;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -12,7 +12,6 @@
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dao.BaseDAOTestCase;
 import org.ovirt.engine.core.dao.FixturesTool;
-
 
 public class VnicProfileDaoTest extends BaseDAOTestCase {
 
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDaoTest.java
similarity index 98%
rename from 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoTest.java
rename to 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDaoTest.java
index 6043867..1a6eff7 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/profiles/VnicProfileViewDaoTest.java
@@ -1,4 +1,4 @@
-package org.ovirt.engine.core.dao.network;
+package org.ovirt.engine.core.dao.profiles;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index 27106df..82f25ad 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -1048,11 +1048,12 @@
         </row>
     </table>
 
-    <table name="vnic_profiles">
+    <table name="profiles">
         <column>id</column>
+        <column>profile_type</column>
         <column>name</column>
         <column>network_id</column>
-        <column>network_qos_id</column>
+        <column>qos_id</column>
         <column>port_mirroring</column>
         <column>custom_properties</column>
         <column>description</column>
@@ -1060,6 +1061,7 @@
         <column>_update_date</column>
         <row>
             <value>fd81f1e1-785b-4579-ab75-1419ebb87052</value>
+            <value>0</value>
             <value>engine_profile</value>
             <value>58d5c1c6-cb15-4832-b2a4-023770607188</value>
             <value>ae956031-6be2-43d6-bb90-5191c9253314</value>
@@ -1071,6 +1073,7 @@
         </row>
         <row>
             <value>a667da39-27b0-47ec-a5fa-d4293a62b222</value>
+            <value>0</value>
             <value>engine_profile_pm</value>
             <value>58d5c1c6-cb15-4832-b2a4-023770607188</value>
             <value>ae956031-6be2-43d6-bb90-5191c9253315</value>
@@ -1082,6 +1085,7 @@
         </row>
         <row>
             <value>d0f2ca62-f564-447c-aa55-ce2aa12ea798</value>
+            <value>0</value>
             <value>engine2_profile</value>
             <value>58d5c1c6-cb15-4832-b2a4-023770607189</value>
             <null />
@@ -1092,6 +1096,7 @@
         </row>
         <row>
             <value>471b199e-9454-47a1-85dd-4461f665abc5</value>
+            <value>0</value>
             <value>engine3_profile</value>
             <value>58d5c1c6-cb15-4832-b2a4-023770607190</value>
             <null />
@@ -1102,6 +1107,7 @@
         </row>
         <row>
             <value>2b75e023-a1fb-4dcb-9738-0ec7fe2d51c6</value>
+            <value>0</value>
             <value>engine4_profile</value>
             <value>58d5c1c6-cb15-4832-b2a4-023770607191</value>
             <value>ae956031-6be2-43d6-bb90-5191c9253314</value>
diff --git a/packaging/dbscripts/create_dwh_views.sql 
b/packaging/dbscripts/create_dwh_views.sql
index de43633..85f9cc2 100644
--- a/packaging/dbscripts/create_dwh_views.sql
+++ b/packaging/dbscripts/create_dwh_views.sql
@@ -297,8 +297,9 @@
             vm_interface._create_date AS create_date,
             vm_interface._update_date AS update_date
 FROM        vm_interface
-            LEFT OUTER JOIN (vnic_profiles JOIN network ON network.id = 
vnic_profiles.network_id)
-            ON vnic_profiles.id = vm_interface.vnic_profile_id
+            -- vnic type = 0 
+            LEFT OUTER JOIN (profiles JOIN network ON profile_type=0 AND 
network.id = profiles.network_id)
+            ON profiles.id = vm_interface.vnic_profile_id
 WHERE     vmt_guid IS NULL AND
           ((vm_interface._create_date >
                           (SELECT     var_datetime
diff --git a/packaging/dbscripts/create_functions.sql 
b/packaging/dbscripts/create_functions.sql
index 9d92dae..80d23df 100644
--- a/packaging/dbscripts/create_functions.sql
+++ b/packaging/dbscripts/create_functions.sql
@@ -290,9 +290,9 @@
        WHEN v_entity_type = 27 THEN -- VNICProfile
 
         SELECT INTO v_profile_network_id
-                    vnic_profiles.network_id
-        FROM vnic_profiles
-        WHERE vnic_profiles.id = v_entity_id;
+                    profiles.network_id
+        FROM profiles
+        WHERE profiles.id = v_entity_id;
         SELECT INTO v_storage_pool_id
                     network.storage_pool_id
         FROM network
@@ -553,7 +553,7 @@
     WHEN v_entity_type = 25 THEN
         result := ( SELECT service_name FROM gluster_services where id = 
v_entity_id );
     WHEN v_entity_type = 27 THEN
-        result := ( SELECT name FROM vnic_profiles where id = v_entity_id );
+        result := ( SELECT name FROM profiles where id = v_entity_id );
     ELSE
         result := 'Unknown type ' ||  v_entity_type;
     END CASE;
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index cb6cd13..8a5e838 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -918,25 +918,26 @@
       vm_interface_statistics.tx_drop, vm_interface_statistics.iface_status, 
vm_interface.type, vm_interface.speed,
       vm_interface.mac_addr, network.name AS network_name, vm_interface.name, 
vm_interface.vnic_profile_id, vm_static.vm_guid, vm_interface.vmt_guid,
       vm_static.vm_name, vm_interface.id, 0 AS boot_protocol, 0 AS is_vds, 
vm_device.is_plugged,
-      vm_device.custom_properties, vnic_profiles.port_mirroring AS 
port_mirroring, vm_interface.linked,
-      vm_static.vds_group_id AS vds_group_id, vm_static.entity_type AS 
vm_entity_type, vnic_profiles.name AS vnic_profile_name
+      vm_device.custom_properties, profiles.port_mirroring AS port_mirroring, 
vm_interface.linked,
+      vm_static.vds_group_id AS vds_group_id, vm_static.entity_type AS 
vm_entity_type, profiles.name AS vnic_profile_name
   FROM vm_interface_statistics
   JOIN vm_interface ON vm_interface_statistics.id = vm_interface.id
   JOIN vm_static ON vm_interface.vm_guid = vm_static.vm_guid
   JOIN vm_device ON vm_interface.vm_guid = vm_device.vm_id AND vm_interface.id 
= vm_device.device_id
-  LEFT JOIN (vnic_profiles JOIN network ON network.id = 
vnic_profiles.network_id) ON vnic_profiles.id = vm_interface.vnic_profile_id
+  -- vnic type = 0
+  LEFT JOIN (profiles JOIN network ON (profiles.profile_type = 0 AND 
network.id = profiles.network_id)) ON (profiles.profile_type = 0 AND 
profiles.id = vm_interface.vnic_profile_id)
   UNION
   SELECT vm_interface_statistics.rx_rate, vm_interface_statistics.tx_rate, 
vm_interface_statistics.rx_drop,
       vm_interface_statistics.tx_drop, vm_interface_statistics.iface_status, 
vm_interface.type, vm_interface.speed,
       vm_interface.mac_addr, network.name AS network_name, vm_interface.name, 
vm_interface.vnic_profile_id, NULL::uuid as vm_guid,
       vm_interface.vmt_guid, vm_templates.vm_name AS vm_name, vm_interface.id, 
0 AS boot_protocol, 0 AS is_vds,
-      vm_device.is_plugged as is_plugged, vm_device.custom_properties as 
custom_properties, vnic_profiles.port_mirroring AS port_mirroring,
-      vm_interface.linked, vm_templates.vds_group_id AS vds_group_id, 
vm_templates.entity_type AS vm_entity_type, vnic_profiles.name AS 
vnic_profile_name
+      vm_device.is_plugged as is_plugged, vm_device.custom_properties as 
custom_properties, profiles.port_mirroring AS port_mirroring,
+      vm_interface.linked, vm_templates.vds_group_id AS vds_group_id, 
vm_templates.entity_type AS vm_entity_type, profiles.name AS vnic_profile_name
   FROM vm_interface_statistics
   RIGHT JOIN vm_interface ON vm_interface_statistics.id = vm_interface.id
   JOIN vm_static AS vm_templates ON vm_interface.vmt_guid = 
vm_templates.vm_guid
   JOIN vm_device ON vm_interface.vmt_guid = vm_device.vm_id AND 
vm_interface.id = vm_device.device_id
-  LEFT JOIN (vnic_profiles JOIN network ON network.id = 
vnic_profiles.network_id) ON vnic_profiles.id = vm_interface.vnic_profile_id;
+  LEFT JOIN (profiles JOIN network ON (profiles.profile_type = 0 AND 
network.id = profiles.network_id)) ON (profiles.profile_type = 0 AND 
profiles.id = vm_interface.vnic_profile_id);
 
 
 
@@ -1188,23 +1189,23 @@
 
 CREATE OR REPLACE VIEW vnic_profiles_view
 AS
-SELECT vnic_profiles.id AS id,
-       vnic_profiles.name AS name,
-       vnic_profiles.network_id as network_id,
-       vnic_profiles.network_qos_id as network_qos_id,
-       vnic_profiles.port_mirroring as port_mirroring,
-       vnic_profiles.custom_properties as custom_properties,
-       vnic_profiles.description as description,
+SELECT profiles.id AS id,
+       profiles.name AS name,
+       profiles.network_id as network_id,
+       profiles.qos_id as qos_id,
+       profiles.port_mirroring as port_mirroring,
+       profiles.custom_properties as custom_properties,
+       profiles.description as description,
        network.name as network_name,
        qos.name as network_qos_name,
        storage_pool.name as data_center_name,
        storage_pool.compatibility_version as compatibility_version,
        storage_pool.id as data_center_id
-FROM vnic_profiles
-
-INNER JOIN network ON vnic_profiles.network_id = network.id
+FROM profiles
 -- 0 = network QoS type
-LEFT JOIN qos ON (vnic_profiles.network_qos_id = qos.id AND qos.qos_type = 0)
+INNER JOIN network ON (profiles.profile_type = 0 AND profiles.network_id = 
network.id)
+-- 0 = network QoS type
+LEFT JOIN qos ON (profiles.qos_id = qos.id AND qos.qos_type = 0)
 INNER JOIN storage_pool ON network.storage_pool_id = storage_pool.id;
 
 
@@ -1549,22 +1550,22 @@
 WHERE      object_type_id = 27 AND role_type = 2
 -- Or the user has permissions on the Network in which the profile belongs to
 UNION ALL
-SELECT     vnic_profiles.id, ad_element_id
-FROM       vnic_profiles
+SELECT     profiles.id, ad_element_id
+FROM       profiles
 INNER JOIN internal_permissions_view ON object_id = network_id
 WHERE      object_type_id = 20 AND allows_viewing_children AND role_type = 2
 -- Or the user has permissions on the Profile-Network's Data-Center directly
 UNION ALL
-SELECT     vnic_profiles.id, ad_element_id
-FROM       vnic_profiles
+SELECT     profiles.id, ad_element_id
+FROM       profiles
 INNER JOIN network ON network.id = network_id
 INNER JOIN internal_permissions_view ON object_id = network.storage_pool_id
 WHERE      object_type_id = 14 AND role_type = 2 AND allows_viewing_children
 -- Or the user has permissions on the Cluster the networks are assigned to
 UNION ALL
-SELECT     vnic_profiles.id, ad_element_id
-FROM       vnic_profiles
-INNER JOIN network_cluster ON network_cluster.network_id = 
vnic_profiles.network_id
+SELECT     profiles.id, ad_element_id
+FROM       profiles
+INNER JOIN network_cluster ON network_cluster.network_id = profiles.network_id
 INNER JOIN internal_permissions_view ON object_id = network_cluster.cluster_id
 WHERE      object_type_id = 9 AND role_type = 2 AND allows_viewing_children
 --Or the user has permissions on the VM with this profile
@@ -1581,9 +1582,9 @@
 WHERE object_type_id = 4 AND role_type = 2
 -- Or the user has permissions on system
 UNION ALL
-SELECT     vnic_profiles.id, ad_element_id
+SELECT     profiles.id, ad_element_id
 FROM       internal_permissions_view
-CROSS JOIN vnic_profiles
+CROSS JOIN profiles
 WHERE      object_type_id = 1 AND allows_viewing_children AND role_type = 2;
 
 CREATE OR REPLACE VIEW user_vnic_profile_permissions_view (entity_id, user_id)
@@ -1598,8 +1599,8 @@
 -- Or the user has permissions on one of the Network's VNIC Profiles
 SELECT     network.id, user_id
 FROM       network
-INNER JOIN vnic_profiles ON network_id = network.id
-INNER JOIN user_vnic_profile_permissions_view ON entity_id = vnic_profiles.id;
+INNER JOIN profiles ON network_id = network.id
+INNER JOIN user_vnic_profile_permissions_view ON entity_id = profiles.id;
 
 CREATE OR REPLACE VIEW user_network_permissions_view (entity_id, user_id)
 AS
diff --git a/packaging/dbscripts/network_sp.sql 
b/packaging/dbscripts/network_sp.sql
index 5a26e41..5b8fe8e 100644
--- a/packaging/dbscripts/network_sp.sql
+++ b/packaging/dbscripts/network_sp.sql
@@ -591,9 +591,11 @@
 BEGIN
    RETURN QUERY SELECT vm_interface.*
    FROM vm_interface
-   INNER JOIN vnic_profiles ON vm_interface.vnic_profile_id = vnic_profiles.id
+   INNER JOIN profiles ON vm_interface.vnic_profile_id = profiles.id
    INNER JOIN vm_static on vm_interface.vm_guid = vm_static.vm_guid
-   WHERE vnic_profiles.network_id = v_network_id
+   -- vnic type = 0
+   WHERE profiles.profile_type = 0
+   AND profiles.network_id = v_network_id
    AND vm_static.entity_type = 'VM';
 END; $procedure$
 LANGUAGE plpgsql;
@@ -605,8 +607,10 @@
    RETURN QUERY SELECT vm_interface.*
    FROM vm_interface
    INNER JOIN vm_static on vm_interface.vmt_guid = vm_static.vm_guid
-   INNER JOIN vnic_profiles ON vm_interface.vnic_profile_id = vnic_profiles.id
-   WHERE vnic_profiles.network_id = v_network_id
+   INNER JOIN profiles ON vm_interface.vnic_profile_id = profiles.id
+   -- vnic type = 0
+   WHERE profiles.profile_type = 0
+   AND profiles.network_id = v_network_id
    AND vm_static.entity_type  = 'TEMPLATE';
 END; $procedure$
 LANGUAGE plpgsql;
@@ -696,8 +700,10 @@
 BEGIN
    RETURN QUERY SELECT vm_interface_view.*
    FROM vm_interface_view
-   INNER JOIN vnic_profiles ON vnic_profiles.id = 
vm_interface_view.vnic_profile_id
-   WHERE vnic_profiles.network_id = v_network_id
+   INNER JOIN profiles ON profiles.id = vm_interface_view.vnic_profile_id
+   -- vnic type = 0
+   WHERE profiles.profile_type = 0
+   AND profiles.network_id = v_network_id
    AND vm_interface_view.vm_entity_type = 'VM';
 END; $procedure$
 LANGUAGE plpgsql;
@@ -708,8 +714,10 @@
 BEGIN
    RETURN QUERY SELECT vm_interface_view.*
    FROM vm_interface_view
-   INNER JOIN vnic_profiles ON vnic_profiles.id = 
vm_interface_view.vnic_profile_id
-   WHERE vnic_profiles.network_id = v_network_id
+   INNER JOIN profiles ON profiles.id = vm_interface_view.vnic_profile_id
+   -- vnic type = 0
+   WHERE profiles.profile_type = 0
+   AND profiles.network_id = v_network_id
    AND vm_interface_view.vm_entity_type = 'TEMPLATE';
 END; $procedure$
 LANGUAGE plpgsql;
@@ -1086,104 +1094,6 @@
 
 
 ----------------------------------------------------------------------
---  Vnic Profile
-----------------------------------------------------------------------
-
-Create or replace FUNCTION GetVnicProfileByVnicProfileId(v_id UUID)
-RETURNS SETOF vnic_profiles STABLE
-   AS $procedure$
-BEGIN
-
-   RETURN QUERY SELECT *
-   FROM vnic_profiles
-   WHERE id = v_id;
-
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-Create or replace FUNCTION InsertVnicProfile(v_id UUID,
-  v_name VARCHAR(50),
-  v_network_id UUID,
-  v_network_qos_id UUID,
-  v_port_mirroring BOOLEAN,
-  v_custom_properties TEXT,
-  v_description TEXT)
-RETURNS VOID
-   AS $procedure$
-BEGIN
-
-   INSERT INTO vnic_profiles(id, name, network_id, network_qos_id, 
port_mirroring, custom_properties, description)
-       VALUES(v_id, v_name, v_network_id, v_network_qos_id, v_port_mirroring, 
v_custom_properties, v_description);
-
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-Create or replace FUNCTION UpdateVnicProfile(v_id UUID,
-  v_name VARCHAR(50),
-  v_network_id UUID,
-  v_network_qos_id UUID,
-  v_port_mirroring BOOLEAN,
-  v_custom_properties TEXT,
-  v_description TEXT)
-RETURNS VOID
-   AS $procedure$
-BEGIN
-
-   UPDATE vnic_profiles
-   SET id = v_id, name = v_name, network_id = v_network_id, network_qos_id = 
v_network_qos_id,
-   port_mirroring = v_port_mirroring, custom_properties = v_custom_properties,
-   description = v_description,_update_date = LOCALTIMESTAMP
-   WHERE id = v_id;
-
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-Create or replace FUNCTION DeleteVnicProfile(v_id UUID)
-RETURNS VOID
-   AS $procedure$
-   DECLARE
-   v_val UUID;
-BEGIN
-
-    DELETE FROM vnic_profiles
-    WHERE id = v_id;
-
-    -- Delete the vnic profiles permissions
-    DELETE FROM permissions WHERE object_id = v_id;
-
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-Create or replace FUNCTION GetAllFromVnicProfiles()
-RETURNS SETOF vnic_profiles STABLE
-   AS $procedure$
-BEGIN
-
-   RETURN QUERY SELECT *
-   FROM vnic_profiles;
-
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-Create or replace FUNCTION GetVnicProfilesByNetworkId(v_network_id UUID)
-RETURNS SETOF vnic_profiles STABLE
-   AS $procedure$
-BEGIN
-
-   RETURN QUERY SELECT *
-   FROM vnic_profiles
-   WHERE network_id = v_network_id;
-
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-----------------------------------------------------------------------
 --  Vnic Profile View
 ----------------------------------------------------------------------
 Create or replace FUNCTION GetVnicProfileViewByVnicProfileViewId(v_id UUID, 
v_user_id uuid, v_is_filtered boolean)
@@ -1285,7 +1195,7 @@
     select option_value into v_old_name from vdc_options where option_name = 
'ManagementNetwork' and version = 'general';
     perform fn_db_update_config_value('ManagementNetwork', v_name, 'general');
     update network set name = v_name where name = v_old_name;
-    update vnic_profiles set name = v_name where name = v_old_name;
+    update profiles set name = v_name where name = v_old_name;
 END; $procedure$
 LANGUAGE plpgsql;
 
diff --git a/packaging/dbscripts/profiles_sp.sql 
b/packaging/dbscripts/profiles_sp.sql
new file mode 100644
index 0000000..0f0ba3c
--- /dev/null
+++ b/packaging/dbscripts/profiles_sp.sql
@@ -0,0 +1,100 @@
+----------------------------------------------------------------------
+--  Profiles
+----------------------------------------------------------------------
+
+Create or replace FUNCTION GetProfileByProfileId(v_id UUID)
+RETURNS SETOF profiles STABLE
+   AS $procedure$
+BEGIN
+
+   RETURN QUERY SELECT *
+   FROM profiles
+   WHERE id = v_id;
+
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION InsertProfile(v_id UUID,
+  v_profile_type SMALLINT,
+  v_name VARCHAR(50),
+  v_network_id UUID,
+  v_qos_id UUID,
+  v_port_mirroring BOOLEAN,
+  v_custom_properties TEXT,
+  v_description TEXT)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+
+   INSERT INTO profiles(id, profile_type, name, network_id, qos_id, 
port_mirroring, custom_properties, description)
+       VALUES(v_id, v_profile_type, v_name, v_network_id, v_qos_id, 
v_port_mirroring, v_custom_properties, v_description);
+
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION UpdateProfile(v_id UUID,
+  v_profile_type SMALLINT,
+  v_name VARCHAR(50),
+  v_network_id UUID,
+  v_qos_id UUID,
+  v_port_mirroring BOOLEAN,
+  v_custom_properties TEXT,
+  v_description TEXT)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+
+   UPDATE profiles
+   SET id = v_id, profile_type = v_profile_type, name = v_name, network_id = 
v_network_id,
+   qos_id = v_qos_id, port_mirroring = v_port_mirroring, custom_properties = 
v_custom_properties,
+   description = v_description,_update_date = LOCALTIMESTAMP
+   WHERE id = v_id;
+
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION DeleteProfile(v_id UUID)
+RETURNS VOID
+   AS $procedure$
+   DECLARE
+   v_val UUID;
+BEGIN
+
+    DELETE FROM profiles
+    WHERE id = v_id;
+
+    -- Delete the profiles permissions
+    DELETE FROM permissions WHERE object_id = v_id;
+
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetAllFromProfiles()
+RETURNS SETOF profiles STABLE
+   AS $procedure$
+BEGIN
+
+   RETURN QUERY SELECT *
+   FROM profiles;
+
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetVnicProfilesByNetworkId(v_network_id UUID)
+RETURNS SETOF profiles STABLE
+   AS $procedure$
+BEGIN
+
+   RETURN QUERY SELECT *
+   FROM profiles
+   -- vnic type = 0
+   WHERE profile_type = 0 AND network_id = v_network_id;
+
+END; $procedure$
+LANGUAGE plpgsql;
+
diff --git a/packaging/dbscripts/upgrade/03_05_0340_aggregate_profiles.sql 
b/packaging/dbscripts/upgrade/03_05_0340_aggregate_profiles.sql
new file mode 100644
index 0000000..87454cb
--- /dev/null
+++ b/packaging/dbscripts/upgrade/03_05_0340_aggregate_profiles.sql
@@ -0,0 +1,28 @@
+-- for more details see http://www.ovirt.org/Features/aggregate_QoS
+
+-- add type column (default is vnic (0))
+ALTER TABLE vnic_profiles ADD profile_type SMALLINT NOT NULL DEFAULT 0;
+-- rename qos column
+ALTER TABLE vnic_profiles RENAME COLUMN network_qos_id TO qos_id;
+-- rename table
+ALTER TABLE vnic_profiles RENAME TO profiles;
+-- drop index, and create a better one
+DROP INDEX idx_vnic_profiles_network_id;
+CREATE UNIQUE INDEX CONCURRENTLY idx_profiles_network_id ON profiles (id);
+-- TODO: ALTER INDEX idx_vnic_profiles_network_id RENAME TO 
idx_profiles_network_id;
+-- rename table constraints (drop + add)
+ALTER TABLE vm_interface DROP CONSTRAINT fk_vm_interface_vnic_profile_id;
+ALTER TABLE profiles DROP CONSTRAINT pk_vnic_profiles_id;
+ALTER TABLE profiles DROP CONSTRAINT fk_vnic_profiles_network_qos_id;
+ALTER TABLE profiles DROP CONSTRAINT vnic_profiles_network_id_fkey;
+ALTER TABLE profiles ADD CONSTRAINT pk_profiles_id PRIMARY KEY USING INDEX 
idx_profiles_network_id;
+ALTER TABLE vm_interface ADD CONSTRAINT fk_vm_interface_vnic_profile_id 
FOREIGN KEY (vnic_profile_id)
+  REFERENCES profiles (id) MATCH SIMPLE
+  ON UPDATE NO ACTION ON DELETE SET NULL;
+ALTER TABLE profiles ADD CONSTRAINT fk_profiles_qos_id FOREIGN KEY (qos_id)
+  REFERENCES qos (id) MATCH SIMPLE
+  ON UPDATE NO ACTION ON DELETE SET NULL;
+ALTER TABLE profiles ADD CONSTRAINT fk_profiles_network_id FOREIGN KEY 
(network_id)
+  REFERENCES network (id) MATCH SIMPLE
+  ON UPDATE NO ACTION ON DELETE CASCADE;
+
diff --git a/packaging/dbscripts/vm_templates_sp.sql 
b/packaging/dbscripts/vm_templates_sp.sql
index 8f795f1..7b17e29 100644
--- a/packaging/dbscripts/vm_templates_sp.sql
+++ b/packaging/dbscripts/vm_templates_sp.sql
@@ -479,9 +479,11 @@
    WHERE EXISTS (
       SELECT 1
       FROM vm_interface
-      INNER JOIN vnic_profiles
-      ON vnic_profiles.id = vm_interface.vnic_profile_id
-      WHERE vnic_profiles.network_id = v_network_id
+      INNER JOIN profiles
+      ON profiles.id = vm_interface.vnic_profile_id
+      -- vnic type = 0
+      WHERE profiles.profile_type = 0
+      AND profiles.network_id = v_network_id
       AND vm_interface.vmt_guid = vm_templates_view.vmt_guid);
 END; $procedure$
 LANGUAGE plpgsql;
diff --git a/packaging/dbscripts/vms_sp.sql b/packaging/dbscripts/vms_sp.sql
index b751d7a..5009f70 100644
--- a/packaging/dbscripts/vms_sp.sql
+++ b/packaging/dbscripts/vms_sp.sql
@@ -1140,9 +1140,11 @@
    WHERE EXISTS (
       SELECT 1
       FROM vm_interface
-      INNER JOIN vnic_profiles
-      ON vnic_profiles.id = vm_interface.vnic_profile_id
-      WHERE vnic_profiles.network_id = v_network_id
+      INNER JOIN profiles
+      ON profiles.id = vm_interface.vnic_profile_id
+      -- vnic type = 0
+      WHERE profiles.profile_type = 0
+      AND profiles.network_id = v_network_id
       AND vm_interface.vm_guid = vms.vm_guid);
 END; $procedure$
 LANGUAGE plpgsql;


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

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

Reply via email to