incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chipchild...@apache.org
Subject [6/50] [abbrv] git commit: [PATCH] CLOUDSTACK-335: fix lb for vpc on kvm
Date Mon, 15 Oct 2012 20:29:47 GMT
[PATCH] CLOUDSTACK-335: fix lb for vpc on kvm


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

Branch: refs/heads/junit-tests
Commit: 9a558d46157f46e24415faa72194212cc4a7c49c
Parents: a23bdab
Author: Edison Su <sudison@gmail.com>
Authored: Fri Oct 12 18:24:50 2012 -0700
Committer: Chip Childers <chip.childers@gmail.com>
Committed: Mon Oct 15 16:19:21 2012 -0400

----------------------------------------------------------------------
 .../virtualnetwork/VirtualRoutingResource.java     |   72 ++++++++++++++-
 1 files changed, 71 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9a558d46/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
index 2bb1145..7e53f03 100755
--- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
+++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
@@ -80,6 +80,7 @@ import com.cloud.utils.component.Manager;
 import com.cloud.utils.net.NetUtils;
 import com.cloud.utils.script.OutputInterpreter;
 import com.cloud.utils.script.Script;
+import com.cloud.utils.ssh.SshHelper;
 
 /**
  * VirtualNetworkResource controls and configures virtual networking
@@ -298,8 +299,77 @@ public class VirtualRoutingResource implements Manager {
         return new SetStaticNatRulesAnswer(cmd, results, endResult);
     }
     
+    protected Answer VPCLoadBalancerConfig(final LoadBalancerConfigCommand cmd) {
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+
+        if (routerIp == null) {
+            return new Answer(cmd);
+        }
+
+        LoadBalancerConfigurator cfgtr = new HAProxyConfigurator();
+        String[] config = cfgtr.generateConfiguration(cmd);
+        String tmpCfgFileContents = "";
+        for (int i = 0; i < config.length; i++) {
+            tmpCfgFileContents += config[i];
+            tmpCfgFileContents += "\n";
+        }
+        File permKey = new File("/root/.ssh/id_rsa.cloud");
+       
+        try {
+        	SshHelper.scpTo(routerIp, 3922, "root", permKey, null, "/etc/haproxy/", tmpCfgFileContents.getBytes(),
"haproxy.cfg.new", null);
+
+        	String[][] rules = cfgtr.generateFwRules(cmd);
+
+        	String[] addRules = rules[LoadBalancerConfigurator.ADD];
+        	String[] removeRules = rules[LoadBalancerConfigurator.REMOVE];
+        	String[] statRules = rules[LoadBalancerConfigurator.STATS];
+
+        	String ip = cmd.getNic().getIp();
+        	String args = " -i " + ip;
+        	StringBuilder sb = new StringBuilder();
+        	if (addRules.length > 0) {
+        		for (int i = 0; i < addRules.length; i++) {
+        			sb.append(addRules[i]).append(',');
+        		}
+
+        		args += " -a " + sb.toString();
+        	}
+
+        	sb = new StringBuilder();
+        	if (removeRules.length > 0) {
+        		for (int i = 0; i < removeRules.length; i++) {
+        			sb.append(removeRules[i]).append(',');
+        		}
+
+        		args += " -d " + sb.toString();
+        	}
+
+        	sb = new StringBuilder();
+        	if (statRules.length > 0) {
+        		for (int i = 0; i < statRules.length; i++) {
+        			sb.append(statRules[i]).append(',');
+        		}
+
+        		args += " -s " + sb.toString();
+        	}
+
+        	String result = routerProxy("vpc_loadbalancer.sh", routerIp, args);
+
+        	if (result != null) {
+        		return new Answer(cmd, false, "LoadBalancerConfigCommand failed");
+        	}
+        	return new Answer(cmd);
+
+        } catch (Exception e) {
+        	return new Answer(cmd, e);
+        }
+    }
 
     private Answer execute(LoadBalancerConfigCommand cmd) {
+        if ( cmd.getVpcId() != null ) {
+            return VPCLoadBalancerConfig(cmd);
+        }
+        
         String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
         File tmpCfgFile = null;
         try {
@@ -520,7 +590,7 @@ public class VirtualRoutingResource implements Manager {
         }
         
         final String result = routerProxy("checkbatchs2svpn.sh", routerIP, args);
-        if (result == null || result.isEmpty()) {
+        if (result != null) {
             return new CheckS2SVpnConnectionsAnswer(cmd, false, "CheckS2SVpnConneciontsCommand
failed");
         }
         return new CheckS2SVpnConnectionsAnswer(cmd, true, result);


Mime
View raw message