Skip to content

Commit e8ade2d

Browse files
committed
Merge pull request #662 from manuiiit/pull-14
CLOUDSTACK-8711: public_ip type resource count for an account is not decremented upon IP range deletionProblem: -------------------------- When you add an IP range and associate it to an account then resource count of public_ip will be updated to the range length. After some time try to delete this range and the resource count of public_up for this account is not descremented and is causing account not to add any more public IPs to it once it reaches the resource limit. RCA: ---------------- We were not decrement the count while deleting the IP range that was associated to an account. Fix: ------------- Up on deletion we are decrementing the resource count for public_up now. * pr/662: Bug-Id: CS-27335: public_ip type resource count for an account is not decremented upon IP range deletion Signed-off-by: Remi Bergsma <github@remi.nl>
2 parents b074fc7 + 865623f commit e8ade2d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

server/src/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3312,6 +3312,7 @@ public boolean deleteVlanAndPublicIpRange(final long userId, final long vlanDbId
33123312
// Check if the VLAN has any allocated public IPs
33133313
final List<IPAddressVO> ips = _publicIpAddressDao.listByVlanId(vlanDbId);
33143314
if (isAccountSpecific) {
3315+
int resourceCountToBeDecrement = 0;
33153316
try {
33163317
vlanRange = _vlanDao.acquireInLockTable(vlanDbId, 30);
33173318
if (vlanRange == null) {
@@ -3338,19 +3339,23 @@ public boolean deleteVlanAndPublicIpRange(final long userId, final long vlanDbId
33383339
throw new InvalidParameterValueException("Can't delete account specific vlan " + vlanDbId + " as ip " + ip
33393340
+ " belonging to the range has firewall rules applied. Cleanup the rules first");
33403341
}
3341-
if(ip.getAllocatedTime() != null) {// This means IP is allocated
3342+
if (ip.getAllocatedTime() != null) {// This means IP is allocated
33423343
// release public ip address here
33433344
success = _ipAddrMgr.disassociatePublicIpAddress(ip.getId(), userId, caller);
33443345
}
33453346
if (!success) {
33463347
s_logger.warn("Some ip addresses failed to be released as a part of vlan " + vlanDbId + " removal");
33473348
} else {
3349+
resourceCountToBeDecrement++;
33483350
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getAccountId(), ip.getDataCenterId(), ip.getId(),
33493351
ip.getAddress().toString(), ip.isSourceNat(), vlanRange.getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), ip.getUuid());
33503352
}
33513353
}
33523354
} finally {
33533355
_vlanDao.releaseFromLockTable(vlanDbId);
3356+
if (resourceCountToBeDecrement > 0) { //Making sure to decrement the count of only success operations above. For any reaason if disassociation fails then this number will vary from original range length.
3357+
_resourceLimitMgr.decrementResourceCount(acctVln.get(0).getAccountId(), ResourceType.public_ip, new Long(resourceCountToBeDecrement));
3358+
}
33543359
}
33553360
} else { // !isAccountSpecific
33563361
final NicIpAliasVO ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(vlanRange.getVlanGateway(), vlanRange.getNetworkId(), NicIpAlias.state.active);

0 commit comments

Comments
 (0)