Skip to content

Commit 5dcded2

Browse files
bvbharatJayapal
authored andcommitted
Cloudstack-4015 No error logged when deleteing all the valns when there are allocateed vnets. Alos not updating the vnet range in physicalnetworks table in the above case.
Signed-off-by: Jayapal <jayapal@apache.org>
1 parent c0e7186 commit 5dcded2

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎engine/schema/src/com/cloud/dc/dao/DataCenterVnetDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ public interface DataCenterVnetDao extends GenericDao<DataCenterVnetVO, Long> {
4848
public int countVnetsDedicatedToAccount(long dcId, long accountId);
4949

5050
List<String> listVnetsByPhysicalNetworkAndDataCenter(long dcId, long physicalNetworkId);
51+
52+
int countAllocatedVnets(long physicalNetworkId);
5153
}

‎engine/schema/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public List<DataCenterVnetVO> listAllocatedVnets(long physicalNetworkId) {
7474
return listBy(sc);
7575
}
7676

77+
@Override
78+
public int countAllocatedVnets(long physicalNetworkId){
79+
SearchCriteria<DataCenterVnetVO> sc = DcSearchAllocated.create();
80+
sc.setParameters("physicalNetworkId", physicalNetworkId);
81+
return listBy(sc).size();
82+
}
7783
public List<DataCenterVnetVO> listAllocatedVnetsInRange(long dcId, long physicalNetworkId, Integer start, Integer end) {
7884
SearchCriteria<DataCenterVnetVO> sc = DcSearchAllocatedInRange.create();
7985
sc.setParameters("dc",dcId);

‎server/src/com/cloud/network/NetworkServiceImpl.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,10 @@ private List<String> getVnetsToremove(PhysicalNetworkVO network, List<Pair<Integ
27142714
if (vnetRanges.size() == 0) {
27152715
//this implies remove all vlans.
27162716
removeVnets.addAll(vnetsInDb);
2717+
int allocated_vnets = _datacneter_vnet.countAllocatedVnets(network.getId());
2718+
if (allocated_vnets > 0) {
2719+
throw new InvalidParameterValueException("physicalnetwork "+ network.getId() + " has "+ allocated_vnets + " vnets in use");
2720+
}
27172721
return removeVnets;
27182722
}
27192723
for (Pair<Integer, Integer>vlan : vnetRanges) {
@@ -2736,7 +2740,8 @@ private List<String> getVnetsToremove(PhysicalNetworkVO network, List<Pair<Integ
27362740
_datacneter_vnet.lockRange(network.getDataCenterId(), network.getId(), start, end);
27372741
List<DataCenterVnetVO> result = _datacneter_vnet.listAllocatedVnetsInRange(network.getDataCenterId(), network.getId(), start, end);
27382742
if (!result.isEmpty()){
2739-
throw new InvalidParameterValueException("Some of the vnets from this range are allocated, can only remove a range which has no allocated vnets");
2743+
throw new InvalidParameterValueException("physicalnetwork "+ network.getId() + " has allocated vnets in the range "+ start+"-"+end);
2744+
27402745
}
27412746
// If the range is partially dedicated to an account fail the request
27422747
List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByPhysicalNetwork(network.getId());

0 commit comments

Comments
 (0)