From 61dd3b3bf92eb0e84bba9ba3ee2bcfe6780a35f0 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 4 Jan 2011 15:01:19 -0800 Subject: [PATCH] bug 7865: Changed ip allocation for guest network to happen during allocation and not reserve time so ip address won't keep changing --- .../cloud/network/guru/GuestNetworkGuru.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index c176e9fdcfe..f422f370d40 100644 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -36,6 +36,7 @@ import com.cloud.network.Network; import com.cloud.network.Network.State; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; +import com.cloud.network.Networks.AddressFormat; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; @@ -162,18 +163,25 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { @Override public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { - if (network.getTrafficType() != TrafficType.Guest) { - return null; - } + assert (network.getTrafficType() == TrafficType.Guest) : "Look at my name! Why are you calling me when the traffic type is : " + network.getTrafficType(); if (nic == null) { nic = new NicProfile(ReservationStrategy.Start, null, null, null, null); - } else if (nic.getIp4Address() != null){ - nic.setStrategy(ReservationStrategy.Create); - } else { - nic.setStrategy(ReservationStrategy.Start); + } + + if (nic.getIp4Address() == null){ + nic.setBroadcastUri(network.getBroadcastUri()); + nic.setIsolationUri(network.getBroadcastUri()); + nic.setGateway(network.getGateway()); + nic.setIp4Address(acquireGuestIpAddress(network)); + nic.setNetmask(NetUtils.cidr2Netmask(network.getCidr())); + nic.setDns1(network.getDns1()); + nic.setDns2(network.getDns2()); + nic.setFormat(AddressFormat.Ip4); } + nic.setStrategy(ReservationStrategy.Start); + if (nic.getMacAddress() == null) { nic.setMacAddress(_networkMgr.getNextAvailableMacAddressInNetwork(network.getId())); if (nic.getMacAddress() == null) { @@ -210,11 +218,6 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { nic.setBroadcastUri(network.getBroadcastUri()); nic.setIsolationUri(network.getBroadcastUri()); - nic.setGateway(network.getGateway()); - nic.setIp4Address(acquireGuestIpAddress(network)); - nic.setNetmask(NetUtils.cidr2Netmask(network.getCidr())); - nic.setDns1(network.getDns1()); - nic.setDns2(network.getDns2()); } @Override