Skip to content

Commit 12fc2b4

Browse files
author
Boris Schrijver
committed
Added countIPs(long dcId, boolean onlyCountAllocated) to IPAddressDao and IPAddressDaoImpl.
1 parent 473f193 commit 12fc2b4

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎engine/schema/src/com/cloud/network/dao/IPAddressDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
4040

4141
List<IPAddressVO> listStaticNatPublicIps(long networkId);
4242

43+
int countIPs(long dcId, boolean onlyCountAllocated);
44+
4345
int countIPs(long dcId, long vlanDbId, boolean onlyCountAllocated);
4446

4547
int countIPs(long dcId, Long accountId, String vlanId, String vlanGateway, String vlanNetmask);

‎engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
5656
protected SearchBuilder<IPAddressVO> VlanDbIdSearchUnallocated;
5757
protected GenericSearchBuilder<IPAddressVO, Integer> AllIpCount;
5858
protected GenericSearchBuilder<IPAddressVO, Integer> AllocatedIpCount;
59+
protected GenericSearchBuilder<IPAddressVO, Integer> AllocatedIpCountForDc;
5960
protected GenericSearchBuilder<IPAddressVO, Integer> AllIpCountForDashboard;
6061
protected SearchBuilder<IPAddressVO> DeleteAllExceptGivenIp;
6162
protected GenericSearchBuilder<IPAddressVO, Long> AllocatedIpCountForAccount;
@@ -107,6 +108,12 @@ public void init() {
107108
AllocatedIpCount.and("allocated", AllocatedIpCount.entity().getAllocatedTime(), Op.NNULL);
108109
AllocatedIpCount.done();
109110

111+
AllocatedIpCountForDc = createSearchBuilder(Integer.class);
112+
AllocatedIpCountForDc.select(null, Func.COUNT, AllocatedIpCountForDc.entity().getAddress());
113+
AllocatedIpCountForDc.and("dc", AllocatedIpCountForDc.entity().getDataCenterId(), Op.EQ);
114+
AllocatedIpCountForDc.and("allocated", AllocatedIpCountForDc.entity().getAllocatedTime(), Op.NNULL);
115+
AllocatedIpCountForDc.done();
116+
110117
AllIpCountForDashboard = createSearchBuilder(Integer.class);
111118
AllIpCountForDashboard.select(null, Func.COUNT, AllIpCountForDashboard.entity().getAddress());
112119
AllIpCountForDashboard.and("dc", AllIpCountForDashboard.entity().getDataCenterId(), Op.EQ);
@@ -281,6 +288,14 @@ public IPAddressVO findByVmIp(String vmIp) {
281288
return findOneBy(sc);
282289
}
283290

291+
@Override
292+
public int countIPs(long dcId, boolean onlyCountAllocated) {
293+
SearchCriteria<Integer> sc = onlyCountAllocated ? AllocatedIpCount.create() : AllIpCount.create();
294+
sc.setParameters("dc", dcId);
295+
296+
return customSearch(sc, null).get(0);
297+
}
298+
284299
@Override
285300
public int countIPs(long dcId, long vlanId, boolean onlyCountAllocated) {
286301
SearchCriteria<Integer> sc = onlyCountAllocated ? AllocatedIpCount.create() : AllIpCount.create();

0 commit comments

Comments
 (0)