From dfd0d7730e19c6f254edc002f2c40dd7accb2bf4 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 b754bcb9077..0c9e445683e 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1326,7 +1326,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 245422f1c36..72799591c3b 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; @@ -68,6 +72,8 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { IPAddressDao _ipAddressDao; @Inject NetworkOfferingDao _networkOfferingDao; + @Inject + PodVlanMapDao _podVlanDao; @Override protected boolean canHandle(NetworkOffering offering, DataCenter dc) { @@ -108,6 +114,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { } else { nic.setStrategy(ReservationStrategy.Create); } + if (rsStrategy == ReservationStrategy.Create) { String mac = _networkMgr.getNextAvailableMacAddressInNetwork(network.getId()); nic.setMacAddress(mac); @@ -118,9 +125,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()); @@ -148,5 +177,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 100644 --- 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';