mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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:
parent
12d6f53898
commit
47f519f5de
@ -2838,6 +2838,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
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) {
|
||||
txn.start();
|
||||
|
||||
@ -52,6 +52,6 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
|
||||
|
||||
IPAddressVO findByAssociatedVmId(long vmId);
|
||||
|
||||
IPAddressVO findByAccountAndIp(long accountId, String ipAddress);
|
||||
IPAddressVO findByIpAndSourceNetworkId(long networkId, String ipAddress);
|
||||
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
|
||||
AllFieldsSearch.and("network", AllFieldsSearch.entity().getAssociatedWithNetworkId(), Op.EQ);
|
||||
AllFieldsSearch.and("associatedWithVmId", AllFieldsSearch.entity().getAssociatedWithVmId(), Op.EQ);
|
||||
AllFieldsSearch.and("oneToOneNat", AllFieldsSearch.entity().isOneToOneNat(), Op.EQ);
|
||||
AllFieldsSearch.and("sourcenetwork", AllFieldsSearch.entity().getSourceNetworkId(), Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
|
||||
VlanDbIdSearchUnallocated = createSearchBuilder();
|
||||
@ -185,9 +186,9 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPAddressVO findByAccountAndIp(long accountId, String ipAddress) {
|
||||
public IPAddressVO findByIpAndSourceNetworkId(long networkId, String ipAddress) {
|
||||
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("accountId", accountId);
|
||||
sc.setParameters("sourcenetwork", networkId);
|
||||
sc.setParameters("ipAddress", ipAddress);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
_networkMgr.markIpAsUnavailable(ip.getId());
|
||||
_ipAddressDao.unassignIpAddress(ip.getId());
|
||||
|
||||
@ -181,7 +181,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
_networkMgr.markIpAsUnavailable(ip.getId());
|
||||
_ipAddressDao.unassignIpAddress(ip.getId());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user