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):
42 resolvconf = file('/etc/resolv.conf', 'w')
43 resolvconf.write("nameserver %d.%d.%d.%d" % tuple(ip))
46 def setMACAddress(self, mac):
47 os.system("echo ifconfig eth0 ether %02x:%02x:%02x:%02x:%02x:%02x" % tuple(mac))
49 def setIPAddress(self, ip):
50 os.system("echo ifconfig eth0 %d.%d.%d.%d" % tuple(ip))
51 self.writeNetworkConfig()
53 def setGateway(self, ip):
54 os.system("echo route add default gw %d.%d.%d.%d" % tuple(ip))
55 self.writeNetworkConfig()
57 def setNetmask(self, ip):
58 os.system("echo ifconfig eth0 netmask %d.%d.%d.%d" % tuple(ip))
59 self.writeNetworkConfig()
62 config.network = ConfigSubsection()
63 config.network.dhcp = configElement("config.network.dhcp", configSelection, 0, ("no", "yes"))
64 config.network.ip = configElement("config.network.ip", configSequence, [192,168,1,45], (("."), (1,255)))
65 config.network.netmask = configElement("config.network.netmask", configSequence, [255,255,255,0], (("."), (1,255)))
66 config.network.gateway = configElement("config.network.gateway", configSequence, [192,168,1,3], (("."), (1,255)))
67 config.network.dns = configElement("config.network.dns", configSequence, [192,168,1,3], (("."), (1,255)))
68 config.network.mac = configElement("config.network.mac", configSequence, [00,11,22,33,44,55], ((":"), (1,255)))
70 #FIXME using this till other concept for this is implemented
71 config.network.activate = configElement("config.network.activate", configSelection, 0, ("yes, sir", "you are my hero"))
75 def writeNetworkConfig(configElement):
76 iNetwork.writeNetworkConfig()
78 def setIPAddress(configElement):
79 iNetwork.setIPAddress(configElement.value)
81 def setGateway(configElement):
82 iNetwork.setGateway(configElement.value)
84 def setNetmask(configElement):
85 iNetwork.setNetmask(configElement.value)
87 def setDHCP(configElement):
88 iNetwork.setDHCP(configElement.value)
90 def setIPNameserver(configElement):
91 iNetwork.setIPNameserver(configElement.value)
93 def setMACAddress(configElement):
94 iNetwork.setMACAddress(configElement.value)
96 def activateNetworkConfig(configElement):
97 iNetwork.activateNetworkConfig()
100 # this will call the "setup-val" initial
101 config.network.dhcp.addNotifier(setDHCP)
102 config.network.ip.addNotifier(setIPAddress)
103 config.network.netmask.addNotifier(setNetmask)
104 config.network.gateway.addNotifier(setGateway)
105 config.network.dns.addNotifier(setIPNameserver)
106 config.network.mac.addNotifier(setMACAddress)
107 config.network.activate.addNotifier(activateNetworkConfig)