cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject [8/8] git commit: updated refs/heads/vpc_simulator to 930ca7f
Date Tue, 04 Jun 2013 16:11:54 GMT
Provide dummy implementations

Signed-off-by: Prasanna Santhanam <tsp@apache.org>


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

Branch: refs/heads/vpc_simulator
Commit: 930ca7f22215013131bdca3281da4727a9f70433
Parents: ceebd83
Author: Prasanna Santhanam <tsp@apache.org>
Authored: Tue Jun 4 21:40:30 2013 +0530
Committer: Prasanna Santhanam <tsp@apache.org>
Committed: Tue Jun 4 21:41:35 2013 +0530

----------------------------------------------------------------------
 .../cloud/agent/manager/MockNetworkManager.java    |   24 ++-
 .../agent/manager/MockNetworkManagerImpl.java      |  120 +++++++++++++--
 .../cloud/agent/manager/SimulatorManagerImpl.java  |    2 +
 3 files changed, 123 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/930ca7f2/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockNetworkManager.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockNetworkManager.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockNetworkManager.java
index 61a556a..0f59319 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockNetworkManager.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockNetworkManager.java
@@ -22,19 +22,27 @@ package com.cloud.agent.manager;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.CheckS2SVpnConnectionsCommand;
 import com.cloud.agent.api.NetworkUsageCommand;
+import com.cloud.agent.api.PlugNicAnswer;
 import com.cloud.agent.api.PlugNicCommand;
 import com.cloud.agent.api.PvlanSetupCommand;
+import com.cloud.agent.api.UnPlugNicAnswer;
 import com.cloud.agent.api.UnPlugNicCommand;
 import com.cloud.agent.api.routing.DhcpEntryCommand;
+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.SetFirewallRulesCommand;
+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;
 import com.cloud.agent.api.routing.SetStaticRouteCommand;
 import com.cloud.agent.api.routing.Site2SiteVpnCfgCommand;
 import com.cloud.utils.component.Manager;
@@ -57,19 +65,21 @@ public interface MockNetworkManager extends Manager {
 
     Answer setupPVLAN(PvlanSetupCommand cmd);
 
-    Answer plugNic(PlugNicCommand cmd);
+    PlugNicAnswer plugNic(PlugNicCommand cmd);
 
-    Answer unplugNic(UnPlugNicCommand cmd);
+    UnPlugNicAnswer unplugNic(UnPlugNicCommand cmd);
 
-    Answer ipAssoc(IpAssocVpcCommand cmd);
+    IpAssocAnswer ipAssoc(IpAssocVpcCommand cmd);
 
-    Answer setSourceNat(SetSourceNatCommand cmd);
+    SetSourceNatAnswer setSourceNat(SetSourceNatCommand cmd);
 
-    Answer setNetworkAcl(SetNetworkACLCommand cmd);
+    SetNetworkACLAnswer setNetworkAcl(SetNetworkACLCommand cmd);
 
-    Answer setVpcPortForwards(SetPortForwardingRulesVpcCommand cmd);
+    SetPortForwardingRulesAnswer setVpcPortForwards(SetPortForwardingRulesVpcCommand cmd);
 
-    Answer setStaticRoute(SetStaticRouteCommand cmd);
+    SetStaticNatRulesAnswer setVPCStaticNatRules(SetStaticNatRulesCommand cmd);
+
+    SetStaticRouteAnswer setStaticRoute(SetStaticRouteCommand cmd);
 
     Answer siteToSiteVpn(Site2SiteVpnCfgCommand cmd);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/930ca7f2/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockNetworkManagerImpl.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockNetworkManagerImpl.java
index 232146a..4035a7a 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockNetworkManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockNetworkManagerImpl.java
@@ -23,24 +23,44 @@ import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.CheckS2SVpnConnectionsCommand;
 import com.cloud.agent.api.NetworkUsageAnswer;
 import com.cloud.agent.api.NetworkUsageCommand;
+import com.cloud.agent.api.PlugNicAnswer;
 import com.cloud.agent.api.PlugNicCommand;
 import com.cloud.agent.api.PvlanSetupCommand;
+import com.cloud.agent.api.UnPlugNicAnswer;
 import com.cloud.agent.api.UnPlugNicCommand;
 import com.cloud.agent.api.routing.DhcpEntryCommand;
+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.SetFirewallRulesAnswer;
 import com.cloud.agent.api.routing.SetFirewallRulesCommand;
+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;
 import com.cloud.agent.api.routing.SetStaticRouteCommand;
 import com.cloud.agent.api.routing.Site2SiteVpnCfgCommand;
+import com.cloud.agent.api.to.IpAddressTO;
+import com.cloud.agent.api.to.PortForwardingRuleTO;
+import com.cloud.simulator.dao.MockVMDao;
 import com.cloud.utils.component.ManagerBase;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
 
 public class MockNetworkManagerImpl extends ManagerBase implements MockNetworkManager {
+    private static final Logger s_logger = Logger.getLogger(MockVmManagerImpl.class);
+
+    @Inject
+    MockVMDao _mockVmDao;
 
     @Override
     public Answer SetStaticNatRules(SetStaticNatRulesCommand cmd) {
@@ -53,8 +73,22 @@ public class MockNetworkManagerImpl extends ManagerBase implements MockNetworkMa
     }
 
     @Override
-    public Answer SetFirewallRules(SetFirewallRulesCommand cmd) {
-        return new Answer(cmd);
+    public SetFirewallRulesAnswer SetFirewallRules(SetFirewallRulesCommand cmd) {
+        String[] results = new String[cmd.getRules().length];
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        if (routerIp == null) {
+            return new SetFirewallRulesAnswer(cmd, false, results);
+        }
+
+        String[][] rules = cmd.generateFwRules();
+        StringBuilder sb = new StringBuilder();
+        String[] fwRules = rules[0];
+        if (fwRules.length > 0) {
+            for (int i = 0; i < fwRules.length; i++) {
+                sb.append(fwRules[i]).append(',');
+            }
+        }
+        return new SetFirewallRulesAnswer(cmd, true, results);
     }
 
 
@@ -84,38 +118,92 @@ public class MockNetworkManagerImpl extends ManagerBase implements MockNetworkMa
     }
 
     @Override
-    public Answer plugNic(PlugNicCommand cmd) {
-        return new Answer(cmd);
+    public PlugNicAnswer plugNic(PlugNicCommand cmd) {
+        String vmname = cmd.getVmName();
+        if (_mockVmDao.findByVmName(vmname) != null) {
+            s_logger.debug("Plugged NIC (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp()
+ ") into " + cmd.getVmName());
+            return new PlugNicAnswer(cmd,  true, "success");
+        }
+        s_logger.error("Plug NIC failed for (dev=" + cmd.getNic().getDeviceId() + ", " +
cmd.getNic().getIp() + ") into " + cmd.getVmName());
+        return new PlugNicAnswer(cmd, false, "failure");
     }
 
     @Override
-    public Answer unplugNic(UnPlugNicCommand cmd) {
-        return new Answer(cmd);
+    public UnPlugNicAnswer unplugNic(UnPlugNicCommand cmd) {
+        String vmname = cmd.getVmName();
+        if (_mockVmDao.findByVmName(vmname) != null) {
+            s_logger.debug("Plugged NIC (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp()
+ ") into " + cmd.getVmName());
+            return new UnPlugNicAnswer(cmd,  true, "success");
+        }
+        s_logger.error("Plug NIC failed for (dev=" + cmd.getNic().getDeviceId() + ", " +
cmd.getNic().getIp() + ") into " + cmd.getVmName());
+        return new UnPlugNicAnswer(cmd, false, "failure");
     }
 
     @Override
-    public Answer ipAssoc(IpAssocVpcCommand cmd) {
-        return new Answer(cmd);
+    public IpAssocAnswer ipAssoc(IpAssocVpcCommand cmd) {
+        String[] results = new String[cmd.getIpAddresses().length];
+        int i = 0;
+        IpAddressTO[] ips = cmd.getIpAddresses();
+        for (IpAddressTO ip : ips) {
+            results[i++] = ip.getPublicIp() + " - success";
+        }
+        return new IpAssocAnswer(cmd, results);
     }
 
     @Override
-    public Answer setSourceNat(SetSourceNatCommand cmd) {
-        return new Answer(cmd);
+    public SetSourceNatAnswer setSourceNat(SetSourceNatCommand cmd) {
+        return new SetSourceNatAnswer(cmd, true, "success");
     }
 
     @Override
-    public Answer setNetworkAcl(SetNetworkACLCommand cmd) {
-        return new Answer(cmd);
+    public SetNetworkACLAnswer setNetworkAcl(SetNetworkACLCommand cmd) {
+        String[] results = new String[cmd.getRules().length];
+        String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+
+        StringBuilder sb = new StringBuilder();
+        sb.append(routerIp);
+        sb.append(routerName);
+
+        String [][] rules = cmd.generateFwRules();
+        String[] aclRules = rules[0];
+
+        for (int i = 0; i < aclRules.length; i++) {
+            sb.append(aclRules[i]).append(',');
+        }
+
+        return new SetNetworkACLAnswer(cmd, true, results);
     }
 
     @Override
-    public Answer setVpcPortForwards(SetPortForwardingRulesVpcCommand cmd) {
-        return new Answer(cmd);
+    public SetPortForwardingRulesAnswer setVpcPortForwards(SetPortForwardingRulesVpcCommand
cmd) {
+        String[] results = new String[cmd.getRules().length];
+        StringBuilder sb = new StringBuilder();
+        for (PortForwardingRuleTO rule : cmd.getRules()) {
+            sb.append("src:");
+            sb.append(rule.getStringSrcPortRange());
+            sb.append("dst:");
+            sb.append(rule.getStringDstPortRange());
+        }
+        return new SetPortForwardingRulesAnswer(cmd, results, true);
     }
 
     @Override
-    public Answer setStaticRoute(SetStaticRouteCommand cmd) {
-        return new Answer(cmd);
+    public SetStaticRouteAnswer setStaticRoute(SetStaticRouteCommand cmd) {
+        String[] results = new String[cmd.getStaticRoutes().length];
+        String [][] rules = cmd.generateSRouteRules();
+        StringBuilder sb = new StringBuilder();
+        String[] srRules = rules[0];
+        for (int i = 0; i < srRules.length; i++) {
+            sb.append(srRules[i]).append(',');
+        }
+        return new SetStaticRouteAnswer(cmd, true, results);
+    }
+
+    @Override
+    public SetStaticNatRulesAnswer setVPCStaticNatRules(SetStaticNatRulesCommand cmd) {
+        String[] results = new String[cmd.getRules().length];
+        return new SetStaticNatRulesAnswer(cmd, results, true);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/930ca7f2/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
index 8f6116c..7329ad1 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
@@ -333,6 +333,8 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
                 return _mockNetworkMgr.setNetworkAcl((SetNetworkACLCommand) cmd);
             } else if (cmd instanceof SetPortForwardingRulesVpcCommand) {
                 return _mockNetworkMgr.setVpcPortForwards((SetPortForwardingRulesVpcCommand)
cmd);
+            } else if (cmd instanceof SetStaticNatRulesCommand) {
+                return _mockNetworkMgr.setVPCStaticNatRules((SetStaticNatRulesCommand) cmd);
             } else if (cmd instanceof SetStaticRouteCommand) {
                 return _mockNetworkMgr.setStaticRoute((SetStaticRouteCommand) cmd);
             } else if (cmd instanceof Site2SiteVpnCfgCommand) {


Mime
View raw message