From 18b59af65675d46f85e5e5d8e90d5d6d15b2bcfb Mon Sep 17 00:00:00 2001 From: alena Date: Wed, 3 Aug 2011 20:43:01 -0700 Subject: [PATCH] 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 --- .../com/cloud/network/NetworkManagerImpl.java | 2 +- .../guru/DirectPodBasedNetworkGuru.java | 35 +++++++++++++++++-- setup/db/db/schema-228to229.sql | 1 + 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 75d1d0cfd63..f04a0ed6f91 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1297,7 +1297,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag 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 155b31803e8..fe1520dd6e3 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; 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 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { IPAddressDao _ipAddressDao; @Inject NetworkOfferingDao _networkOfferingDao; + @Inject + PodVlanMapDao _podVlanDao; @Override protected boolean canHandle(NetworkOffering offering, DataCenter dc) { @@ -103,6 +109,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { } else { nic.setStrategy(ReservationStrategy.Create); } + if (rsStrategy == ReservationStrategy.Create) { String mac = _networkMgr.getNextAvailableMacAddressInNetwork(network.getId()); nic.setMacAddress(mac); @@ -113,9 +120,31 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { @Override public void reserve(NicProfile nic, Network network, VirtualMachineProfile 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 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 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { 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 d2033063be6..92226ad7028 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-serve 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';