diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java index cb076568b13..fbf5c576855 100644 --- a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java +++ b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java @@ -40,6 +40,8 @@ public interface IPAddressDao extends GenericDao { List listStaticNatPublicIps(long networkId); + int countIPs(long dcId, boolean onlyCountAllocated); + int countIPs(long dcId, long vlanDbId, boolean onlyCountAllocated); int countIPs(long dcId, Long accountId, String vlanId, String vlanGateway, String vlanNetmask); diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java index 5122876adf8..5c8b9b13786 100644 --- a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java @@ -56,6 +56,7 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen protected SearchBuilder VlanDbIdSearchUnallocated; protected GenericSearchBuilder AllIpCount; protected GenericSearchBuilder AllocatedIpCount; + protected GenericSearchBuilder AllocatedIpCountForDc; protected GenericSearchBuilder AllIpCountForDashboard; protected SearchBuilder DeleteAllExceptGivenIp; protected GenericSearchBuilder AllocatedIpCountForAccount; @@ -107,6 +108,12 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen AllocatedIpCount.and("allocated", AllocatedIpCount.entity().getAllocatedTime(), Op.NNULL); AllocatedIpCount.done(); + AllocatedIpCountForDc = createSearchBuilder(Integer.class); + AllocatedIpCountForDc.select(null, Func.COUNT, AllocatedIpCountForDc.entity().getAddress()); + AllocatedIpCountForDc.and("dc", AllocatedIpCountForDc.entity().getDataCenterId(), Op.EQ); + AllocatedIpCountForDc.and("allocated", AllocatedIpCountForDc.entity().getAllocatedTime(), Op.NNULL); + AllocatedIpCountForDc.done(); + AllIpCountForDashboard = createSearchBuilder(Integer.class); AllIpCountForDashboard.select(null, Func.COUNT, AllIpCountForDashboard.entity().getAddress()); AllIpCountForDashboard.and("dc", AllIpCountForDashboard.entity().getDataCenterId(), Op.EQ); @@ -281,6 +288,14 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen return findOneBy(sc); } + @Override + public int countIPs(long dcId, boolean onlyCountAllocated) { + SearchCriteria sc = onlyCountAllocated ? AllocatedIpCount.create() : AllIpCount.create(); + sc.setParameters("dc", dcId); + + return customSearch(sc, null).get(0); + } + @Override public int countIPs(long dcId, long vlanId, boolean onlyCountAllocated) { SearchCriteria sc = onlyCountAllocated ? AllocatedIpCount.create() : AllIpCount.create();