Commit 17cf1338 authored by Nikos Skalkotos's avatar Nikos Skalkotos

windows: Add a VirtIO install entry in dialog menu

Merge the Parameter menu entry with Sysprep and add a new entry for
installing VirtIO drivers. This will only be visible in Windows.
parent 9df74818
......@@ -24,6 +24,7 @@ import textwrap
import StringIO
import json
import re
import time
from image_creator import __version__ as version
from image_creator.util import MD5, FatalError
......@@ -640,7 +641,7 @@ def exclude_tasks(session):
return True
def update_sysprep_param(session, name):
def update_sysprep_param(session, name, title=None):
"""Modify the value of a sysprep parameter"""
d = session['dialog']
image = session['image']
......@@ -649,18 +650,20 @@ def update_sysprep_param(session, name):
while 1:
if param.type in ("file", "dir"):
if not title:
title = "Please select a %s to use for the `%s' parameter" % \
(name, 'file' if param.type == 'file' else 'directory')
('file' if param.type == 'file' else 'directory', name)
ftype = "br" if param.type == 'file' else 'd'
value = select_file(d, ftype=ftype, title=title)
if value is None:
return False
if not title:
title = "Please provide a new value for configuration " \
"parameter: `%s'" % name
(code, answer) = d.inputbox(
"Please provide a new value for configuration parameter: `%s'"
% name, width=WIDTH, init=str(param.value))
title, width=WIDTH, init=str(param.value))
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
return False
......@@ -674,6 +677,8 @@ def update_sysprep_param(session, name):
return True
def sysprep_params(session):
"""Collect the needed sysprep parameters"""
......@@ -718,6 +723,114 @@ def sysprep_params(session):
return True
def virtio(session):
"""Display the state of the VirtIO drivers in the media"""
d = session['dialog']
image = session['image']
assert hasattr(image.os, 'virtio_state')
assert hasattr(image.os, 'install_virtio_drivers')
default_item = image.os.virtio_state.keys()[0]
while 1:
choices = []
for name, infs in image.os.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]
details = "<not installed>" if len(infs) == 0 else ", ".join(vers)
choices.append((name, details))
(code, choice) =
"In this menu you can see details about the installed VirtIO "
"drivers on the input media. Press <OK> to see more information "
"about a specific installed driver or <Update> to install one or "
"more new drivers.", height=16, width=WIDTH, choices=choices,
menu_height=len(choices), cancel="Back", title="VirtIO Drivers",
extra_button=1, extra_label="Update", default_item=default_item)
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
return True
elif code == d.DIALOG_OK:
default_item = choice
# Create a string with the driver details and display it.
details = ""
for fname, driver in image.os.virtio_state[choice].items():
details += "%s\n%s\n" % (fname, "=" * len(fname))
name = ""
if 'DriverPackageDisplayName' in driver:
name = driver['DriverPackageDisplayName']
provider = ""
if 'Provider' in driver:
provider = driver['Provider']
date = ""
version = ""
if 'DriverVer' in driver:
version = driver['DriverVer'].split(',', 1)
date = version[0].strip()
version = version[1] if len(version) > 1 else ""
date = time.strptime(
date, "%m/%d/%y").strftime('%d/%m/%Y', date)
except ValueError:
dtype = ""
if 'DriverPackageType' in driver:
dtype = driver['DriverPackageType']
dclass = ""
if 'Class' in driver:
dclass = driver['Class']
details += "Name: %s\n" % name.strip('\'"')
details += "Provider: %s\n" % provider.strip('\'"')
details += "Date: %s\n" % date
details += "Version: %s\n" % version
details += "Type: %s\n" % dtype
details += "Class: %s\n\n" % dclass
if len(details):
d.scrollbox(details, width=WIDTH)
else: # Update button
title = "Please select a directory that hosts VirtIO drivers."
if not update_sysprep_param(session, "virtio", title=title):
return True
def install_virtio_drivers(session):
"""Installs new VirtIO drivers in the image"""
d = session['dialog']
image = session['image']
assert hasattr(image.os, 'install_virtio_drivers')
if d.yesno("Continue with the installation of the VirtIO drivers?",
width=SMALL_WIDTH, defaultno=1):
return False
title = "VirtIO Drivers Installation"
infobox = InfoBoxOutput(d, title)
except FatalError as e:
d.msgbox("VirtIO Drivers Installation failed: %s" % e, title=title,
return False
return True
def sysprep(session):
"""Perform various system preparation tasks on the image"""
d = session['dialog']
......@@ -760,13 +873,18 @@ def sysprep(session):
(code, tags) = d.checklist(
"Please choose which system preparation tasks you would like to "
"run on the image. Press <Help> to see details about the system "
"preparation tasks.", title="Run system preparation tasks",
choices=choices, width=70, ok_label="Run", help_button=1)
"run on the image. Press <Params> to view or modify the "
"customization parameters or <Help> to see details about the "
"system preparation tasks.", title="Run system preparation tasks",
choices=choices, width=70, ok_label="Run", help_button=1,
extra_button=1, extra_label="Params")
tags = map(lambda x: x.strip('"'), tags) # Needed for OpenSUSE
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
return False
elif code == d.DIALOG_EXTRA:
elif code == d.DIALOG_HELP:
d.scrollbox(sysprep_help, width=WIDTH)
elif code == d.DIALOG_OK:
......@@ -847,16 +965,20 @@ def shrink(session):
def customization_menu(session):
"""Show image customization menu"""
d = session['dialog']
image = session['image']
choices = [("Parameters", "View & Modify customization parameters"),
("Sysprep", "Run various image preparation tasks"),
choices = []
if hasattr(image.os, "install_virtio_drivers"):
choices.append(("Virtio", "Install or update the VirtIO drivers"))
[("Sysprep", "Run various image preparation tasks"),
("Shrink", "Shrink image"),
("Properties", "View & Modify image properties"),
("Exclude", "Exclude various deployment tasks from running")]
("Exclude", "Exclude various deployment tasks from running")])
default_item = 0
actions = {"Parameters": sysprep_params,
actions = {"Virtio": virtio,
"Sysprep": sysprep,
"Shrink": shrink,
"Properties": modify_properties,
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment