You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2012/08/01 23:00:42 UTC

git commit: Another clean up for unnecessary parameter conn Clean up unused parameter conn. Add test for LibvirtVMDef Add support for ethernet type RB: https://reviews.apache.org/r/6284/ Send-by: tomoe@midokura.com

Updated Branches:
  refs/heads/master 3a184a1b4 -> 05df0a196


Another clean up for unnecessary parameter conn Clean up unused
parameter conn. Add test for LibvirtVMDef Add support for ethernet type
RB: https://reviews.apache.org/r/6284/
Send-by: tomoe@midokura.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/05df0a19
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/05df0a19
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/05df0a19

Branch: refs/heads/master
Commit: 05df0a1965ef4fc9f8646fa3bd4fa47d63e31f4f
Parents: 3a184a1
Author: Edison Su <su...@gmail.com>
Authored: Wed Aug 1 13:59:11 2012 -0700
Committer: Edison Su <su...@gmail.com>
Committed: Wed Aug 1 13:59:11 2012 -0700

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java     |   26 +++++-----
 .../hypervisor/kvm/resource/LibvirtVMDef.java      |    7 +++
 .../hypervisor/kvm/resource/LibvirtVMDefTest.java  |   38 +++++++++++++++
 3 files changed, 58 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/05df0a19/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 ea12b98..73101a9 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
@@ -698,7 +698,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
         }
 
         try {
-            createControlNetwork(conn);
+            createControlNetwork();
         } catch (LibvirtException e) {
             throw new ConfigurationException(e.getMessage());
         }
@@ -1220,7 +1220,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
             nicTO.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlanId));
         }
 
-        InterfaceDef nic = createVif(conn, nicTO, InterfaceDef.nicModel.VIRTIO);
+        InterfaceDef nic = createVif(nicTO, InterfaceDef.nicModel.VIRTIO);
         Domain vm = getDomain(conn, vmName);
         vm.attachDevice(nic.toString());
     }
@@ -2122,7 +2122,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
                     }
                 } else if (nic.getType() == TrafficType.Control) {
                     /* Make sure the network is still there */
-                    createControlNetwork(conn);
+                    createControlNetwork();
                 } else if (nic.getType() == TrafficType.Public) {
                     if (nic.getBroadcastType() == BroadcastDomainType.Vlan
                             && !vlanId.equalsIgnoreCase("untagged")) {
@@ -2516,13 +2516,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements
         return vm;
     }
 
-    protected void createVifs(Connect conn, VirtualMachineTO vmSpec,
-            LibvirtVMDef vm) throws InternalErrorException, LibvirtException {
+    protected void createVifs(VirtualMachineTO vmSpec,
+                              LibvirtVMDef vm) throws InternalErrorException, LibvirtException {
         NicTO[] nics = vmSpec.getNics();
         for (int i = 0; i < nics.length; i++) {
             for (NicTO nic : vmSpec.getNics()) {
                 if (nic.getDeviceId() == i) {
-                    createVif(conn, vm, nic);
+                    createVif(vm, nic);
                 }
             }
         }
@@ -2546,7 +2546,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
 
             createVbd(conn, vmSpec, vmName, vm);
 
-            createVifs(conn, vmSpec, vm);
+            createVifs(vmSpec, vm);
 
             s_logger.debug("starting " + vmName + ": " + vm.toString());
             startDomain(conn, vmName, vm.toString());
@@ -2734,8 +2734,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements
         return brName;
     }
 
-    private InterfaceDef createVif(Connect conn, NicTO nic,
-            InterfaceDef.nicModel model) throws InternalErrorException,
+    private InterfaceDef createVif(NicTO nic,
+                                   InterfaceDef.nicModel model) throws InternalErrorException,
             LibvirtException {
         InterfaceDef intf = new InterfaceDef();
 
@@ -2755,7 +2755,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
             }
         } else if (nic.getType() == TrafficType.Control) {
             /* Make sure the network is still there */
-            createControlNetwork(conn);
+            createControlNetwork();
             intf.defBridgeNet(_linkLocalBridgeName, null, nic.getMac(), model);
         } else if (nic.getType() == TrafficType.Public) {
             if (nic.getBroadcastType() == BroadcastDomainType.Vlan
@@ -2776,10 +2776,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
         return intf;
     }
 
-    private void createVif(Connect conn, LibvirtVMDef vm, NicTO nic)
+    private void createVif(LibvirtVMDef vm, NicTO nic)
             throws InternalErrorException, LibvirtException {
         vm.getDevices().addDevice(
-                createVif(conn, nic, getGuestNicModel(vm.getGuestOSType())));
+                createVif(nic, getGuestNicModel(vm.getGuestOSType())));
     }
 
     protected CheckSshAnswer execute(CheckSshCommand cmd) {
@@ -4098,7 +4098,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
         return new Pair<Double, Double>(rx, tx);
     }
 
-    private void createControlNetwork(Connect conn) throws LibvirtException {
+    private void createControlNetwork() throws LibvirtException {
         _virtRouterResource.createControlNetwork(_linkLocalBridgeName);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/05df0a19/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
index e1cfa54..457d9ac 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
@@ -665,6 +665,13 @@ public class LibvirtVMDef {
             _model = model;
         }
 
+        public void defEthernet(String targetName, String macAddr,  nicModel model) {
+            _netType = guestNetType.ETHERNET;
+            _networkName = targetName;
+            _macAddr = macAddr;
+            _model = model;
+         }
+
         public void setHostNetType(hostNicType hostNetType) {
             _hostNetType = hostNetType;
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/05df0a19/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java
new file mode 100644
index 0000000..b723875
--- /dev/null
+++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.hypervisor.kvm.resource;
+
+import junit.framework.TestCase;
+
+public class LibvirtVMDefTest extends TestCase {
+
+    public void testInterfaceEtehrnet() {
+        LibvirtVMDef.InterfaceDef ifDef = new LibvirtVMDef.InterfaceDef();
+        ifDef.defEthernet("targetDeviceName", "00:11:22:aa:bb:dd", LibvirtVMDef.InterfaceDef.nicModel.VIRTIO);
+
+        String expected = "<interface type='ethernet'>\n" +
+                "<target dev='targetDeviceName'/>\n" +
+                "<mac address='00:11:22:aa:bb:dd'/>\n" +
+                "<model type='virtio'/>\n" +
+                "</interface>\n";
+
+        assertEquals(expected, ifDef.toString());
+    }
+}