Exemple #1
0
def get_keymap():
    entries = generalui.getKeymaps()

    (button, entry) = snackutil.ListboxChoiceWindowEx(
        tui.screen,
        "Select Keymap",
        "Please select the keymap you would like to use:",
        entries, ['Ok'],
        height=8,
        scroll=1,
        help="keymap",
        timeout_ms=500)

    return entry
Exemple #2
0
def get_local_disk(answers):
    diskEntries = diskutil.getQualifiedDiskList()

    entries = []
    target_is_sr = {}

    for de in diskEntries:
        (vendor, model, size) = diskutil.getExtendedDiskInfo(de)
        # determine current usage
        target_is_sr[de] = False
        (boot, root, state, storage, logs) = diskutil.probeDisk(de)
        if storage[0]:
            target_is_sr[de] = True
        (vendor, model, size) = diskutil.getExtendedDiskInfo(de)
        stringEntry = "%s - %s [%s %s]" % (diskutil.getHumanDiskName(de),
                                           diskutil.getHumanDiskSize(size),
                                           vendor, model)
        e = (stringEntry, de)
        entries.append(e)

    # default value:
    default = None
    if 'dest-disk' in answers:
        default = selectDefault(answers['dest-disk'], entries)

    tui.update_help_line([None, "<F5> more info"])

    scroll, height = snackutil.scrollHeight(4, len(entries))
    (button, entry) = snackutil.ListboxChoiceWindowEx(
        tui.screen,
        "Select Device",
        "Please select the device to store the report on.",
        entries, ['Ok', 'Back'],
        55,
        scroll,
        height,
        default,
        help='getlocaldisk:info',
        hotkeys={'F5': disk_more_info})

    tui.screen.popHelpLine()

    if button == 'back': return uicontroller.LEFT_BACKWARDS

    # entry contains the 'de' part of the tuple passed in
    answers['dest-disk'] = entry

    return uicontroller.RIGHT_FORWARDS
Exemple #3
0
def get_local_dest(answers):
    partitions = diskutil.partitionsOnDisk(answers['dest-disk'])

    if len(partitions) == 0:
        answers['dest-address'] = answers['dest-disk']
    elif len(partitions) == 1:
        answers['dest-address'] = '/dev/' + partitions[0]
    else:
        entries = []

        for part in partitions:
            e = (part, '/dev/' + part)
            entries.append(e)

        # default value:
        default = None
        if 'dest-address' in answers:
            default = selectDefault(answers['dest-address'], entries)

        tui.update_help_line([None, "<F5> more info"])

        scroll, height = snackutil.scrollHeight(4, len(entries))
        (button, entry) = snackutil.ListboxChoiceWindowEx(
            tui.screen,
            "Select Device",
            "Please select the partition to store the report on.",
            entries, ['Ok', 'Back'],
            55,
            scroll,
            height,
            default,
            help='getlocaldest:info',
            hotkeys={'F5': disk_more_info})

        tui.screen.popHelpLine()

        if button == 'back': return uicontroller.LEFT_BACKWARDS

        # entry contains the 'de' part of the tuple passed in
        answers['dest-address'] = entry

    return uicontroller.RIGHT_FORWARDS
Exemple #4
0
def select_primary_disk(answers):
    button = None
    diskEntries = filter_out_raid_member(sorted_disk_list())
    entries = []
    target_is_sr = {}

    if answers['create-new-partitions']:
        min_primary_disk_size = constants.min_primary_disk_size
    else:
        min_primary_disk_size = constants.min_primary_disk_size_old
    for de in diskEntries:
        (vendor, model, size) = diskutil.getExtendedDiskInfo(de)
        if min_primary_disk_size <= diskutil.blockSizeToGBSize(size):
            # determine current usage
            target_is_sr[de] = False
            (boot, root, state, storage, logs) = diskutil.probeDisk(de)
            if storage[0]:
                target_is_sr[de] = True
            (vendor, model, size) = diskutil.getExtendedDiskInfo(de)
            stringEntry = "%s - %s [%s %s]" % (diskutil.getHumanDiskName(de), diskutil.getHumanDiskSize(size), vendor, model)
            e = (stringEntry, de)
            entries.append(e)

    # we should have at least one disk
    if len(entries) == 0:
        ButtonChoiceWindow(tui.screen,
                           "No Primary Disk",
                           "No disk with sufficient space to install %s on was found." % MY_PRODUCT_BRAND,
                           ['Cancel'])
        return EXIT

    # if only one disk, set default:
    if len(entries) == 1:
        answers['primary-disk'] = entries[0][1]
    else:
        # default value:
        default = None
        if answers.has_key('primary-disk'):
            default = selectDefault(answers['primary-disk'], entries)

        tui.update_help_line([None, "<F5> more info"])

        scroll, height = snackutil.scrollHeight(4, len(entries))
        (button, entry) = snackutil.ListboxChoiceWindowEx(
            tui.screen,
            "Select Primary Disk",
            """Please select the disk you would like to install %s on (disks with insufficient space are not shown).

You may need to change your system settings to boot from this disk.""" % (MY_PRODUCT_BRAND),
            entries,
            ['Ok', 'Software RAID', 'Back'], 55, scroll, height, default, help = 'pridisk:info',
            hotkeys = {'F5': disk_more_info})

        tui.screen.popHelpLine()

        # entry contains the 'de' part of the tuple passed in
        answers['primary-disk'] = entry

    if 'installation-to-overwrite' in answers:
        answers['target-is-sr'] = target_is_sr[answers['primary-disk']]

    # Warn if not all of the disk is usable.
    # This can happen if we are unable to use GPT because we are currently
    # using DOS and need to preserve some utility partitions.
    blocks = diskutil.getDiskDeviceSize(answers['primary-disk'])
    tool = PartitionTool(answers['primary-disk'])
    if diskutil.blockSizeToGBSize(blocks) > constants.max_primary_disk_size_dos and tool.partTableType == 'DOS':
        if constants.GPT_SUPPORT and tool.utilityPartitions():
            val = snackutil.ButtonChoiceWindowEx(tui.screen,
                               "Large Disk Detected",
                               "The disk selected is larger than the %d GB limit imposed by the DOS partitioning scheme.  Would you like to remove the OEM partitions that require the DOS partitioning scheme, so that the whole disk can be used?" % constants.max_primary_disk_size_dos,
                               ['Yes', 'No'], default=1)
            answers['zap-utility-partitions'] = (val == 'yes')
        elif not constants.GPT_SUPPORT:
            ButtonChoiceWindow(tui.screen,
                               "Large Disk Detected",
                               "The disk selected to install %s to is greater than %d GB.  The partitioning scheme is limited to this value and therefore the remainder of this disk will be unavailable." % (MY_PRODUCT_BRAND, constants.max_primary_disk_size_dos),
                               ['Ok'])

    if button == None: return RIGHT_FORWARDS
    if button == 'software raid':
        return raid_array_ui(answers)
    if button == 'back': return LEFT_BACKWARDS

    return RIGHT_FORWARDS
Exemple #5
0
def get_installation_type(answers):
    entries = []
    for x in answers['upgradeable-products']:
        entries.append(("Upgrade %s" % str(x), (x, x.settingsAvailable())))
    for b in answers['backups']:
        entries.append(("Restore %s from backup" % str(b), (b, None)))

    entries.append( ("Perform clean installation", None) )

    # default value?
    if answers.has_key('install-type') and answers['install-type'] == constants.INSTALL_TYPE_REINSTALL:
        default = selectDefault(answers['installation-to-overwrite'], entries)
    elif answers.has_key('install-type') and answers['install-type'] == constants.INSTALL_TYPE_RESTORE:
        default = selectDefault(answers['backup-to-restore'], entries)
    else:
        default = None

    if len(answers['upgradeable-products']) > 0:
        text = "One or more existing product installations that can be upgraded have been detected."
        if len(answers['backups']) > 0:
            text += "  In addition one or more backups have been detected."
    else:
        text = "One or more backups have been detected."
    text += "\n\nWhat would you like to do?"

    tui.update_help_line([None, "<F5> more info"])

    def more_info(context):
        if not context: return True
        obj, _ = context
        if isinstance(obj, product.ExistingInstallation):
            use = "%s installation" % obj.visual_brand
        elif isinstance(obj, product.XenServerBackup):
            use = "%s backup" % obj.visual_brand
        else:
            return True

        date = "Unknown"
        if 'INSTALLATION_DATE' in obj.inventory:
            date = obj.inventory['INSTALLATION_DATE']
        dev = "Unknown"
        if 'PRIMARY_DISK' in obj.inventory:
            pd = obj.inventory['PRIMARY_DISK']
            if pd == "ToBeDetermined":
                dev = diskutil.getHumanDiskName(obj.primary_disk)
            else:
                dev = "%s (%s)" % (diskutil.getHumanDiskName(os.path.realpath(pd)),
                               diskutil.getHumanDiskName(pd))

        tui.update_help_line([' ', ' '])
        snackutil.TableDialog(tui.screen, "Details", ("Use:", use),
                              ("Version:", str(obj.visual_version)),
                              ("Build:", str(obj.build)),
                              ("Installed:", date),
                              ("Disk:", dev))
        tui.screen.popHelpLine()
        return True

    (button, entry) = snackutil.ListboxChoiceWindowEx(
        tui.screen,
        "Action To Perform",
        text,
        entries,
        ['Ok', 'Back'], width=60, default = default, help = 'action:info',
        hotkeys = {'F5': more_info})

    tui.screen.popHelpLine()

    if button == 'back': 
        return LEFT_BACKWARDS

    if entry == None:
        answers['install-type'] = constants.INSTALL_TYPE_FRESH
        answers['preserve-settings'] = False

        if answers.has_key('installation-to-overwrite'):
            del answers['installation-to-overwrite']
    elif isinstance(entry[0], product.ExistingInstallation):
        answers['install-type'] = constants.INSTALL_TYPE_REINSTALL
        answers['installation-to-overwrite'], preservable = entry
        answers['preserve-settings'] = preservable
        if 'primary-disk' not in answers:
            answers['primary-disk'] = answers['installation-to-overwrite'].primary_disk

        for k in ['guest-disks', 'default-sr-uuid']:
            if answers.has_key(k):
                del answers[k]
    elif isinstance(entry[0], product.XenServerBackup):
        answers['install-type'] = constants.INSTALL_TYPE_RESTORE
        answers['backup-to-restore'], _ = entry

    return RIGHT_FORWARDS
Exemple #6
0
def select_netif(text, conf, offer_existing=False, default=None):
    """ Display a screen that displays a choice of network interfaces to the
    user, with 'text' as the informative text as the data, and conf being the
    netutil.scanConfiguration() output to be used. 
    """

    netifs = conf.keys()
    netifs.sort(lambda l, r: int(l[3:]) - int(r[3:]))

    if default not in netifs:
        # find first link that is up
        default = None
        for iface in netifs:
            if netutil.linkUp(iface):
                default = iface
                break

    def lentry(iface):
        key = iface
        tag = netutil.linkUp(iface) and '          ' or ' [no link]'
        text = "%s (%s)%s" % (iface, conf[iface].hwaddr, tag)
        return (text, key)

    def iface_details(context):
        tui.update_help_line([' ', ' '])
        if context:
            nic = conf[context]

            table = [("Name:", nic.name), ("Driver:", nic.driver),
                     ("MAC Address:", nic.hwaddr),
                     ("PCI Details:", nic.pci_string)]
            if nic.smbioslabel != "":
                table.append(("BIOS Label:", nic.smbioslabel))

            snackutil.TableDialog(tui.screen, "Interface Details", *table)
        else:
            netifs_all = netutil.getNetifList(include_vlan=True)
            details = map(lambda x: (x, netutil.ipaddr(x)),
                          filter(netutil.interfaceUp, netifs_all))
            snackutil.TableDialog(tui.screen, "Networking Details", *details)
        tui.screen.popHelpLine()
        return True

    def update(listbox):
        old = listbox.current()
        for item in listbox.item2key.keys():
            if item:
                text, _ = lentry(item)
                listbox.replace(text, item)
        listbox.setCurrent(old)
        return True

    tui.update_help_line([None, "<F5> more info"])

    def_iface = None
    if offer_existing and netutil.networkingUp():
        netif_list = [("Use existing configuration", None)]
    else:
        netif_list = []
        if default:
            def_iface = lentry(default)
    netif_list += [lentry(x) for x in netifs]
    scroll, height = snackutil.scrollHeight(6, len(netif_list))
    rc, entry = snackutil.ListboxChoiceWindowEx(tui.screen,
                                                "Networking",
                                                text,
                                                netif_list, ['Ok', 'Back'],
                                                45,
                                                scroll,
                                                height,
                                                def_iface,
                                                help='selif:info',
                                                hotkeys={'F5': iface_details},
                                                timeout_ms=5000,
                                                timeout_cb=update)

    tui.screen.popHelpLine()

    if rc == 'back': return LEFT_BACKWARDS, None
    return RIGHT_FORWARDS, entry
Exemple #7
0
def select_fcoe_ifaces(answers):
    """ Display a screen that displays all network interfaces that are
    FCoE-capable and allows the user to select one or more.
    """

    conf = netutil.scanConfiguration()
    fcoe_ifaces = fcoeutil.get_dcb_capable_ifaces(True)

    if len(fcoe_ifaces) == 0:
        button = ButtonChoiceWindow(tui.screen,
                                    "FCoE Interfaces",
                                    "No DCB capable interfaces found",
                                    ['Back'],
                                    width=60)

        return

    netifs = fcoe_ifaces.keys()
    netifs.sort(lambda l, r: int(l[3:]) - int(r[3:]))

    def iface_details(context):
        tui.update_help_line([' ', ' '])

        nic = conf[context]

        table = [("Name:", nic.name), ("Driver:", nic.driver),
                 ("MAC Address:", nic.hwaddr),
                 ("Link Status:", netutil.linkUp(context) and 'Up' or 'Down')]

        snackutil.TableDialog(tui.screen, "Interface Details", *table)
        tui.screen.popHelpLine()
        return True

    # Map between soft/off and soft/hard (depending on interface property)
    def dcb_state_label(iface, state):
        if state:
            return '[soft]'
        if not fcoe_ifaces[iface]:
            return '[hard]'
        return '      '

    if 'fcoe-interfaces' not in answers:
        answers['fcoe-interfaces'] = {}

    entries = {}
    for ne in netifs:
        state = dcb_state_label(
            ne, answers['fcoe-interfaces'].get(ne, fcoe_ifaces[ne]))
        entry = "%s %s" % (ne, state)
        entries[ne] = entry

    text = TextboxReflowed(54,
                           "Select one or more interfaces to setup for FCoE.")
    buttons = ButtonBar(tui.screen, [('Ok', 'ok'), ('DCB', 'dcb'),
                                     ('Back', 'back')])
    scroll, _ = snackutil.scrollHeight(3, len(entries.keys()))
    cbt = CheckboxTree(3, scroll)
    for iface in netifs:
        cbt.append(entries[iface], iface, iface in answers['fcoe-interfaces'])

    gf = GridFormHelp(tui.screen, 'FCoE Interfaces', 'fcoeiface:info', 1, 3)
    gf.add(text, 0, 0, padding=(0, 0, 0, 1))
    gf.add(cbt, 0, 1, padding=(0, 0, 0, 1))
    gf.add(buttons, 0, 2, growx=1)
    gf.addHotKey('F5')

    tui.update_help_line([None, "<F5> more info"])

    loop = True
    while loop:
        rc = gf.run()
        if rc == 'F5':
            iface_details(cbt.getCurrent())
        elif buttons.buttonPressed(rc) == 'dcb':
            ne = cbt.getCurrent()
            new = dcb_state_label(ne, not entries[ne].endswith('[soft]'))
            entries[ne] = "%s %s" % (ne, new)
            cbt.setEntry(ne, entries[ne])
        else:
            loop = False
    tui.screen.popWindow()
    tui.screen.popHelpLine()

    button = buttons.buttonPressed(rc)

    if button == 'back':
        return

    r = dict(
        map(lambda (k): (k, entries[k].endswith('[soft]')),
            cbt.getSelection()))
    answers['fcoe-interfaces'] = r
    xelogging.log("Selected fcoe interfaces %s" % str(r))

    tui.update_help_line([' ', ' '])

    # Bring up FCoE devices
    tui.progress.showMessageDialog("Please wait", "Discovering devices...")
    result = fcoeutil.start_fcoe(answers['fcoe-interfaces'])
    xelogging.log("fcoe result %s" % str(result))
    tui.progress.clearModelessDialog()

    fail = {k: v for k, v in result.iteritems() if v != 'OK'}
    if len(fail.keys()) > 0:
        # Report any errors
        err_text = '\n'.join(
            map(lambda (x, y): "%s %s" % (x, y), fail.iteritems()))
        text = TextboxReflowed(
            60, "The following errors occured while discovering FCoE disks.")
        errs = Textbox(30, 6, err_text, scroll=len(fail.keys()) > 6)
        buttons = ButtonBar(tui.screen, [('Ok', 'ok')])

        gf = GridFormHelp(tui.screen, 'Discovery Failure', 'fipvlanfail', 1, 3)
        gf.add(text, 0, 0, padding=(0, 0, 0, 1))
        gf.add(errs, 0, 1, padding=(0, 0, 0, 1))
        gf.add(buttons, 0, 2, growx=1)
        gf.run()
        tui.screen.popWindow()

    # Get the results and build a dict of LUNs
    d = fcoeutil.get_fcoe_luns()

    luns = {}
    for k, v in d.items():
        for k2, v2 in v.items():
            for lun in v2['luns'].values():
                luns[os.path.basename(lun['device'])] = {
                    'Capacity': lun['capacity'],
                    'Description': lun['description'],
                    'Port': v2['Port Name'],
                    'VLAN': k
                }

    xelogging.log("fcoe luns discovered %s" % str(luns))

    def disk_details(context):
        tui.update_help_line([' ', ' '])
        table = [("Name:", context)]
        for label in ("VLAN", "Capacity", "Port", "Description"):
            table.append((label + ':', luns[context][label]))
        snackutil.TableDialog(tui.screen, "Disk Details", *table)
        tui.screen.popHelpLine()
        return True

    if len(luns.keys()) > 0:
        disk_list = []
        for lun in sorted(luns.keys()):
            disk_list.append(("%s - %s" % (lun, luns[lun]['Capacity']), lun))

        tui.update_help_line([None, "<F5> more info"])
        scroll, height = snackutil.scrollHeight(6, len(disk_list))
        snackutil.ListboxChoiceWindowEx(
            tui.screen,
            "FCoE Disks",
            "The following devices are now available.",
            disk_list, ['Ok'],
            45,
            scroll,
            height,
            None,
            help='fcoedisks:info',
            hotkeys={'F5': disk_details})
        tui.screen.popHelpLine()