[virt-tools-list] [python-virtinst 2/2] virt-install: Create OS dict from libosinfo

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Fri Jul 1 20:32:41 UTC 2011


From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>

Issues:

* Some info is still hard-coded

* We lose the following information:
  * distro
  * sortby

* I get the following error from pylint:

  E: 25: No name 'Libosinfo' in module 'gi.repository'

  Apparently pylint doesn't know about how introspection works.

* libosinfo is not yet in a stage that we can add a dependency on
  it so this patch must not be merged into git master yet.
---
 virtinst/osdict.py |  401 +++++++++++++---------------------------------------
 1 files changed, 100 insertions(+), 301 deletions(-)

diff --git a/virtinst/osdict.py b/virtinst/osdict.py
index a520faa..040bd24 100644
--- a/virtinst/osdict.py
+++ b/virtinst/osdict.py
@@ -22,6 +22,7 @@
 import support
 from VirtualDevice import VirtualDevice
 from virtinst import _virtinst as _
+from gi.repository import Libosinfo as libosinfo
 
 HV_ALL = "all"
 
@@ -36,31 +37,42 @@ INPUT = VirtualDevice.VIRTUAL_DEV_INPUT
 SOUND = VirtualDevice.VIRTUAL_DEV_AUDIO
 VIDEO = VirtualDevice.VIRTUAL_DEV_VIDEO
 
-VIRTIO_DISK = {
-    "bus" : [
-        (support.SUPPORT_CONN_HV_VIRTIO, "virtio"),
-    ]
-}
-
-VIRTIO_NET = {
-    "model" : [
-        (support.SUPPORT_CONN_HV_VIRTIO, "virtio"),
-    ]
-}
-
-USB_TABLET = {
-    "type" : [
-        (HV_ALL, "tablet"),
-    ],
-    "bus"  : [
-        (HV_ALL, "usb"),
-    ]
-}
-
-VGA_VIDEO = {
-    "model_type": [
-        (HV_ALL, "vga"),
-    ]
+DEVICES = {
+    "http://pciids.sourceforge.net/v2.2/pci.ids/1af4/1001": {
+        "bus" : [
+            (support.SUPPORT_CONN_HV_VIRTIO, "virtio"),
+        ]
+    },
+    "http://pciids.sourceforge.net/v2.2/pci.ids/1af4/1000": {
+        "model" : [
+                (support.SUPPORT_CONN_HV_VIRTIO, "virtio"),
+        ]
+    },
+    "http://www.linux-usb.org/usb.ids/80ee/0021": {
+        "type" : [
+                (HV_ALL, "tablet"),
+        ],
+        "bus"  : [
+                (HV_ALL, "usb"),
+        ]
+    },
+    "http://pciids.sourceforge.net/v2.2/pci.ids/1234/1111": {
+        "model_type": [
+                (HV_ALL, "vga"),
+        ]
+    },
+    "http://pciids.sourceforge.net/v2.2/pci.ids/10ec/8029": {
+        "model" : [ (HV_ALL, "ne2k_pci")
+        ]
+    },
+    "http://pciids.sourceforge.net/v2.2/pci.ids/8086/100e": {
+        "model" : [ (HV_ALL, "e1000")
+        ]
+    },
+    "http://pciids.sourceforge.net/v2.2/pci.ids/1022/2000": {
+        "model" : [ (HV_ALL, "pcnet")
+        ]
+    }
 }
 
 DEFAULTS = {
@@ -222,285 +234,72 @@ def lookup_device_param(conn, hv_type, os_type, var, device_key, param):
     raise RuntimeError(_("Invalid dictionary entry for device '%s %s'" %
                        (device_key, param)))
 
+def get_devices_for_os(os):
+    devices = {}
+    for device in os.get_devices(None).get_elements():
+        device_id = device.get_id()
+        device_class = device.get_class()
 
-# NOTE: keep variant keys using only lowercase so we can do case
-#       insensitive checks on user passed input
-OS_TYPES = {
-"linux": {
-    "label": "Linux",
-    "variants": {
-        "rhel2.1": { "label": "Red Hat Enterprise Linux 2.1",
-                     "distro": "rhel" },
-        "rhel3": { "label": "Red Hat Enterprise Linux 3",
-                   "distro": "rhel" },
-        "rhel4": { "label": "Red Hat Enterprise Linux 4",
-                   "distro": "rhel" },
-        "rhel5": { "label": "Red Hat Enterprise Linux 5",
-                   "distro": "rhel" },
-        "rhel5.4": { "label": "Red Hat Enterprise Linux 5.4 or later",
-                     "distro": "rhel",
-                      "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                      }, },
-        "rhel6": { "label": "Red Hat Enterprise Linux 6", "distro": "rhel",
-                   "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                        INPUT: USB_TABLET,
-                   }},
-        "fedora5": { "sortby": "fedora05",
-                     "label": "Fedora Core 5", "distro": "fedora" },
-        "fedora6": { "sortby": "fedora06",
-                     "label": "Fedora Core 6", "distro": "fedora" },
-        "fedora7": { "sortby": "fedora07",
-                     "label": "Fedora 7", "distro": "fedora" },
-        "fedora8": { "sortby": "fedora08",
-                     "label": "Fedora 8", "distro": "fedora" },
-        "fedora9": { "sortby":  "fedora09",
-                     "label": "Fedora 9", "distro": "fedora",
-                      "devices" : {
-                        # Apparently F9 has selinux errors when installing
-                        # with virtio:
-                        # https://bugzilla.redhat.com/show_bug.cgi?id=470386
-                        #DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                      }},
-        "fedora10": { "label": "Fedora 10", "distro": "fedora",
-                      "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                      }},
-        "fedora11": { "label": "Fedora 11", "distro": "fedora",
-                      "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                        INPUT: USB_TABLET,
-                     }},
-        "fedora12": { "label": "Fedora 12", "distro": "fedora",
-                      "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                        INPUT: USB_TABLET,
-                     }},
-        "fedora13": { "label": "Fedora 13", "distro": "fedora",
-                      "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                        INPUT: USB_TABLET,
-                     }},
-        "fedora14": { "label": "Fedora 14", "distro": "fedora",
-                      "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                        INPUT: USB_TABLET,
-                     }},
-        "fedora15": { "label": "Fedora 15", "distro": "fedora",
-                      "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                        INPUT: USB_TABLET,
-                     }},
-
-        "sles10": { "label": "Suse Linux Enterprise Server",
-                    "distro": "suse" },
-        "sles11": { "label": "Suse Linux Enterprise Server 11",
-                    "distro": "suse",
-                      "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                      },
-                  },
-
-        "mandriva2009": { "label": "Mandriva Linux 2009 and earlier",
-                          "distro": "mandriva" },
-        "mandriva2010": { "label": "Mandriva Linux 2010 and later",
-                          "distro": "mandriva",
-                          "devices" : {
-                            DISK : VIRTIO_DISK,
-                            NET  : VIRTIO_NET,
-                        },
-                  },
-
-        "mes5": { "label": "Mandriva Enterprise Server 5.0",
-                    "distro": "mandriva" },
-        "mes5.1": { "label": "Mandriva Enterprise Server 5.1 and later",
-                    "distro": "mandriva",
-                    "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                    },
-                  },
-        "debianetch": { "label": "Debian Etch", "distro": "debian",
-                        "sortby": "debian4" },
-        "debianlenny": { "label": "Debian Lenny", "distro": "debian",
-                         "sortby": "debian5",
-                      "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                      }},
-        "debiansqueeze": { "label": "Debian Squeeze", "distro": "debian",
-                         "sortby": "debian6",
-                      "devices" : {
-                        DISK : VIRTIO_DISK,
-                        NET  : VIRTIO_NET,
-                        INPUT: USB_TABLET,
-                     }},
-        "ubuntuhardy": { "label": "Ubuntu 8.04 LTS (Hardy Heron)",
-                         "distro": "ubuntu",
-                         "devices" : {
-                            NET  : VIRTIO_NET,
-                         }},
-        "ubuntuintrepid": { "label": "Ubuntu 8.10 (Intrepid Ibex)",
-                            "distro": "ubuntu",
-                            "devices" : {
-                              NET  : VIRTIO_NET,
-                           }},
-        "ubuntujaunty": { "label": "Ubuntu 9.04 (Jaunty Jackalope)",
-                          "distro": "ubuntu",
-                          "devices" : {
-                            DISK : VIRTIO_DISK,
-                            NET  : VIRTIO_NET,
-                        }},
-        "ubuntukarmic": { "label": "Ubuntu 9.10 (Karmic Koala)",
-                          "distro": "ubuntu",
-                          "devices" : {
-                            DISK : VIRTIO_DISK,
-                            NET  : VIRTIO_NET,
-                        }},
-        "ubuntulucid": { "label": "Ubuntu 10.04 (Lucid Lynx)",
-                         "distro": "ubuntu",
-                         "devices" : {
-                            DISK : VIRTIO_DISK,
-                            NET  : VIRTIO_NET,
-                        }},
-        "ubuntumaverick": {
-            "label": "Ubuntu 10.10 (Maverick Meerkat)",
-            "distro": "ubuntu",
-            "devices" : {
-                DISK : VIRTIO_DISK,
-                NET  : VIRTIO_NET,
-            }},
-        "ubuntunatty": {
-            "label": "Ubuntu 11.04 (Natty Narwhal)",
-            "distro": "ubuntu",
-            "devices" : {
-                DISK : VIRTIO_DISK,
-                NET  : VIRTIO_NET,
-            }},
-        "ubuntuoneiric": {
-            "label": "Ubuntu 11.10 (Oneiric Ocelot)",
-            "distro": "ubuntu",
-            "devices" : {
-                DISK : VIRTIO_DISK,
-                NET  : VIRTIO_NET,
-            }},
-        "generic24": { "label": "Generic 2.4.x kernel" },
-        "generic26": { "label": "Generic 2.6.x kernel" },
-        "virtio26": { "sortby": "genericvirtio26",
-                      "label": "Generic 2.6.25 or later kernel with virtio",
-                      "devices" : {
-                            DISK : VIRTIO_DISK,
-                            NET  : VIRTIO_NET,
-                    }},
+        if device_id in DEVICES:
+            devices[device_class] = DEVICES[device_id]
 
-    },
-},
+    upgraded = os.get_related(libosinfo.ProductRelationship.UPGRADES)
+    derived = os.get_related(libosinfo.ProductRelationship.DERIVES_FROM)
+    cloned = os.get_related(libosinfo.ProductRelationship.CLONES)
+    related = libosinfo.ProductList.new_union(upgraded, derived)
+    related = libosinfo.ProductList.new_union(related, cloned)
 
-"windows": {
-    "label": "Windows",
-    "clock": "localtime",
-    "continue": True,
-    "devices" : {
-        INPUT : USB_TABLET,
-        VIDEO : VGA_VIDEO,
-    },
-    "variants": {
-        "winxp": { "label": "Microsoft Windows XP",
-                   "sortby": "mswin5", "distro" : "win",
-                  "acpi": [
-                    (support.SUPPORT_CONN_HV_SKIP_DEFAULT_ACPI, False),
-                  ],
-                  "apic": [
-                    (support.SUPPORT_CONN_HV_SKIP_DEFAULT_ACPI, False),
-                  ],
-        },
-        "winxp64": { "label": "Microsoft Windows XP (x86_64)",
-                     "sortby": "mswin564", "distro": "win"},
-        "win2k": { "label": "Microsoft Windows 2000",
-                     "sortby" : "mswin4", "distro": "win",
-                  "acpi": [
-                    (support.SUPPORT_CONN_HV_SKIP_DEFAULT_ACPI, False),
-                  ],
-                  "apic": [
-                    (support.SUPPORT_CONN_HV_SKIP_DEFAULT_ACPI, False),
-                  ],
-        },
-        "win2k3": { "label": "Microsoft Windows Server 2003",
-                     "sortby" : "mswinserv2003", "distro": "winserv"},
-        "win2k8": { "label": "Microsoft Windows Server 2008",
-                    "sortby": "mswinserv2008", "distro": "winserv" },
-        "vista": { "label": "Microsoft Windows Vista",
-                    "sortby": "mswin6", "distro": "win" },
-        "win7": { "label": "Microsoft Windows 7",
-                  "sortby": "mswin7", "distro": "win"}
-    },
-},
-
-"solaris": {
-    "label": "Solaris",
-    "clock": "localtime",
-    "pv_cdrom_install": True,
-    "variants": {
-        "solaris9": { "label": "Sun Solaris 9", },
-        "solaris10": { "label": "Sun Solaris 10",
-                       "devices" : {
-                            INPUT : USB_TABLET,
-                         },
-                       },
-        "opensolaris": { "label": "Sun OpenSolaris",
-                       "devices" : {
-                            INPUT : USB_TABLET,
-                         },
-                       },
-    },
-},
-
-"unix": {
-    "label": "UNIX",
-    "variants": {
-        "freebsd6": { "label": "FreeBSD 6.x" ,
-                      # http://www.nabble.com/Re%3A-Qemu%3A-bridging-on-FreeBSD-7.0-STABLE-p15919603.html
-                      "devices" : {
-                        NET : { "model" : [ (HV_ALL, "ne2k_pci") ] }
-                      }},
-        "freebsd7": { "label": "FreeBSD 7.x" ,
-                      "devices" : {
-                        NET : { "model" : [ (HV_ALL, "ne2k_pci") ] }
-                      }},
-        "freebsd8": { "label": "FreeBSD 8.x" ,
-                      "devices" : {
-                        NET : { "model" : [ (HV_ALL, "e1000") ] }
-                      }},
-        "openbsd4": { "label": "OpenBSD 4.x" ,
-                      # http://calamari.reverse-dns.net:980/cgi-bin/moin.cgi/OpenbsdOnQemu
-                      # https://www.redhat.com/archives/et-mgmt-tools/2008-June/msg00018.html
-                      "devices" : {
-                        NET  : { "model" : [ (HV_ALL, "pcnet") ] }
-                    }},
-    },
-},
-
-"other": {
-    "label": "Other",
-    "variants": {
-        "msdos": { "label": "MS-DOS", "acpi": False, "apic": False },
-        "netware4": { "label": "Novell Netware 4" },
-        "netware5": { "label": "Novell Netware 5" },
-        "netware6": { "label": "Novell Netware 6", "pv_cdrom_install": True, },
-        "generic": { "label": "Generic" },
-    },
-}}
+    for relative in related.get_elements():
+        devices.update(get_devices_for_os(relative))
+
+    return devices
+
+def os_to_variant(os):
+    variant = { "label": os.get_name() }
+
+    devices = get_devices_for_os(os)
+
+    if len(devices) != 0:
+        variant["devices"] = devices
+
+    return variant
+
+def create_os_types_dict():
+    loader = libosinfo.Loader()
+    loader.process_default_path()
+    db = loader.get_db()
+
+    families = db.unique_values_for_property_in_os("family")
+    families.sort()
+
+    os_types = {}
+
+    for family in families:
+        os_filter = libosinfo.Filter()
+        os_filter.add_constraint("family", family)
+
+        oses = db.get_os_list().new_filtered(os_filter).get_elements()
+        variants = {}
+        for os in oses:
+            variants[os.get_param_value("short-id")] = os_to_variant(os)
+
+        os_types[family.lower()] = { "label": family,
+                                     "variants": variants }
+
+    return os_types
+
+OS_TYPES = create_os_types_dict()
+
+OS_TYPES["windows"]["clock"] = "localtime"
+OS_TYPES["windows"]["continue"] = True
+OS_TYPES["windows"]["variants"]["winxp"]["acpi"] = \
+OS_TYPES["windows"]["variants"]["winxp"]["apic"] = \
+OS_TYPES["windows"]["variants"]["win2k"]["acpi"] = \
+OS_TYPES["windows"]["variants"]["win2k"]["apic"] = \
+        [(support.SUPPORT_CONN_HV_SKIP_DEFAULT_ACPI, False)]
+
+OS_TYPES["solaris"]["clock"] = "localtime"
+OS_TYPES["solaris"]["pv_cdrom_install"] = True
 
 # Back compatibility entries
 solaris_compat = OS_TYPES["unix"]["variants"]
-- 
1.7.5.4




More information about the virt-tools-list mailing list