bug 10954: when start a vm, always check if it's being started in original pod; if not - release old ip address, and allocate the new one from the new pod
status 10954: resolved fixed
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index 75d1d0c..f04a0ed 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -1297,7 +1297,7 @@
NetworkGuru guru = _networkGurus.get(network.getGuruName());
nic.setState(Nic.State.Releasing);
_nicDao.update(nic.getId(), nic);
- NicProfile profile = new NicProfile(nic, network, null, null, null);
+ NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null);
if (guru.release(profile, vmProfile, nic.getReservationId())) {
applyProfileToNicForRelease(nic, profile);
nic.setState(Nic.State.Allocated);
diff --git a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
index 155b318..fe1520d 100644
--- a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
@@ -19,6 +19,7 @@
package com.cloud.network.guru;
import java.net.URI;
+import java.util.List;
import javax.ejb.Local;
@@ -29,14 +30,17 @@
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.Pod;
+import com.cloud.dc.PodVlanMapVO;
import com.cloud.dc.Vlan;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.PodVlanMapDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
+import com.cloud.network.IPAddressVO;
import com.cloud.network.Network;
import com.cloud.network.NetworkManager;
import com.cloud.network.Networks.AddressFormat;
@@ -67,6 +71,8 @@
IPAddressDao _ipAddressDao;
@Inject
NetworkOfferingDao _networkOfferingDao;
+ @Inject
+ PodVlanMapDao _podVlanDao;
@Override
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
@@ -103,6 +109,7 @@
} else {
nic.setStrategy(ReservationStrategy.Create);
}
+
if (rsStrategy == ReservationStrategy.Create) {
String mac = _networkMgr.getNextAvailableMacAddressInNetwork(network.getId());
nic.setMacAddress(mac);
@@ -113,9 +120,31 @@
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
- if (nic.getIp4Address() == null) {
+
+ String oldIp = nic.getIp4Address();
+ boolean getNewIp = false;
+
+ if (oldIp == null) {
+ getNewIp = true;
+ } else {
+ // we need to get a new ip address if we try to deploy a vm in a different pod
+ IPAddressVO ipVO = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), oldIp);
+ if (ipVO != null) {
+ List<PodVlanMapVO> mapVO = _podVlanDao.listPodVlanMapsByVlan(ipVO.getVlanId());
+ if (mapVO.get(0).getPodId() != dest.getPod().getId()) {
+ //release the old ip here
+ _networkMgr.markIpAsUnavailable(ipVO.getId());
+ _ipAddressDao.unassignIpAddress(ipVO.getId());
+
+ nic.setIp4Address(null);
+ getNewIp = true;
+ }
+ }
+ }
+
+ if (getNewIp) {
+ //we don't set reservationStrategy to Create because we need this method to be called again for the case when vm fails to deploy in Pod1, and we try to redeploy it in Pod2
getIp(nic, dest.getPod(), vm, network);
- nic.setStrategy(ReservationStrategy.Create);
}
DataCenter dc = _dcDao.findById(network.getDataCenterId());
@@ -143,5 +172,5 @@
nic.setDns1(dc.getDns1());
nic.setDns2(dc.getDns2());
}
-
+
}
diff --git a/setup/db/db/schema-228to229.sql b/setup/db/db/schema-228to229.sql
index d203306..92226ad 100755
--- a/setup/db/db/schema-228to229.sql
+++ b/setup/db/db/schema-228to229.sql
@@ -54,3 +54,4 @@
INSERT IGNORE INTO configuration VALUES ('Network', 'DEFAULT', 'management-server', 'network.loadbalancer.haproxy.stats.auth','admin1:AdMiN123','Load Balancer(haproxy) authetication string in the format username:password');
INSERT IGNORE INTO configuration VALUES ('Network', 'DEFAULT', 'management-server', 'network.loadbalancer.haproxy.stats.port','8081','Load Balancer(haproxy) stats port number.');
+UPDATE `cloud`.`nics` SET strategy='Start' where reserver_name='DirectPodBasedNetworkGuru';