[virt-tools-list] [PATCH virt-manager 2/2] virt-manager: use libosinfo media detection

Giuseppe Scrivano gscrivan at redhat.com
Tue Mar 25 13:45:55 UTC 2014


Enhance the media detection with the data provided by libosinfo, now
the installation media detection is enabled for CD/ISO images too.

Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
---
 virtManager/create.py | 55 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 39 insertions(+), 16 deletions(-)

diff --git a/virtManager/create.py b/virtManager/create.py
index a368eff..1b97187 100644
--- a/virtManager/create.py
+++ b/virtManager/create.py
@@ -132,7 +132,7 @@ class vmmCreate(vmmGObjectUI):
             "on_install_url_box_changed": self.url_box_changed,
             "on_install_local_cdrom_toggled": self.toggle_local_cdrom,
             "on_install_local_cdrom_combo_changed": self.detect_media_os,
-            "on_install_local_box_changed": self.detect_media_os,
+            "on_install_local_box_changed": self.local_box_changed,
             "on_install_local_browse_clicked": self.browse_iso,
             "on_install_import_browse_clicked": self.browse_import,
             "on_install_app_browse_clicked": self.browse_app,
@@ -551,6 +551,11 @@ class vmmCreate(vmmGObjectUI):
 
         self.mediacombo = vmmMediaCombo(self.conn, self.builder, self.topwin,
                                         MEDIA_CDROM)
+        def mediacombo_changed(src):
+            ignore = src
+            self.mediaDetected = False
+            self.detect_media_os(only_local=True)
+        self.mediacombo.combo.connect("changed", mediacombo_changed)
         self.mediacombo.reset_state()
         self.widget("install-local-cdrom-align").add(
             self.mediacombo.top_box)
@@ -1117,25 +1122,31 @@ class vmmCreate(vmmGObjectUI):
 
         self.change_caps(self.capsguest.os_type, arch)
 
-    def url_box_changed(self, ignore):
+    def media_box_changed(self, widget, only_local):
         self.mediaDetected = False
 
-        # If the url_entry has focus, don't fire detect_media_os, it means
+        # If the widget has focus, don't fire detect_media_os, it means
         # the user is probably typing
-        if self.widget("install-url-box").get_child().has_focus():
+        if self.widget(widget).get_child().has_focus():
             return
 
-        self.detect_media_os()
+        self.detect_media_os(only_local=only_local)
+
+    def url_box_changed(self, ignore):
+        self.media_box_changed("install-url-box", False)
+
+    def local_box_changed(self, ignore):
+        self.media_box_changed("install-local-box", True)
 
     def should_detect_media(self):
         return (self.is_detect_active() and not self.mediaDetected)
 
-    def detect_media_os(self, ignore1=None, forward=False):
+    def detect_media_os(self, ignore1=None, forward=False, only_local=False):
         if not self.should_detect_media():
             return
         if not self.is_install_page():
             return
-        self.start_detection(forward=forward)
+        self.start_detection(forward=forward, only_local=only_local)
 
     def toggle_detect_os(self, src):
         dodetect = src.get_active()
@@ -1190,7 +1201,8 @@ class vmmCreate(vmmGObjectUI):
         is_active = src.get_active()
         if is_active and self.mediacombo.get_path():
             # Local CDROM was selected with media preset, detect distro
-            self.detect_media_os()
+            self.mediaDetected = False
+            self.detect_media_os(only_local=True)
 
         self.widget("install-local-cdrom-align").set_sensitive(is_active)
 
@@ -1198,6 +1210,8 @@ class vmmCreate(vmmGObjectUI):
         uselocal = src.get_active()
         self.widget("install-local-box").set_sensitive(uselocal)
         self.widget("install-local-browse").set_sensitive(uselocal)
+        self.mediaDetected = False
+        self.detect_media_os(only_local=True)
 
     def detect_visibility_changed(self, src, ignore=None):
         is_visible = src.get_visible()
@@ -1249,11 +1263,7 @@ class vmmCreate(vmmGObjectUI):
                                    INSTALL_PAGE_CONTAINER_OS]
         osbox.set_visible(iscontainer)
 
-        # Detection only works/ is valid for URL,
-        # FIXME: Also works for CDROM if running as root (since we need to
-        # mount the iso/cdrom), but we should probably make this work for
-        # more distros (like windows) before we enable it
-        if (instpage == INSTALL_PAGE_URL):
+        if instpage in (INSTALL_PAGE_ISO, INSTALL_PAGE_URL):
             detectbox.show()
         else:
             detectbox.hide()
@@ -1968,7 +1978,7 @@ class vmmCreate(vmmGObjectUI):
         if forward:
             self.idle_add(self.forward, ())
 
-    def start_detection(self, forward):
+    def start_detection(self, forward, only_local):
         if self.detectedDistro == DETECT_INPROGRESS:
             return
 
@@ -1983,13 +1993,26 @@ class vmmCreate(vmmGObjectUI):
 
         detectThread = threading.Thread(target=self.actually_detect,
                                         name="Actual media detection",
-                                        args=(media,))
+                                        args=(media, only_local,))
         detectThread.setDaemon(True)
         detectThread.start()
 
         self.check_detection(0, forward)
 
-    def actually_detect(self, media):
+    def actually_detect(self, media, only_local):
+        # First try with libosinfo detection
+        try:
+            os = virtinst.osdict.lookup_os_by_media(media)
+            if os:
+                self.detectedDistro = os
+                return
+        except:
+            pass
+
+        if only_local:
+            self.detectedDistro = DETECT_FAILED
+            return
+
         try:
             installer = virtinst.DistroInstaller(self.conn.get_backend())
             installer.location = media
-- 
1.8.5.3




More information about the virt-tools-list mailing list