cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject [02/50] [abbrv] git commit: updated refs/heads/affinity_groups to 857ed16
Date Fri, 29 Mar 2013 18:20:18 GMT
CLOUDSTACK-1771: fixed VirtualRouter nics assignment in the Shared networks. Before the fix VR could get a different IP address from the network upon recreation. With the fix the IP address assigned to the first VR in the network, will remain with the network till its entire lifecycle (stored in placeholder nic) and will be assigned to the VR every time it recreates in the network.
Shared networks in both - Advance and Basic - zone types are covered by this checkin


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/26b892da
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/26b892da
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/26b892da

Branch: refs/heads/affinity_groups
Commit: 26b892daf3cdccc2e25711730c7e1efcdec7d2dc
Parents: ba81253
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Mon Mar 25 16:34:04 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Tue Mar 26 13:29:57 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/network/NetworkModel.java        |    2 +
 .../network/ExternalFirewallDeviceManagerImpl.java |   48 +++----
 .../ExternalLoadBalancerDeviceManagerImpl.java     |   42 ++-----
 server/src/com/cloud/network/NetworkManager.java   |    3 +
 .../src/com/cloud/network/NetworkManagerImpl.java  |  104 ++++++++++++---
 server/src/com/cloud/network/NetworkModelImpl.java |   23 +++-
 .../network/element/VpcVirtualRouterElement.java   |    4 +-
 .../com/cloud/network/guru/DirectNetworkGuru.java  |   92 ++++++++++---
 .../network/guru/DirectPodBasedNetworkGuru.java    |   37 +++++-
 .../router/VirtualNetworkApplianceManagerImpl.java |   35 +++--
 .../src/com/cloud/upgrade/dao/Upgrade410to420.java |   38 ++++++
 server/src/com/cloud/vm/dao/NicDao.java            |    3 +
 server/src/com/cloud/vm/dao/NicDaoImpl.java        |    8 +
 .../com/cloud/network/MockNetworkManagerImpl.java  |    7 +
 .../com/cloud/network/MockNetworkModelImpl.java    |    9 +-
 .../test/com/cloud/vpc/MockNetworkManagerImpl.java |   13 ++
 .../test/com/cloud/vpc/MockNetworkModelImpl.java   |    9 +-
 17 files changed, 357 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/api/src/com/cloud/network/NetworkModel.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/NetworkModel.java b/api/src/com/cloud/network/NetworkModel.java
index 60e1f7f..916f28a 100644
--- a/api/src/com/cloud/network/NetworkModel.java
+++ b/api/src/com/cloud/network/NetworkModel.java
@@ -259,4 +259,6 @@ public interface NetworkModel {
 	void checkRequestedIpAddresses(long networkId, String ip4, String ip6) throws InvalidParameterValueException;
 
 	String getStartIpv6Address(long id);
+
+    Nic getPlaceholderNic(Network network, Long podId);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java
index f6ab778..ae00bf2 100644
--- a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java
+++ b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java
@@ -25,6 +25,9 @@ import java.util.Map;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.response.ExternalFirewallResponse;
+import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
@@ -42,7 +45,6 @@ import com.cloud.agent.api.to.FirewallRuleTO;
 import com.cloud.agent.api.to.IpAddressTO;
 import com.cloud.agent.api.to.PortForwardingRuleTO;
 import com.cloud.agent.api.to.StaticNatRuleTO;
-import org.apache.cloudstack.api.ApiConstants;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.DataCenter;
@@ -60,7 +62,6 @@ import com.cloud.host.Host;
 import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
 import com.cloud.host.dao.HostDetailsDao;
-import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.dao.ExternalFirewallDeviceDao;
 import com.cloud.network.dao.ExternalFirewallDeviceVO;
@@ -80,10 +81,10 @@ import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
 import com.cloud.network.dao.PhysicalNetworkVO;
 import com.cloud.network.dao.VpnUserDao;
 import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.rules.FirewallRule.Purpose;
 import com.cloud.network.rules.FirewallRuleVO;
 import com.cloud.network.rules.PortForwardingRule;
 import com.cloud.network.rules.StaticNat;
-import com.cloud.network.rules.FirewallRule.Purpose;
 import com.cloud.network.rules.dao.PortForwardingRulesDao;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.offerings.dao.NetworkOfferingDao;
@@ -92,7 +93,6 @@ import com.cloud.resource.ResourceState;
 import com.cloud.resource.ResourceStateAdapter;
 import com.cloud.resource.ServerResource;
 import com.cloud.resource.UnableDeleteHostException;
-import org.apache.cloudstack.api.response.ExternalFirewallResponse;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.dao.AccountDao;
@@ -105,9 +105,8 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
 import com.cloud.utils.net.UrlUtil;
-import com.cloud.vm.Nic.ReservationStrategy;
-import com.cloud.vm.Nic.State;
 import com.cloud.vm.NicVO;
+import com.cloud.vm.Nic.ReservationStrategy;
 import com.cloud.vm.dao.DomainRouterDao;
 import com.cloud.vm.dao.NicDao;
 
@@ -116,7 +115,8 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
     @Inject HostDao _hostDao;
     @Inject NetworkServiceMapDao _ntwkSrvcProviderDao;
     @Inject DataCenterDao _dcDao;
-    @Inject NetworkModel _networkMgr;
+    @Inject NetworkModel _networkModel;
+    @Inject NetworkManager _networkMgr;
     @Inject InlineLoadBalancerNicMapDao _inlineLoadBalancerNicMapDao;
     @Inject NicDao _nicDao;
     @Inject AgentManager _agentMgr;
@@ -428,7 +428,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
         IPAddressVO sourceNatIp = null;
         if (!sharedSourceNat) {
             // Get the source NAT IP address for this account          
-            List<? extends IpAddress> sourceNatIps = _networkMgr.listPublicIpsAssignedToAccount(network.getAccountId(), 
+            List<? extends IpAddress> sourceNatIps = _networkModel.listPublicIpsAssignedToAccount(network.getAccountId(), 
                     zoneId, true);
 
             if (sourceNatIps.size() != 1) {
@@ -455,7 +455,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
         }
 
         // Get network rate
-        Integer networkRate = _networkMgr.getNetworkRate(network.getId(), null);
+        Integer networkRate = _networkModel.getNetworkRate(network.getId(), null);
 
         IpAddressTO ip = new IpAddressTO(account.getAccountId(), sourceNatIpAddress, add, false, !sharedSourceNat, publicVlanTag, null, null, null, networkRate, false);
         IpAddressTO[] ips = new IpAddressTO[1];
@@ -483,7 +483,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
 
         if (add && (!reservedIpAddressesForGuestNetwork.contains(network.getGateway()))) {
             // Insert a new NIC for this guest network to reserve the gateway address
-            savePlaceholderNic(network,  network.getGateway());
+            _networkMgr.savePlaceholderNic(network,  network.getGateway());
         }
         
         // Delete any mappings used for inline external load balancers in this network
@@ -499,14 +499,13 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
         
         // on network shutdown, delete placeHolder nics used for the firewall device
         if (!add) {
-            List<NicVO> guestIps = _nicDao.listByNetworkId(network.getId());
-            for (NicVO guestIp : guestIps) {
-                // only external firewall and external load balancer will create NicVO with PlaceHolder reservation strategy
-                if (guestIp.getReservationStrategy().equals(ReservationStrategy.PlaceHolder) && guestIp.getIp4Address().equals(network.getGateway())) {
-                    _nicDao.remove(guestIp.getId());
+            List<NicVO> nics = _nicDao.listByNetworkId(network.getId());
+            for (NicVO nic : nics) {
+                if (nic.getReservationStrategy().equals(ReservationStrategy.PlaceHolder) && nic.getIp4Address().equals(network.getGateway())) {
+                    s_logger.debug("Removing placeholder nic " + nic + " for the network " + network);
+                    _nicDao.remove(nic.getId());
                 }
             }
-
             freeFirewallForNetwork(network);
         }
 
@@ -516,6 +515,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
         return true;
     }
 
+
     @Override
     public boolean applyFirewallRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
         // Find the external firewall in this zone
@@ -541,7 +541,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
             if (rule.getSourceCidrList() == null && (rule.getPurpose() == Purpose.Firewall || rule.getPurpose() == Purpose.NetworkACL)) {
                 _fwRulesDao.loadSourceCidrs((FirewallRuleVO)rule);
             }
-            IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
+            IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
             FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, sourceIp.getAddress().addr());
             rulesTO.add(ruleTO);
         }
@@ -568,7 +568,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
         List<StaticNatRuleTO> staticNatRules = new ArrayList<StaticNatRuleTO>();
         
         for (StaticNat rule : rules) {
-            IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
+            IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
             Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
 
             StaticNatRuleTO ruleTO = new StaticNatRuleTO(0,vlan.getVlanTag(), sourceIp.getAddress().addr(), -1, -1, rule.getDestIpAddress(), -1, -1, "any", rule.isForRevoke(), false);
@@ -632,7 +632,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
         }
         
         // Create/delete VPN
-        IpAddress ip = _networkMgr.getIp(vpn.getServerAddressId());
+        IpAddress ip = _networkModel.getIp(vpn.getServerAddressId());
         
         // Mask the IP range with the network's VLAN tag
         String[] ipRange = vpn.getIpRange().split("-");
@@ -712,14 +712,6 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
         return vlanTag - lowestVlanTag;
     }
     
-    private NicVO savePlaceholderNic(Network network, String ipAddress) {
-        NicVO nic = new NicVO(null, null, network.getId(), null);
-        nic.setIp4Address(ipAddress);
-        nic.setReservationStrategy(ReservationStrategy.PlaceHolder);
-        nic.setState(State.Reserved);
-        return _nicDao.persist(nic);
-    }
-    
     public int getGloballyConfiguredCidrSize() {
         try {
             String globalVlanBits = _configDao.getValue(Config.GuestVlanBits.key());
@@ -771,7 +763,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
         List<PortForwardingRuleTO> pfRules = new ArrayList<PortForwardingRuleTO>();
 
         for (PortForwardingRule rule : rules) {
-            IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
+            IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
             Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
 
             PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
index 049099d..b2a56fc 100644
--- a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
+++ b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
@@ -26,6 +26,9 @@ import java.util.UUID;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.response.ExternalLoadBalancerResponse;
+import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
@@ -41,7 +44,6 @@ import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.agent.api.to.IpAddressTO;
 import com.cloud.agent.api.to.LoadBalancerTO;
-import org.apache.cloudstack.api.ApiConstants;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.DataCenter;
@@ -61,7 +63,6 @@ import com.cloud.host.Host;
 import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
 import com.cloud.host.dao.HostDetailsDao;
-import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
 import com.cloud.network.Network.Provider;
 import com.cloud.network.Network.Service;
 import com.cloud.network.Networks.TrafficType;
@@ -69,6 +70,8 @@ import com.cloud.network.addr.PublicIp;
 import com.cloud.network.dao.ExternalFirewallDeviceDao;
 import com.cloud.network.dao.ExternalLoadBalancerDeviceDao;
 import com.cloud.network.dao.ExternalLoadBalancerDeviceVO;
+import com.cloud.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceAllocationState;
+import com.cloud.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceState;
 import com.cloud.network.dao.IPAddressDao;
 import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.InlineLoadBalancerNicMapDao;
@@ -83,8 +86,6 @@ import com.cloud.network.dao.PhysicalNetworkDao;
 import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
 import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
 import com.cloud.network.dao.PhysicalNetworkVO;
-import com.cloud.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceAllocationState;
-import com.cloud.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceState;
 import com.cloud.network.element.IpDeployer;
 import com.cloud.network.element.NetworkElement;
 import com.cloud.network.element.StaticNatServiceProvider;
@@ -104,7 +105,6 @@ import com.cloud.resource.ResourceState;
 import com.cloud.resource.ResourceStateAdapter;
 import com.cloud.resource.ServerResource;
 import com.cloud.resource.UnableDeleteHostException;
-import org.apache.cloudstack.api.response.ExternalLoadBalancerResponse;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.dao.AccountDao;
@@ -118,8 +118,7 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
 import com.cloud.utils.net.UrlUtil;
-import com.cloud.vm.Nic.ReservationStrategy;
-import com.cloud.vm.Nic.State;
+import com.cloud.vm.Nic;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.dao.DomainRouterDao;
 import com.cloud.vm.dao.NicDao;
@@ -698,25 +697,6 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
         return false;
     }
 
-    private NicVO savePlaceholderNic(Network network, String ipAddress) {
-        NicVO nic = new NicVO(null, null, network.getId(), null);
-        nic.setIp4Address(ipAddress);
-        nic.setReservationStrategy(ReservationStrategy.PlaceHolder);
-        nic.setState(State.Reserved);
-        return _nicDao.persist(nic);
-    }
-
-    private NicVO getPlaceholderNic(Network network) {
-        List<NicVO> guestIps = _nicDao.listByNetworkId(network.getId());
-        for (NicVO guestIp : guestIps) {
-            // only external firewall and external load balancer will create NicVO with PlaceHolder reservation strategy
-            if (guestIp.getReservationStrategy().equals(ReservationStrategy.PlaceHolder) && guestIp.getVmType() == null
-                    && guestIp.getReserver() == null && !guestIp.getIp4Address().equals(network.getGateway())) {
-                return guestIp;
-            }
-        }
-        return null;
-    }
 
     private void applyStaticNatRuleForInlineLBRule(DataCenterVO zone, Network network, boolean revoked, String publicIp, String privateIp) throws ResourceUnavailableException {
         List<StaticNat> staticNats = new ArrayList<StaticNat>();
@@ -776,7 +756,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
                 // If a NIC doesn't exist for the load balancing IP address, create one
                 loadBalancingIpNic = _nicDao.findByIp4AddressAndNetworkId(loadBalancingIpAddress, network.getId());
                 if (loadBalancingIpNic == null) {
-                    loadBalancingIpNic = savePlaceholderNic(network, loadBalancingIpAddress);
+                    loadBalancingIpNic = _networkMgr.savePlaceholderNic(network, loadBalancingIpAddress);
                 }
 
                 // Save a mapping between the source IP address and the load balancing IP address NIC
@@ -985,7 +965,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
 
         if (add) {
 		    // on restart network, network could have already been implemented. If already implemented then return
-            NicVO selfipNic = getPlaceholderNic(guestConfig);
+            Nic selfipNic = _networkModel.getPlaceholderNic(guestConfig, null);
             if (selfipNic != null) {
 		    return true;
             }
@@ -999,7 +979,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
             }
         } else {
             // get the self-ip used by the load balancer
-            NicVO selfipNic = getPlaceholderNic(guestConfig);
+            Nic selfipNic = _networkModel.getPlaceholderNic(guestConfig, null);
             if (selfipNic == null) {
                 s_logger.warn("Network shutdwon requested on external load balancer element, which did not implement the network." +
                         " Either network implement failed half way through or already network shutdown is completed. So just returning.");
@@ -1027,10 +1007,10 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
 
         if (add) {
             // Insert a new NIC for this guest network to reserve the self IP
-            savePlaceholderNic(guestConfig, selfIp);
+            _networkMgr.savePlaceholderNic(guestConfig, selfIp);
         } else {
             // release the self-ip obtained from guest network
-            NicVO selfipNic = getPlaceholderNic(guestConfig);
+            Nic selfipNic = _networkModel.getPlaceholderNic(guestConfig, null);
             _nicDao.remove(selfipNic.getId());
 
             // release the load balancer allocated for the network

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/network/NetworkManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java
index 48e017e..e961f04 100755
--- a/server/src/com/cloud/network/NetworkManager.java
+++ b/server/src/com/cloud/network/NetworkManager.java
@@ -52,6 +52,7 @@ import com.cloud.utils.Pair;
 import com.cloud.vm.Nic;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicSecondaryIp;
+import com.cloud.vm.NicVO;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
@@ -346,4 +347,6 @@ public interface NetworkManager  {
     String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod, Account caller, String requestedIp) throws InsufficientAddressCapacityException;
     boolean removeVmSecondaryIpsOfNic(long nicId);
 
+    NicVO savePlaceholderNic(Network network, String ip4Address);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index b1236cc..b2ceb46 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -44,7 +44,14 @@ import org.springframework.stereotype.Component;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.Listener;
-import com.cloud.agent.api.*;
+import com.cloud.agent.api.AgentControlAnswer;
+import com.cloud.agent.api.AgentControlCommand;
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.CheckNetworkAnswer;
+import com.cloud.agent.api.CheckNetworkCommand;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.StartupCommand;
+import com.cloud.agent.api.StartupRoutingCommand;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.alert.AlertManager;
 import com.cloud.api.ApiDBUtils;
@@ -52,9 +59,15 @@ import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.Resource.ResourceType;
 import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.*;
+import com.cloud.dc.AccountVlanMapVO;
+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.VlanVO;
 import com.cloud.dc.dao.AccountVlanMapDao;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.dc.dao.PodVlanMapDao;
@@ -67,14 +80,28 @@ import com.cloud.domain.dao.DomainDao;
 import com.cloud.event.EventTypes;
 import com.cloud.event.UsageEventUtils;
 import com.cloud.event.dao.UsageEventDao;
-import com.cloud.exception.*;
+import com.cloud.exception.AccountLimitException;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.ConnectionException;
+import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.PermissionDeniedException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.exception.UnsupportedServiceException;
 import com.cloud.host.Host;
 import com.cloud.host.HostVO;
 import com.cloud.host.Status;
 import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.network.IpAddress.State;
-import com.cloud.network.Network.*;
+import com.cloud.network.Network.Capability;
+import com.cloud.network.Network.Event;
+import com.cloud.network.Network.GuestType;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
 import com.cloud.network.Networks.AddressFormat;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.Networks.IsolationType;
@@ -84,7 +111,6 @@ import com.cloud.network.dao.FirewallRulesDao;
 import com.cloud.network.dao.IPAddressDao;
 import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.LoadBalancerDao;
-import com.cloud.network.dao.LoadBalancerVO;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.NetworkDomainDao;
 import com.cloud.network.dao.NetworkServiceMapDao;
@@ -104,13 +130,16 @@ import com.cloud.network.element.NetworkElement;
 import com.cloud.network.element.StaticNatServiceProvider;
 import com.cloud.network.element.UserDataServiceProvider;
 import com.cloud.network.guru.NetworkGuru;
-import com.cloud.network.lb.LoadBalancingRule;
-import com.cloud.network.lb.LoadBalancingRule.LbDestination;
-import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
-import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
 import com.cloud.network.lb.LoadBalancingRulesManager;
-import com.cloud.network.rules.*;
+import com.cloud.network.rules.FirewallManager;
+import com.cloud.network.rules.FirewallRule;
 import com.cloud.network.rules.FirewallRule.Purpose;
+import com.cloud.network.rules.FirewallRuleVO;
+import com.cloud.network.rules.PortForwardingRuleVO;
+import com.cloud.network.rules.RulesManager;
+import com.cloud.network.rules.StaticNat;
+import com.cloud.network.rules.StaticNatRule;
+import com.cloud.network.rules.StaticNatRuleImpl;
 import com.cloud.network.rules.dao.PortForwardingRulesDao;
 import com.cloud.network.vpc.NetworkACLManager;
 import com.cloud.network.vpc.VpcManager;
@@ -123,7 +152,12 @@ import com.cloud.offerings.NetworkOfferingVO;
 import com.cloud.offerings.dao.NetworkOfferingDao;
 import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
 import com.cloud.org.Grouping;
-import com.cloud.user.*;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.ResourceLimitService;
+import com.cloud.user.User;
+import com.cloud.user.UserContext;
+import com.cloud.user.UserVO;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.user.dao.UserDao;
 import com.cloud.utils.Journal;
@@ -133,18 +167,21 @@ import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
-import com.cloud.utils.db.*;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.JoinBuilder.JoinType;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.fsm.NoTransitionException;
 import com.cloud.utils.fsm.StateMachine2;
 import com.cloud.utils.net.Ip;
 import com.cloud.utils.net.NetUtils;
-import com.cloud.vm.*;
 import com.cloud.vm.Nic;
+import com.cloud.vm.Nic.ReservationStrategy;
 import com.cloud.vm.NicProfile;
-import com.cloud.vm.NicSecondaryIp;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.ReservationContextImpl;
@@ -152,6 +189,7 @@ import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.Type;
+import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.dao.NicDao;
 import com.cloud.vm.dao.NicSecondaryIpDao;
 import com.cloud.vm.dao.NicSecondaryIpVO;
@@ -3401,14 +3439,35 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
         return success;
     }
 
+    @Override
+    @DB
     public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm, Network network,
     							 String requestedIpv4, String requestedIpv6) throws InsufficientVirtualNetworkCapcityException,
             InsufficientAddressCapacityException {
     	boolean ipv4 = false, ipv6 = false;
+    	
+    	Transaction txn = Transaction.currentTxn();
+        txn.start();
+        
     	if (network.getGateway() != null) {
     		if (nic.getIp4Address() == null) {
     			ipv4 = true;
-    			PublicIp ip = assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.DirectAttached, network.getId(), requestedIpv4, false);
+    			PublicIp ip = null;
+    			
+    			//Get ip address from the placeholder and don't allocate a new one
+    			if (requestedIpv4 != null && vm.getType() == VirtualMachine.Type.DomainRouter) {
+    			    Nic placeholderNic = _networkModel.getPlaceholderNic(network, null);
+    			    if (placeholderNic != null) {
+    			        IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIp4Address());
+                        ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
+                        s_logger.debug("Nic got an ip address " + placeholderNic.getIp4Address() + " stored in placeholder nic for the network " + network);
+                    }
+    			}
+    			
+    			if (ip == null) {
+                    ip = assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.DirectAttached, network.getId(), requestedIpv4, false);
+    			}
+    						
     			nic.setIp4Address(ip.getAddress().toString());
     			nic.setGateway(ip.getGateway());
     			nic.setNetmask(ip.getNetmask());
@@ -3423,6 +3482,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
     		nic.setDns2(dc.getDns2());
     	}
     	
+    	//FIXME - get ipv6 address from the placeholder if it's stored there
     	if (network.getIp6Gateway() != null) {
     		if (nic.getIp6Address() == null) {
     			ipv6 = true;
@@ -3445,7 +3505,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
     		nic.setIp6Dns1(dc.getIp6Dns1());
     		nic.setIp6Dns2(dc.getIp6Dns2());
     	}
-
+    	
+    	txn.commit();
     }
 
 	@Override
@@ -3649,5 +3710,14 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
             Ip ipAddr = ip.getAddress();
             return ipAddr.addr();
         }
-
+        
+        @Override
+        public NicVO savePlaceholderNic(Network network, String ip4Address) {
+            NicVO nic = new NicVO(null, null, network.getId(), null); 
+            nic.setIp4Address(ip4Address);
+            nic.setReservationStrategy(ReservationStrategy.PlaceHolder);
+            nic.setState(Nic.State.Reserved);
+            return _nicDao.persist(nic);
+        }
+        
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/network/NetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java
index 40a18c7..41ce103 100644
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -93,7 +93,6 @@ import com.cloud.user.DomainManager;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.component.ComponentContext;
-import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.JoinBuilder;
@@ -1994,4 +1993,26 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
     	}
 		return startIpv6;
 	}
+	
+    @Override
+    public NicVO getPlaceholderNic(Network network, Long podId) {
+        List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkId(network.getId());
+        for (NicVO nic : nics) {
+            if (nic.getVmType() == null && nic.getReserver() == null && nic.getIp4Address() != null && !nic.getIp4Address().equals(network.getGateway())) {
+                if (podId == null) {
+                    return nic;
+                } else {
+                    //return nic only when its ip address belong to the pod range (for the Basic zone case)
+                    List<? extends Vlan> vlans = _vlanDao.listVlansForPod(podId);
+                    for (Vlan vlan : vlans) {
+                        IpAddress ip = _ipAddressDao.findByIpAndNetworkId(network.getId(), nic.getIp4Address());
+                        if (ip != null && ip.getVlanId() == vlan.getId()) {
+                            return nic;
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
index aa8f10d..c7d4aed 100644
--- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
@@ -142,7 +142,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
 
         Long vpcId = network.getVpcId();
         if (vpcId == null) {
-            s_logger.warn("Network " + network + " is not associated with any VPC");
+            s_logger.trace("Network " + network + " is not associated with any VPC");
             return false;
         }
 
@@ -185,7 +185,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
 
         Long vpcId = network.getVpcId();
         if (vpcId == null) {
-            s_logger.warn("Network " + network + " is not associated with any VPC");
+            s_logger.trace("Network " + network + " is not associated with any VPC");
             return false;
         }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/network/guru/DirectNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
index 8707cfd..2c8acbb 100755
--- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
@@ -44,7 +44,6 @@ import com.cloud.network.NetworkProfile;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.Networks.Mode;
 import com.cloud.network.Networks.TrafficType;
-import com.cloud.network.UserIpv6AddressVO;
 import com.cloud.network.dao.IPAddressDao;
 import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.NetworkVO;
@@ -55,13 +54,15 @@ import com.cloud.user.Account;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Transaction;
+import com.cloud.vm.Nic;
 import com.cloud.vm.Nic.ReservationStrategy;
-import com.cloud.vm.dao.NicSecondaryIpDao;
 import com.cloud.vm.NicProfile;
-import com.cloud.vm.NicSecondaryIp;
+import com.cloud.vm.NicVO;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.dao.NicDao;
+import com.cloud.vm.dao.NicSecondaryIpDao;
 
 @Local(value = { NetworkGuru.class })
 public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@@ -85,6 +86,8 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
     Ipv6AddressManager _ipv6Mgr;
     @Inject
     NicSecondaryIpDao _nicSecondaryIpDao;
+    @Inject
+    NicDao _nicDao;
 
     private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
     
@@ -198,7 +201,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
             nic.setStrategy(ReservationStrategy.Create);
         }
 
-        _networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIpv4(), nic.getRequestedIpv6());
+        allocateDirectIp(nic, network, vm, dc, nic.getRequestedIpv4(), nic.getRequestedIpv6());
         nic.setStrategy(ReservationStrategy.Create);
 
         return nic;
@@ -208,11 +211,31 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
     public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context)
             throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
         if (nic.getIp4Address() == null && nic.getIp6Address() == null) {
-            _networkMgr.allocateDirectIp(nic, dest.getDataCenter(), vm, network, null, null);
+            allocateDirectIp(nic, network, vm, dest.getDataCenter(), null, null);
             nic.setStrategy(ReservationStrategy.Create);
         }
     }
 
+    @DB
+    protected void allocateDirectIp(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DataCenter dc, String requestedIp4Addr, String requestedIp6Addr)
+            throws InsufficientVirtualNetworkCapcityException,
+            InsufficientAddressCapacityException {
+        
+        //FIXME - save ipv6 informaiton in the placeholder nic
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        _networkMgr.allocateDirectIp(nic, dc, vm, network, requestedIp4Addr, requestedIp6Addr);
+        //save the placeholder nic if the vm is the Virtual router
+        if (vm.getType() == VirtualMachine.Type.DomainRouter) {
+            Nic placeholderNic = _networkModel.getPlaceholderNic(network, null);
+            if (placeholderNic == null) {
+                s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIp4Address() + " and ipv6 address " + requestedIp6Addr + " for the network " + network);
+                _networkMgr.savePlaceholderNic(network, nic.getIp4Address());
+            }
+        }
+        txn.commit();
+    }
+
     @Override
     public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, String reservationId) {
         return true;
@@ -230,24 +253,32 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
         }
     	
     	if (nic.getIp4Address() != null) {
-        IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
-        if (ip != null) {
-            Transaction txn = Transaction.currentTxn();
-            txn.start();
-            _networkMgr.markIpAsUnavailable(ip.getId());
-            _ipAddressDao.unassignIpAddress(ip.getId());
-            //unassign nic secondary ip address
-            s_logger.debug("remove nic " + nic.getId() + " secondary ip ");
-            List<String> nicSecIps = null;
-            nicSecIps = _nicSecondaryIpDao.getSecondaryIpAddressesForNic(nic.getId());
-            for (String secIp: nicSecIps) {
-                IPAddressVO pubIp = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), secIp);
-                _networkMgr.markIpAsUnavailable(pubIp.getId());
-                _ipAddressDao.unassignIpAddress(pubIp.getId());
+            IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
+            if (ip != null) {
+                Transaction txn = Transaction.currentTxn();
+                txn.start();
+                
+                // if the ip address a part of placeholder, don't release it
+                Nic placeholderNic = _networkModel.getPlaceholderNic(network, null);
+                if (placeholderNic != null && placeholderNic.getIp4Address().equalsIgnoreCase(ip.getAddress().addr())) {
+                    s_logger.debug("Not releasing direct ip " + ip.getId() +" yet as its ip is saved in the placeholder");
+                } else {
+                    _networkMgr.markIpAsUnavailable(ip.getId());
+                    _ipAddressDao.unassignIpAddress(ip.getId());
+                }
+               
+                //unassign nic secondary ip address
+                s_logger.debug("remove nic " + nic.getId() + " secondary ip ");
+                List<String> nicSecIps = null;
+                nicSecIps = _nicSecondaryIpDao.getSecondaryIpAddressesForNic(nic.getId());
+                for (String secIp: nicSecIps) {
+                    IPAddressVO pubIp = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), secIp);
+                    _networkMgr.markIpAsUnavailable(pubIp.getId());
+                    _ipAddressDao.unassignIpAddress(pubIp.getId());
+                }
+    
+                txn.commit();
             }
-
-            txn.commit();
-        }
     	}
     	
     	if (nic.getIp6Address() != null) {
@@ -261,7 +292,24 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
     }
 
     @Override
+    @DB
     public boolean trash(Network network, NetworkOffering offering, Account owner) {
+        //Have to remove all placeholder nics
+        List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkId(network.getId());
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        for (Nic nic : nics) {
+            if (nic.getIp4Address() != null) {
+                s_logger.debug("Releasing ip " + nic.getIp4Address() + " of placeholder nic " + nic);
+                IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
+                _networkMgr.markIpAsUnavailable(ip.getId());
+                _ipAddressDao.unassignIpAddress(ip.getId());
+                s_logger.debug("Removing placeholder nic " + nic);
+                _nicDao.remove(nic.getId());
+            }
+        }
+        
+        txn.commit();
         return true;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
index 8efbcd7..d74cd06 100755
--- a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
@@ -17,6 +17,7 @@
 package com.cloud.network.guru;
 
 import java.net.URI;
+import java.util.List;
 
 import javax.ejb.Local;
 import javax.inject.Inject;
@@ -50,6 +51,7 @@ import com.cloud.offerings.dao.NetworkOfferingDao;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.Nic;
 import com.cloud.vm.Nic.ReservationStrategy;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.ReservationContext;
@@ -155,11 +157,34 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
         nic.setDns2(dc.getDns2());
     }
 
+    @DB
     protected void getIp(NicProfile nic, Pod pod, VirtualMachineProfile<? extends VirtualMachine> vm, Network network) throws InsufficientVirtualNetworkCapcityException,
             InsufficientAddressCapacityException, ConcurrentOperationException {
         DataCenter dc = _dcDao.findById(pod.getDataCenterId());
         if (nic.getIp4Address() == null) {
-            PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, false);
+            Transaction txn = Transaction.currentTxn();
+            txn.start();
+            
+            PublicIp ip = null;
+            List<PodVlanMapVO> podRefs = _podVlanDao.listPodVlanMapsByPod(pod.getId());
+            String podRangeGateway = null;
+            if (!podRefs.isEmpty()) {
+                podRangeGateway = _vlanDao.findById(podRefs.get(0).getVlanDbId()).getVlanGateway();
+            }
+            //Get ip address from the placeholder and don't allocate a new one
+            if (vm.getType() == VirtualMachine.Type.DomainRouter) {
+                Nic placeholderNic = _networkModel.getPlaceholderNic(network, null);
+                if (placeholderNic != null) {
+                    IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIp4Address());
+                    ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
+                    s_logger.debug("Nic got an ip address " + placeholderNic.getIp4Address() + " stored in placeholder nic for the network " + network + " and gateway " + podRangeGateway);
+                }
+            }
+            
+            if (ip == null) {
+                ip = _networkMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, false);
+            }
+            
             nic.setIp4Address(ip.getAddress().toString());
             nic.setFormat(AddressFormat.Ip4);
             nic.setGateway(ip.getGateway());
@@ -171,6 +196,16 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
             }
             nic.setReservationId(String.valueOf(ip.getVlanTag()));
             nic.setMacAddress(ip.getMacAddress());
+            
+            //save the placeholder nic if the vm is the Virtual router
+            if (vm.getType() == VirtualMachine.Type.DomainRouter) {
+                Nic placeholderNic = _networkModel.getPlaceholderNic(network, null);
+                if (placeholderNic == null) {
+                    s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIp4Address() + " for the network " + network + " with the gateway " + podRangeGateway);
+                    _networkMgr.savePlaceholderNic(network, nic.getIp4Address());
+                }
+            }
+            txn.commit();
         }
         nic.setDns1(dc.getDns1());
         nic.setDns2(dc.getDns2());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 6742f7b..45b11f7 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -27,11 +27,9 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Queue;
 import java.util.Set;
 import java.util.TimeZone;
 import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -41,8 +39,8 @@ import java.util.concurrent.TimeUnit;
 import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
+
 import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
-import com.cloud.agent.api.to.*;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -174,7 +172,6 @@ import com.cloud.network.router.VirtualRouter.RedundantState;
 import com.cloud.network.router.VirtualRouter.Role;
 import com.cloud.network.rules.FirewallRule;
 import com.cloud.network.rules.FirewallRule.Purpose;
-import com.cloud.network.rules.FirewallRuleVO;
 import com.cloud.network.rules.PortForwardingRule;
 import com.cloud.network.rules.RulesManager;
 import com.cloud.network.rules.StaticNat;
@@ -210,7 +207,6 @@ import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.PasswordGenerator;
 import com.cloud.utils.StringUtils;
-
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.DB;
@@ -1703,15 +1699,30 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
             if (!setupPublicNetwork) {
             	if (guestNetwork.getCidr() != null) {
-            		String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
-            		if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
-            			defaultNetworkStartIp = startIp;
-            		} else if (s_logger.isDebugEnabled()){
-            			s_logger.debug("First ip " + startIp + " in network id=" + guestNetwork.getId() + 
-            					" is already allocated, can't use it for domain router; will get random ip address from the range");
-            		}
+            	    //Check the placeholder nic, and if it's ip address is not empty, allocate it from there
+            	    String requestedGateway = null;
+            	    if (guestNetwork.getGateway() != null) {
+            	        requestedGateway = guestNetwork.getGateway();
+            	    } else if (plan != null && plan.getPodId() != null) {
+            	        Pod pod = _configMgr.getPod(plan.getPodId());
+            	        requestedGateway = pod.getGateway();
+            	    }
+            	    Nic placeholder = _networkModel.getPlaceholderNic(guestNetwork, null);
+            	    if (placeholder != null) {
+            	        s_logger.debug("Requesting ip address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + guestNetwork);
+            	        defaultNetworkStartIp = placeholder.getIp4Address();
+            	    } else {
+            	        String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
+                        if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
+                            defaultNetworkStartIp = startIp;
+                        } else if (s_logger.isDebugEnabled()){
+                            s_logger.debug("First ip " + startIp + " in network id=" + guestNetwork.getId() + 
+                                    " is already allocated, can't use it for domain router; will get random ip address from the range");
+                        }
+            	    }
             	}
             	
+            	//FIXME - get ipv6 stored in the placeholder
             	if (guestNetwork.getIp6Cidr() != null) {
             		String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
             		if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
index db562b1..f210dc1 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -60,6 +60,7 @@ public class Upgrade410to420 implements DbUpgrade {
 	@Override
 	public void performDataMigration(Connection conn) {
         upgradeVmwareLabels(conn);
+        createPlaceHolderNics(conn);
         PreparedStatement sql = null;
         try {
             sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
@@ -158,4 +159,41 @@ public class Upgrade410to420 implements DbUpgrade {
             }
         }
     }
+    
+    private void createPlaceHolderNics(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("SELECT network_id, gateway, ip4_address FROM `cloud`.`nics` WHERE reserver_name IN ('DirectNetworkGuru','DirectPodBasedNetworkGuru') and vm_type='DomainRouter' AND removed IS null");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                    Long networkId = rs.getLong(1);
+                    String gateway = rs.getString(2);
+                    String ip = rs.getString(3);
+                    String uuid = UUID.randomUUID().toString();
+                    //Insert placeholder nic for each Domain router nic in Shared network
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`nics` (uuid, ip4_address, gateway, network_id, state, strategy) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder')");
+                    pstmt.setString(1, uuid);
+                    pstmt.setString(2, ip);
+                    pstmt.setString(3, gateway);
+                    pstmt.setLong(4, networkId);
+                    pstmt.executeUpdate();
+                    s_logger.debug("Created placeholder nic for the ipAddress " + ip);
+                
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to create placeholder nics", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/vm/dao/NicDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/dao/NicDao.java b/server/src/com/cloud/vm/dao/NicDao.java
index 35d7191..eb38a8d 100644
--- a/server/src/com/cloud/vm/dao/NicDao.java
+++ b/server/src/com/cloud/vm/dao/NicDao.java
@@ -62,4 +62,7 @@ public interface NicDao extends GenericDao<NicVO, Long> {
     List<NicVO> listByVmIdAndNicId(Long vmId, Long nicId);
 
     NicVO findByIp4AddressAndVmId(String ip4Address, long instance);
+    
+    List<NicVO> listPlaceholderNicsByNetworkId(long networkId);
+    
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/src/com/cloud/vm/dao/NicDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/dao/NicDaoImpl.java b/server/src/com/cloud/vm/dao/NicDaoImpl.java
index b9ec72e..b427d4e 100644
--- a/server/src/com/cloud/vm/dao/NicDaoImpl.java
+++ b/server/src/com/cloud/vm/dao/NicDaoImpl.java
@@ -221,4 +221,12 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
         return findOneBy(sc);
     }
 
+    @Override
+    public List<NicVO> listPlaceholderNicsByNetworkId(long networkId) {
+        SearchCriteria<NicVO> sc = AllFieldsSearch.create();
+        sc.setParameters("network", networkId);
+        sc.setParameters("strategy", Nic.ReservationStrategy.PlaceHolder.toString());
+        return listBy(sc);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java
index eb43cce..6da48ec 100755
--- a/server/test/com/cloud/network/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java
@@ -67,6 +67,7 @@ import com.cloud.utils.component.ManagerBase;
 import com.cloud.vm.Nic;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicSecondaryIp;
+import com.cloud.vm.NicVO;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
@@ -881,4 +882,10 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
         // TODO Auto-generated method stub
         return false;
     }
+
+    @Override
+    public NicVO savePlaceholderNic(Network network, String ip4Address) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/test/com/cloud/network/MockNetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkModelImpl.java b/server/test/com/cloud/network/MockNetworkModelImpl.java
index 83dddf4..b926519 100644
--- a/server/test/com/cloud/network/MockNetworkModelImpl.java
+++ b/server/test/com/cloud/network/MockNetworkModelImpl.java
@@ -34,16 +34,13 @@ import com.cloud.network.Network.GuestType;
 import com.cloud.network.Network.Provider;
 import com.cloud.network.Network.Service;
 import com.cloud.network.Networks.TrafficType;
-import com.cloud.network.addr.PublicIp;
 import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.NetworkVO;
 import com.cloud.network.element.NetworkElement;
 import com.cloud.network.element.UserDataServiceProvider;
-import com.cloud.network.rules.FirewallRule;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.offerings.NetworkOfferingVO;
 import com.cloud.user.Account;
-import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.vm.Nic;
 import com.cloud.vm.NicProfile;
@@ -841,4 +838,10 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
 		// TODO Auto-generated method stub
 		return null;
 	}
+
+    @Override
+    public Nic getPlaceholderNic(Network network, Long podId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index c798cdf..ead0051 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -83,6 +83,7 @@ import com.cloud.utils.component.ManagerBase;
 import com.cloud.vm.Nic;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicSecondaryIp;
+import com.cloud.vm.NicVO;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
@@ -1411,4 +1412,16 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
         // TODO Auto-generated method stub
         return false;
     }
+
+
+
+
+
+    @Override
+    public NicVO savePlaceholderNic(Network network, String ip4Address) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26b892da/server/test/com/cloud/vpc/MockNetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkModelImpl.java b/server/test/com/cloud/vpc/MockNetworkModelImpl.java
index 7f1f945..b05e8ea 100644
--- a/server/test/com/cloud/vpc/MockNetworkModelImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkModelImpl.java
@@ -41,17 +41,14 @@ import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.PhysicalNetwork;
 import com.cloud.network.PhysicalNetworkSetupInfo;
 import com.cloud.network.PublicIpAddress;
-import com.cloud.network.addr.PublicIp;
 import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.NetworkVO;
 import com.cloud.network.element.NetworkElement;
 import com.cloud.network.element.UserDataServiceProvider;
-import com.cloud.network.rules.FirewallRule;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.offerings.NetworkOfferingVO;
 import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
 import com.cloud.user.Account;
-import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.vm.Nic;
 import com.cloud.vm.NicProfile;
@@ -854,4 +851,10 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
 		return null;
 	}
 
+    @Override
+    public Nic getPlaceholderNic(Network network, Long podId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }


Mime
View raw message