mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +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
@ -2839,6 +2839,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||||||
|
|
||||||
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();
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user