Skip to content

Commit 80ebaae

Browse files
committed
Update 11811: update ip on shared network to Allocated state
1 parent 8c4dbd4 commit 80ebaae

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4772,6 +4772,15 @@ public NicVO doInTransaction(TransactionStatus status) {
47724772
}
47734773
});
47744774

4775+
if (selectedIp != null && GuestType.Shared.equals(network.getGuestType())) {
4776+
IPAddressVO ipAddressVO = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), selectedIp);
4777+
if (ipAddressVO != null && IpAddress.State.Free.equals(ipAddressVO.getState())) {
4778+
ipAddressVO.setState(IPAddressVO.State.Allocated);
4779+
ipAddressVO.setAllocatedTime(new Date());
4780+
_ipAddressDao.update(ipAddressVO.getId(), ipAddressVO);
4781+
}
4782+
}
4783+
47754784
final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
47764785
final NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network),
47774786
_networkModel.getNetworkTag(vm.getHypervisorType(), network));
@@ -4791,7 +4800,7 @@ protected String getSelectedIpForNicImport(Network network, DataCenter dataCente
47914800
protected String getSelectedIpForNicImportOnSharedNetwork(String requestedIp, Network network, DataCenter dataCenter) {
47924801
IPAddressVO ipAddressVO = StringUtils.isBlank(requestedIp) ?
47934802
_ipAddressDao.findBySourceNetworkIdAndDatacenterIdAndState(network.getId(), dataCenter.getId(), IpAddress.State.Free):
4794-
_ipAddressDao.findByIp(requestedIp);
4803+
_ipAddressDao.findByIpAndSourceNetworkId(network.getId(), requestedIp);
47954804
if (ipAddressVO == null || ipAddressVO.getState() != IpAddress.State.Free) {
47964805
String msg = String.format("Cannot find a free IP to assign to VM NIC on network %s", network.getName());
47974806
logger.error(msg);

engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ public void testGetGuestIpForNicImportBasicZoneManualIP() {
822822
Mockito.when(network.getId()).thenReturn(networkId);
823823
Mockito.when(dataCenter.getId()).thenReturn(dataCenterId);
824824
Mockito.when(ipAddresses.getIp4Address()).thenReturn(requestedIp);
825-
Mockito.when(testOrchestrator._ipAddressDao.findByIp(requestedIp)).thenReturn(ipAddressVO);
825+
Mockito.when(testOrchestrator._ipAddressDao.findByIpAndSourceNetworkId(networkId, requestedIp)).thenReturn(ipAddressVO);
826826
String ipAddress = testOrchestrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses);
827827
Assert.assertEquals(requestedIp, ipAddress);
828828
}

0 commit comments

Comments
 (0)