Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def sysprep(session):
    """Perform various system preparation tasks on the image"""
    d = session['dialog']
    image = session['image']

    # Is the image already shrinked?
    if image.os.shrinked:
        msg = "It seems you have shrinked the image. Running system " \
              "preparation tasks on a shrinked image is dangerous."

        if d.yesno("%s\n\nDo you really want to continue?" % msg,
                   width=SMALL_WIDTH, defaultno=1) != d.OK:
            return

    wrapper = textwrap.TextWrapper(width=WIDTH-5)

    syspreps = image.os.list_syspreps()

    if len(syspreps) == 0:
        d.msgbox("No system preparation task available to run!",
                 title="System Preparation", width=SMALL_WIDTH)
        return

    while 1:
        choices = []
        index = 0

        help_title = "System Preparation Tasks"
        sysprep_help = "%s\n%s\n\n" % (help_title, '=' * len(help_title))

        for task in syspreps:
            name, descr, display = image.os.sysprep_info(task)
            sysprep_help += "%s\n" % display
            sysprep_help += "%s\n" % ('-' * len(display))
            sysprep_help += "%s\n\n" % wrapper.fill(" ".join(descr.split()))
            enabled = 1 if image.os.sysprep_enabled(task) else 0
            choices.append((str(index + 1), display, enabled))
            index += 1

        (code, tags) = d.checklist(
            "Please choose which system preparation tasks you would like to "
            "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 = [x.strip('"') for x in tags]  # Needed for OpenSUSE

        if code in (d.CANCEL, d.ESC):
            return False
        elif code == d.EXTRA:
            sysprep_params(session)
        elif code == d.HELP:
            d.scrollbox(sysprep_help, width=WIDTH)
        elif code == d.OK:
            # Enable selected syspreps and disable the rest
            for i in range(len(syspreps)):
                if str(i + 1) in tags:
                    image.os.enable_sysprep(syspreps[i])
                else:
                    image.os.disable_sysprep(syspreps[i])

            if len([s for s in image.os.list_syspreps()
                    if image.os.sysprep_enabled(s)]) == 0:
                d.msgbox("No system preparation task is selected!",
                         title="System Preparation", width=SMALL_WIDTH)
                continue

            infobox = InfoBoxOutput(d, "Image Configuration")
            try:
                image.out.append(infobox)
                try:
                    # The checksum is invalid. We have mounted the image rw
                    if 'checksum' in session:
                        del session['checksum']

                    # Monitor the metadata changes during syspreps
                    with MetadataMonitor(session, image.os.meta):
                        try:
                            image.os.do_sysprep()
                            update_background_title(session)
                            infobox.finalize()
                        except FatalError as error:
                            d.msgbox("System Preparation failed: %s" % error,
                                     title="System Preparation",
                                     width=SMALL_WIDTH)
                finally:
                    image.out.remove(infobox)
            finally:
                infobox.cleanup()
            break
    return True
Exemplo n.º 4
0
def sysprep(session):
    """Perform various system preparation tasks on the image"""
    d = session['dialog']
    image = session['image']

    # Is the image already shrinked?
    if image.os.shrinked:
        msg = "It seems you have shrinked the image. Running system " \
              "preparation tasks on a shrinked image is dangerous."

        if d.yesno("%s\n\nDo you really want to continue?" % msg,
                   width=SMALL_WIDTH,
                   defaultno=1) != d.OK:
            return

    wrapper = textwrap.TextWrapper(width=WIDTH - 5)

    syspreps = image.os.list_syspreps()

    if len(syspreps) == 0:
        d.msgbox("No system preparation task available to run!",
                 title="System Preparation",
                 width=SMALL_WIDTH)
        return

    while 1:
        choices = []
        index = 0

        help_title = "System Preparation Tasks"
        sysprep_help = "%s\n%s\n\n" % (help_title, '=' * len(help_title))

        for task in syspreps:
            _, descr, display = image.os.sysprep_info(task)
            sysprep_help += "%s\n" % display
            sysprep_help += "%s\n" % ('-' * len(display))
            sysprep_help += "%s\n\n" % wrapper.fill(" ".join(descr.split()))
            enabled = 1 if image.os.sysprep_enabled(task) else 0
            choices.append((str(index + 1), display, enabled))
            index += 1

        (code, tags) = d.checklist(
            "Please choose which system preparation tasks you would like to "
            "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 = [x.strip('"') for x in tags]  # Needed for OpenSUSE

        if code in (d.CANCEL, d.ESC):
            return False
        elif code == d.EXTRA:
            sysprep_params(session)
        elif code == d.HELP:
            d.scrollbox(sysprep_help, width=WIDTH)
        elif code == d.OK:
            # Enable selected syspreps and disable the rest
            for i, _ in enumerate(syspreps):
                if str(i + 1) in tags:
                    image.os.enable_sysprep(syspreps[i])
                else:
                    image.os.disable_sysprep(syspreps[i])

            if len([
                    s for s in image.os.list_syspreps()
                    if image.os.sysprep_enabled(s)
            ]) == 0:
                d.msgbox("No system preparation task is selected!",
                         title="System Preparation",
                         width=SMALL_WIDTH)
                continue

            infobox = InfoBoxOutput(d, "Image Configuration")
            try:
                image.out.append(infobox)
                try:
                    # The checksum is invalid. We have mounted the image rw
                    if 'checksum' in session:
                        del session['checksum']

                    # Monitor the metadata changes during syspreps
                    with MetadataMonitor(session, image.os.meta):
                        try:
                            image.os.do_sysprep()
                            update_background_title(session)
                            infobox.finalize()
                        except FatalError as error:
                            d.msgbox("System Preparation failed: %s" % error,
                                     title="System Preparation",
                                     width=SMALL_WIDTH)
                finally:
                    image.out.remove(infobox)
            finally:
                infobox.cleanup()
            break
    return True