From 08b2f7e37e71393ad3bd347be9952692b374b698 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 26 Jun 2012 16:12:38 -0700 Subject: [PATCH] VPC : handle staticnat and loadbalaner --- .../xen/resource/CitrixResourceBase.java | 89 +++++++++++++++++++ .../config/opt/cloud/bin/vpc_loadbalancer.sh | 5 +- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 27afe9adc9d..5c0ca6051e6 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -1490,7 +1490,34 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return new SetPortForwardingRulesAnswer(cmd, results, endResult); } + protected SetStaticNatRulesAnswer SetVPCStaticNatRules(SetStaticNatRulesCommand cmd) { + Connection conn = getConnection(); + String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); + //String args = routerIp; + String[] results = new String[cmd.getRules().length]; + int i = 0; + boolean endResult = true; + for (StaticNatRuleTO rule : cmd.getRules()) { + String args = "vpc_staticnat.sh " + routerIp; + args += rule.revoked() ? " -D" : " -A"; + args += " -l " + rule.getSrcIp(); + args += " -r " + rule.getDstIp(); + String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args.toString()); + + if (result == null || result.isEmpty()) { + results[i++] = "Failed"; + endResult = false; + } else { + results[i++] = null; + } + } + return new SetStaticNatRulesAnswer(cmd, results, endResult); + } + protected SetStaticNatRulesAnswer execute(SetStaticNatRulesCommand cmd) { + if ( cmd.getVpcId() != null ) { + return SetVPCStaticNatRules(cmd); + } Connection conn = getConnection(); String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); @@ -1526,7 +1553,69 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return new SetStaticNatRulesAnswer(cmd, results, endResult); } + protected Answer VPCLoadBalancerConfig(final LoadBalancerConfigCommand cmd) { + Connection conn = getConnection(); + 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"; + } + String[][] rules = cfgtr.generateFwRules(cmd); + + String[] addRules = rules[LoadBalancerConfigurator.ADD]; + String[] removeRules = rules[LoadBalancerConfigurator.REMOVE]; + String[] statRules = rules[LoadBalancerConfigurator.STATS]; + + String args = "vpc_loadbalancer.sh " + routerIp; + args += " -f " + tmpCfgFileContents; + + 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 = callHostPlugin(conn, "vmops", "routerProxy", "args", args); + + if (result == null || result.isEmpty()) { + return new Answer(cmd, false, "LoadBalancerConfigCommand failed"); + } + return new Answer(cmd); + } + protected Answer execute(final LoadBalancerConfigCommand cmd) { + if ( cmd.getVpcId() != null ) { + return VPCLoadBalancerConfig(cmd); + } Connection conn = getConnection(); String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); diff --git a/patches/systemvm/debian/config/opt/cloud/bin/vpc_loadbalancer.sh b/patches/systemvm/debian/config/opt/cloud/bin/vpc_loadbalancer.sh index ce49b9b514f..938f79bbf42 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/vpc_loadbalancer.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/vpc_loadbalancer.sh @@ -118,6 +118,7 @@ fw_entry() { #Hot reconfigure HA Proxy in the routing domain reconfig_lb() { + echo "$cfgContent" > /etc/haproxy/haproxy.cfg.new /root/reconfigLB.sh return $? } @@ -155,7 +156,7 @@ do removedIps="$OPTARG" ;; f) fflag=1 - cfgfile="$OPTARG" + cfgContent="$OPTARG" ;; s) sflag=1 statsIp="$OPTARG" @@ -177,7 +178,7 @@ then fi # hot reconfigure haproxy -reconfig_lb $cfgfile +reconfig_lb if [ $? -gt 0 ] then