incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [43/51] [abbrv] git commit: Modified virtual router startup procedure - initial start happens with control nic only; then we plug Public and then Guest nic to it
Date Fri, 15 Jun 2012 22:38:03 GMT
Modified virtual router startup procedure - initial start happens with control nic only; then
we plug Public and then Guest nic to it


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

Branch: refs/heads/vpc
Commit: 72974831a01e30f6b800fc694fd5a7863d9953d2
Parents: 0a7faa9
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Tue Jun 5 10:55:20 2012 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Fri Jun 15 14:22:19 2012 -0700

----------------------------------------------------------------------
 .../commands/CreateVirtualRouterElementCmd.java    |    3 +-
 .../network/VirtualNetworkApplianceService.java    |    6 +-
 .../element/VirtualRouterElementService.java       |    3 +-
 .../xen/resource/CitrixResourceBase.java           |   40 ++++-
 .../src/com/cloud/network/NetworkManagerImpl.java  |    5 +-
 .../network/element/VirtualRouterElement.java      |    6 +-
 .../router/VirtualNetworkApplianceManagerImpl.java |  159 +++++++++++++--
 .../VpcVirtualNetworkApplianceManagerImpl.java     |   15 ++-
 wscript                                            |    7 +-
 9 files changed, 209 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72974831/api/src/com/cloud/api/commands/CreateVirtualRouterElementCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateVirtualRouterElementCmd.java b/api/src/com/cloud/api/commands/CreateVirtualRouterElementCmd.java
index 595011d..2c44663 100644
--- a/api/src/com/cloud/api/commands/CreateVirtualRouterElementCmd.java
+++ b/api/src/com/cloud/api/commands/CreateVirtualRouterElementCmd.java
@@ -30,6 +30,7 @@ import com.cloud.api.response.VirtualRouterProviderResponse;
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.network.VirtualRouterProvider;
+import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
 import com.cloud.network.element.VirtualRouterElementService;
 import com.cloud.user.Account;
 import com.cloud.user.UserContext;
@@ -96,7 +97,7 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
 
     @Override
     public void create() throws ResourceAllocationException {
-        VirtualRouterProvider result = _service.addElement(getNspId());
+        VirtualRouterProvider result = _service.addElement(getNspId(), VirtualRouterProviderType.VirtualRouter);
         if (result != null) {
             setEntityId(result.getId());
         } else {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72974831/api/src/com/cloud/network/VirtualNetworkApplianceService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java
index 8c32f79..e35573f 100644
--- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java
+++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java
@@ -71,7 +71,8 @@ public interface VirtualNetworkApplianceService {
      * @throws ResourceUnavailableException
      * @throws InsufficientCapacityException
      */
-    boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
+    boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant)

+            throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
 
     /**
      * @param router
@@ -81,5 +82,6 @@ public interface VirtualNetworkApplianceService {
      * @throws ConcurrentOperationException
      * @throws ResourceUnavailableException
      */
-    boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant)
throws ConcurrentOperationException, ResourceUnavailableException;
+    boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant)
+            throws ConcurrentOperationException, ResourceUnavailableException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72974831/api/src/com/cloud/network/element/VirtualRouterElementService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/element/VirtualRouterElementService.java b/api/src/com/cloud/network/element/VirtualRouterElementService.java
index d84fc0c..bf8cad2 100644
--- a/api/src/com/cloud/network/element/VirtualRouterElementService.java
+++ b/api/src/com/cloud/network/element/VirtualRouterElementService.java
@@ -21,11 +21,12 @@ import java.util.List;
 import com.cloud.api.commands.ConfigureVirtualRouterElementCmd;
 import com.cloud.api.commands.ListVirtualRouterElementsCmd;
 import com.cloud.network.VirtualRouterProvider;
+import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
 import com.cloud.utils.component.PluggableService;
 
 public interface VirtualRouterElementService extends PluggableService{
     VirtualRouterProvider configure(ConfigureVirtualRouterElementCmd cmd);
-    VirtualRouterProvider addElement(Long nspId);
+    VirtualRouterProvider addElement(Long nspId, VirtualRouterProviderType providerType);
     VirtualRouterProvider getCreatedElement(long id);
     List<? extends VirtualRouterProvider> searchForVirtualRouterElement(ListVirtualRouterElementsCmd
cmd);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72974831/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index 121675e..2605b2e 100644
--- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -103,6 +103,8 @@ import com.cloud.agent.api.PingCommand;
 import com.cloud.agent.api.PingRoutingWithNwGroupsCommand;
 import com.cloud.agent.api.PingRoutingWithOvsCommand;
 import com.cloud.agent.api.PingTestCommand;
+import com.cloud.agent.api.PlugNicAnswer;
+import com.cloud.agent.api.PlugNicCommand;
 import com.cloud.agent.api.PoolEjectCommand;
 import com.cloud.agent.api.PrepareForMigrationAnswer;
 import com.cloud.agent.api.PrepareForMigrationCommand;
@@ -115,6 +117,8 @@ import com.cloud.agent.api.SecurityGroupRuleAnswer;
 import com.cloud.agent.api.SecurityGroupRulesCmd;
 import com.cloud.agent.api.SetupAnswer;
 import com.cloud.agent.api.SetupCommand;
+import com.cloud.agent.api.SetupGuestNetworkAnswer;
+import com.cloud.agent.api.SetupGuestNetworkCommand;
 import com.cloud.agent.api.StartAnswer;
 import com.cloud.agent.api.StartCommand;
 import com.cloud.agent.api.StartupCommand;
@@ -123,6 +127,8 @@ import com.cloud.agent.api.StartupStorageCommand;
 import com.cloud.agent.api.StopAnswer;
 import com.cloud.agent.api.StopCommand;
 import com.cloud.agent.api.StoragePoolInfo;
+import com.cloud.agent.api.UnPlugNicAnswer;
+import com.cloud.agent.api.UnPlugNicCommand;
 import com.cloud.agent.api.UpdateHostPasswordCommand;
 import com.cloud.agent.api.UpgradeSnapshotCommand;
 import com.cloud.agent.api.VmStatsEntry;
@@ -516,12 +522,17 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
             return execute((GetDomRVersionCmd)cmd);
         } else if (clazz == CheckNetworkCommand.class) {
             return execute((CheckNetworkCommand) cmd);
-        } else {
+        } else if (clazz == SetupGuestNetworkCommand.class) {
+            return execute((SetupGuestNetworkCommand) cmd);
+        } else if (clazz == PlugNicCommand.class) {
+            return execute((PlugNicCommand) cmd);
+        } else if (clazz == UnPlugNicCommand.class) {
+            return execute((UnPlugNicCommand) cmd);
+        }else {
             return Answer.createUnsupportedCommandAnswer(cmd);
         }
     }
 
-
     protected XsLocalNetwork getNativeNetworkForTraffic(Connection conn, TrafficType type,
String name) throws XenAPIException, XmlRpcException {
         if (name != null) {
             if (s_logger.isDebugEnabled()) {
@@ -6957,7 +6968,32 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
         return changes;
     }
 
+    /**
+     * @param cmd
+     * @return
+     */
+    private UnPlugNicAnswer execute(UnPlugNicCommand cmd) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 
+    /**
+     * @param cmd
+     * @return
+     */
+    private PlugNicAnswer execute(PlugNicCommand cmd) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /**
+     * @param cmd
+     * @return
+     */
+    private SetupGuestNetworkAnswer execute(SetupGuestNetworkCommand cmd) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72974831/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 338c840..52865bf 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -108,6 +108,7 @@ import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.Networks.IsolationType;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.PhysicalNetwork.BroadcastDomainRange;
+import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
 import com.cloud.network.addr.PublicIp;
 import com.cloud.network.dao.FirewallRulesDao;
 import com.cloud.network.dao.IPAddressDao;
@@ -6524,7 +6525,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService,
Manag
         if (element == null) {
             throw new CloudRuntimeException("Unable to find the Network Element implementing
the VirtualRouter Provider");
         }
-        element.addElement(nsp.getId());
+        element.addElement(nsp.getId(), VirtualRouterProviderType.VirtualRouter);
 
         return nsp;
     }
@@ -6538,7 +6539,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService,
Manag
         if (element == null) {
             throw new CloudRuntimeException("Unable to find the Network Element implementing
the VPCVirtualRouter Provider");
         }
-        element.addElement(nsp.getId());
+        element.addElement(nsp.getId(), VirtualRouterProviderType.VPCVirtualRouter);
 
         return nsp;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72974831/server/src/com/cloud/network/element/VirtualRouterElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java
index a642cd6..b2f139e 100755
--- a/server/src/com/cloud/network/element/VirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VirtualRouterElement.java
@@ -696,13 +696,13 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
     }
 
     @Override
-    public VirtualRouterProvider addElement(Long nspId) {
-        VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, VirtualRouterProviderType.VirtualRouter);
+    public VirtualRouterProvider addElement(Long nspId, VirtualRouterProviderType providerType)
{
+        VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, providerType);
         if (element != null) {
             s_logger.debug("There is already a virtual router element with service provider
id " + nspId);
             return null;
         }
-        element = new VirtualRouterProviderVO(nspId, VirtualRouterProviderType.VirtualRouter);
+        element = new VirtualRouterProviderVO(nspId, providerType);
         _vrProviderDao.persist(element);
         return element;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72974831/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 52a7a59..1ec4936 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -60,6 +60,7 @@ import com.cloud.agent.api.UnPlugNicCommand;
 import com.cloud.agent.api.check.CheckSshAnswer;
 import com.cloud.agent.api.check.CheckSshCommand;
 import com.cloud.agent.api.routing.DhcpEntryCommand;
+import com.cloud.agent.api.routing.IpAssocAnswer;
 import com.cloud.agent.api.routing.IpAssocCommand;
 import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
@@ -200,7 +201,6 @@ import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.MacAddress;
 import com.cloud.utils.net.NetUtils;
 import com.cloud.vm.DomainRouterVO;
-import com.cloud.vm.Nic;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.ReservationContext;
@@ -1259,11 +1259,15 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
         }
         
         //3) Deploy Virtual Router(s)
+        PublicIp sourceNatIp = null;
+        if (publicNetwork) {
+            sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork);
+        }
         try {
             int count = routerCount - routers.size();
             for (int i = 0; i < count; i++) {
                 DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant,
vrProvider, offeringId,
-                        null);
+                        null, sourceNatIp);
                 routers.add(router);
             }
         } finally {
@@ -1276,7 +1280,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
 
     protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan
plan, Map<Param, Object> params,
             boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId,
-            Long vpcId) throws ConcurrentOperationException, 
+            Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, 
             InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,

             StorageUnavailableException, ResourceUnavailableException {
         
@@ -1374,7 +1378,17 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
             }
         } 
         
-        //3) Plug public nic 
+        //3) Plug public nic
+        boolean addToPublicNtwk = true;
+        if (sourceNatIp != null) {
+            Network publicNetwork = _networkDao.listByZoneAndTrafficType(dest.getDataCenter().getId(),
TrafficType.Public).get(0);
+            addToPublicNtwk = addRouterToPublicNetwork(router, publicNetwork, sourceNatIp);

+        }
+        
+        if (!addToPublicNtwk) {
+            s_logger.warn("Failed to add router " + router + " to public network in zone
" + dest.getDataCenter() + " cleaninig up");
+            destroyRouter(router.getId());
+        }
         
         return router;
     }
@@ -2956,9 +2970,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
             InsufficientCapacityException {     
         boolean result = true;
         
-        //FIXME - Anthony, here I send plug nic command on xen side
         try {
-             
             PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic);
             
             Commands cmds = new Commands(OnError.Stop);
@@ -2983,7 +2995,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
     public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
             ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException {
         
-        //FIXME - Anthony, add unplug nic agent command on xen side
         boolean result = true;
         DomainRouterVO router = _routerDao.findById(vm.getId());
         try {
@@ -3013,7 +3024,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
         String networkDomain = network.getNetworkDomain();
         String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId()));
         
-        //FIXME - Anthony, add setup guest network command logic on Xen side
         boolean result = true;
         long guestVlanTag = Long.parseLong(network.getBroadcastUri().getHost());
         
@@ -3054,7 +3064,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
         sendCommandsToRouter(router, cmds);
         
         SetupGuestNetworkAnswer setupAnswer = cmds.getAnswer(SetupGuestNetworkAnswer.class);
-        String setup = add ? "set" : "unset";
+        String setup = add ? "set" : "destroy";
         if (!(setupAnswer != null && setupAnswer.getResult())) {
             s_logger.warn("Unable to " + setup + " guest network on router " + router);
             result = false;
@@ -3062,20 +3072,24 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
         
         return result;
     }
-    
 
     @Override
     public boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean
isRedundant) throws ConcurrentOperationException, 
                     ResourceUnavailableException, InsufficientCapacityException {
         
-        //Check if router is already a part of the network
+        if (network.getTrafficType() != TrafficType.Guest) {
+            s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest);
+            return false;
+        }
+        
+        //Check if router is already a part of the Guest network
         if (_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
-            s_logger.debug("Router " + router + " is already part of the network " + network);
+            s_logger.debug("Router " + router + " is already part of the Guest network "
+ network);
             return true;
         }
         
-        //Add router to network
-        boolean result = false;
+        //Add router to the Guest network
+        boolean result = true;
         try {
             DomainRouterVO routerVO = _routerDao.findById(router.getId());
             s_logger.debug("Plugging nic for vpc virtual router " + router + " in network
" + network);
@@ -3090,6 +3104,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
             }
         } catch (Exception ex) {
             s_logger.warn("Failed to add router " + router + " to network " + network);
+            result = false;
         } finally {
             if (!result) {
                 s_logger.debug("Removing the router " + router + " from network " + network
+ " as a part of cleanup");
@@ -3108,16 +3123,20 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
     @Override
     public boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean
isRedundant) 
             throws ConcurrentOperationException, ResourceUnavailableException {
+        if (network.getTrafficType() != TrafficType.Guest) {
+            s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest);
+            return false;
+        }
         
-        //Check if router is a part of the network
+        //Check if router is a part of the Guest network
         if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
-            s_logger.debug("Router " + router + " is not a part of the network " + network);
+            s_logger.debug("Router " + router + " is not a part of the Guest network " +
network);
             return true;
         }
         
         boolean result = setupGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router,
network.getId()));
         if (!result) {
-            s_logger.warn("Failed to reset guest network config " + network + " on router
" + router);
+            s_logger.warn("Failed to destroy guest network config " + network + " on router
" + router);
             return false;
         }
         
@@ -3131,4 +3150,110 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
         }
         return result;
     }
+    
+    protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork,
IpAddress sourceNatIp) 
+            throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException
{
+        
+        if (publicNetwork.getTrafficType() != TrafficType.Public) {
+            s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public);
+            return false;
+        }
+        
+        //Check if router is already a part of the Public network
+        if (_networkMgr.isVmPartOfNetwork(router.getId(), publicNetwork.getId())) {
+            s_logger.debug("Router " + router + " is already part of the Public network "
+ publicNetwork);
+            return true;
+        }
+        
+        //Add router to the Public network
+        boolean result = true;
+        try {
+            
+            NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork);
+            //setup public network
+            if (publicNic != null) {
+                if (sourceNatIp != null) {
+                    IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId());
+                    PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()),

+                            NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
+                    result = setupPublicNetwork(publicNetwork, router, false, publicIp);
+                }
+            } else {
+                result = false;
+                s_logger.warn("Failed to add router " + router + " to the public network
" + publicNetwork);
+            }
+        } catch (Exception ex) {
+            s_logger.warn("Failed to add router " + router + " to the public network " +
publicNetwork);
+        } finally {
+            if (!result) {
+                s_logger.debug("Removing the router " + router + " from public network "
+ publicNetwork + " as a part of cleanup");
+                if (removeRouterFromPublicNetwork(router, publicNetwork)) {
+                    s_logger.debug("Removed the router " + router + " from public network
" + publicNetwork + " as a part of cleanup");
+                } else {
+                    s_logger.warn("Failed to remove the router " + router + " from public
network " + publicNetwork + " as a part of cleanup");
+                }
+            }
+        }
+        
+        return result;
+    }
+    
+    
+    protected boolean removeRouterFromPublicNetwork(VirtualRouter router, Network publicNetwork)

+            throws ConcurrentOperationException, ResourceUnavailableException {
+        
+        if (publicNetwork.getTrafficType() != TrafficType.Public) {
+            s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public);
+            return false;
+        }
+        
+        //Check if router is a part of the Guest network
+        if (!_networkMgr.isVmPartOfNetwork(router.getId(), publicNetwork.getId())) {
+            s_logger.debug("Router " + router + " is not a part of the Public network " +
publicNetwork);
+            return true;
+        }
+        
+        String routerIpStr = router.getPublicIpAddress();
+        
+        IPAddressVO sourceNatIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNetwork.getId(),
routerIpStr);
+        
+        assert sourceNatIp.isSourceNat() : "Ip " + sourceNatIp + " is not source nat";
+        
+        boolean result = true;
+        if (sourceNatIp != null) {
+            IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId());
+            _networkMgr.markIpAsUnavailable(ipVO.getId());
+            PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), 
+                    NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
+            result = setupPublicNetwork(publicNetwork, router, false, publicIp);
+        }
+        
+        if (!result) {
+            s_logger.warn("Failed to destroy public network config " + publicNetwork + "
on router " + router);
+            return false;
+        }
+        
+        result = result && _itMgr.removeVmFromNetwork(router, publicNetwork);
+        
+        return result;
+    }
+    
+    protected boolean setupPublicNetwork(Network network, VirtualRouter router, boolean add,
PublicIp sourceNatIp) 
+            throws ConcurrentOperationException, ResourceUnavailableException{
+        
+        List<PublicIp> publicIps = new ArrayList<PublicIp>(1);
+        Commands cmds = new Commands(OnError.Stop);
+        createAssociateIPCommands(router, publicIps, cmds, 0);
+        sendCommandsToRouter(router, cmds);
+
+        boolean result = true;
+        IpAssocAnswer ipAssocAnswer = cmds.getAnswer(IpAssocAnswer.class);
+        String setup = add ? "set" : "destroy";
+        if (!(ipAssocAnswer != null && ipAssocAnswer.getResult())) {
+            s_logger.warn("Unable to " + setup + " guest network on router " + router);
+            result = false;
+        }
+        
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72974831/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index 513ee5c..b967e80 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -27,6 +27,7 @@ import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.NetworkService;
 import com.cloud.network.PhysicalNetwork;
+import com.cloud.network.PhysicalNetworkServiceProvider;
 import com.cloud.network.VirtualRouterProvider;
 import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
 import com.cloud.network.addr.PublicIp;
@@ -38,6 +39,7 @@ import com.cloud.user.Account;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.Inject;
 import com.cloud.utils.db.DB;
+import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.DomainRouterVO;
 import com.cloud.vm.VirtualMachineProfile.Param;
 
@@ -99,16 +101,25 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
             List<? extends PhysicalNetwork> pNtwks = _pNtwkDao.listByZone(vpc.getZoneId());
             
             VirtualRouterProvider vpcVrProvider = null;
+           
             for (PhysicalNetwork pNtwk : pNtwks) {
-                vpcVrProvider = _vrProviderDao.findByNspIdAndType(pNtwk.getId(), 
+                PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(pNtwk.getId(),

+                        VirtualRouterProviderType.VPCVirtualRouter.toString());
+                if (provider == null) {
+                    throw new CloudRuntimeException("Cannot find service provider " + 
+                            VirtualRouterProviderType.VPCVirtualRouter.toString() + " in
physical network " + pNtwk.getId());
+                }
+                vpcVrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), 
                         VirtualRouterProviderType.VPCVirtualRouter);
                 if (vpcVrProvider != null) {
                     break;
                 }
             }
             
+            PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc);
+            
             DomainRouterVO router = deployRouter(owner, dest, plan, params, false, vpcVrProvider,
offeringId,
-                    vpc.getId());
+                    vpc.getId(), sourceNatIp);
             routers.add(router);
             
         } finally {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72974831/wscript
----------------------------------------------------------------------
diff --git a/wscript b/wscript
index 2a518e3..d38cc11 100644
--- a/wscript
+++ b/wscript
@@ -3,11 +3,8 @@
 
 # the following two variables are used by the target "waf dist"
 # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry
there, and add an entry in debian/changelog
-<<<<<<< HEAD
-VERSION = '3.0.3.2012-06-04T23:35:51Z'
-=======
-VERSION = '3.0.3.2012-06-04T21:10:12Z'
->>>>>>> Support for adding private network
+
+VERSION = '3.0.3.2012-06-05T18:30:03Z'
 APPNAME = 'cloud'
 
 import shutil,os


Mime
View raw message