Blob Blame History Raw
# HG changeset patch
# User Cole Robinson <crobinso@redhat.com>
# Date 1247587582 14400
# Node ID 8b5d60a01fe3f4300683b105c8cd3bffd62649bf
# Parent  020c0a312e7fc3b39936b731f6373398aad1dcf2
Refactor osdict lookup routines.

Allow specifying minimally supported libvirt and hypervisor version for
various parameters. Move most of this code out of Guest and into osdict.

diff -r 020c0a312e7f -r 8b5d60a01fe3 virtinst/Guest.py
--- a/virtinst/Guest.py	Tue Jul 14 09:53:46 2009 -0400
+++ b/virtinst/Guest.py	Tue Jul 14 12:06:22 2009 -0400
@@ -816,34 +816,16 @@
         Using self.os_type and self.os_variant to find key in OSTYPES
         @returns: dict value, or None if os_type/variant wasn't set
         """
-        typ = self.os_type
-        var = self.os_variant
-        if typ:
-            if var and self._OS_TYPES[typ]["variants"][var].has_key(key):
-                return self._OS_TYPES[typ]["variants"][var][key]
-            elif self._OS_TYPES[typ].has_key(key):
-                return self._OS_TYPES[typ][key]
-        return self._DEFAULTS[key]
+        return osdict.lookup_osdict_key(self.conn, self.type, self.os_type,
+                                        self.os_variant, key)
 
     def _lookup_device_param(self, device_key, param):
         """
         Check the OS dictionary for the prefered device setting for passed
         device type and param (bus, model, etc.)
         """
-        os_devs = self._lookup_osdict_key("devices")
-        default_devs = self._DEFAULTS["devices"]
-        for devs in [os_devs, default_devs]:
-            if not devs.has_key(device_key):
-                continue
-            for ent in devs[device_key][param]:
-                hv_types = ent[0]
-                param_value = ent[1]
-                if self.type in hv_types:
-                    return param_value
-                elif "all" in hv_types:
-                    return param_value
-        raise RuntimeError(_("Invalid dictionary entry for device '%s %s'" % \
-                             (device_key, param)))
+        return osdict.lookup_device_param(self.conn, self.type, self.os_type,
+                                          self.os_variant, device_key, param)
 
     def terminate_console(self):
         if self._consolechild:
diff -r 020c0a312e7f -r 8b5d60a01fe3 virtinst/osdict.py
--- a/virtinst/osdict.py	Tue Jul 14 09:53:46 2009 -0400
+++ b/virtinst/osdict.py	Tue Jul 14 12:06:22 2009 -0400
@@ -19,6 +19,9 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA 02110-1301 USA.
 
+import libvirt
+
+import _util
 
 """
 Default values for OS_TYPES keys. Can be overwritten at os_type or
@@ -64,6 +67,68 @@
 
     return retlist
 
+def parse_key_entry(conn, hv_type, key_entry):
+    d = _util.get_uri_driver(conn.getURI())
+    libver = libvirt.getVersion()
+    try:
+        drvver = libvirt.getVersion(d)[1]
+    except:
+        drvver = 0
+
+    if type(key_entry) == list:
+        # List of tuples with hv_type, version, etc. mappings
+        for tup in key_entry:
+            exp_hvs = tup[0]
+            if type(exp_hvs) != list:
+                exp_hvs = [exp_hvs]
+            exp_hv_ver = 0
+            exp_lib_ver = 0
+            val = tup[-1]
+
+            if len(tup) > 2:
+                exp_hv_ver = tup[1]
+            if len(tup) > 3:
+                exp_lib_ver = tup[2]
+
+            if hv_type not in exp_hvs and "all" not in exp_hvs:
+                continue
+
+            if exp_hv_ver and drvver > exp_hv_ver:
+                continue
+
+            if exp_lib_ver and libver > exp_lib_ver:
+                continue
+
+            return val
+    else:
+        return key_entry
+
+def lookup_osdict_key(conn, hv_type, os_type, var, key):
+
+    dictval = DEFAULTS[key]
+    if os_type:
+        if var and OS_TYPES[os_type]["variants"][var].has_key(key):
+            dictval = OS_TYPES[os_type]["variants"][var][key]
+        elif OS_TYPES[os_type].has_key(key):
+            dictval = OS_TYPES[os_type][key]
+
+    return parse_key_entry(conn, hv_type, dictval)
+
+
+def lookup_device_param(conn, hv_type, os_type, var, device_key, param):
+
+    os_devs = lookup_osdict_key(conn, hv_type, os_type, var, "devices")
+    default_devs = DEFAULTS["devices"]
+
+    for devs in [os_devs, default_devs]:
+        if not devs.has_key(device_key):
+            continue
+
+        return parse_key_entry(conn, hv_type, devs[device_key][param])
+
+    raise RuntimeError(_("Invalid dictionary entry for device '%s %s'" %
+                       (device_key, param)))
+
 # NOTE: keep variant keys using only lowercase so we can do case
 #       insensitive checks on user passed input
 OS_TYPES = {\
# HG changeset patch
# User Cole Robinson <crobinso@redhat.com>
# Date 1247588030 14400
# Node ID 3c68ba7758a6190f28ec32ab20a3ce96f7802542
# Parent  8b5d60a01fe3f4300683b105c8cd3bffd62649bf
Turn on ACPI/APIC for windows, except for Xen < 3.1.0.

See discussion at:

https://www.redhat.com/archives/et-mgmt-tools/2009-July/msg00000.html

diff -r 8b5d60a01fe3 -r 3c68ba7758a6 virtinst/osdict.py
--- a/virtinst/osdict.py	Tue Jul 14 12:06:22 2009 -0400
+++ b/virtinst/osdict.py	Tue Jul 14 12:13:50 2009 -0400
@@ -225,10 +225,16 @@
     },
     "variants": { \
         "winxp":{ "label": "Microsoft Windows XP (x86)",
-                  "acpi": False, "apic": False },
+                  "acpi": [ ("xen", 3001000, False),
+                            ("all", True ), ],
+                  "apic": [ ("xen", 3001000, False),
+                            ("all", True ), ], },
         "winxp64":{ "label": "Microsoft Windows XP (x86_64)" },
         "win2k": { "label": "Microsoft Windows 2000",
-                   "acpi": False, "apic": False },
+                  "acpi": [ ("xen", 3001000, False),
+                            ("all", True ), ],
+                  "apic": [ ("xen", 3001000, False),
+                            ("all", True ), ], },
         "win2k3": { "label": "Microsoft Windows 2003" },
         "win2k8": { "label": "Microsoft Windows 2008" },
         "vista": { "label": "Microsoft Windows Vista" },