When release public ip address, make a search by ip+networkId instead of ip+accountId as ipAddress is unique in network only.

This commit is contained in:
alena 2011-07-08 15:41:47 -07:00
parent 12d6f53898
commit 47f519f5de
5 changed files with 11 additions and 5 deletions

View File

@ -2838,6 +2838,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
IPAddressVO ip = _ipAddressDao.findById(addrId); IPAddressVO ip = _ipAddressDao.findById(addrId);
if (ip.getAllocatedToAccountId() == null && ip.getAllocatedTime() == null) {
s_logger.trace("Ip address id=" + addrId + " is already released");
return ip;
}
if (ip.getState() != State.Releasing) { if (ip.getState() != State.Releasing) {
txn.start(); txn.start();

View File

@ -52,6 +52,6 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
IPAddressVO findByAssociatedVmId(long vmId); IPAddressVO findByAssociatedVmId(long vmId);
IPAddressVO findByAccountAndIp(long accountId, String ipAddress); IPAddressVO findByIpAndSourceNetworkId(long networkId, String ipAddress);
} }

View File

@ -69,6 +69,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
AllFieldsSearch.and("network", AllFieldsSearch.entity().getAssociatedWithNetworkId(), Op.EQ); AllFieldsSearch.and("network", AllFieldsSearch.entity().getAssociatedWithNetworkId(), Op.EQ);
AllFieldsSearch.and("associatedWithVmId", AllFieldsSearch.entity().getAssociatedWithVmId(), Op.EQ); AllFieldsSearch.and("associatedWithVmId", AllFieldsSearch.entity().getAssociatedWithVmId(), Op.EQ);
AllFieldsSearch.and("oneToOneNat", AllFieldsSearch.entity().isOneToOneNat(), Op.EQ); AllFieldsSearch.and("oneToOneNat", AllFieldsSearch.entity().isOneToOneNat(), Op.EQ);
AllFieldsSearch.and("sourcenetwork", AllFieldsSearch.entity().getSourceNetworkId(), Op.EQ);
AllFieldsSearch.done(); AllFieldsSearch.done();
VlanDbIdSearchUnallocated = createSearchBuilder(); VlanDbIdSearchUnallocated = createSearchBuilder();
@ -185,9 +186,9 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
} }
@Override @Override
public IPAddressVO findByAccountAndIp(long accountId, String ipAddress) { public IPAddressVO findByIpAndSourceNetworkId(long networkId, String ipAddress) {
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create(); SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
sc.setParameters("accountId", accountId); sc.setParameters("sourcenetwork", networkId);
sc.setParameters("ipAddress", ipAddress); sc.setParameters("ipAddress", ipAddress);
return findOneBy(sc); return findOneBy(sc);
} }

View File

@ -210,7 +210,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@Override @Override
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) { public void deallocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
IPAddressVO ip = _ipAddressDao.findByAccountAndIp(vm.getVirtualMachine().getAccountId(), nic.getIp4Address()); IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
if (ip != null) { if (ip != null) {
_networkMgr.markIpAsUnavailable(ip.getId()); _networkMgr.markIpAsUnavailable(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId()); _ipAddressDao.unassignIpAddress(ip.getId());

View File

@ -181,7 +181,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
@Override @Override
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) { public void deallocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
IPAddressVO ip = _ipAddressDao.findByAccountAndIp(vm.getVirtualMachine().getAccountId(), nic.getIp4Address()); IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
if (ip != null) { if (ip != null) {
_networkMgr.markIpAsUnavailable(ip.getId()); _networkMgr.markIpAsUnavailable(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId()); _ipAddressDao.unassignIpAddress(ip.getId());