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 ...@@ -24,6 +24,7 @@ import textwrap
import StringIO import StringIO
import json import json
import re import re
import time
from image_creator import __version__ as version from image_creator import __version__ as version
from image_creator.util import MD5, FatalError from image_creator.util import MD5, FatalError
...@@ -640,7 +641,7 @@ def exclude_tasks(session): ...@@ -640,7 +641,7 @@ def exclude_tasks(session):
return True return True
def update_sysprep_param(session, name): def update_sysprep_param(session, name, title=None):
"""Modify the value of a sysprep parameter""" """Modify the value of a sysprep parameter"""
d = session['dialog'] d = session['dialog']
image = session['image'] image = session['image']
...@@ -649,18 +650,20 @@ def update_sysprep_param(session, name): ...@@ -649,18 +650,20 @@ def update_sysprep_param(session, name):
while 1: while 1:
if param.type in ("file", "dir"): if param.type in ("file", "dir"):
if not title:
title = "Please select a %s to use for the `%s' parameter" % \ 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' ftype = "br" if param.type == 'file' else 'd'
value = select_file(d, ftype=ftype, title=title) value = select_file(d, ftype=ftype, title=title)
if value is None: if value is None:
return False return False
else: else:
if not title:
title = "Please provide a new value for configuration " \
"parameter: `%s'" % name
(code, answer) = d.inputbox( (code, answer) = d.inputbox(
"Please provide a new value for configuration parameter: `%s'" title, width=WIDTH, init=str(param.value))
% name, width=WIDTH, init=str(param.value))
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
return False return False
...@@ -674,6 +677,8 @@ def update_sysprep_param(session, name): ...@@ -674,6 +677,8 @@ def update_sysprep_param(session, name):
continue continue
break break
return True
def sysprep_params(session): def sysprep_params(session):
"""Collect the needed sysprep parameters""" """Collect the needed sysprep parameters"""
...@@ -718,6 +723,114 @@ def sysprep_params(session): ...@@ -718,6 +723,114 @@ def sysprep_params(session):
return True 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) = d.menu(
"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 ""
try:
date = time.strptime(
date, "%m/%d/%y").strftime('%d/%m/%Y', date)
except ValueError:
pass
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):
continue
install_virtio_drivers(session)
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)
try:
image.out.add(infobox)
try:
image.os.install_virtio_drivers()
infobox.finalize()
except FatalError as e:
d.msgbox("VirtIO Drivers Installation failed: %s" % e, title=title,
width=SMALL_WIDTH)
return False
finally:
image.out.remove(infobox)
finally:
infobox.cleanup()
return True
def sysprep(session): def sysprep(session):
"""Perform various system preparation tasks on the image""" """Perform various system preparation tasks on the image"""
d = session['dialog'] d = session['dialog']
...@@ -760,13 +873,18 @@ def sysprep(session): ...@@ -760,13 +873,18 @@ def sysprep(session):
(code, tags) = d.checklist( (code, tags) = d.checklist(
"Please choose which system preparation tasks you would like to " "Please choose which system preparation tasks you would like to "
"run on the image. Press <Help> to see details about the system " "run on the image. Press <Params> to view or modify the "
"preparation tasks.", title="Run system preparation tasks", "customization parameters or <Help> to see details about the "
choices=choices, width=70, ok_label="Run", help_button=1) "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 tags = map(lambda x: x.strip('"'), tags) # Needed for OpenSUSE
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
return False return False
elif code == d.DIALOG_EXTRA:
sysprep_params(session)
elif code == d.DIALOG_HELP: elif code == d.DIALOG_HELP:
d.scrollbox(sysprep_help, width=WIDTH) d.scrollbox(sysprep_help, width=WIDTH)
elif code == d.DIALOG_OK: elif code == d.DIALOG_OK:
...@@ -847,16 +965,20 @@ def shrink(session): ...@@ -847,16 +965,20 @@ def shrink(session):
def customization_menu(session): def customization_menu(session):
"""Show image customization menu""" """Show image customization menu"""
d = session['dialog'] d = session['dialog']
image = session['image']
choices = [("Parameters", "View & Modify customization parameters"), choices = []
("Sysprep", "Run various image preparation tasks"), if hasattr(image.os, "install_virtio_drivers"):
("Shrink", "Shrink image"), choices.append(("Virtio", "Install or update the VirtIO drivers"))
("Properties", "View & Modify image properties"), choices.extend(
("Exclude", "Exclude various deployment tasks from running")] [("Sysprep", "Run various image preparation tasks"),
("Shrink", "Shrink image"),
("Properties", "View & Modify image properties"),
("Exclude", "Exclude various deployment tasks from running")])
default_item = 0 default_item = 0
actions = {"Parameters": sysprep_params, actions = {"Virtio": virtio,
"Sysprep": sysprep, "Sysprep": sysprep,
"Shrink": shrink, "Shrink": shrink,
"Properties": modify_properties, "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