Example #1
0
File: __init__.py Project: xtha/pxe
    def out_of_order_pool_upgrade_fn(answers):
        if 'installation-to-overwrite' not in answers:
            return False

        ret = False
        settings = answers['installation-to-overwrite'].readSettings()
        if settings['master']:
            if not netutil.networkingUp():
                pass

            try:
                s = xmlrpclib.Server("http://"+settings['master'])
                session = s.session.slave_login("", settings['pool-token'])["Value"]
                pool = s.pool.get_all(session)["Value"][0]
                master = s.pool.get_master(session, pool)["Value"]
                software_version = s.host.get_software_version(session, master)["Value"]
                s.session.logout(session)

                # compare versions
                master_ver = product.Version.from_string(software_version['product_version'])
                if master_ver < product.THIS_PRODUCT_VERSION:
                    ret = True
            except:
                pass

        return ret
Example #2
0
    def out_of_order_pool_upgrade_fn(answers):
        if 'installation-to-overwrite' not in answers:
            return False

        ret = False
        settings = answers['installation-to-overwrite'].readSettings()
        if settings['master']:
            if not netutil.networkingUp():
                pass

            try:
                s = xmlrpclib.Server("http://" + settings['master'])
                session = s.session.slave_login(
                    "", settings['pool-token'])["Value"]
                pool = s.pool.get_all(session)["Value"][0]
                master = s.pool.get_master(session, pool)["Value"]
                software_version = s.host.get_software_version(
                    session, master)["Value"]
                s.session.logout(session)

                # compare versions
                master_ver = product.Version.from_string(
                    software_version['product_version'])
                if master_ver < product.THIS_PRODUCT_VERSION:
                    ret = True
            except:
                pass

        return ret
Example #3
0
def requireNetworking(answers,
                      defaults=None,
                      msg=None,
                      keys=['net-admin-interface', 'net-admin-configuration']):
    """ Display the correct sequence of screens to get networking
    configuration.  Bring up the network according to this configuration.
    If answers is a dictionary, set 
      answers[keys[0]] to the interface chosen, and 
      answers[keys[1]] to the interface configuration chosen, and
      answers['runtime-iface-configuration'] to current manual network config, in format (all-dhcp, manual-config).
    If defaults.has_key[keys[0]] then use defaults[keys[0]] as the default network interface.
    If defaults.has_key[keys[1]] then use defaults[keys[1]] as the default network interface configuration."""

    interface_key = keys[0]
    config_key = keys[1]

    nethw = answers['network-hardware']
    if len(nethw.keys()) == 0:
        tui.progress.OKDialog("Networking",
                              "No available ethernet device found")
        return REPEAT_STEP

    # Display a screen asking which interface to configure, then what the
    # configuration for that interface should be:
    def select_interface(answers, default, msg):
        """ Show the dialog for selecting an interface.  Sets
        answers['interface'] to the name of the interface selected (a
        string). """
        if answers.has_key('interface'):
            default = answers['interface']
        if msg == None:
            msg = "%s Setup needs network access to continue.\n\nWhich network interface would you like to configure to access your %s product repository?" % (
                version.PRODUCT_BRAND or version.PLATFORM_NAME,
                version.PRODUCT_BRAND or version.PLATFORM_NAME)
        direction, iface = select_netif(msg, nethw, True, default)
        if direction == RIGHT_FORWARDS:
            answers['reuse-networking'] = (iface == None)
            if iface:
                answers['interface'] = iface
        return direction

    def specify_configuration(answers, txt, defaults):
        """ Show the dialog for setting nic config.  Sets answers['config']
        to the configuration used.  Assumes answers['interface'] is a string
        identifying by name the interface to configure. """

        if 'reuse-networking' in answers and answers['reuse-networking']:
            return RIGHT_FORWARDS

        direction, conf = get_iface_configuration(nethw[answers['interface']],
                                                  txt,
                                                  defaults=defaults,
                                                  include_dns=True)
        if direction == RIGHT_FORWARDS:
            answers['config'] = conf
        return direction

    conf_dict = {}
    def_iface = None
    def_conf = None
    if type(defaults) == dict:
        if defaults.has_key(interface_key):
            def_iface = defaults[interface_key]
        if defaults.has_key(config_key):
            def_conf = defaults[config_key]
    if len(nethw.keys()) > 1 or netutil.networkingUp():
        seq = [
            uicontroller.Step(select_interface, args=[def_iface, msg]),
            uicontroller.Step(specify_configuration, args=[None, def_conf])
        ]
    else:
        text = "%s Setup needs network access to continue.\n\nHow should networking be configured at this time?" % (
            version.PRODUCT_BRAND or version.PLATFORM_NAME)
        conf_dict['interface'] = nethw.keys()[0]
        seq = [uicontroller.Step(specify_configuration, args=[text, def_conf])]
    direction = uicontroller.runSequence(seq, conf_dict)

    if direction == RIGHT_FORWARDS and 'config' in conf_dict:
        netutil.writeNetInterfaceFiles(
            {conf_dict['interface']: conf_dict['config']})
        netutil.writeResolverFile(
            {conf_dict['interface']: conf_dict['config']}, '/etc/resolv.conf')
        tui.progress.showMessageDialog(
            "Networking",
            "Configuring network interface, please wait...",
        )
        ifaceName = conf_dict['config'].getInterfaceName(
            conf_dict['interface'])
        netutil.ifdown(ifaceName)

        # check that we have *some* network:
        if netutil.ifup(ifaceName) != 0 or not netutil.interfaceUp(ifaceName):
            tui.progress.clearModelessDialog()
            tui.progress.OKDialog(
                "Networking",
                "The network still does not appear to be active.  Please check your settings, and try again."
            )
            direction = REPEAT_STEP
        else:
            if answers and type(answers) == dict:
                # write out results
                answers[interface_key] = conf_dict['interface']
                answers[config_key] = conf_dict['config']
                # update cache of manual configurations
                manual_config = {}
                all_dhcp = False
                if answers.has_key('runtime-iface-configuration'):
                    manual_config = answers['runtime-iface-configuration'][1]
                manual_config[conf_dict['interface']] = conf_dict['config']
                answers['runtime-iface-configuration'] = (all_dhcp,
                                                          manual_config)
            tui.progress.clearModelessDialog()

    return direction
Example #4
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
Example #5
0
File: network.py Project: xtha/pxe
def requireNetworking(answers, defaults=None, msg=None, keys=['net-admin-interface', 'net-admin-configuration']):
    """ Display the correct sequence of screens to get networking
    configuration.  Bring up the network according to this configuration.
    If answers is a dictionary, set 
      answers[keys[0]] to the interface chosen, and 
      answers[keys[1]] to the interface configuration chosen, and
      answers['runtime-iface-configuration'] to current manual network config, in format (all-dhcp, manual-config).
    If defaults.has_key[keys[0]] then use defaults[keys[0]] as the default network interface.
    If defaults.has_key[keys[1]] then use defaults[keys[1]] as the default network interface configuration."""

    interface_key = keys[0]
    config_key = keys[1]

    nethw = answers['network-hardware']
    if len(nethw.keys()) == 0:
        tui.progress.OKDialog("Networking", "No available ethernet device found")
        return REPEAT_STEP

    # Display a screen asking which interface to configure, then what the 
    # configuration for that interface should be:
    def select_interface(answers, default, msg):
        """ Show the dialog for selecting an interface.  Sets
        answers['interface'] to the name of the interface selected (a
        string). """
        if answers.has_key('interface'):
            default = answers['interface']
        if msg == None:
            msg = "%s Setup needs network access to continue.\n\nWhich network interface would you like to configure to access your %s product repository?" % (version.PRODUCT_BRAND or version.PLATFORM_NAME, version.PRODUCT_BRAND or version.PLATFORM_NAME)
        direction, iface = select_netif(msg, nethw, True, default)
        if direction == RIGHT_FORWARDS:
            answers['reuse-networking'] = (iface == None)
            if iface:
                answers['interface'] = iface
        return direction

    def specify_configuration(answers, txt, defaults):
        """ Show the dialog for setting nic config.  Sets answers['config']
        to the configuration used.  Assumes answers['interface'] is a string
        identifying by name the interface to configure. """

        if 'reuse-networking' in answers and answers['reuse-networking']:
            return RIGHT_FORWARDS

        direction, conf = get_iface_configuration(nethw[answers['interface']], txt, 
                                                  defaults=defaults, include_dns=True)
        if direction == RIGHT_FORWARDS:
            answers['config'] = conf
        return direction

    conf_dict = {}
    def_iface = None
    def_conf = None
    if type(defaults) == dict:
        if defaults.has_key(interface_key):
            def_iface = defaults[interface_key]
        if defaults.has_key(config_key):
            def_conf = defaults[config_key]
    if len(nethw.keys()) > 1 or netutil.networkingUp():
        seq = [ uicontroller.Step(select_interface, args=[def_iface, msg]), 
                uicontroller.Step(specify_configuration, args=[None, def_conf]) ]
    else:
        text = "%s Setup needs network access to continue.\n\nHow should networking be configured at this time?" % (version.PRODUCT_BRAND or version.PLATFORM_NAME)
        conf_dict['interface'] = nethw.keys()[0]
        seq = [ uicontroller.Step(specify_configuration, args=[text, def_conf]) ]
    direction = uicontroller.runSequence(seq, conf_dict)

    if direction == RIGHT_FORWARDS and 'config' in conf_dict:
        netutil.writeDebStyleInterfaceFile(
            {conf_dict['interface']: conf_dict['config']},
            '/etc/network/interfaces'
            )
        netutil.writeResolverFile(
            {conf_dict['interface']: conf_dict['config']},
            '/etc/resolv.conf'
            )
        tui.progress.showMessageDialog(
            "Networking",
            "Configuring network interface, please wait...",
            )
        netutil.ifdown(conf_dict['interface'])

        # check that we have *some* network:
        if netutil.ifup(conf_dict['interface']) != 0 or not netutil.interfaceUp(conf_dict['interface']):
            tui.progress.clearModelessDialog()
            tui.progress.OKDialog("Networking", "The network still does not appear to be active.  Please check your settings, and try again.")
            direction = REPEAT_STEP
        else:
            if answers and type(answers) == dict:
                # write out results
                answers[interface_key] = conf_dict['interface']
                answers[config_key] = conf_dict['config']
                # update cache of manual configurations
                manual_config = {}
                all_dhcp = False
                if answers.has_key('runtime-iface-configuration'):
                    manual_config = answers['runtime-iface-configuration'][1]
                manual_config[conf_dict['interface']] = conf_dict['config']
                answers['runtime-iface-configuration'] = (all_dhcp, manual_config)
            tui.progress.clearModelessDialog()
        
    return direction
Example #6
0
File: network.py Project: xtha/pxe
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:
            details = map(lambda x: (x, netutil.ipaddr(x)), filter(netutil.interfaceUp, netifs))

            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',
                                        hotkey='F5', hotkey_cb=iface_details, timeout_ms=5000, timeout_cb=update)

    tui.screen.popHelpLine()

    if rc == 'back': return LEFT_BACKWARDS, None
    return RIGHT_FORWARDS, entry