You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ap...@apache.org on 2013/06/10 07:41:57 UTC
git commit: updated refs/heads/master to 673b293
Updated Branches:
refs/heads/master 22a850828 -> 673b293d7
CLOUDSTACK-2761 Fixed PF/StaticNAT in vmware vpc
Signed-off-by: Abhinandan Prateek <ap...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/673b293d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/673b293d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/673b293d
Branch: refs/heads/master
Commit: 673b293d75419a4b76379092db2b204cdc6160a4
Parents: 22a8508
Author: Jayapal <ja...@citrix.com>
Authored: Wed Jun 5 19:13:03 2013 +0530
Committer: Abhinandan Prateek <ap...@apache.org>
Committed: Mon Jun 10 11:04:01 2013 +0530
----------------------------------------------------------------------
.../vmware/resource/VmwareResource.java | 48 +++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/673b293d/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 5944cc8..46219c3 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -811,7 +811,53 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
return new SetFirewallRulesAnswer(cmd, true, results);
}
+ protected SetStaticNatRulesAnswer SetVPCStaticNatRules(SetStaticNatRulesCommand cmd) {
+ if (s_logger.isInfoEnabled()) {
+ s_logger.info("Executing resource SetVPCStaticNatRulesCommand: " + _gson.toJson(cmd));
+ }
+
+ String[] results = new String[cmd.getRules().length];
+ VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
+ String controlIp = getRouterSshControlIp(cmd);
+
+ int i = 0;
+ boolean endResult = true;
+ for (StaticNatRuleTO rule : cmd.getRules()) {
+ // Prepare command to be send to VPC VR
+ String args = "";
+ args += rule.revoked() ? " -D" : " -A";
+ args += " -l " + rule.getSrcIp();
+ args += " -r " + rule.getDstIp();
+
+ // Invoke command on VPC VR.
+ try {
+ Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null, "/opt/cloud/bin/vpc_staticnat.sh " + args);
+
+ if (s_logger.isDebugEnabled())
+ s_logger.debug("Executing script on domain router " + controlIp + ": /opt/cloud/bin/vpc_staticnat.sh " + args);
+
+ if (!result.first()) {
+ s_logger.error("SetVPCStaticNatRulesCommand failure on setting one rule. args: " + args);
+ results[i++] = "Failed";
+ endResult = false;
+ } else {
+ results[i++] = null;
+ }
+ } catch (Throwable e) {
+ s_logger.error("SetVPCStaticNatRulesCommand (args: " + args + ") failed on setting one rule due to " + VmwareHelper.getExceptionMessage(e), e);
+ results[i++] = "Failed";
+ endResult = false;
+ }
+ }
+ return new SetStaticNatRulesAnswer(cmd, results, endResult);
+ }
+
protected Answer execute(SetStaticNatRulesCommand cmd) {
+
+ if (cmd.getVpcId() != null) {
+ return SetVPCStaticNatRules(cmd);
+ }
+
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource SetFirewallRuleCommand: " + _gson.toJson(cmd));
}
@@ -1262,7 +1308,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
args += rule.revoked() ? " -D" : " -A";
args += " -P " + rule.getProtocol().toLowerCase();
args += " -l " + rule.getSrcIp();
- args += " -p " + rule.getStringSrcPortRange().replace(":", "-");
+ args += " -p " + rule.getStringSrcPortRange();
args += " -r " + rule.getDstIp();
args += " -d " + rule.getStringDstPortRange().replace(":", "-");