Skip to content

Commit da00066

Browse files
author
Kishan Kavala
committed
CLOUDSTACK-3124: Deletion of ACL associated with a tier/ pvt gateway should not be allowed. Check for associated tiers/gateways before deletion
1 parent e9df9c2 commit da00066

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ public interface VpcGatewayDao extends GenericDao<VpcGatewayVO, Long>{
3030
Long getNetworkAclIdForPrivateIp(long vpcId, long networkId, String ipaddr);
3131

3232
List<VpcGatewayVO> listByVpcIdAndType(long vpcId, VpcGateway.Type type);
33+
34+
List<VpcGatewayVO> listByAclIdAndType(long aclId, VpcGateway.Type type);
3335
}

engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDaoImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected VpcGatewayDaoImpl() {
4141
AllFieldsSearch.and("type", AllFieldsSearch.entity().getType(), SearchCriteria.Op.EQ);
4242
AllFieldsSearch.and("networkid", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
4343
AllFieldsSearch.and("ipaddress", AllFieldsSearch.entity().getIp4Address(), SearchCriteria.Op.EQ);
44+
AllFieldsSearch.and("aclId", AllFieldsSearch.entity().getNetworkACLId(), SearchCriteria.Op.EQ);
4445
AllFieldsSearch.done();
4546
}
4647

@@ -86,4 +87,11 @@ public List<VpcGatewayVO> listByVpcIdAndType(long vpcId, VpcGateway.Type type) {
8687
return listBy(sc);
8788
}
8889

90+
@Override
91+
public List<VpcGatewayVO> listByAclIdAndType(long aclId, VpcGateway.Type type) {
92+
SearchCriteria<VpcGatewayVO> sc = AllFieldsSearch.create();
93+
sc.setParameters("aclId", aclId);
94+
sc.setParameters("type", type);
95+
return listBy(sc);
96+
}
8997
}

server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ public boolean deleteNetworkACL(NetworkACL acl) {
122122
if(aclItems.size() > 0){
123123
throw new CloudRuntimeException("ACL is not empty. Cannot delete network ACL: "+acl.getUuid());
124124
}
125+
126+
List<NetworkVO> networks = _networkDao.listByAclId(acl.getId());
127+
if(networks != null && networks.size() > 0){
128+
throw new CloudRuntimeException("ACL is still associated with "+networks.size()+" tier(s). Cannot delete network ACL: "+acl.getUuid());
129+
}
130+
131+
List<VpcGatewayVO> pvtGateways = _vpcGatewayDao.listByAclIdAndType(acl.getId(), VpcGateway.Type.Private);
132+
133+
if(pvtGateways != null && pvtGateways.size() > 0){
134+
throw new CloudRuntimeException("ACL is still associated with "+pvtGateways.size()+" private gateway(s). Cannot delete network ACL: "+acl.getUuid());
135+
}
136+
125137
return _networkACLDao.remove(acl.getId());
126138
}
127139

0 commit comments

Comments
 (0)