cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: updated refs/heads/master to bf9375b
Date Mon, 10 Mar 2014 18:42:55 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 1d74daf6f -> bf9375b8b


CLOUDSTACK-6214: apply network rules when plug new guest nic to router for the network in
Setup state
Conflicts:
	server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java
	server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java

Conflicts:
	api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java
	server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java
	server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
	server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java


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

Branch: refs/heads/master
Commit: bf9375b8b9c437bf314d0459233f17860d85d3f3
Parents: 1d74daf
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Fri Mar 7 15:06:35 2014 -0800
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Mon Mar 10 11:42:24 2014 -0700

----------------------------------------------------------------------
 .../VpcVirtualNetworkApplianceService.java      |  8 +++--
 .../element/VpcVirtualRouterElement.java        | 14 ++++++--
 .../VpcVirtualNetworkApplianceManagerImpl.java  | 34 +++++++++++++++++---
 .../MockVpcVirtualNetworkApplianceManager.java  |  7 ++--
 4 files changed, 51 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf9375b8/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java b/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java
index eee62ce..382c460 100644
--- a/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java
+++ b/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java
@@ -16,10 +16,13 @@
 // under the License.
 package com.cloud.network;
 
+import java.util.Map;
+
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.router.VirtualRouter;
+import com.cloud.vm.VirtualMachineProfile;
 
 public interface VpcVirtualNetworkApplianceService extends VirtualNetworkApplianceService
{
 
@@ -27,13 +30,14 @@ public interface VpcVirtualNetworkApplianceService extends VirtualNetworkApplian
      * @param router
      * @param network
      * @param isRedundant
+     * @param params TODO
      * @return
      * @throws ConcurrentOperationException
      * @throws ResourceUnavailableException
      * @throws InsufficientCapacityException
      */
-    boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant)
throws ConcurrentOperationException, ResourceUnavailableException,
-        InsufficientCapacityException;
+    boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant,
Map<VirtualMachineProfile.Param, Object> params)
+            throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
 
     /**
      * @param router

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf9375b8/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 5695a2c..b433fe4 100644
--- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
@@ -36,6 +36,7 @@ import com.cloud.network.Network;
 import com.cloud.network.Network.Capability;
 import com.cloud.network.Network.Provider;
 import com.cloud.network.Network.Service;
+import com.cloud.network.Network.State;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.PublicIpAddress;
 import com.cloud.network.RemoteAccessVpn;
@@ -179,7 +180,11 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements
Vpc
         DomainRouterVO router = routers.get(0);
         //Add router to guest network if needed
         if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
-            if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(router, network, false)) {
+            Map<VirtualMachineProfile.Param, Object> paramsForRouter = new HashMap<VirtualMachineProfile.Param,
Object>(1);
+            if (network.getState() == State.Setup) {
+                paramsForRouter.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
+            }
+            if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(router, network, false, paramsForRouter))
{
                 throw new CloudRuntimeException("Failed to add VPC router " + router + "
to guest network " + network);
             } else {
                 s_logger.debug("Successfully added VPC router " + router + " to guest network
" + network);
@@ -220,7 +225,12 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements
Vpc
             DomainRouterVO router = routers.get(0);
             //Add router to guest network if needed
             if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
-                if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(router, network, false)) {
+                Map<VirtualMachineProfile.Param, Object> paramsForRouter = new HashMap<VirtualMachineProfile.Param,
Object>(1);
+                // need to reprogram guest network if it comes in a setup state
+                if (network.getState() == State.Setup) {
+                    paramsForRouter.put(VirtualMachineProfile.Param.ReProgramGuestNetworks,
true);
+                }
+                if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(router, network, false, paramsForRouter))
{
                     throw new CloudRuntimeException("Failed to add VPC router " + router
+ " to guest network " + network);
                 } else {
                     s_logger.debug("Successfully added VPC router " + router + " to guest
network " + network);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf9375b8/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 bed30df..f7fdd08 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -36,6 +36,7 @@ import org.springframework.stereotype.Component;
 
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.Command;
+import com.cloud.agent.api.Command.OnError;
 import com.cloud.agent.api.NetworkUsageCommand;
 import com.cloud.agent.api.PlugNicCommand;
 import com.cloud.agent.api.SetupGuestNetworkCommand;
@@ -246,9 +247,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
     }
 
     @Override
-    public boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean
isRedundant) throws ConcurrentOperationException,
-        ResourceUnavailableException, InsufficientCapacityException {
-
+    public boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean
isRedundant, Map<VirtualMachineProfile.Param, Object> params)
+            throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException
{
         if (network.getTrafficType() != TrafficType.Guest) {
             s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest);
             return false;
@@ -257,16 +257,23 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         //Add router to the Guest network
         boolean result = true;
         try {
+
+            // 1) add nic to the router
             _routerDao.addRouterToGuestNetwork(router, network);
 
             NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null);
-            //setup guest network
+            //2) setup guest network
             if (guestNic != null) {
                 result = setupVpcGuestNetwork(network, router, true, guestNic);
             } else {
                 s_logger.warn("Failed to add router " + router + " to guest network " + network);
                 result = false;
             }
+            //3) apply networking rules
+            if (result && params.get(Param.ReProgramGuestNetworks) != null
+                    && (Boolean) params.get(Param.ReProgramGuestNetworks) == true)
{
+                sendNetworkRulesToRouter(router.getId(), network.getId());
+            }
         } catch (Exception ex) {
             s_logger.warn("Failed to add router " + router + " to network " + network + "
due to ", ex);
             result = false;
@@ -885,6 +892,25 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         }
     }
 
+
+    protected boolean sendNetworkRulesToRouter(long routerId, long networkId)
+            throws ResourceUnavailableException {
+        DomainRouterVO router = _routerDao.findById(routerId);
+        Commands cmds = new Commands(OnError.Continue);
+
+        VirtualRouterProvider vrProvider = _vrProviderDao.findById(router.getElementId());
+        if (vrProvider == null) {
+            throw new CloudRuntimeException("Cannot find related virtual router provider
of router: " + router.getHostName());
+        }
+        Provider provider = Network.Provider.getProvider(vrProvider.getType().toString());
+        if (provider == null) {
+            throw new CloudRuntimeException("Cannot find related provider of virtual router
provider: " + vrProvider.getType().toString());
+        }
+
+        finalizeNetworkRulesForNetwork(cmds, router, provider, networkId);
+        return sendCommandsToRouter(router, cmds);
+    }
+
     @Override
     public boolean setupPrivateGateway(PrivateGateway gateway, VirtualRouter router) throws
ConcurrentOperationException, ResourceUnavailableException {
         boolean result = true;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bf9375b8/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java b/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
index 4802cff..e0c599d 100644
--- a/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
+++ b/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
@@ -23,10 +23,9 @@ import java.util.Map;
 import javax.ejb.Local;
 import javax.naming.ConfigurationException;
 
-import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
 import org.apache.cloudstack.api.command.admin.router.UpgradeRouterTemplateCmd;
+import org.springframework.stereotype.Component;
 
 import com.cloud.deploy.DeployDestination;
 import com.cloud.exception.ConcurrentOperationException;
@@ -313,8 +312,8 @@ public class MockVpcVirtualNetworkApplianceManager extends ManagerBase
implement
      * @see com.cloud.network.VpcVirtualNetworkApplianceService#addVpcRouterToGuestNetwork(com.cloud.network.router.VirtualRouter,
com.cloud.network.Network, boolean)
      */
     @Override
-    public boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean
isRedundant) throws ConcurrentOperationException,
-        ResourceUnavailableException, InsufficientCapacityException {
+    public boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean
isRedundant, Map<VirtualMachineProfile.Param, Object> params)
+            throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException
{
         // TODO Auto-generated method stub
         return false;
     }


Mime
View raw message