[PATCH 08 of 11] virt-convert: implement network device handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



# HG changeset patch
# User john.levon@xxxxxxx
# Date 1215697571 25200
# Node ID 72eec78868efe7a872eab6c08502b3b84bf00a46
# Parent  8ffd21ddf5c72ddbe8a30f65f0761e2f39705d57
virt-convert: implement network device handling

Signed-off-by: John Levon <john.levon@xxxxxxx>

diff --git a/virtconv/netdevcfg.py b/virtconv/netdevcfg.py
new file mode 100644
--- /dev/null
+++ b/virtconv/netdevcfg.py
@@ -0,0 +1,39 @@
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free  Software Foundation; either version 2 of the License, or
+# (at your option)  any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301 USA.
+#
+
+NETDEV_TYPE_UNKNOWN = 0
+NETDEV_TYPE_BRIDGE = 1
+NETDEV_TYPE_DEV = 2
+NETDEV_TYPE_NETWORK = 3
+
+class netdev(object):
+    """Definition of an individual network device."""
+
+    def __init__(self, mac = "auto", type = NETDEV_TYPE_UNKNOWN,
+        source = None, driver = None):
+        """@mac: either a MAC address, or "auto"
+           @type: NETDEV_TYPE_*
+           @source: bridge or net device, or network name
+           @driver: device emulated for VM (e.g. vmxnet)
+           """ 
+        self.mac = mac
+        self.type = type
+        self.source = source
+        self.driver = driver
diff --git a/virtconv/parsers/virtimage.py b/virtconv/parsers/virtimage.py
--- a/virtconv/parsers/virtimage.py
+++ b/virtconv/parsers/virtimage.py
@@ -65,8 +65,8 @@
   <devices>
    <vcpu>%(nr_vcpus)s</vcpu>
    <memory>%(memory)s</memory>
-   <interface/>
-   <graphics/>
+   %(interface)s
+   <graphics />
   </devices>
  </domain>
  <storage>
@@ -185,6 +185,11 @@
         # xend wants the name to match r'^[A-Za-z0-9_\-\.\:\/\+]+$'
         vmname = re.sub(r'[^A-Za-z0-9_.:/+-]+',  '_', vm.name)
 
+        # Hmm.  Any interface is a good interface?
+        interface = None
+        if len(vm.netdevs):
+            interface = "<interface />"
+
         if vm.type == vmcfg.VM_TYPE_PV:
             boot_template = pv_boot_template
         else:
@@ -204,6 +209,7 @@
             "nr_vcpus" : vm.nr_vcpus,
             # Mb to Kb
             "memory" : int(vm.memory) * 1024,
+            "interface" : interface,
             "storage" : "".join(storage),
         }
 
diff --git a/virtconv/parsers/vmx.py b/virtconv/parsers/vmx.py
--- a/virtconv/parsers/vmx.py
+++ b/virtconv/parsers/vmx.py
@@ -21,9 +21,34 @@
 import virtconv.formats as formats
 import virtconv.vmcfg as vmcfg
 import virtconv.diskcfg as diskcfg
+import virtconv.netdevcfg as netdevcfg
 
 import re
 import os
+
+def parse_netdev_entry(vm, fullkey, value):
+    """
+    Parse a particular key/value for a network.  Throws ValueError.
+    """
+
+    _, _, inst, key = re.split("^(ethernet)([0-9]+).", fullkey)
+
+    lvalue = value.lower()
+
+    if key == "present" and lvalue == "false":
+        return
+
+    if not vm.netdevs.get(inst):
+        vm.netdevs[inst] = netdevcfg.netdev(type = netdevcfg.NETDEV_TYPE_UNKNOWN)
+
+    # "vlance", "vmxnet", "e1000"
+    if key == "virtualDev":
+        vm.netdevs[inst].driver = lvalue
+    if key == "addressType" and lvalue == "generated":
+        vm.netdevs[inst].mac = "auto"
+    # we ignore .generatedAddress for auto mode
+    if key == "address":
+        vm.netdevs[inst].mac = lvalue
 
 def parse_disk_entry(vm, fullkey, value):
     """
@@ -126,6 +151,8 @@
 
                 if key.startswith("scsi") or key.startswith("ide"):
                     parse_disk_entry(vm, key, value)
+                if key.startswith("ethernet"):
+                    parse_netdev_entry(vm, key, value)
             except:
                 raise Exception("Syntax error at line %d: %s" %
                     (line_nr + 1, line.strip()))
diff --git a/virtconv/vmcfg.py b/virtconv/vmcfg.py
--- a/virtconv/vmcfg.py
+++ b/virtconv/vmcfg.py
@@ -52,6 +52,7 @@
         self.memory = None
         self.nr_vcpus = None
         self.disks = {}
+        self.netdevs = {}
         self.type = VM_TYPE_HVM
         self.arch = "i686"
 

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux