コード例 #1
0
    def save(self):
        Device.save(self)
        conf = ConfDevice(self.DeviceId)
        conf["TYPE"] = "Ethernet"
        if not self.Alias:
            conf["NETTYPE"] = "lcs"
            ports = ""
            hardwarelist = getHardwareList()
            for hw in hardwarelist:
                if hw.Name == self.Device:
                    if hw.MacAddress:
                        conf["MACADDR"] = hw.MacAddress
                    else:
                        del conf["MACADDR"]

                    if (hw.Card.IoPort and hw.Card.IoPort1
                            and hw.Card.IoPort2):
                        ports = "%s,%s,%s" % (hw.Card.IoPort, hw.Card.IoPort1,
                                              hw.Card.IoPort2)
                    break
            if ports:
                conf["SUBCHANNELS"] = ports
            if hw.Card.Options:
                conf["OPTIONS"] = hw.Card.Options
            else:
                if conf.has_key("OPTIONS"):
                    del conf["OPTIONS"]

        conf.write()
コード例 #2
0
    def setState(self):
        """
        Build the list of devices
        """
        self.li = snack.Listbox(5, returnExit=1)
        l = 0
        le = self.mscreen.width - 6
        if le <= 0:
            le = 5
        for dev in getDeviceList():
            if not hasattr(dev, "getDialog") or not dev.getDialog():
                #li.append("No dialog for %s" % dev.Device, None)
                continue

            l += 1
            for hw in getHardwareList():
                if hw.Name == dev.Device and hw.Description:
                    self.li.append(
                        ("%s (%s) - %s" %
                         (dev.DeviceId, dev.Device, hw.Description))[:le], dev)
                    break

            else:
                self.li.append(("%s (%s) - %s" %
                                (dev.DeviceId, dev.Device, dev.Type))[:le],
                               dev)

        if not l:
            return None

        self.li.append(_("<New Device>"), None)
コード例 #3
0
    def setState(self, dev=None):
        """
        Set the default values of the fields
        according to the given device
        @dev The NCDevice (type devernet) to use as default values
        """
        if not dev:
            dev = self.dev

        if dev:
            if dev.DeviceId:
                self.name.set(dev.DeviceId)
            if dev.Device:
                self.hwdev.set(dev.Device)
            if dev.BootProto:
                bp = dev.BootProto.lower()
                if (bp == "dhcp") or (bp == "bootp"):
                    self.dynip.setValue("*")
            if dev.IP:
                self.statip.set(dev.IP)
            if dev.Netmask:
                self.netmask.set(dev.Netmask)
            if dev.Gateway:
                self.gwy.set(dev.Gateway)

            hardwarelist = getHardwareList()
            for hw in hardwarelist:
                if hw.Name == dev.Device:
                    self.ioport.set(hw.Card.IoPort or '')
                    self.ioport1.set(hw.Card.IoPort1 or '')
                    self.ioport2.set(hw.Card.IoPort2 or '')
                    self.options.set(hw.Card.Options or '')
                    self.macaddr.set(hw.MacAddress or '')
                    break
コード例 #4
0
    def saveModule(self):
        if not self.Card.ModuleName:
            return
        from netconfpkg.NCHardwareList import getMyConfModules, getHardwareList
        hl = getHardwareList()
        modules = getMyConfModules()
        dic = modules[self.Name]
        if dic:
            dic['alias'] = self.Card.ModuleName
            modules[self.Name] = dic
            log.lch(2, modules.filename,
                    "%s alias %s" % (self.Name, self.Card.ModuleName))
        # No, no, no... only delete known options!!!
        #WRONG: modules[self.Card.ModuleName] = {}
        #WRONG: modules[self.Card.ModuleName]['options'] = {}
        #
        # Better do it this way!

        if (modules.has_key(self.Card.ModuleName)
                and modules[self.Card.ModuleName].has_key('options')):
            for (key, confkey) in hl.keydict.items():
                if modules[self.Card.ModuleName]['options'].has_key(confkey):
                    del modules[self.Card.ModuleName]['options'][confkey]

        for (selfkey, confkey) in hl.keydict.items():
            if self.Card.__dict__[selfkey]:
                if (not (selfkey == 'IRQ' and (self.Card.IRQ == _('Unknown') or
                                               (self.Card.IRQ == 'Unknown')))):
                    dic = modules[self.Card.ModuleName]
                    if not dic.has_key('options'):
                        dic['options'] = {}

                    dic['options'][confkey] = str(self.Card.__dict__[selfkey])
                    modules[self.Card.ModuleName] = dic
コード例 #5
0
    def deactivate(self, dialog=None):
        ret = DevEthernet.deactivate(self, dialog)
        if not self.Alias:
            hardwarelist = getHardwareList()
            for hw in hardwarelist:
                if hw.Name == self.Device and (hw.Card.IoPort
                                               and hw.Card.IoPort1
                                               and hw.Card.IoPort2):
                    os.system(
                        "echo 0 > /sys/bus/ccwgroup/drivers/lcs/%s/online; echo 1 > /sys/bus/ccwgroup/drivers/lcs/%s/ungroup"
                        % (hw.Card.IoPort, hw.Card.IoPort))
                    break

        return ret
コード例 #6
0
    def activate(self, dialog=None):
        """activate the lcs device"""
        if not self.Alias:
            hardwarelist = getHardwareList()
            for hw in hardwarelist:
                if hw.Name == self.Device and (hw.Card.IoPort
                                               and hw.Card.IoPort1
                                               and hw.Card.IoPort2):
                    os.system(
                        'SUBSYSTEM="ccw" DEVPATH="bus/ccwgroup/drivers/lcs/%s" /lib/udev/ccw_init'
                        % hw.Card.IoPort)
                    break

        return DevEthernet.activate(self, dialog)
コード例 #7
0
    def on_hw_config_page_prepare(self, druid_page, druid):
        hardwarelist = getHardwareList()
        hardwarelist.updateFromSystem()

        clist = self.xml.get_widget("hardwareList")
        clist.clear()
        self.devlist = []
        for hw in hardwarelist:
            if hw.Type == ETHERNET:
                desc = hw.Description + " (" + hw.Name + ")"
                clist.append([desc])
                self.devlist.append(hw.Name)

        clist.append([_("Other Ethernet Card")])
        clist.select_row(self.hw_sel, 0)
コード例 #8
0
    def on_hw_config_page_prepare(self, druid_page,
                                  druid):  # pylint: disable-msg=W0613
        hardwarelist = getHardwareList()
        hardwarelist.updateFromSystem()

        clist = self.xml.get_widget("hardwareList")
        clist.clear()
        self.devlist = []
        for hw in hardwarelist:
            if hw.Type == QETH:
                desc = hw.Description + " (" + hw.Name + ")"
                clist.append([desc])
                self.devlist.append(hw.Name)

        clist.append([_("Other QETH Device")])
        clist.select_row(self.hw_sel, 0)
コード例 #9
0
    def on_finish_page_finish(self, druid_page, druid):
        hardwarelist = getHardwareList()

        hardwarelist.commit()
        #print self.devicelist
        self.devicelist.append(self.device)
        self.device.commit()

        for prof in self.profilelist:
            if prof.Active == False:
                continue
            prof.ActiveDevices.append(self.device.DeviceId)
            break

        self.profilelist.commit()
        self.devicelist.commit()

        self.toplevel.destroy()
        gtk.main_quit()
コード例 #10
0
def dsl_hardware_hydrate(xml, device):
    hwlist = getHardwareList()
    (hwcurr,
     hwdesc) = NC_functions.create_ethernet_combo(hwlist,
                                                  device.Dialup.EthDevice)
    omenu = xml.get_widget("hwdvOmenu")
    omenu.remove_menu()
    menu = gtk.Menu()
    history = 0
    for i in range(0, len(hwdesc)):
        item = gtk.MenuItem(hwdesc[i])
        item.show()
        menu.append(item)
        if hwdesc[i] == hwcurr:
            history = i
    omenu.set_menu(menu)
    omenu.show_all()
    omenu.set_history(history)
    omenu.show_all()
コード例 #11
0
def hardware_hydrate(xml, device):
    hwlist = getHardwareList()
    (hwcurr, hwdesc) = NC_functions.create_generic_combo(hwlist,
                                                         device.Device,
                                                         mtype=device.Type)
    omenu = xml.get_widget("hwdvOmenu")
    omenu.remove_menu()
    menu = gtk.Menu()
    history = 0
    for i in range(0, len(hwdesc)):
        item = gtk.MenuItem(hwdesc[i])
        item.show()
        menu.append(item)
        if hwdesc[i] == hwcurr:
            history = i
    omenu.set_menu(menu)
    omenu.show_all()
    omenu.set_history(history)
    omenu.show_all()

    if device.Alias != None:
        xml.get_widget("hardwareAliasesSpin").set_value(int(device.Alias))
        xml.get_widget("hardwareAliasesToggle").set_active(False)
        xml.get_widget("hardwareAliasesToggle").set_active(True)
    else:
        xml.get_widget("hardwareAliasesToggle").set_active(True)
        xml.get_widget("hardwareAliasesToggle").set_active(False)

    if device.HardwareAddress != None:
        xml.get_widget("hardwareMACToggle").set_active(False)
        xml.get_widget("hardwareMACToggle").set_active(True)
        xml.get_widget("hardwareMACEntry").set_text(device.HardwareAddress)
        xml.get_widget("hardwareMACEntry").set_sensitive(True)
        xml.get_widget("hardwareProbeButton").set_sensitive(True)
    else:
        xml.get_widget("hardwareMACToggle").set_active(True)
        xml.get_widget("hardwareMACToggle").set_active(False)
        xml.get_widget("hardwareMACEntry").set_text('')
        xml.get_widget("hardwareMACEntry").set_sensitive(False)
        xml.get_widget("hardwareProbeButton").set_sensitive(False)

    if device.Slave:
        xml.get_widget("hardwareMACToggle").set_sensitive(False)
コード例 #12
0
    def processInfo(self):
        """
        Extracts info from the screen, and puts it into a device object
        """

        self.dev.DeviceId = self.name.value()
        self.dev.Device = self.hwdev.value()
        hardwarelist = getHardwareList()
        for hw in hardwarelist:
            if hw.Name == self.dev.Device:
                break
        else:
            i = hardwarelist.addHardware(QETH)
            hw = hardwarelist[i]
            hw.Status = HW_CONF
            hw.Name = self.dev.Device
            hw.Type = QETH

        # pylint: disable-msg=W0631
        if not hw.Card:
            hw.createCard()
        hw.Card.ModuleName = "qeth"
        hw.Card.IoPort = self.ioport.value()
        hw.Card.IoPort1 = self.ioport1.value()
        hw.Card.IoPort2 = self.ioport2.value()
        ports = "%s,%s,%s" % (hw.Card.IoPort, hw.Card.IoPort1, hw.Card.IoPort2)
        hw.Description = "qeth %s" % ports
        hw.Options = self.options.value()
        hw.MacAddress = self.macaddr.value()

        if self.dynip.value():
            self.dev.BootProto = "dhcp"
            self.dev.IP = None
            self.dev.Netmask = None
            self.dev.Gateway = None
        else:
            self.dev.IP = self.statip.value()
            self.dev.Netmask = self.netmask.value()
            self.dev.Gateway = self.gwy.value()
            self.dev.BootProto = None
コード例 #13
0
    def hydrate(self):
        DialupInterfaceDialog.hydrate(self)
        hardwarelist = getHardwareList()
        devicelist = []
        for hw in hardwarelist:
            if hw.Type == 'Modem':
                devicelist.append(hw.Name)
                continue

        if devicelist:
            self.xml.get_widget("modemPortCombo").set_popdown_strings(\
                devicelist)

        dialup = self.device.Dialup
        if dialup.HangupTimeout:
            self.xml.get_widget("hangupTimeoutSB").set_value(\
                dialup.HangupTimeout)
        if dialup.DialMode:
            if dialup.DialMode == DM_AUTO:
                dialmode = DialModes[DM_AUTO]
            else:
                dialmode = DialModes[DM_MANUAL]
        else:
            dialmode = DialModes[DM_MANUAL]
        self.xml.get_widget("dialModeEntry").set_text(dialmode)

        if dialup.InitString:
            self.xml.get_widget("modemInitEntry").set_text(dialup.InitString)

        if dialup.Persist:
            self.xml.get_widget("persistCB").set_active(dialup.Persist)

        if dialup.DefRoute != None:
            self.xml.get_widget("defrouteCB").set_active(dialup.DefRoute)

        if dialup.Inherits:
            self.xml.get_widget("modemPortEntry").set_text(dialup.Inherits)

        self.xml.get_widget("stupidModeCB").set_active(\
            self.device.Dialup.StupidMode == True)
コード例 #14
0
    def on_finish_page_prepare(self, druid_page,
                               druid):  # pylint: disable-msg=W0613
        self.device.DeviceId = self.device.Device
        if self.device.Alias:
            self.device.DeviceId = self.device.DeviceId + ":" \
                                   + str(self.device.Alias)

        try:
            hwaddr = ethtool.get_hwaddr(self.device.Device)
        except IOError:
            pass
        else:
            self.device.HardwareAddress = hwaddr

        # FIXME: Bad style for translation
        s = str(
            _("You have selected the following information:") + "\n\n" +
            "   " + _("Device:") + " " + str(self.device.DeviceId) + " ")

        hardwarelist = getHardwareList()
        for hw in hardwarelist:
            if hw.Name == self.device.Device:
                s = s + "(" + hw.Description + ")"
                break

        s = s + "\n" + "   "

        if (self.device.BootProto == "static"
                or self.device.BootProto == "none"):
            s = str(s + _("Address:") + " " + self.device.IP + "\n" + "   " +
                    _("Subnet mask:") + " " + self.device.Netmask + "\n" +
                    "   " + _("Default gateway address:") + " " +
                    self.device.Gateway + "\n" + "   ")
        else:
            s = str(s + _("Automatically obtain IP address settings with:") +
                    " " + self.device.BootProto + "\n")

        druid_page.set_text(s)
コード例 #15
0
    def load(self, name):
        Device.load(self, name)
        conf = ConfDevice(name)
        self.Type = LCS
        if conf.has_key("SUBCHANNELS"):
            hardwarelist = getHardwareList()
            hw = None
            for hw in hardwarelist:
                if hw.Name == self.Device and hw.Type == LCS:
                    break
            else:
                i = hardwarelist.addHardware(LCS)
                hw = hardwarelist[i]
                hw.Status = HW_CONF
                hw.Name = self.Device
                hw.Type = LCS

            hw.Description = "lcs %s" % conf["SUBCHANNELS"]
            hw.createCard()
            hw.Card.ModuleName = "lcs"
            try:
                hw.MacAddress = conf["MACADDR"]
            except:
                pass

            try:
                ports = conf["SUBCHANNELS"].split(",")
                hw.Card.IoPort = ports[0]
                hw.Card.IoPort1 = ports[1]
                hw.Card.IoPort2 = ports[2]
                hw.Card.Options = conf["OPTIONS"]
            except:
                pass

            hw.commit(changed=False)
            hardwarelist.commit(changed=False)
コード例 #16
0
        self.device.DeviceId = self.device.Device
        if self.device.Alias:
            self.device.DeviceId = self.device.DeviceId + ":" \
                                   + str(self.device.Alias)

        try:
            hwaddr = ethtool.get_hwaddr(self.device.Device)
        except IOError, err:
            pass
        else:
            self.device.HardwareAddress = hwaddr

        s = _("You have selected the following information:") + "\n\n" + "   "\
            + _("Device:") + " " + str(self.device.DeviceId) + " "

        hardwarelist = getHardwareList()
        for hw in hardwarelist:
            if hw.Name == self.device.Device:
                s = s + "(" + hw.Description + ")"
                break

        s = s + "\n" + "   "

        if (self.device.BootProto == "static"
                or self.device.BootProto == "none"):
            # FIXME: Bad style for translation
            s = s + str(
                _("Address:") + " " + (self.device.IP or '') + "\n" + "   " +
                _("Subnet mask:") + " " + (self.device.Netmask or '') + "\n" +
                "   " + _("Default gateway address:") + " " +
                (self.device.Gateway or '') + "\n" + "   ")
コード例 #17
0
 def saveHardware(self):
     if not self.do_save:
         return
     hardwarelist = getHardwareList()
     hardwarelist.save()
コード例 #18
0
def main(mcmdline):
    from netconfpkg.NCDeviceList import getDeviceList
    from netconfpkg.NCHardwareList import getHardwareList               
    from netconfpkg.NCIPsecList import getIPsecList
    from netconfpkg.NCProfileList import getProfileList
    from netconfpkg.NC_functions import log

    signal.signal (signal.SIGINT, signal.SIG_DFL)
    class BadUsage(Exception):
        pass

    #progname = os.path.basename(sys.argv[0])
    NC_functions.setVerboseLevel(2)
    NC_functions.setDebugLevel(0)

    do_activate = 0
    switch_profile = 0
    profile = None
    test = 0
    EXPORT = 1
    IMPORT = 2
    SWITCH = 3
    mode = EXPORT
    filename = None
    clear = 0
    chroot = None
    debug = None
    devlists = []

    try:
        opts = getopt.getopt(mcmdline, "asp:?r:dhvtief:co",
                                   [
                                    "activate",
                                    "profile=",
                                    "help",
                                    "devicelist",
                                    "verbose",
                                    "test",
                                    "import",
                                    "export",
                                    "clear",
                                    "root=",
                                    "file=",
                                    "debug",
                                    "hardwarelist",
                                    "ipseclist",
                                    "profilelist"])[0]
        for opt, val in opts:
            if opt == '-r' or opt == '--root':                
                chroot = val
                NC_functions.prepareRoot(chroot)
                NC_functions.updateNetworkScripts()
                continue
    except (getopt.error, BadUsage):
        pass

    try:
        opts = getopt.getopt(mcmdline, "asp:?r:dhvtief:co",
                                   [
                                    "activate",
                                    "profile=",
                                    "help",
                                    "devicelist",
                                    "verbose",
                                    "test",
                                    "import",
                                    "export",
                                    "clear",
                                    "root=",
                                    "file=",
                                    "debug",
                                    "hardwarelist",
                                    "ipseclist",
                                    "profilelist"])[0]
        for opt, val in opts:
            if opt == '-d' or opt == '--devicelist':
                devlists.append(getDeviceList())
                continue

            if opt == '-h' or opt == '--hardwarelist':
                devlists.append(getHardwareList())
                continue

            if opt == '-s' or opt == '--ipseclist':
                devlists.append(getIPsecList())
                continue

            if opt == '-o' or opt == '--profilelist':
                devlists.append(getProfileList())
                continue

            if opt == '-p' or opt == '--profile':
                mode = SWITCH
                switch_profile = 1
                profile = val
                continue

            if opt == '-f' or opt == '--file':
                filename = val
                continue

            if opt == '-r' or opt == '--root':
                # already parsed
                continue

            if opt == '-c' or opt == '--clear':
                clear = 1
                continue

            if opt == '-t' or opt == '--test':
                test = 1
                continue

            if opt == '-a' or opt == '--activate':
                mode = SWITCH
                do_activate = 1
                continue

            if opt == '-i' or opt == '--import':
                mode = IMPORT
                continue

            if opt == '-e' or opt == '--export':
                mode = EXPORT
                continue

            if opt == '-?' or opt == '--help':
                Usage()
                return(0)

            if opt == '-v' or opt == '--verbose':
                NC_functions.setVerboseLevel(NC_functions.getVerboseLevel()+1)
                continue

            if opt == '--debug':
                NC_functions.setDebugLevel(NC_functions.getDebugLevel()+1)
                debug = 1
                continue

            sys.stderr.write(_("Unknown option %s\n" % opt))
            raise BadUsage

    except (getopt.error, BadUsage):
        Usage()
        return(1)

    try:

        if not NC_functions.getDebugLevel():
            log.handler = log.syslog_handler
            log.open()
        else:
            log.handler = log.file_handler
            log.open(sys.stderr)

        if not len(devlists):
            devlists = [getDeviceList(), getHardwareList(),
                        getIPsecList(),
                        getProfileList()]

        if clear:
            for devlist in devlists:
                del devlist[0:len(devlist)]

        if mode == EXPORT:
            for devlist in devlists:
                devstr =  str(devlist)
                if len(devstr):
                    # remove the last \n
                    print devstr[:-1]
            return(0)

        elif mode == IMPORT:
            devlistsdict = {
                "HardwareList" : getHardwareList(),
                "DeviceList" : getDeviceList(),
                "IPsecList" : getIPsecList(),
                "ProfileList" : getProfileList() }

            if filename:
                mfile = open(filename, "r")
            else:
                mfile = sys.stdin

            lines = mfile.readlines()

            for line in lines:
                try:
                    line = line[:-1]
                    log.log(3, "Parsing '%s'\n" % line)
                    vals = line.split("=")
                    if len(vals) <= 1:
                        continue
                    key = vals[0]
                    value = "=".join(vals[1:])

                    vals = key.split(".")
                    if devlistsdict.has_key(vals[0]):
                        # pylint: disable-msg=W0212
                        devlistsdict[vals[0]].fromstr(vals, value)
                    else:
                        sys.stderr.write(_("Unknown List %s\n", vals[0]))
                        raise ParseError

                except Exception, e:
                    pe = ParseError(_("Error parsing line: %s") % line)
                    pe.args += e.args
                    raise pe


            for devlist in devlists:
                log.log(1, "%s" % devlist)
                devlist.save()

            return(0)

        elif test:
            return(0)