3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
8 # expected /proc/partitions format
12 from Exceptions import *
14 import BootServerRequest
21 Write out the network configuration for this machine:
23 /etc/sysconfig/network-scripts/ifcfg-eth0
24 /etc/resolv.conf (if applicable)
25 /etc/sysconfig/network
27 The values to be used for the network settings are to be set in vars
28 in the variable 'NETWORK_SETTINGS', which is a dictionary
31 Key Used by this function
32 -----------------------------------------------
47 Expect the following variables from the store:
48 SYSIMG_PATH the path where the system image will be mounted
49 (always starts with TEMP_PATH)
50 NETWORK_SETTINGS A dictionary of the values from the network
52 NODE_NETWORKS All the network associated with this node
53 Sets the following variables:
57 log.write( "\n\nStep: Install: Writing Network Configuration files.\n" )
60 SYSIMG_PATH= vars["SYSIMG_PATH"]
62 raise ValueError, "SYSIMG_PATH"
65 raise BootManagerException, "Missing variable in vars: %s\n" % var
66 except ValueError, var:
67 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
71 network_settings= vars['NETWORK_SETTINGS']
73 raise BootManagerException, "No network settings found in vars."
76 hostname= network_settings['hostname']
77 domainname= network_settings['domainname']
78 method= network_settings['method']
79 ip= network_settings['ip']
80 gateway= network_settings['gateway']
81 network= network_settings['network']
82 netmask= network_settings['netmask']
83 dns1= network_settings['dns1']
84 mac= network_settings['mac']
86 raise BootManagerException, "Missing value %s in network settings." % str(e)
90 dns2= network_settings['dns2']
95 # Node Manager needs at least PLC_API_HOST and PLC_BOOT_HOST
96 log.write("Writing /etc/planetlab/plc_config\n")
97 utils.makedirs("%s/etc/planetlab" % SYSIMG_PATH)
98 plc_config = file("%s/etc/planetlab/plc_config" % SYSIMG_PATH, "w")
100 bs= BootServerRequest.BootServerRequest()
101 if bs.BOOTSERVER_CERTS:
102 print >> plc_config, "PLC_BOOT_HOST='%s'" % bs.BOOTSERVER_CERTS.keys()[0]
104 api_url = vars['BOOT_API_SERVER']
105 (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(api_url)
106 parts = netloc.split(':')
112 print >> plc_config, "PLC_API_HOST='%s'" % host
113 print >> plc_config, "PLC_API_PORT='%s'" % port
114 print >> plc_config, "PLC_API_PATH='%s'" % path
119 log.write( "Writing /etc/hosts\n" )
120 hosts_file= file("%s/etc/hosts" % SYSIMG_PATH, "w" )
121 hosts_file.write( "127.0.0.1 localhost\n" )
122 if method == "static":
123 hosts_file.write( "%s %s.%s\n" % (ip, hostname, domainname) )
128 if method == "static":
129 log.write( "Writing /etc/resolv.conf\n" )
130 resolv_file= file("%s/etc/resolv.conf" % SYSIMG_PATH, "w" )
132 resolv_file.write( "nameserver %s\n" % dns1 )
134 resolv_file.write( "nameserver %s\n" % dns2 )
135 resolv_file.write( "search %s\n" % domainname )
139 log.write( "Writing /etc/sysconfig/network\n" )
140 network_file= file("%s/etc/sysconfig/network" % SYSIMG_PATH, "w" )
141 network_file.write( "NETWORKING=yes\n" )
142 network_file.write( "HOSTNAME=%s.%s\n" % (hostname, domainname) )
143 if method == "static":
144 network_file.write( "GATEWAY=%s\n" % gateway )
150 for network in vars['NODE_NETWORKS']:
151 if method == "static" or method == "dhcp":
152 if network['is_primary'] == 1:
160 int['HWADDR'] = network['mac']
162 if network['method'] == "static":
163 int['BOOTPROTO'] = "static"
164 int['IPADDR'] = network['ip']
165 int['NETMASK'] = network['netmask']
167 elif network['method'] == "dhcp":
168 int['BOOTPROTO'] = "dhcp"
169 if network['hostname']:
170 int['DHCP_HOSTNAME'] = network['hostname']
172 int['DHCP_HOSTNAME'] = hostname
173 if not network['is_primary']:
174 int['DHCLIENTARGS'] = "-R subnet-mask"
177 if len(network['nodenetwork_setting_ids']) > 0:
178 settings = BootAPI.call_api_function(vars, "GetNodeNetworkSettings",
179 ({'nodenetwork_setting_id': network['nodenetwork_setting_ids']},))
180 for setting in settings:
181 if setting['category'].upper() == "WLAN":
182 if setting['name'].upper() == "SSID":
183 int['ESSID'] = setting['value']
184 elif setting['name'].upper() == "IWCONFIG":
185 int['IWCONFIG'] = setting['value']
186 elif setting['name'].upper() == "MODE":
187 int['MODE'] = setting['value']
188 elif setting['category'].upper() == "MULTIHOME":
189 if setting['name'].upper() == "ALIAS":
190 alias = ":" + setting['value']
192 if alias and 'HWADDR' in int:
193 for (dev, i) in interfaces.iteritems():
194 if i['HWADDR'] == int['HWADDR']:
197 interfaces[dev + alias] = int
200 interfaces["eth%d" % ifnum] = int
202 for (dev, int) in interfaces.iteritems():
203 path = "%s/etc/sysconfig/network-scripts/ifcfg-%s" % (
206 log.write("Writing %s\n" % path.replace(SYSIMG_PATH, ""))
208 f.write("DEVICE=%s\n" % dev)
209 f.write("ONBOOT=yes\n")
210 f.write("USERCTL=no\n")
211 for (key, val) in int.iteritems():
212 f.write('%s="%s"\n' % (key, val))