cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From muralire...@apache.org
Subject [04/17] git commit: updated refs/heads/regionvpc to cf18fe1
Date Tue, 28 Jan 2014 09:26:35 GMT
CLOUDSTACK-5779: Generalize calling to execute or create file for KVM


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

Branch: refs/heads/regionvpc
Commit: 285f23f11be9d7908e9e3b087d977dc0e223f4fe
Parents: 2d30225
Author: Sheng Yang <sheng.yang@citrix.com>
Authored: Mon Jan 20 12:03:06 2014 -0800
Committer: Sheng Yang <sheng.yang@citrix.com>
Committed: Fri Jan 24 18:28:25 2014 -0800

----------------------------------------------------------------------
 api/src/com/cloud/agent/api/to/IpAddressTO.java |  17 +
 .../api/routing/NetworkElementCommand.java      |  13 +-
 .../virtualnetwork/VirtualRouterDeployer.java   |  27 +
 .../virtualnetwork/VirtualRoutingResource.java  | 800 +++++++------------
 .../kvm/resource/LibvirtComputingResource.java  | 316 ++++----
 .../cloud/utils/script/OutputInterpreter.java   |   4 +-
 utils/src/com/cloud/utils/script/Script.java    |  15 +-
 7 files changed, 486 insertions(+), 706 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/285f23f1/api/src/com/cloud/agent/api/to/IpAddressTO.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/to/IpAddressTO.java b/api/src/com/cloud/agent/api/to/IpAddressTO.java
index 5f31313..1169820 100644
--- a/api/src/com/cloud/agent/api/to/IpAddressTO.java
+++ b/api/src/com/cloud/agent/api/to/IpAddressTO.java
@@ -33,6 +33,8 @@ public class IpAddressTO {
     private Integer networkRate;
     private TrafficType trafficType;
     private String networkName;
+    private Integer nicDevId;
+    private boolean newNic;
 
     public IpAddressTO(long accountId, String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String broadcastUri, String vlanGateway, String vlanNetmask,
             String vifMacAddress, Integer networkRate, boolean isOneToOneNat) {
@@ -116,4 +118,19 @@ public class IpAddressTO {
         return networkRate;
     }
 
+    public Integer getNicDevId() {
+        return nicDevId;
+    }
+
+    public void setNicDevId(Integer nicDevId) {
+        this.nicDevId = nicDevId;
+    }
+
+    public boolean isNewNic() {
+        return newNic;
+    }
+
+    public void setNewNic(boolean newNic) {
+        this.newNic = newNic;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/285f23f1/core/src/com/cloud/agent/api/routing/NetworkElementCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/routing/NetworkElementCommand.java b/core/src/com/cloud/agent/api/routing/NetworkElementCommand.java
index 9a2bea8..217e962 100644
--- a/core/src/com/cloud/agent/api/routing/NetworkElementCommand.java
+++ b/core/src/com/cloud/agent/api/routing/NetworkElementCommand.java
@@ -16,10 +16,10 @@
 // under the License.
 package com.cloud.agent.api.routing;
 
-import java.util.HashMap;
-
 import com.cloud.agent.api.Command;
 
+import java.util.HashMap;
+
 public abstract class NetworkElementCommand extends Command {
     HashMap<String, String> accessDetails = new HashMap<String, String>(0);
 
@@ -35,6 +35,8 @@ public abstract class NetworkElementCommand extends Command {
     public static final String VPC_PRIVATE_GATEWAY = "vpc.gateway.private";
     public static final String FIREWALL_EGRESS_DEFAULT = "firewall.egress.default";
 
+    private String routerAccessIp;
+
     protected NetworkElementCommand() {
         super();
     }
@@ -52,4 +54,11 @@ public abstract class NetworkElementCommand extends Command {
         return false;
     }
 
+    public String getRouterAccessIp() {
+        return routerAccessIp;
+    }
+
+    public void setRouterAccessIp(String routerAccessIp) {
+        this.routerAccessIp = routerAccessIp;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/285f23f1/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRouterDeployer.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRouterDeployer.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRouterDeployer.java
new file mode 100644
index 0000000..243098a
--- /dev/null
+++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRouterDeployer.java
@@ -0,0 +1,27 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.agent.resource.virtualnetwork;
+
+import com.cloud.agent.api.routing.NetworkElementCommand;
+import com.cloud.utils.ExecutionResult;
+
+public interface VirtualRouterDeployer {
+    ExecutionResult executeInVR(String routerIp, String script, String args);
+    ExecutionResult createFileInVR(String routerIp, String path, String filename, String content);
+    ExecutionResult prepareCommand(NetworkElementCommand cmd);
+    ExecutionResult cleanupCommand(NetworkElementCommand cmd);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/285f23f1/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 b27ed55..f63824e 100755
--- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
+++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
@@ -25,9 +25,8 @@ import com.cloud.agent.api.CheckS2SVpnConnectionsCommand;
 import com.cloud.agent.api.Command;
 import com.cloud.agent.api.GetDomRVersionAnswer;
 import com.cloud.agent.api.GetDomRVersionCmd;
-import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
-import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
-import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
+import com.cloud.agent.api.SetupGuestNetworkAnswer;
+import com.cloud.agent.api.SetupGuestNetworkCommand;
 import com.cloud.agent.api.routing.CreateIpAliasCommand;
 import com.cloud.agent.api.routing.DeleteIpAliasCommand;
 import com.cloud.agent.api.routing.DhcpEntryCommand;
@@ -35,6 +34,7 @@ import com.cloud.agent.api.routing.DnsMasqConfigCommand;
 import com.cloud.agent.api.routing.IpAliasTO;
 import com.cloud.agent.api.routing.IpAssocAnswer;
 import com.cloud.agent.api.routing.IpAssocCommand;
+import com.cloud.agent.api.routing.IpAssocVpcCommand;
 import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand;
@@ -42,9 +42,13 @@ import com.cloud.agent.api.routing.SavePasswordCommand;
 import com.cloud.agent.api.routing.SetFirewallRulesAnswer;
 import com.cloud.agent.api.routing.SetFirewallRulesCommand;
 import com.cloud.agent.api.routing.SetMonitorServiceCommand;
+import com.cloud.agent.api.routing.SetNetworkACLAnswer;
+import com.cloud.agent.api.routing.SetNetworkACLCommand;
 import com.cloud.agent.api.routing.SetPortForwardingRulesAnswer;
 import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
 import com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand;
+import com.cloud.agent.api.routing.SetSourceNatAnswer;
+import com.cloud.agent.api.routing.SetSourceNatCommand;
 import com.cloud.agent.api.routing.SetStaticNatRulesAnswer;
 import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
 import com.cloud.agent.api.routing.SetStaticRouteAnswer;
@@ -55,33 +59,22 @@ import com.cloud.agent.api.routing.VpnUsersCfgCommand;
 import com.cloud.agent.api.to.DhcpTO;
 import com.cloud.agent.api.to.FirewallRuleTO;
 import com.cloud.agent.api.to.IpAddressTO;
+import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.PortForwardingRuleTO;
 import com.cloud.agent.api.to.StaticNatRuleTO;
-import com.cloud.exception.InternalErrorException;
 import com.cloud.network.HAProxyConfigurator;
 import com.cloud.network.LoadBalancerConfigurator;
 import com.cloud.network.rules.FirewallRule;
+import com.cloud.utils.ExecutionResult;
 import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.component.ComponentLifecycle;
-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;
 import com.google.gson.Gson;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.log4j.Logger;
 
-import javax.ejb.Local;
 import javax.naming.ConfigurationException;
-import java.io.BufferedReader;
-import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.net.InetSocketAddress;
-import java.net.URL;
-import java.net.URLConnection;
 import java.nio.channels.SocketChannel;
 import java.util.HashMap;
 import java.util.List;
@@ -95,24 +88,27 @@ import java.util.Map;
  *    || Param Name | Description | Values | Default ||
  *  }
  **/
-@Local(value = {VirtualRoutingResource.class})
-public class VirtualRoutingResource implements Manager {
+public class VirtualRoutingResource {
     private static final Logger s_logger = Logger.getLogger(VirtualRoutingResource.class);
-    private String _publicIpAddress;
-    private String _publicEthIf;
-    private String _privateEthIf;
-    private String _routerProxyPath;
-
-    private int _timeout;
-    private int _startTimeout;
-    private String _scriptsDir;
+    private VirtualRouterDeployer _vrDeployer;
+
     private String _name;
     private int _sleep;
     private int _retry;
     private int _port;
 
+    public VirtualRoutingResource(VirtualRouterDeployer deployer) {
+        this._vrDeployer = deployer;
+    }
+
     public Answer executeRequest(final Command cmd) {
         try {
+            ExecutionResult rc = _vrDeployer.prepareCommand((NetworkElementCommand)cmd);
+            if (!rc.isSuccess()) {
+                s_logger.error("Failed to prepare VR command due to " + rc.getDetails());
+                return new Answer(cmd, false, rc.getDetails());
+            }
+
             if (cmd instanceof SetPortForwardingRulesVpcCommand) {
                 return execute((SetPortForwardingRulesVpcCommand)cmd);
             } else if (cmd instanceof SetPortForwardingRulesCommand) {
@@ -123,12 +119,6 @@ public class VirtualRoutingResource implements Manager {
                 return execute((SetStaticNatRulesCommand)cmd);
             } else if (cmd instanceof LoadBalancerConfigCommand) {
                 return execute((LoadBalancerConfigCommand)cmd);
-            } else if (cmd instanceof IpAssocCommand) {
-                return execute((IpAssocCommand)cmd);
-            } else if (cmd instanceof CheckConsoleProxyLoadCommand) {
-                return execute((CheckConsoleProxyLoadCommand)cmd);
-            } else if (cmd instanceof WatchConsoleProxyLoadCommand) {
-                return execute((WatchConsoleProxyLoadCommand)cmd);
             } else if (cmd instanceof SavePasswordCommand) {
                 return execute((SavePasswordCommand)cmd);
             } else if (cmd instanceof DhcpEntryCommand) {
@@ -158,12 +148,27 @@ public class VirtualRoutingResource implements Manager {
             } else if (cmd instanceof CheckS2SVpnConnectionsCommand) {
                 return execute((CheckS2SVpnConnectionsCommand)cmd);
             } else if (cmd instanceof SetMonitorServiceCommand) {
-                return execute((SetMonitorServiceCommand) cmd);
+                return execute((SetMonitorServiceCommand)cmd);
+            } else if (cmd instanceof SetupGuestNetworkCommand) {
+                return execute((SetupGuestNetworkCommand)cmd);
+            } else if (cmd instanceof SetNetworkACLCommand) {
+                return execute((SetNetworkACLCommand)cmd);
+            } else if (cmd instanceof SetSourceNatCommand) {
+                return execute((SetSourceNatCommand)cmd);
+            } else if (cmd instanceof IpAssocVpcCommand) {
+                return execute((IpAssocVpcCommand)cmd);
+            } else if (cmd instanceof IpAssocCommand) {
+                return execute((IpAssocCommand)cmd);
             } else {
                 return Answer.createUnsupportedCommandAnswer(cmd);
             }
         } catch (final IllegalArgumentException e) {
             return new Answer(cmd, false, e.getMessage());
+        } finally {
+            ExecutionResult rc = _vrDeployer.cleanupCommand((NetworkElementCommand)cmd);
+            if (!rc.isSuccess()) {
+                s_logger.error("Failed to cleanup VR command due to " + rc.getDetails());
+            }
         }
     }
 
@@ -177,9 +182,9 @@ public class VirtualRoutingResource implements Manager {
                 args += "-u ";
                 args += userpwd.getUsernamePassword();
             }
-            String result = executeInVR(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), "vpn_l2tp.sh", args);
-            if (result != null) {
-                return new Answer(cmd, false, "Configure VPN user failed for user " + userpwd.getUsername());
+            ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "vpn_l2tp.sh", args);
+            if (!result.isSuccess()) {
+                return new Answer(cmd, false, "Configure VPN user failed for user " + userpwd.getUsername() + ":" + result.getDetails());
             }
         }
         return new Answer(cmd);
@@ -204,11 +209,8 @@ public class VirtualRoutingResource implements Manager {
         }
         args += " -C " + cmd.getLocalCidr();
         args += " -i " + cmd.getPublicInterface();
-        String result = executeInVR(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), "vpn_l2tp.sh", args);
-        if (result != null) {
-            return new Answer(cmd, false, "Configure VPN failed");
-        }
-        return new Answer(cmd);
+        ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "vpn_l2tp.sh", args);
+        return new Answer(cmd, result.isSuccess(), result.getDetails());
     }
 
     private Answer execute(SetFirewallRulesCommand cmd) {
@@ -216,10 +218,10 @@ public class VirtualRoutingResource implements Manager {
         for (int i = 0; i < cmd.getRules().length; i++) {
             results[i] = "Failed";
         }
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        String routerAccessIp = cmd.getRouterAccessIp();
         String egressDefault = cmd.getAccessDetail(NetworkElementCommand.FIREWALL_EGRESS_DEFAULT);
 
-        if (routerIp == null) {
+        if (routerAccessIp == null) {
             return new SetFirewallRulesAnswer(cmd, false, results);
         }
 
@@ -230,7 +232,7 @@ public class VirtualRoutingResource implements Manager {
         String args = " -F";
 
         if (trafficType == FirewallRule.TrafficType.Egress) {
-            args += "-E";
+            args += " -E";
             if (egressDefault.equals("true")) {
                 args += " -P 1";
             } else if (egressDefault.equals("System")) {
@@ -249,15 +251,15 @@ public class VirtualRoutingResource implements Manager {
             args += " -a " + sb.toString();
         }
 
-        String result = null;
+        ExecutionResult result;
 
         if (trafficType == FirewallRule.TrafficType.Egress) {
-            result = executeInVR(routerIp, "firewall_egress.sh", args);
+            result = _vrDeployer.executeInVR(routerAccessIp, "firewall_egress.sh", args);
         } else {
-            result = executeInVR(routerIp, "firewall_ingress.sh", args);
+            result = _vrDeployer.executeInVR(routerAccessIp, "firewall_ingress.sh", args);
         }
 
-        if (result != null) {
+        if (!result.isSuccess()) {
             return new SetFirewallRulesAnswer(cmd, false, results);
         }
         return new SetFirewallRulesAnswer(cmd, true, null);
@@ -265,7 +267,6 @@ public class VirtualRoutingResource implements Manager {
     }
 
     private Answer execute(SetPortForwardingRulesCommand cmd) {
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
         String[] results = new String[cmd.getRules().length];
         int i = 0;
         boolean endResult = true;
@@ -278,9 +279,9 @@ public class VirtualRoutingResource implements Manager {
             args.append(" -r ").append(rule.getDstIp());
             args.append(" -d ").append(rule.getStringDstPortRange());
 
-            String result = executeInVR(routerIp, "firewall_nat.sh", args.toString());
+            ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "firewall_nat.sh", args.toString());
 
-            if (result == null || result.isEmpty()) {
+            if (!result.isSuccess()) {
                 results[i++] = "Failed";
                 endResult = false;
             } else {
@@ -292,7 +293,6 @@ public class VirtualRoutingResource implements Manager {
     }
 
     protected Answer SetVPCStaticNatRules(SetStaticNatRulesCommand cmd) {
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
         String[] results = new String[cmd.getRules().length];
         int i = 0;
         boolean endResult = true;
@@ -302,9 +302,9 @@ public class VirtualRoutingResource implements Manager {
             args += " -l " + rule.getSrcIp();
             args += " -r " + rule.getDstIp();
 
-            String result = executeInVR(routerIp, "vpc_staticnat.sh", args);
+            ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "vpc_staticnat.sh", args);
 
-            if (result == null) {
+            if (!result.isSuccess()) {
                 results[i++] = null;
             } else {
                 results[i++] = "Failed";
@@ -319,7 +319,6 @@ public class VirtualRoutingResource implements Manager {
         if (cmd.getVpcId() != null) {
             return SetVPCStaticNatRules(cmd);
         }
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
         String[] results = new String[cmd.getRules().length];
         int i = 0;
         boolean endResult = true;
@@ -337,9 +336,9 @@ public class VirtualRoutingResource implements Manager {
             args.append(" -d ").append(rule.getStringSrcPortRange());
             args.append(" -G ");
 
-            String result = executeInVR(routerIp, "firewall_nat.sh", args.toString());
+            ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "firewall_nat.sh", args.toString());
 
-            if (result == null || result.isEmpty()) {
+            if (!result.isSuccess()) {
                 results[i++] = "Failed";
                 endResult = false;
             } else {
@@ -350,19 +349,6 @@ public class VirtualRoutingResource implements Manager {
         return new SetStaticNatRulesAnswer(cmd, results, endResult);
     }
 
-    protected boolean createFileInVR(String routerIp, String path, String filename, String content) {
-        File permKey = new File("/root/.ssh/id_rsa.cloud");
-        boolean result = true;
-
-        try {
-            SshHelper.scpTo(routerIp, 3922, "root", permKey, null, path, content.getBytes(), filename, null);
-        } catch (Exception e) {
-            s_logger.warn("Fail to create file " + path + filename + " in VR " + routerIp, e);
-            result = false;
-        }
-        return result;
-    }
-
     private Answer execute(LoadBalancerConfigCommand cmd) {
         String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
 
@@ -378,67 +364,58 @@ public class VirtualRoutingResource implements Manager {
             tmpCfgFileContents += "\n";
         }
 
-        if (!createFileInVR(routerIp, "/etc/haproxy/", "haproxy.cfg.new", tmpCfgFileContents)) {
+        if (!_vrDeployer.createFileInVR(cmd.getRouterAccessIp(), "/etc/haproxy/", "haproxy.cfg.new", tmpCfgFileContents).isSuccess()) {
             return new Answer(cmd, false, "Fail to copy LB config file to VR");
         }
 
-        try {
-            String[][] rules = cfgtr.generateFwRules(cmd);
+        String[][] rules = cfgtr.generateFwRules(cmd);
 
-            String[] addRules = rules[LoadBalancerConfigurator.ADD];
-            String[] removeRules = rules[LoadBalancerConfigurator.REMOVE];
-            String[] statRules = rules[LoadBalancerConfigurator.STATS];
+        String[] addRules = rules[LoadBalancerConfigurator.ADD];
+        String[] removeRules = rules[LoadBalancerConfigurator.REMOVE];
+        String[] statRules = rules[LoadBalancerConfigurator.STATS];
 
-            String args = "";
-            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();
+        String args = "";
+        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 (removeRules.length > 0) {
+            for (int i = 0; i < removeRules.length; i++) {
+                sb.append(removeRules[i]).append(',');
             }
 
-            sb = new StringBuilder();
-            if (statRules.length > 0) {
-                for (int i = 0; i < statRules.length; i++) {
-                    sb.append(statRules[i]).append(',');
-                }
+            args += " -d " + sb.toString();
+        }
 
-                args += " -s " + sb.toString();
+        sb = new StringBuilder();
+        if (statRules.length > 0) {
+            for (int i = 0; i < statRules.length; i++) {
+                sb.append(statRules[i]).append(',');
             }
 
-            String result;
+            args += " -s " + sb.toString();
+        }
 
-            if (cmd.getVpcId() == null) {
-                args = " -i " + routerIp + args;
-                result = executeInVR(routerIp, "loadbalancer.sh", args);
-            } else {
-                args = " -i " + cmd.getNic().getIp() + args;
-                result = executeInVR(routerIp, "vpc_loadbalancer.sh", args);
-            }
+        ExecutionResult result;
 
-            if (result != null) {
-                return new Answer(cmd, false, "LoadBalancerConfigCommand failed");
-            }
-            return new Answer(cmd);
-
-        } catch (Exception e) {
-            return new Answer(cmd, e);
+        if (cmd.getVpcId() == null) {
+            args = " -i " + routerIp + args;
+            result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "loadbalancer.sh", args);
+        } else {
+            args = " -i " + cmd.getNic().getIp() + args;
+            result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "vpc_loadbalancer.sh", args);
         }
+
+        return new Answer(cmd, result.isSuccess(), result.getDetails());
     }
 
 
     protected Answer execute(VmDataCommand cmd) {
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
         Map<String, List<String[]>> data = new HashMap<String, List<String[]>>();
         data.put(cmd.getVmIpAddress(), cmd.getVmData());
 
@@ -449,32 +426,8 @@ public class VirtualRoutingResource implements Manager {
 
         String args = "-d " + json;
 
-        final String result = executeInVR(routerIp, "vmdata.py", args);
-        if (result != null) {
-            return new Answer(cmd, false, "VmDataCommand failed, check agent logs");
-        }
-        return new Answer(cmd);
-    }
-
-    protected Answer execute(final IpAssocCommand cmd) {
-        IpAddressTO[] ips = cmd.getIpAddresses();
-        String[] results = new String[cmd.getIpAddresses().length];
-        int i = 0;
-        String result = null;
-        String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
-        for (IpAddressTO ip : ips) {
-            result =
-                assignPublicIpAddress(routerName, routerIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getBroadcastUri(), ip.getVlanGateway(),
-                    ip.getVlanNetmask(), ip.getVifMacAddress(), 2, false);
-            if (result != null) {
-                results[i++] = IpAssocAnswer.errorResult;
-            } else {
-                results[i++] = ip.getPublicIp() + " - success";
-                ;
-            }
-        }
-        return new IpAssocAnswer(cmd, results);
+        final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "vmdata.py", args);
+        return new Answer(cmd, result.isSuccess(), result.getDetails());
     }
 
     protected Answer execute(final SavePasswordCommand cmd) {
@@ -485,11 +438,8 @@ public class VirtualRoutingResource implements Manager {
         String args = "-v " + vmIpAddress;
         args += " -p " + password;
 
-        String result = executeInVR(routerPrivateIPAddress, "savepassword.sh", args);
-        if (result != null) {
-            return new Answer(cmd, false, "Unable to save password to DomR.");
-        }
-        return new Answer(cmd);
+        ExecutionResult result = _vrDeployer.executeInVR(routerPrivateIPAddress, "savepassword.sh", args);
+        return new Answer(cmd, result.isSuccess(), result.getDetails());
     }
 
     protected Answer execute(final DhcpEntryCommand cmd) {
@@ -520,23 +470,21 @@ public class VirtualRoutingResource implements Manager {
             args += " -N";
         }
 
-        final String result = executeInVR(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), "edithosts.sh", args);
-        return new Answer(cmd, result == null, result);
+        final ExecutionResult result = _vrDeployer.executeInVR(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), "edithosts.sh", args);
+        return new Answer(cmd, result.isSuccess(), result.getDetails());
     }
 
     protected Answer execute(final CreateIpAliasCommand cmd) {
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
         List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
         String args = "";
         for (IpAliasTO ipaliasto : ipAliasTOs) {
             args = args + ipaliasto.getAlias_count() + ":" + ipaliasto.getRouterip() + ":" + ipaliasto.getNetmask() + "-";
         }
-        final String result = executeInVR(routerIp, "createipAlias.sh", args);
-        return new Answer(cmd, result == null, result);
+        final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "createipAlias.sh", args);
+        return new Answer(cmd, result.isSuccess(), result.getDetails());
     }
 
     protected Answer execute(final DeleteIpAliasCommand cmd) {
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
         String args = "";
         List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
         for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
@@ -547,38 +495,18 @@ public class VirtualRoutingResource implements Manager {
         for (IpAliasTO ipAliasTO : activeIpAliasTOs) {
             args = args + ipAliasTO.getAlias_count() + ":" + ipAliasTO.getRouterip() + ":" + ipAliasTO.getNetmask() + "-";
         }
-        final String result = executeInVR(routerIp, "deleteipAlias.sh", args);
-        return new Answer(cmd, result == null, result);
+        final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "deleteipAlias.sh", args);
+        return new Answer(cmd, result.isSuccess(), result.getDetails());
     }
 
     protected Answer execute(final DnsMasqConfigCommand cmd) {
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
         List<DhcpTO> dhcpTos = cmd.getIps();
         String args = "";
         for (DhcpTO dhcpTo : dhcpTos) {
             args = args + dhcpTo.getRouterIp() + ":" + dhcpTo.getGateway() + ":" + dhcpTo.getNetmask() + ":" + dhcpTo.getStartIpOfSubnet() + "-";
         }
-        final String result = executeInVR(routerIp, "dnsmasq.sh", args);
-        return new Answer(cmd, result == null, result);
-    }
-
-    public String getRouterStatus(String routerIP) {
-        return routerProxyWithParser("checkrouter.sh", routerIP, null);
-    }
-
-    public String routerProxyWithParser(String script, String routerIP, String args) {
-        final Script command = new Script(_routerProxyPath, _timeout, s_logger);
-        final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
-        command.add(script);
-        command.add(routerIP);
-        if (args != null) {
-            command.add(args);
-        }
-        String result = command.execute(parser);
-        if (result == null) {
-            return parser.getLine();
-        }
-        return null;
+        final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "dnsmasq.sh", args);
+        return new Answer(cmd, result.isSuccess(), result.getDetails());
     }
 
     private CheckS2SVpnConnectionsAnswer execute(CheckS2SVpnConnectionsCommand cmd) {
@@ -589,65 +517,37 @@ public class VirtualRoutingResource implements Manager {
             args += " " + ip;
         }
 
-        final String result = executeInVR(routerIP, "checkbatchs2svpn.sh", args);
-        if (result == null || result.isEmpty()) {
-            return new CheckS2SVpnConnectionsAnswer(cmd, false, "CheckS2SVpnConneciontsCommand failed");
-        }
-        return new CheckS2SVpnConnectionsAnswer(cmd, true, result);
-    }
-
-    public String executeInVR(String routerIP, String script, String args) {
-        final Script command = new Script(_routerProxyPath, _timeout, s_logger);
-        command.add(script);
-        command.add(routerIP);
-        if (args != null) {
-            command.add(args);
-        }
-        return command.execute();
+        ExecutionResult result = _vrDeployer.executeInVR(routerIP, "checkbatchs2svpn.sh", args);
+        return new CheckS2SVpnConnectionsAnswer(cmd, result.isSuccess(), result.getDetails());
     }
 
     protected Answer execute(CheckRouterCommand cmd) {
         final String routerPrivateIPAddress = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
 
-        final String result = getRouterStatus(routerPrivateIPAddress);
-        if (result == null || result.isEmpty()) {
-            return new CheckRouterAnswer(cmd, "CheckRouterCommand failed");
+        final ExecutionResult result = _vrDeployer.executeInVR(routerPrivateIPAddress, "checkrouter.sh", null);
+        if (!result.isSuccess()) {
+            return new CheckRouterAnswer(cmd, result.getDetails());
         }
-        return new CheckRouterAnswer(cmd, result, true);
+        return new CheckRouterAnswer(cmd, result.getDetails(), true);
     }
 
     protected Answer execute(BumpUpPriorityCommand cmd) {
-        String result = executeInVR(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), "bumpup_priority.sh", null);
-        if (result != null) {
-            return new Answer(cmd, false, "BumpUpPriorityCommand failed due to " + result);
-        }
-        return new Answer(cmd, true, null);
-    }
-
-    protected String getDomRVersion(String routerIP) {
-        return routerProxyWithParser("get_template_version.sh", routerIP, null);
+        ExecutionResult result = _vrDeployer.executeInVR(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), "bumpup_priority.sh", null);
+        return new Answer(cmd, result.isSuccess(), result.getDetails());
     }
 
     protected Answer execute(GetDomRVersionCmd cmd) {
         final String routerPrivateIPAddress = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
 
-        final String result = getDomRVersion(routerPrivateIPAddress);
-        if (result == null || result.isEmpty()) {
+        final ExecutionResult result = _vrDeployer.executeInVR(routerPrivateIPAddress, "get_template_version.sh", null);
+        if (!result.isSuccess()) {
             return new GetDomRVersionAnswer(cmd, "GetDomRVersionCmd failed");
         }
-        String[] lines = result.split("&");
+        String[] lines = result.getDetails().split("&");
         if (lines.length != 2) {
-            return new GetDomRVersionAnswer(cmd, result);
+            return new GetDomRVersionAnswer(cmd, result.getDetails());
         }
-        return new GetDomRVersionAnswer(cmd, result, lines[0], lines[1]);
-    }
-
-    protected Answer execute(final CheckConsoleProxyLoadCommand cmd) {
-        return executeProxyLoadScan(cmd, cmd.getProxyVmId(), cmd.getProxyVmName(), cmd.getProxyManagementIp(), cmd.getProxyCmdPort());
-    }
-
-    protected Answer execute(final WatchConsoleProxyLoadCommand cmd) {
-        return executeProxyLoadScan(cmd, cmd.getProxyVmId(), cmd.getProxyVmName(), cmd.getProxyManagementIp(), cmd.getProxyCmdPort());
+        return new GetDomRVersionAnswer(cmd, result.getDetails(), lines[0], lines[1]);
     }
 
     protected Answer execute(Site2SiteVpnCfgCommand cmd) {
@@ -692,59 +592,45 @@ public class VirtualRoutingResource implements Manager {
             args += " -N ";
             args += cmd.getPeerGuestCidrList();
         }
-        String result = executeInVR(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), "ipsectunnel.sh", args);
-        if (result != null) {
-            return new Answer(cmd, false, "Configure site to site VPN failed due to " + result);
+        ExecutionResult result = _vrDeployer.executeInVR(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), "ipsectunnel.sh", args);
+        if (!result.isSuccess()) {
+            return new Answer(cmd, false, "Configure site to site VPN failed due to " + result.getDetails());
         }
         return new Answer(cmd);
     }
 
-    private Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, final String proxyVmName, final String proxyManagementIp, final int cmdPort) {
-        String result = null;
-
-        final StringBuffer sb = new StringBuffer();
-        sb.append("http://").append(proxyManagementIp).append(":" + cmdPort).append("/cmd/getstatus");
+    protected Answer execute(SetMonitorServiceCommand cmd) {
+        String config = cmd.getConfiguration();
 
-        boolean success = true;
-        try {
-            final URL url = new URL(sb.toString());
-            final URLConnection conn = url.openConnection();
+        String args = " -c " + config;
+        ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "monitor_service.sh", args);
 
-            final InputStream is = conn.getInputStream();
-            final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
-            final StringBuilder sb2 = new StringBuilder();
-            String line = null;
-            try {
-                while ((line = reader.readLine()) != null) {
-                    sb2.append(line + "\n");
-                }
-                result = sb2.toString();
-            } catch (final IOException e) {
-                success = false;
-            } finally {
-                try {
-                    is.close();
-                } catch (final IOException e) {
-                    s_logger.warn("Exception when closing , console proxy address : " + proxyManagementIp);
-                    success = false;
-                }
-            }
-        } catch (final IOException e) {
-            s_logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp);
-            success = false;
+        if (!result.isSuccess()) {
+            return new Answer(cmd, false, result.getDetails());
         }
-
-        return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success, result);
+        return new Answer(cmd);
     }
 
-    public String configureMonitor(final String routerIP, final String config) {
-
-        String args = " -c " + config;
-        return executeInVR(routerIP, "monitor_service.sh", args);
-    }
+    protected SetupGuestNetworkAnswer execute(SetupGuestNetworkCommand cmd) {
+        NicTO nic = cmd.getNic();
+        String routerIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        String routerGIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP);
+        String gateway = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY);
+        String cidr = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));
+        String domainName = cmd.getNetworkDomain();
+        String dns = cmd.getDefaultDns1();
+
+        if (dns == null || dns.isEmpty()) {
+            dns = cmd.getDefaultDns2();
+        } else {
+            String dns2 = cmd.getDefaultDns2();
+            if (dns2 != null && !dns2.isEmpty()) {
+                dns += "," + dns2;
+            }
+        }
 
-    public String assignGuestNetwork(final String dev, final String routerIP, final String routerGIP, final String gateway, final String cidr, final String netmask,
-        final String dns, final String domainName) {
+        String dev = "eth" + nic.getDeviceId();
+        String netmask = NetUtils.getSubNet(routerGIP, nic.getNetmask());
 
         String args = " -C";
         args += " -d " + dev;
@@ -758,33 +644,74 @@ public class VirtualRoutingResource implements Manager {
         if (domainName != null && !domainName.isEmpty()) {
             args += " -e " + domainName;
         }
-        return executeInVR(routerIP, "vpc_guestnw.sh", args);
+        ExecutionResult result = _vrDeployer.executeInVR(routerIP, "vpc_guestnw.sh", args);
+
+        if (!result.isSuccess()) {
+            return new SetupGuestNetworkAnswer(cmd, false, "Creating guest network failed due to " + result.getDetails());
+        }
+        return new SetupGuestNetworkAnswer(cmd, true, "success");
     }
 
-    public String assignNetworkACL(final String routerIP, final String dev, final String routerGIP, final String netmask, final String rule, String privateGw) {
-        String args = " -d " + dev;
-        if (privateGw != null) {
-            args += " -a " + rule;
-            return executeInVR(routerIP, "vpc_privategw_acl.sh", args);
-        } else {
-            args += " -i " + routerGIP;
-            args += " -m " + netmask;
-            args += " -a " + rule;
-            return executeInVR(routerIP, "vpc_acl.sh", args);
+    private SetNetworkACLAnswer execute(SetNetworkACLCommand cmd) {
+        String[] results = new String[cmd.getRules().length];
+
+        String privateGw = cmd.getAccessDetail(NetworkElementCommand.VPC_PRIVATE_GATEWAY);
+
+        try {
+            String[][] rules = cmd.generateFwRules();
+            String[] aclRules = rules[0];
+            NicTO nic = cmd.getNic();
+            String dev = "eth" + nic.getDeviceId();
+            String netmask = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));
+            StringBuilder sb = new StringBuilder();
+
+            for (int i = 0; i < aclRules.length; i++) {
+                sb.append(aclRules[i]).append(',');
+            }
+
+            String rule = sb.toString();
+            ExecutionResult result;
+
+            String args = " -d " + dev;
+            if (privateGw != null) {
+                args += " -a " + rule;
+                result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "vpc_privategw_acl.sh", args);
+            } else {
+                args += " -i " + nic.getIp();
+                args += " -m " + netmask;
+                args += " -a " + rule;
+                result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "vpc_acl.sh", args);
+            }
+
+            if (!result.isSuccess()) {
+                for (int i = 0; i < results.length; i++) {
+                    results[i] = "Failed";
+                }
+                return new SetNetworkACLAnswer(cmd, false, results);
+            }
+
+            return new SetNetworkACLAnswer(cmd, true, results);
+        } catch (Exception e) {
+            String msg = "SetNetworkACL failed due to " + e.toString();
+            s_logger.error(msg, e);
+            return new SetNetworkACLAnswer(cmd, false, results);
         }
     }
 
-    public String assignSourceNat(final String routerIP, final String pubIP, final String dev) {
+    protected SetSourceNatAnswer execute(SetSourceNatCommand cmd) {
+        String routerIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        IpAddressTO pubIP = cmd.getIpAddress();
+        String dev = "eth" + pubIP.getNicDevId();
         String args = " -A ";
         args += " -l ";
-        args += pubIP;
+        args += pubIP.getPublicIp();
         args += " -c ";
         args += dev;
-        return executeInVR(routerIP, "vpc_snat.sh", args);
+        ExecutionResult result = _vrDeployer.executeInVR(routerIP, "vpc_snat.sh", args);
+        return new SetSourceNatAnswer(cmd, result.isSuccess(), result.getDetails());
     }
 
     private SetPortForwardingRulesAnswer execute(SetPortForwardingRulesVpcCommand cmd) {
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
         String[] results = new String[cmd.getRules().length];
         int i = 0;
 
@@ -797,9 +724,9 @@ public class VirtualRoutingResource implements Manager {
             args += " -r " + rule.getDstIp();
             args += " -d " + rule.getStringDstPortRange().replace(":", "-");
 
-            String result = executeInVR(routerIp, "vpc_portforwarding.sh", args);
+            ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "vpc_portforwarding.sh", args);
 
-            if (result != null) {
+            if (!result.isSuccess()) {
                 results[i++] = "Failed";
                 endResult = false;
             } else {
@@ -809,44 +736,56 @@ public class VirtualRoutingResource implements Manager {
         return new SetPortForwardingRulesAnswer(cmd, results, endResult);
     }
 
-    public void assignVpcIpToRouter(final String routerIP, final boolean add, final String pubIP, final String nicname, final String gateway, final String netmask,
-        final String subnet, boolean sourceNat) throws InternalErrorException {
+    public IpAssocAnswer execute(IpAssocVpcCommand cmd) {
+        String routerIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        String[] results = new String[cmd.getIpAddresses().length];
         String args = "";
         String snatArgs = "";
-
-        if (add) {
-            args += " -A ";
-            snatArgs += " -A ";
-        } else {
-            args += " -D ";
-            snatArgs += " -D ";
+        for (int i = 0; i < cmd.getIpAddresses().length; i ++) {
+            results[i] = "Failed";
         }
 
-        args += " -l ";
-        args += pubIP;
-        args += " -c ";
-        args += nicname;
-        args += " -g ";
-        args += gateway;
-        args += " -m ";
-        args += netmask;
-        args += " -n ";
-        args += subnet;
-
-        String result = executeInVR(routerIP, "vpc_ipassoc.sh", args);
-        if (result != null) {
-            throw new InternalErrorException("KVM plugin \"vpc_ipassoc\" failed:" + result);
-        }
-        if (sourceNat) {
-            snatArgs += " -l " + pubIP;
-            snatArgs += " -c " + nicname;
+        int i = 0;
+        for (IpAddressTO ip : cmd.getIpAddresses()) {
+            if (ip.isAdd()) {
+                args += " -A ";
+                snatArgs += " -A ";
+            } else {
+                args += " -D ";
+                snatArgs += " -D ";
+            }
 
-            result = executeInVR(routerIP, "vpc_privateGateway.sh", snatArgs);
-            if (result != null) {
-                throw new InternalErrorException("KVM plugin \"vpc_privateGateway\" failed:" + result);
+            args += " -l ";
+            args += ip.getPublicIp();
+            String nicName = "eth" + ip.getNicDevId();
+            args += " -c ";
+            args += nicName;
+            args += " -g ";
+            args += ip.getVlanGateway();
+            args += " -m ";
+            args += Long.toString(NetUtils.getCidrSize(ip.getVlanNetmask()));
+            args += " -n ";
+            args += NetUtils.getSubNet(ip.getPublicIp(), ip.getVlanNetmask());
+
+            ExecutionResult result = _vrDeployer.executeInVR(routerIP, "vpc_ipassoc.sh", args);
+            if (!result.isSuccess()) {
+                results[i++] = ip.getPublicIp() + " - vpc_ipassoc failed:" + result.getDetails();
+                break;
             }
 
+            if (ip.isSourceNat()) {
+                snatArgs += " -l " + ip.getPublicIp();
+                snatArgs += " -c " + nicName;
+
+                result = _vrDeployer.executeInVR(routerIP, "vpc_privateGateway.sh", snatArgs);
+                if (result != null) {
+                    results[i++] = ip.getPublicIp() + " - vpc_privateGateway failed:" + result.getDetails();
+                    break;
+                }
+            }
+            results[i++] = ip.getPublicIp() + " - success ";
         }
+        return new IpAssocAnswer(cmd, results);
     }
 
     private SetStaticRouteAnswer execute(SetStaticRouteCommand cmd) {
@@ -862,9 +801,9 @@ public class VirtualRoutingResource implements Manager {
             }
 
             String args = " -a " + sb.toString();
-            String result = executeInVR(routerIP, "vpc_staticroute.sh", args);
+            ExecutionResult result = _vrDeployer.executeInVR(routerIP, "vpc_staticroute.sh", args);
 
-            if (result != null) {
+            if (!result.isSuccess()) {
                 for (int i = 0; i < results.length; i++) {
                     results[i] = "Failed";
                 }
@@ -879,161 +818,56 @@ public class VirtualRoutingResource implements Manager {
         }
     }
 
-    private Answer execute(SetMonitorServiceCommand cmd) {
-
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
-        String config = cmd.getConfiguration();
-
-        String result = configureMonitor(routerIp, config);
-
-        if (result != null) {
-            return new Answer(cmd, false, "SetMonitorServiceCommand failed");
-        }
-        return new Answer(cmd);
-
-    }
-
-    public String assignPublicIpAddress(final String vmName, final String privateIpAddress, final String publicIpAddress, final boolean add, final boolean firstIP,
-        final boolean sourceNat, final String broadcastUri, final String vlanGateway, final String vlanNetmask, final String vifMacAddress, int nicNum, boolean newNic) {
-
-        String args = "";
-        if (add) {
-            args += "-A";
-        } else {
-            args += "-D";
-        }
-        String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask));
-        if (sourceNat) {
-            args += " -s";
-        }
-        if (firstIP) {
-            args += " -f";
+    public Answer execute(IpAssocCommand cmd) {
+        String[] results = new String[cmd.getIpAddresses().length];
+        for (int i = 0; i < results.length; i++) {
+            results[i] = IpAssocAnswer.errorResult;
         }
-        args += " -l ";
-        args += publicIpAddress + "/" + cidrSize;
 
-        String publicNic = "eth" + nicNum;
-        args += " -c ";
-        args += publicNic;
-
-        args += " -g ";
-        args += vlanGateway;
+        int i = 0;
+        for (IpAddressTO ip: cmd.getIpAddresses()) {
+            String args = "";
+            if (ip.isAdd()) {
+                args += "-A";
+            } else {
+                args += "-D";
+            }
+            String cidrSize = Long.toString(NetUtils.getCidrSize(ip.getVlanNetmask()));
+            if (ip.isSourceNat()) {
+                args += " -s";
+            }
+            if (ip.isFirstIP()) {
+                args += " -f";
+            }
+            args += " -l ";
+            args += ip.getPublicIp() + "/" + cidrSize;
 
-        if (newNic) {
-            args += " -n";
-        }
+            String publicNic = "eth" + ip.getNicDevId();
+            args += " -c ";
+            args += publicNic;
 
-        return executeInVR(privateIpAddress, "ipassoc.sh", args);
-    }
+            args += " -g ";
+            args += ip.getVlanGateway();
 
-    private void deleteBridge(String brName) {
-        Script cmd = new Script("/bin/sh", _timeout);
-        cmd.add("-c");
-        cmd.add("ifconfig " + brName + " down;brctl delbr " + brName);
-        cmd.execute();
-    }
+            if (ip.isNewNic()) {
+                args += " -n";
+            }
 
-    private boolean isDNSmasqRunning(String dnsmasqName) {
-        Script cmd = new Script("/bin/sh", _timeout);
-        cmd.add("-c");
-        cmd.add("ls -l /var/run/libvirt/network/" + dnsmasqName + ".pid");
-        String result = cmd.execute();
-        if (result != null) {
-            return false;
-        } else {
-            return true;
+            ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), "ipassoc.sh", args);
+            if (result.isSuccess()) {
+                results[i++] = ip.getPublicIp() + " - success";
+            } else {
+                results[i++] = ip.getPublicIp() + " - failed:" + result.getDetails();
+                break;
+            }
         }
+        return new IpAssocAnswer(cmd, results);
     }
 
-    private void stopDnsmasq(String dnsmasqName) {
-        Script cmd = new Script("/bin/sh", _timeout);
-        cmd.add("-c");
-        cmd.add("kill -9 `cat /var/run/libvirt/network/" + dnsmasqName + ".pid`");
-        cmd.execute();
-    }
-
-    //    protected Answer execute(final SetFirewallRuleCommand cmd) {
-    //        String args;
-    //        if(cmd.getProtocol().toLowerCase().equals(NetUtils.NAT_PROTO)){
-    //            //1:1 NAT needs instanceip;publicip;domrip;op
-    //            if(cmd.isCreate()) {
-    //                args = "-A";
-    //            } else {
-    //                args = "-D";
-    //            }
-    //
-    //            args += " -l " + cmd.getPublicIpAddress();
-    //            args += " -i " + cmd.getRouterIpAddress();
-    //            args += " -r " + cmd.getPrivateIpAddress();
-    //            args += " -G " + cmd.getProtocol();
-    //        }else{
-    //            if (cmd.isEnable()) {
-    //                args = "-A";
-    //            } else {
-    //                args = "-D";
-    //            }
-    //
-    //            args += " -P " + cmd.getProtocol().toLowerCase();
-    //            args += " -l " + cmd.getPublicIpAddress();
-    //            args += " -p " + cmd.getPublicPort();
-    //            args += " -n " + cmd.getRouterName();
-    //            args += " -i " + cmd.getRouterIpAddress();
-    //            args += " -r " + cmd.getPrivateIpAddress();
-    //            args += " -d " + cmd.getPrivatePort();
-    //            args += " -N " + cmd.getVlanNetmask();
-    //
-    //            String oldPrivateIP = cmd.getOldPrivateIP();
-    //            String oldPrivatePort = cmd.getOldPrivatePort();
-    //
-    //            if (oldPrivateIP != null) {
-    //                args += " -w " + oldPrivateIP;
-    //            }
-    //
-    //            if (oldPrivatePort != null) {
-    //                args += " -x " + oldPrivatePort;
-    //            }
-    //        }
-    //
-    //        final Script command = new Script(_firewallPath, _timeout, s_logger);
-    //        String [] argsArray = args.split(" ");
-    //        for (String param : argsArray) {
-    //            command.add(param);
-    //        }
-    //        String result = command.execute();
-    //        return new Answer(cmd, result == null, result);
-    //    }
-
-    protected String getDefaultScriptsDir() {
-        return "scripts/network/domr/dom0";
-    }
-
-    protected String findScript(final String script) {
-        return Script.findScript(_scriptsDir, script);
-    }
-
-    @Override
     public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
         _name = name;
 
-        _scriptsDir = (String)params.get("domr.scripts.dir");
-        if (_scriptsDir == null) {
-            if (s_logger.isInfoEnabled()) {
-                s_logger.info("VirtualRoutingResource _scriptDir can't be initialized from domr.scripts.dir param, use default");
-            }
-            _scriptsDir = getDefaultScriptsDir();
-        }
-
-        if (s_logger.isInfoEnabled()) {
-            s_logger.info("VirtualRoutingResource _scriptDir to use: " + _scriptsDir);
-        }
-
-        String value = (String)params.get("scripts.timeout");
-        _timeout = NumbersUtil.parseInt(value, 120) * 1000;
-
-        value = (String)params.get("start.script.timeout");
-        _startTimeout = NumbersUtil.parseInt(value, 360) * 1000;
-
-        value = (String)params.get("ssh.sleep");
+        String value = (String)params.get("ssh.sleep");
         _sleep = NumbersUtil.parseInt(value, 10) * 1000;
 
         value = (String)params.get("ssh.retry");
@@ -1042,26 +876,8 @@ public class VirtualRoutingResource implements Manager {
         value = (String)params.get("ssh.port");
         _port = NumbersUtil.parseInt(value, 3922);
 
-        _publicIpAddress = (String)params.get("public.ip.address");
-        if (_publicIpAddress != null) {
-            s_logger.warn("Incoming public ip address is overriden.  Will always be using the same ip address: " + _publicIpAddress);
-        }
-
-        _publicEthIf = (String)params.get("public.network.device");
-        if (_publicEthIf == null) {
-            _publicEthIf = "xenbr1";
-        }
-        _publicEthIf = _publicEthIf.toLowerCase();
-
-        _privateEthIf = (String)params.get("private.network.device");
-        if (_privateEthIf == null) {
-            _privateEthIf = "xenbr0";
-        }
-        _privateEthIf = _privateEthIf.toLowerCase();
-
-        _routerProxyPath = findScript("router_proxy.sh");
-        if (_routerProxyPath == null) {
-            throw new ConfigurationException("Unable to find router_proxy.sh");
+        if (_vrDeployer == null) {
+            throw new ConfigurationException("Unable to find the resource for VirtualRouterDeployer!");
         }
         return true;
     }
@@ -1141,50 +957,4 @@ public class VirtualRoutingResource implements Manager {
 
         return false;
     }
-
-    @Override
-    public String getName() {
-        return _name;
-    }
-
-    @Override
-    public void setName(String name) {
-        _name = name;
-    }
-
-    @Override
-    public boolean start() {
-        return true;
-    }
-
-    @Override
-    public boolean stop() {
-        return true;
-    }
-
-    @Override
-    public int getRunLevel() {
-        return ComponentLifecycle.RUN_LEVEL_COMPONENT;
-    }
-
-    public void setRunLevel() {
-    }
-
-    @Override
-    public void setConfigParams(Map<String, Object> params) {
-        // TODO Auto-generated method stub
-
-    }
-
-    @Override
-    public Map<String, Object> getConfigParams() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public void setRunLevel(int level) {
-        // TODO Auto-generated method stub
-
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/285f23f1/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index c40cd75..fa0d99f 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -16,73 +16,12 @@
 // under the License.
 package com.cloud.hypervisor.kvm.resource;
 
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.InetAddress;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.text.DateFormat;
-import java.text.MessageFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.log4j.Logger;
-import org.libvirt.Connect;
-import org.libvirt.Domain;
-import org.libvirt.DomainBlockStats;
-import org.libvirt.DomainInfo;
-import org.libvirt.DomainInterfaceStats;
-import org.libvirt.DomainSnapshot;
-import org.libvirt.LibvirtException;
-import org.libvirt.NodeInfo;
-
 import com.ceph.rados.IoCTX;
 import com.ceph.rados.Rados;
 import com.ceph.rados.RadosException;
 import com.ceph.rbd.Rbd;
 import com.ceph.rbd.RbdException;
 import com.ceph.rbd.RbdImage;
-
-import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
-import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
-import org.apache.cloudstack.storage.to.VolumeObjectTO;
-import org.apache.cloudstack.utils.qemu.QemuImg;
-import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
-import org.apache.cloudstack.utils.qemu.QemuImgException;
-import org.apache.cloudstack.utils.qemu.QemuImgFile;
-
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.AttachIsoCommand;
 import com.cloud.agent.api.AttachVolumeAnswer;
@@ -155,7 +94,6 @@ import com.cloud.agent.api.RebootCommand;
 import com.cloud.agent.api.RebootRouterCommand;
 import com.cloud.agent.api.SecurityGroupRuleAnswer;
 import com.cloud.agent.api.SecurityGroupRulesCmd;
-import com.cloud.agent.api.SetupGuestNetworkAnswer;
 import com.cloud.agent.api.SetupGuestNetworkCommand;
 import com.cloud.agent.api.StartAnswer;
 import com.cloud.agent.api.StartCommand;
@@ -174,13 +112,9 @@ import com.cloud.agent.api.check.CheckSshCommand;
 import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
 import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
 import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
-import com.cloud.agent.api.routing.IpAssocAnswer;
 import com.cloud.agent.api.routing.IpAssocCommand;
 import com.cloud.agent.api.routing.IpAssocVpcCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
-import com.cloud.agent.api.routing.SetNetworkACLAnswer;
-import com.cloud.agent.api.routing.SetNetworkACLCommand;
-import com.cloud.agent.api.routing.SetSourceNatAnswer;
 import com.cloud.agent.api.routing.SetSourceNatCommand;
 import com.cloud.agent.api.storage.CopyVolumeAnswer;
 import com.cloud.agent.api.storage.CopyVolumeCommand;
@@ -201,6 +135,7 @@ import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.StorageFilerTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.api.to.VolumeTO;
+import com.cloud.agent.resource.virtualnetwork.VirtualRouterDeployer;
 import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
 import com.cloud.dc.Vlan;
 import com.cloud.exception.InternalErrorException;
@@ -250,17 +185,77 @@ import com.cloud.storage.template.Processor.FormatInfo;
 import com.cloud.storage.template.QCOW2Processor;
 import com.cloud.storage.template.TemplateLocation;
 import com.cloud.storage.template.TemplateProp;
+import com.cloud.utils.ExecutionResult;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.PropertiesUtil;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
 import com.cloud.utils.script.OutputInterpreter;
+import com.cloud.utils.script.OutputInterpreter.AllLinesParser;
 import com.cloud.utils.script.Script;
+import com.cloud.utils.ssh.SshHelper;
 import com.cloud.vm.DiskProfile;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.PowerState;
 import com.cloud.vm.VirtualMachine.State;
+import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
+import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
+import org.apache.cloudstack.storage.to.VolumeObjectTO;
+import org.apache.cloudstack.utils.qemu.QemuImg;
+import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
+import org.apache.cloudstack.utils.qemu.QemuImgException;
+import org.apache.cloudstack.utils.qemu.QemuImgFile;
+import org.apache.commons.io.FileUtils;
+import org.apache.log4j.Logger;
+import org.libvirt.Connect;
+import org.libvirt.Domain;
+import org.libvirt.DomainBlockStats;
+import org.libvirt.DomainInfo;
+import org.libvirt.DomainInterfaceStats;
+import org.libvirt.DomainSnapshot;
+import org.libvirt.LibvirtException;
+import org.libvirt.NodeInfo;
+
+import javax.ejb.Local;
+import javax.naming.ConfigurationException;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.text.DateFormat;
+import java.text.MessageFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * LibvirtComputingResource execute requests on the computing/routing host using
@@ -285,7 +280,7 @@ import com.cloud.vm.VirtualMachine.State;
  *         pool | the parent of the storage pool hierarchy * }
  **/
 @Local(value = {ServerResource.class})
-public class LibvirtComputingResource extends ServerResourceBase implements ServerResource {
+public class LibvirtComputingResource extends ServerResourceBase implements ServerResource, VirtualRouterDeployer {
     private static final Logger s_logger = Logger.getLogger(LibvirtComputingResource.class);
 
     private String _modifyVlanPath;
@@ -322,6 +317,58 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
     protected static final String DEFAULT_OVS_VIF_DRIVER_CLASS_NAME = "com.cloud.hypervisor.kvm.resource.OvsVifDriver";
     protected static final String DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver";
 
+    @Override
+    public ExecutionResult executeInVR(String routerIp, String script, String args) {
+        final Script command = new Script(_routerProxyPath, _timeout, s_logger);
+        final AllLinesParser parser = new AllLinesParser();
+        command.add(script);
+        command.add(routerIp);
+        if (args != null) {
+            command.add(args);
+        }
+        String details = command.execute(parser);
+        if (details == null) {
+            details = parser.getLines();
+        }
+        return new ExecutionResult(command.getExitValue() == 0, details);
+    }
+
+    @Override
+    public ExecutionResult createFileInVR(String routerIp, String path, String filename, String content) {
+        File permKey = new File("/root/.ssh/id_rsa.cloud");
+        String error = null;
+
+        try {
+            SshHelper.scpTo(routerIp, 3922, "root", permKey, null, path, content.getBytes(), filename, null);
+        } catch (Exception e) {
+            s_logger.warn("Fail to create file " + path + filename + " in VR " + routerIp, e);
+            error = e.getMessage();
+        }
+        return new ExecutionResult(error == null, error);
+    }
+
+    @Override
+    public ExecutionResult prepareCommand(NetworkElementCommand cmd) {
+        //Update IP used to access router
+        cmd.setRouterAccessIp(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP));
+
+        if (cmd instanceof IpAssocVpcCommand) {
+            return prepareNetworkElementCommand((IpAssocVpcCommand)cmd);
+        } else if (cmd instanceof IpAssocCommand) {
+            return prepareNetworkElementCommand((IpAssocCommand)cmd);
+        } else if (cmd instanceof SetupGuestNetworkCommand) {
+            return prepareNetworkElementCommand((SetupGuestNetworkCommand)cmd);
+        } else if (cmd instanceof SetSourceNatCommand) {
+            return prepareNetworkElementCommand((SetSourceNatCommand)cmd);
+        }
+        return new ExecutionResult(true, null);
+    }
+
+    @Override
+    public ExecutionResult cleanupCommand(NetworkElementCommand cmd) {
+        return new ExecutionResult(true, null);
+    }
+
     private static final class KeyValueInterpreter extends OutputInterpreter {
         private final Map<String, String> map = new HashMap<String, String>();
 
@@ -537,7 +584,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
 
         params.put("domr.scripts.dir", domrScriptsDir);
 
-        _virtRouterResource = new VirtualRoutingResource();
+        _virtRouterResource = new VirtualRoutingResource(this);
         success = _virtRouterResource.configure(name, params);
 
         if (!success) {
@@ -1258,16 +1305,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
                 return execute((PlugNicCommand)cmd);
             } else if (cmd instanceof UnPlugNicCommand) {
                 return execute((UnPlugNicCommand)cmd);
-            } else if (cmd instanceof SetupGuestNetworkCommand) {
-                return execute((SetupGuestNetworkCommand)cmd);
-            } else if (cmd instanceof SetNetworkACLCommand) {
-                return execute((SetNetworkACLCommand)cmd);
-            } else if (cmd instanceof SetSourceNatCommand) {
-                return execute((SetSourceNatCommand)cmd);
-            } else if (cmd instanceof IpAssocVpcCommand) {
-                return execute((IpAssocVpcCommand)cmd);
-            } else if (cmd instanceof IpAssocCommand) {
-                return execute((IpAssocCommand)cmd);
             } else if (cmd instanceof NetworkElementCommand) {
                 return _virtRouterResource.executeRequest(cmd);
             } else if (cmd instanceof CheckSshCommand) {
@@ -1977,25 +2014,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
         }
     }
 
-    private SetupGuestNetworkAnswer execute(SetupGuestNetworkCommand cmd) {
+    private ExecutionResult prepareNetworkElementCommand(SetupGuestNetworkCommand cmd) {
         Connect conn;
         NicTO nic = cmd.getNic();
-        String routerIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
-        String routerGIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP);
         String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
-        String gateway = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY);
-        String cidr = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));
-        String domainName = cmd.getNetworkDomain();
-        String dns = cmd.getDefaultDns1();
-
-        if (dns == null || dns.isEmpty()) {
-            dns = cmd.getDefaultDns2();
-        } else {
-            String dns2 = cmd.getDefaultDns2();
-            if (dns2 != null && !dns2.isEmpty()) {
-                dns += "," + dns2;
-            }
-        }
 
         try {
             conn = LibvirtConnection.getConnectionByVmName(routerName);
@@ -2010,62 +2032,18 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
             }
 
             if (routerNic == null) {
-                return new SetupGuestNetworkAnswer(cmd, false, "Can not find nic with mac " + nic.getMac() + " for VM " + routerName);
+                return new ExecutionResult(false, "Can not find nic with mac " + nic.getMac() + " for VM " + routerName);
             }
 
-            String dev = "eth" + nic.getDeviceId();
-            String netmask = NetUtils.getSubNet(routerGIP, nic.getNetmask());
-            String result = _virtRouterResource.assignGuestNetwork(dev, routerIP, routerGIP, gateway, cidr, netmask, dns, domainName);
-
-            if (result != null) {
-                return new SetupGuestNetworkAnswer(cmd, false, "Creating guest network failed due to " + result);
-            }
-            return new SetupGuestNetworkAnswer(cmd, true, "success");
+            return new ExecutionResult(true, null);
         } catch (LibvirtException e) {
             String msg = "Creating guest network failed due to " + e.toString();
             s_logger.warn(msg, e);
-            return new SetupGuestNetworkAnswer(cmd, false, msg);
+            return new ExecutionResult(false, msg);
         }
     }
 
-
-    private SetNetworkACLAnswer execute(SetNetworkACLCommand cmd) {
-        String[] results = new String[cmd.getRules().length];
-
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
-        String privateGw = cmd.getAccessDetail(NetworkElementCommand.VPC_PRIVATE_GATEWAY);
-
-        try {
-            String[][] rules = cmd.generateFwRules();
-            String[] aclRules = rules[0];
-            NicTO nic = cmd.getNic();
-            String dev = "eth" + nic.getDeviceId();
-            String netmask = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));
-            StringBuilder sb = new StringBuilder();
-
-            for (int i = 0; i < aclRules.length; i++) {
-                sb.append(aclRules[i]).append(',');
-            }
-
-            String rule = sb.toString();
-            String result = _virtRouterResource.assignNetworkACL(routerIp, dev, nic.getIp(), netmask, rule, privateGw);
-
-            if (result != null) {
-                for (int i = 0; i < results.length; i++) {
-                    results[i] = "Failed";
-                }
-                return new SetNetworkACLAnswer(cmd, false, results);
-            }
-
-            return new SetNetworkACLAnswer(cmd, true, results);
-        } catch (Exception e) {
-            String msg = "SetNetworkACL failed due to " + e.toString();
-            s_logger.error(msg, e);
-            return new SetNetworkACLAnswer(cmd, false, results);
-        }
-    }
-
-    protected SetSourceNatAnswer execute(SetSourceNatCommand cmd) {
+    protected ExecutionResult prepareNetworkElementCommand(SetSourceNatCommand cmd) {
         Connect conn;
         String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
         String routerIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
@@ -2086,7 +2064,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
                     /*skip over, no physical bridge device exists*/
                 } else if (pluggedVlanId == null) {
                     /*this should only be true in the case of link local bridge*/
-                    return new SetSourceNatAnswer(cmd, false, "unable to find the vlan id for bridge " + pluggedVlanBr + " when attempting to set up" + pubVlan +
+                    return new ExecutionResult(false, "unable to find the vlan id for bridge " + pluggedVlanBr + " when attempting to set up" + pubVlan +
                             " on router " + routerName);
                 } else if (pluggedVlanId.equals(pubVlan)) {
                     break;
@@ -2094,26 +2072,20 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
                 devNum++;
             }
 
-            String dev = "eth" + devNum;
-            String result = _virtRouterResource.assignSourceNat(routerIP, pubIP.getPublicIp(), dev);
+            pubIP.setNicDevId(devNum);
 
-            if (result != null) {
-                return new SetSourceNatAnswer(cmd, false, "KVM plugin \"vpc_snat\" failed:" + result);
-            }
-            return new SetSourceNatAnswer(cmd, true, "success");
+            return new ExecutionResult(true, "success");
         } catch (LibvirtException e) {
             String msg = "Ip SNAT failure due to " + e.toString();
             s_logger.error(msg, e);
-            return new SetSourceNatAnswer(cmd, false, msg);
+            return new ExecutionResult(false, msg);
         }
     }
 
-    protected IpAssocAnswer execute(IpAssocVpcCommand cmd) {
+    protected ExecutionResult prepareNetworkElementCommand(IpAssocVpcCommand cmd) {
         Connect conn;
-        String[] results = new String[cmd.getIpAddresses().length];
         int i = 0;
         String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
-        String routerIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
 
         try {
             conn = LibvirtConnection.getConnectionByVmName(routerName);
@@ -2136,31 +2108,19 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
             }
 
             for (IpAddressTO ip : ips) {
-                String nicName = "eth" + broadcastUriToNicNum.get(ip.getBroadcastUri());
-                String netmask = Long.toString(NetUtils.getCidrSize(ip.getVlanNetmask()));
-                String subnet = NetUtils.getSubNet(ip.getPublicIp(), ip.getVlanNetmask());
-                _virtRouterResource.assignVpcIpToRouter(routerIP, ip.isAdd(), ip.getPublicIp(), nicName, ip.getVlanGateway(), netmask, subnet, ip.isSourceNat());
-                results[i++] = ip.getPublicIp() + " - success";
+                ip.setNicDevId(broadcastUriToNicNum.get(ip.getBroadcastUri()));
             }
 
+            return new ExecutionResult(true, null);
         } catch (LibvirtException e) {
             s_logger.error("Ip Assoc failure on applying one ip due to exception:  ", e);
-            results[i++] = IpAssocAnswer.errorResult;
-        } catch (InternalErrorException e) {
-            s_logger.error("Ip Assoc failure on applying one ip due to exception:  ", e);
-            results[i++] = IpAssocAnswer.errorResult;
+            return new ExecutionResult(false, e.getMessage());
         }
-
-        return new IpAssocAnswer(cmd, results);
     }
 
-    public Answer execute(IpAssocCommand cmd) {
+    public ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd) {
         String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
         String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
-        String[] results = new String[cmd.getIpAddresses().length];
-        for (int i = 0; i < results.length; i++) {
-            results[i] = IpAssocAnswer.errorResult;
-        }
         Connect conn;
         try {
             conn = LibvirtConnection.getConnectionByVmName(routerName);
@@ -2182,11 +2142,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
                 nicPos++;
             }
             IpAddressTO[] ips = cmd.getIpAddresses();
-            int i = 0;
-            String result = null;
             int nicNum = 0;
-            boolean newNic = false;
             for (IpAddressTO ip : ips) {
+                boolean newNic = false;
                 if (!broadcastUriAllocatedToVM.containsKey(ip.getBroadcastUri())) {
                     /* plug a vif into router */
                     VifHotPlug(conn, routerName, ip.getBroadcastUri(), ip.getVifMacAddress());
@@ -2195,21 +2153,17 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
                 }
                 nicNum = broadcastUriAllocatedToVM.get(ip.getBroadcastUri());
                 networkUsage(routerIp, "addVif", "eth" + nicNum);
-                result =
-                        _virtRouterResource.assignPublicIpAddress(routerName, routerIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getBroadcastUri(),
-                                ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), nicNum, newNic);
 
-                if (result == null) {
-                    results[i++] = ip.getPublicIp() + " - success";
-                }
+                ip.setNicDevId(nicNum);
+                ip.setNewNic(newNic);
             }
-            return new IpAssocAnswer(cmd, results);
+            return new ExecutionResult(true, null);
         } catch (LibvirtException e) {
             s_logger.error("ipassoccmd failed", e);
-            return new IpAssocAnswer(cmd, results);
+            return new ExecutionResult(false, e.getMessage());
         } catch (InternalErrorException e) {
             s_logger.error("ipassoccmd failed", e);
-            return new IpAssocAnswer(cmd, results);
+            return new ExecutionResult(false, e.getMessage());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/285f23f1/utils/src/com/cloud/utils/script/OutputInterpreter.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/script/OutputInterpreter.java b/utils/src/com/cloud/utils/script/OutputInterpreter.java
index 5af607e..5845c9c 100755
--- a/utils/src/com/cloud/utils/script/OutputInterpreter.java
+++ b/utils/src/com/cloud/utils/script/OutputInterpreter.java
@@ -16,11 +16,11 @@
 // under the License.
 package com.cloud.utils.script;
 
+import org.apache.log4j.Logger;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 
-import org.apache.log4j.Logger;
-
 /**
  */
 public abstract class OutputInterpreter {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/285f23f1/utils/src/com/cloud/utils/script/Script.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java
index 91f32de..8dad697 100755
--- a/utils/src/com/cloud/utils/script/Script.java
+++ b/utils/src/com/cloud/utils/script/Script.java
@@ -16,6 +16,11 @@
 // under the License.
 package com.cloud.utils.script;
 
+import com.cloud.utils.PropertiesUtil;
+import com.cloud.utils.concurrency.NamedThreadFactory;
+import com.cloud.utils.script.OutputInterpreter.TimedOutLogger;
+import org.apache.log4j.Logger;
+
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
@@ -35,12 +40,6 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.log4j.Logger;
-
-import com.cloud.utils.PropertiesUtil;
-import com.cloud.utils.concurrency.NamedThreadFactory;
-import com.cloud.utils.script.OutputInterpreter.TimedOutLogger;
-
 public class Script implements Callable<String> {
     private static final Logger s_logger = Logger.getLogger(Script.class);
 
@@ -61,6 +60,10 @@ public class Script implements Callable<String> {
     Process _process;
     Thread _thread;
 
+    public int getExitValue()  {
+        return _process.exitValue();
+    }
+
     public Script(String command, long timeout, Logger logger) {
         _command = new ArrayList<String>();
         _command.add(command);


Mime
View raw message