network setup fixes
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Tue, 26 Aug 2008 10:56:57 +0000 (10:56 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Tue, 26 Aug 2008 10:56:57 +0000 (10:56 +0000)
lib/python/Components/Network.py
lib/python/Screens/NetworkSetup.py

index cde6b7efcb0bde424f0c952ab7b4ecf576b1b705..79ec1ed64f1831d3620b5ba14fed76968801a130 100644 (file)
@@ -30,7 +30,7 @@ class Network:
                        except AttributeError:
                                pass
 
                        except AttributeError:
                                pass
 
-               print "self.ifaces:", self.ifaces
+               #print "self.ifaces:", self.ifaces
                self.loadNetworkConfig()
                #self.writeNetworkConfig()
                #print ord(' ')
                self.loadNetworkConfig()
                #self.writeNetworkConfig()
                #print ord(' ')
@@ -67,7 +67,7 @@ class Network:
                fp = popen("ifconfig " + iface)
                result = fp.readlines()
                fp.close()
                fp = popen("ifconfig " + iface)
                result = fp.readlines()
                fp.close()
-               data = { 'up': False, 'dhcp': False }
+               data = { 'up': False, 'dhcp': False, 'preup' : False, 'postdown' : False }
                for line in result:
                        ip = self.regExpMatch(ipPattern, self.regExpMatch(ipLinePattern, line))
                        netmask = self.regExpMatch(ipPattern, self.regExpMatch(netmaskLinePattern, line))
                for line in result:
                        ip = self.regExpMatch(ipPattern, self.regExpMatch(ipLinePattern, line))
                        netmask = self.regExpMatch(ipPattern, self.regExpMatch(netmaskLinePattern, line))
@@ -113,9 +113,9 @@ class Network:
                        if iface['up'] == True:
                                fp.write("auto " + ifacename + "\n")
                                self.configuredInterfaces.append(ifacename)
                        if iface['up'] == True:
                                fp.write("auto " + ifacename + "\n")
                                self.configuredInterfaces.append(ifacename)
-                       if iface['dhcp'] == True and iface['up'] == True:
+                       if iface['dhcp'] == True:
                                fp.write("iface "+ ifacename +" inet dhcp\n")
                                fp.write("iface "+ ifacename +" inet dhcp\n")
-                       if iface['dhcp'] == False and iface['up'] == True:
+                       if iface['dhcp'] == False:
                                fp.write("iface "+ ifacename +" inet static\n")
                                if iface.has_key('ip'):
                                        print tuple(iface['ip'])
                                fp.write("iface "+ ifacename +" inet static\n")
                                if iface.has_key('ip'):
                                        print tuple(iface['ip'])
@@ -125,6 +125,9 @@ class Network:
                                                fp.write("      gateway %d.%d.%d.%d\n" % tuple(iface['gateway']))
                        if iface.has_key("configStrings"):
                                fp.write("\n" + iface["configStrings"] + "\n")
                                                fp.write("      gateway %d.%d.%d.%d\n" % tuple(iface['gateway']))
                        if iface.has_key("configStrings"):
                                fp.write("\n" + iface["configStrings"] + "\n")
+                       if iface["preup"] is not False and not iface.has_key("configStrings"):
+                               fp.write(iface["preup"])
+                               fp.write(iface["postdown"])
                        fp.write("\n")                          
                fp.close()
                self.writeNameserverConfig()
                        fp.write("\n")                          
                fp.close()
                self.writeNameserverConfig()
@@ -164,13 +167,15 @@ class Network:
                                        ifaces[currif]["netmask"] = map(int, split[1].split('.'))
                                if (split[0] == "gateway"):
                                        ifaces[currif]["gateway"] = map(int, split[1].split('.'))
                                        ifaces[currif]["netmask"] = map(int, split[1].split('.'))
                                if (split[0] == "gateway"):
                                        ifaces[currif]["gateway"] = map(int, split[1].split('.'))
-               
-               #self.configuredInterfaces = ifaces
+                               if (split[0] == "pre-up"):
+                                       self.ifaces[currif]["preup"] = i
+                               if (split[0] == "post-down"):
+                                       self.ifaces[currif]["postdown"] = i
+
                print "read interfaces:", ifaces
                for ifacename, iface in ifaces.items():
                        if self.ifaces.has_key(ifacename):
                                self.ifaces[ifacename]["dhcp"] = iface["dhcp"]
                print "read interfaces:", ifaces
                for ifacename, iface in ifaces.items():
                        if self.ifaces.has_key(ifacename):
                                self.ifaces[ifacename]["dhcp"] = iface["dhcp"]
-
                print "self.ifaces after loading:", self.ifaces
 
        def loadNameserverConfig(self):
                print "self.ifaces after loading:", self.ifaces
 
        def loadNameserverConfig(self):
index d9679bb18dc031e9014b3247608cef7c2e3aa186..29f9705f3f3f4aa985e441ff7dd420001208a829 100644 (file)
@@ -390,23 +390,24 @@ class AdapterSetup(Screen, ConfigListScreen):
 
        def ok(self):
                iNetwork.setAdapterAttribute(self.iface, "up", self.activateInterfaceEntry.value)
 
        def ok(self):
                iNetwork.setAdapterAttribute(self.iface, "up", self.activateInterfaceEntry.value)
-               if self.activateInterfaceEntry.value is True:
-                       iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
-                       iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
-                       iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
-                       if self.hasGatewayConfigEntry.value:
-                               iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
-                       else:
-                               iNetwork.removeAdapterAttribute(self.iface, "gateway")
-                       if self.extended is not None and self.configStrings is not None:
-                               iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
-                               self.ws.writeConfig()
+               #if self.activateInterfaceEntry.value is True:
+               iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
+               iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
+               iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
+               if self.hasGatewayConfigEntry.value:
+                       iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
                else:
                else:
-                       iNetwork.removeAdapterAttribute(self.iface, "ip")
-                       iNetwork.removeAdapterAttribute(self.iface, "netmask")
                        iNetwork.removeAdapterAttribute(self.iface, "gateway")
                        iNetwork.removeAdapterAttribute(self.iface, "gateway")
+               if self.extended is not None and self.configStrings is not None:
+                       iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
+                       self.ws.writeConfig()
+               #else:
+               #       iNetwork.removeAdapterAttribute(self.iface, "ip")
+               #       iNetwork.removeAdapterAttribute(self.iface, "netmask")
+               #       iNetwork.removeAdapterAttribute(self.iface, "gateway")
+               #       iNetwork.deactivateInterface(self.iface)
+               if self.activateInterfaceEntry.value is False:
                        iNetwork.deactivateInterface(self.iface)
                        iNetwork.deactivateInterface(self.iface)
-
                iNetwork.deactivateNetworkConfig()
                iNetwork.writeNetworkConfig()
                iNetwork.activateNetworkConfig()
                iNetwork.deactivateNetworkConfig()
                iNetwork.writeNetworkConfig()
                iNetwork.activateNetworkConfig()