From 3d0758691f4cc39084af42c8c7c5b164b1a9bfa2 Mon Sep 17 00:00:00 2001 From: alena Date: Thu, 4 Aug 2011 10:01:06 -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 Conflicts: setup/db/db/schema-228to229.sql --- .../com/cloud/network/NetworkManagerImpl.java | 2 +- .../guru/DirectPodBasedNetworkGuru.java | 35 +++++++++++++++++-- setup/db/db/schema-228to229.sql | 3 ++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 6d188b79c7e..040ac8c4919 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1322,7 +1322,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 0c5101fff1d..a772f1013b8 100644 --- a/setup/db/db/schema-228to229.sql +++ b/setup/db/db/schema-228to229.sql @@ -21,4 +21,7 @@ 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.'); + INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'use.external.dns', 'false', 'Bypass internal dns, use exetrnal dns1 and dns2'); +UPDATE `cloud`.`nics` SET strategy='Start' where reserver_name='DirectPodBasedNetworkGuru'; +