Skip to content

Commit 1a89bc0

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 c1e7880 commit 1a89bc0

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
@@ -2713,6 +2713,10 @@ private List<String> getVnetsToremove(PhysicalNetworkVO network, List<Pair<Integ
27132713
if (vnetRanges.size() == 0) {
27142714
//this implies remove all vlans.
27152715
removeVnets.addAll(vnetsInDb);
2716+
int allocated_vnets = _datacneter_vnet.countAllocatedVnets(network.getId());
2717+
if (allocated_vnets > 0) {
2718+
throw new InvalidParameterValueException("physicalnetwork "+ network.getId() + " has "+ allocated_vnets + " vnets in use");
2719+
}
27162720
return removeVnets;
27172721
}
27182722
for (Pair<Integer, Integer>vlan : vnetRanges) {
@@ -2735,7 +2739,8 @@ private List<String> getVnetsToremove(PhysicalNetworkVO network, List<Pair<Integ
27352739
_datacneter_vnet.lockRange(network.getDataCenterId(), network.getId(), start, end);
27362740
List<DataCenterVnetVO> result = _datacneter_vnet.listAllocatedVnetsInRange(network.getDataCenterId(), network.getId(), start, end);
27372741
if (!result.isEmpty()){
2738-
throw new InvalidParameterValueException("Some of the vnets from this range are allocated, can only remove a range which has no allocated vnets");
2742+
throw new InvalidParameterValueException("physicalnetwork "+ network.getId() + " has allocated vnets in the range "+ start+"-"+end);
2743+
27392744
}
27402745
// If the range is partially dedicated to an account fail the request
27412746
List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByPhysicalNetwork(network.getId());

0 commit comments

Comments
 (0)