10 def writeNetworkConfig(self):
11 # fixme restarting and updating the network too often. possible fix: check current config and execute only if changed :/
12 # fixme using interfaces.tmp instead of interfaces for now
13 fp = file('/etc/network/interfaces.tmp', 'w')
14 fp.write("auto eth0\n")
15 if (config.network.dhcp.value == "yes"):
16 fp.write("iface eth0 inet dhcp\n")
18 fp.write("iface eth0 inet static\n")
19 fp.write(" address %d.%d.%d.%d\n" % tuple(config.network.ip.value))
20 fp.write(" netmask %d.%d.%d.%d\n" % tuple(config.network.netmask.value))
21 fp.write(" gateway %d.%d.%d.%d\n" % tuple(config.network.gateway.value))
24 def activateNetworkConfig(self):
26 #os.system("/etc/init.d/networking restart")
28 def setDHCP(self, useDHCP):
31 config.network.ip.enabled = False
32 config.network.netmask.enabled = False
33 config.network.gateway.enabled = False
34 config.network.dns.enabled = False
36 print "NOT using DHCP"
37 config.network.ip.enabled = True
38 config.network.netmask.enabled = True
39 config.network.gateway.enabled = True
40 config.network.dns.enabled = True
42 def setIPNameserver(self, ip):
44 resolvconf = file('/etc/resolv.conf', 'w')
45 resolvconf.write("nameserver %d.%d.%d.%d" % tuple(ip))
48 def setMACAddress(self, mac):
49 #os.system("echo ifconfig eth0 ether %02x:%02x:%02x:%02x:%02x:%02x" % tuple(mac))
52 def setIPAddress(self, ip):
53 os.system("echo ifconfig eth0 %d.%d.%d.%d" % tuple(ip))
54 self.writeNetworkConfig()
56 def setGateway(self, ip):
57 os.system("echo route add default gw %d.%d.%d.%d" % tuple(ip))
58 self.writeNetworkConfig()
60 def setNetmask(self, ip):
61 os.system("echo ifconfig eth0 netmask %d.%d.%d.%d" % tuple(ip))
62 self.writeNetworkConfig()
65 ipstr = gethostbyname(gethostname()).split('.')
70 config.network = ConfigSubsection()
71 config.network.dhcp = configElement_nonSave("config.network.dhcp", configSelection, 1, ("no", "yes"))
72 config.network.ip = configElement_nonSave("config.network.ip", configSequence, ip, (("."), (1,255)))
73 config.network.netmask = configElement_nonSave("config.network.netmask", configSequence, [255,255,255,0], (("."), (1,255)))
74 config.network.gateway = configElement_nonSave("config.network.gateway", configSequence, [192,168,1,3], (("."), (1,255)))
75 config.network.dns = configElement_nonSave("config.network.dns", configSequence, [192,168,1,3], (("."), (1,255)))
76 config.network.mac = configElement_nonSave("config.network.mac", configSequence, [00,11,22,33,44,55], ((":"), (1,255)))
78 #FIXME using this till other concept for this is implemented
79 #config.network.activate = configElement("config.network.activate", configSelection, 0, ("yes, sir", "you are my hero"))
80 #config.network.activate = configElement("config.network.activate", configSelection, 0, ("yes", "you are my hero"))
84 def writeNetworkConfig(configElement):
85 iNetwork.writeNetworkConfig()
87 def setIPAddress(configElement):
88 iNetwork.setIPAddress(configElement.value)
90 def setGateway(configElement):
91 iNetwork.setGateway(configElement.value)
93 def setNetmask(configElement):
94 iNetwork.setNetmask(configElement.value)
96 def setDHCP(configElement):
97 iNetwork.setDHCP(configElement.value)
99 def setIPNameserver(configElement):
100 iNetwork.setIPNameserver(configElement.value)
102 def setMACAddress(configElement):
103 iNetwork.setMACAddress(configElement.value)
106 # this will call the "setup-val" initial
107 config.network.dhcp.addNotifier(setDHCP)
108 config.network.ip.addNotifier(setIPAddress)
109 config.network.netmask.addNotifier(setNetmask)
110 config.network.gateway.addNotifier(setGateway)
111 config.network.dns.addNotifier(setIPNameserver)
112 config.network.mac.addNotifier(setMACAddress)