incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject git commit: Implement PlugNicCommand, UnPlugNicCommand for KVM This is part 1 in enabling VPC for KVM. The various commands needing implementation will be submitted individually unless I'm told to do otherwise, in case I don't complete all of the commands
Date Thu, 30 Aug 2012 17:29:03 GMT
Updated Branches:
  refs/heads/master d3921139e -> 3429c55e5


Implement PlugNicCommand,UnPlugNicCommand for KVM
This is part 1 in enabling VPC for KVM. The various commands needing
implementation will be submitted individually unless I'm told to do
otherwise, in case I don't complete all of the commands, such that
someone else can take over or build on my work.

RB: https://reviews.apache.org/r/6859
Send-by: shadowsor@gmail.com


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

Branch: refs/heads/master
Commit: 3429c55e5580f82710ca49e9cd2e03ded16e0b18
Parents: d392113
Author: Edison Su <sudison@gmail.com>
Authored: Thu Aug 30 10:28:03 2012 -0700
Committer: Edison Su <sudison@gmail.com>
Committed: Thu Aug 30 10:28:03 2012 -0700

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java     |   46 +++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3429c55e/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 48dc3d0..7e8a11c 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
@@ -115,6 +115,8 @@ import com.cloud.agent.api.PingCommand;
 import com.cloud.agent.api.PingRoutingCommand;
 import com.cloud.agent.api.PingRoutingWithNwGroupsCommand;
 import com.cloud.agent.api.PingTestCommand;
+import com.cloud.agent.api.PlugNicAnswer;
+import com.cloud.agent.api.PlugNicCommand;
 import com.cloud.agent.api.PrepareForMigrationAnswer;
 import com.cloud.agent.api.PrepareForMigrationCommand;
 import com.cloud.agent.api.ReadyAnswer;
@@ -131,6 +133,8 @@ import com.cloud.agent.api.StartupRoutingCommand;
 import com.cloud.agent.api.StartupStorageCommand;
 import com.cloud.agent.api.StopAnswer;
 import com.cloud.agent.api.StopCommand;
+import com.cloud.agent.api.UnPlugNicAnswer;
+import com.cloud.agent.api.UnPlugNicCommand;
 import com.cloud.agent.api.UpgradeSnapshotCommand;
 import com.cloud.agent.api.VmStatsEntry;
 import com.cloud.agent.api.check.CheckSshAnswer;
@@ -1020,6 +1024,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
                 return execute((FenceCommand) cmd);
             } else if (cmd instanceof StartCommand) {
                 return execute((StartCommand) cmd);
+            } else if (cmd instanceof PlugNicCommand) {
+                return execute((PlugNicCommand) cmd);
+            } else if (cmd instanceof UnPlugNicCommand) {
+                return execute((UnPlugNicCommand) cmd);
             } else if (cmd instanceof IpAssocCommand) {
                 return execute((IpAssocCommand) cmd);
             } else if (cmd instanceof NetworkElementCommand) {
@@ -1234,6 +1242,44 @@ public class LibvirtComputingResource extends ServerResourceBase implements
         vm.attachDevice(_vifDriver.plug(nicTO, "Other PV").toString());
     }
 
+    private PlugNicAnswer execute(PlugNicCommand cmd) {
+        Connect conn;
+        NicTO nic = cmd.getNic();
+        String vmName = cmd.getVmName();
+        try {
+            conn = LibvirtConnection.getConnection();
+            Domain vm = getDomain(conn, vmName);
+            vm.attachDevice(_vifDriver.plug(nic, "Other PV").toString());
+            return new PlugNicAnswer(cmd, true, "success");
+        } catch (Exception e) {
+            String msg = " Plug Nic failed due to " + e.toString();
+            s_logger.warn(msg, e);
+            return new PlugNicAnswer(cmd, false, msg);
+        }
+    }
+
+    private UnPlugNicAnswer execute(UnPlugNicCommand cmd) {
+        Connect conn;
+        NicTO nic = cmd.getNic();
+        String vmName = cmd.getInstanceName();
+        try {
+            conn = LibvirtConnection.getConnection();
+            Domain vm = getDomain(conn, vmName);
+            List<InterfaceDef> pluggedNics = getInterfaces(conn, vmName);
+            for (InterfaceDef pluggedNic : pluggedNics) {
+                if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) {
+                    vm.detachDevice(pluggedNic.toString());
+                    return new UnPlugNicAnswer(cmd, true, "success");
+                }
+            }
+            return new UnPlugNicAnswer(cmd, true, "success");
+        } catch (Exception e) {
+            String msg = " Unplug Nic failed due to " + e.toString();
+            s_logger.warn(msg, e);
+            return new UnPlugNicAnswer(cmd, false, msg);
+        } 
+    }
+
     public Answer execute(IpAssocCommand cmd) {
         String routerName = cmd
                 .getAccessDetail(NetworkElementCommand.ROUTER_NAME);


Mime
View raw message