From 8fb10dd2a60004f975ddb7a8b45caea8dfdfddf6 Mon Sep 17 00:00:00 2001
From: Nikos Skalkotos <skalkoto@grnet.gr>
Date: Thu, 7 Aug 2014 17:40:53 +0300
Subject: [PATCH] Display the discovered VirtIO drvs in expert mode

When the user picks a directory that contains VirtIO drivers, show him
the version of the discovered drivers in the confirmation box.
---
 image_creator/dialog_menu.py   | 18 ++++++++++++++----
 image_creator/dialog_util.py   | 13 -------------
 image_creator/dialog_wizard.py |  4 ++--
 image_creator/util.py          | 13 +++++++++++++
 4 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/image_creator/dialog_menu.py b/image_creator/dialog_menu.py
index c4438b2..847fb0a 100644
--- a/image_creator/dialog_menu.py
+++ b/image_creator/dialog_menu.py
@@ -27,13 +27,13 @@ import re
 import time
 
 from image_creator import __version__ as version
-from image_creator.util import MD5, FatalError
+from image_creator.util import MD5, FatalError, virtio_versions
 from image_creator.output.dialog import GaugeOutput, InfoBoxOutput
 from image_creator.kamaki_wrapper import Kamaki, ClientError
 from image_creator.help import get_help_file
 from image_creator.dialog_util import SMALL_WIDTH, WIDTH, \
     update_background_title, confirm_reset, confirm_exit, Reset, \
-    extract_image, add_cloud, edit_cloud, virtio_versions, update_sysprep_param
+    extract_image, add_cloud, edit_cloud, update_sysprep_param
 
 CONFIGURATION_TASKS = [
     ("Partition table manipulation", ["FixPartitionTable"],
@@ -768,8 +768,18 @@ def install_virtio_drivers(session):
 
     assert hasattr(image.os, 'install_virtio_drivers')
 
-    if d.yesno("Continue with the installation of the VirtIO drivers?",
-               width=SMALL_WIDTH, defaultno=1):
+    virtio = image.os.sysprep_params['virtio'].value
+    new_drivers = virtio_versions(image.os.compute_virtio_state(virtio))
+
+    msg = \
+        "The following VirtIO drivers were discovered in the directory you "\
+        "specified:\n\n"
+    for drv, drv_ver in new_drivers.items():
+        msg += "%s: %s\n" % (drv, drv_ver)
+    msg += "\nPress <Install> to continue with the installation of the " \
+        "aforementioned drivers or <Cancel> to return to the previous menu."
+    if d.yesno(msg, width=WIDTH, defaultno=1, height=11+len(new_drivers),
+               yes_label="Install", no_label="Cancel"):
         return False
 
     title = "VirtIO Drivers Installation"
diff --git a/image_creator/dialog_util.py b/image_creator/dialog_util.py
index 360f630..2b64b91 100644
--- a/image_creator/dialog_util.py
+++ b/image_creator/dialog_util.py
@@ -336,19 +336,6 @@ def edit_cloud(session, name):
     return True
 
 
-def virtio_versions(virtio_state):
-    """Returns the versions of the drivers defined by the virtio state"""
-
-    ret = {}
-    for name, infs in virtio_state.items():
-        driver_ver = [drv['DriverVer'].split(',', 1) if 'DriverVer' in drv
-                      else [] for drv in infs.values()]
-        vers = [v[1] if len(v) > 1 else " " for v in driver_ver]
-        ret[name] = "<not found>" if len(infs) == 0 else ", ".join(vers)
-
-    return ret
-
-
 def update_sysprep_param(session, name, title=None):
     """Modify the value of a sysprep parameter"""
     d = session['dialog']
diff --git a/image_creator/dialog_wizard.py b/image_creator/dialog_wizard.py
index 1adb75c..7ce24cb 100644
--- a/image_creator/dialog_wizard.py
+++ b/image_creator/dialog_wizard.py
@@ -25,10 +25,10 @@ import json
 import re
 
 from image_creator.kamaki_wrapper import Kamaki, ClientError
-from image_creator.util import MD5, FatalError
+from image_creator.util import MD5, FatalError, virtio_versions
 from image_creator.output.cli import OutputWthProgress
 from image_creator.dialog_util import extract_image, update_background_title, \
-    add_cloud, edit_cloud, virtio_versions, update_sysprep_param
+    add_cloud, edit_cloud, update_sysprep_param
 
 PAGE_WIDTH = 70
 PAGE_HEIGHT = 12
diff --git a/image_creator/util.py b/image_creator/util.py
index c34d41d..d5370ff 100644
--- a/image_creator/util.py
+++ b/image_creator/util.py
@@ -118,4 +118,17 @@ class MD5:
 
         return checksum
 
+
+def virtio_versions(virtio_state):
+    """Returns the versions of the drivers defined by the virtio state"""
+
+    ret = {}
+    for name, infs in virtio_state.items():
+        driver_ver = [drv['DriverVer'].split(',', 1) if 'DriverVer' in drv
+                      else [] for drv in infs.values()]
+        vers = [v[1] if len(v) > 1 else " " for v in driver_ver]
+        ret[name] = "<not found>" if len(infs) == 0 else ", ".join(vers)
+
+    return ret
+
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
-- 
GitLab