def display_installed_drivers(): """Returns the installed VirtIO drivers""" image = session['image'] versions = virtio_versions(image.os.virtio_state) ret = "Installed Block Device Driver: %(netkvm)s\n" \ "Installed Network Device Driver: %(viostor)s\n" % versions virtio = image.os.sysprep_params['virtio'].value if virtio: ret += "\nBlock Device Driver to be installed: %(netkvm)s\n" \ "Network Device Driver to be installed: %(viostor)s\n" % \ virtio_versions(image.os.compute_virtio_state(virtio)) return ret
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') 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") != d.OK: return False title = "VirtIO Drivers Installation" infobox = InfoBoxOutput(d, title) try: image.out.append(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 install_virtio_drivers(session): """Installs new VirtIO drivers in the image""" d = session['dialog'] image = session['image'] assert hasattr(image.os, 'install_virtio_drivers') 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") != d.OK: return False title = "VirtIO Drivers Installation" infobox = InfoBoxOutput(d, title) try: image.out.append(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 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, details in virtio_versions(image.os.virtio_state).items(): 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 <Info> to see more information " "about a specific installed driver or <Update> to install one or " "more new drivers.", height=16, width=WIDTH, choices=choices, ok_label="Info", menu_height=len(choices), cancel="Back", title="VirtIO Drivers", extra_button=1, extra_label="Update", default_item=default_item) if code in (d.CANCEL, d.ESC): return True elif code == d.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 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, details in virtio_versions(image.os.virtio_state).items(): 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 <Info> to see more information " "about a specific installed driver or <Update> to install one or " "more new drivers.", height=16, width=WIDTH, choices=choices, ok_label="Info", menu_height=len(choices), cancel="Back", title="VirtIO Drivers", extra_button=1, extra_label="Update", default_item=default_item) if code in (d.CANCEL, d.ESC): return True elif code == d.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