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