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
20 Write out the network configuration for this machine:
22 /etc/sysconfig/network-scripts/ifcfg-eth0
23 /etc/resolv.conf (if applicable)
24 /etc/sysconfig/network
26 The values to be used for the network settings are to be set in vars
27 in the variable 'NETWORK_SETTINGS', which is a dictionary
30 Key Used by this function
31 -----------------------------------------------
46 Expect the following variables from the store:
47 SYSIMG_PATH the path where the system image will be mounted
48 (always starts with TEMP_PATH)
49 NETWORK_SETTINGS A dictionary of the values from the network
51 Sets the following variables:
55 log.write( "\n\nStep: Install: Writing Network Configuration files.\n" )
58 SYSIMG_PATH= vars["SYSIMG_PATH"]
60 raise ValueError, "SYSIMG_PATH"
63 raise BootManagerException, "Missing variable in vars: %s\n" % var
64 except ValueError, var:
65 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
69 network_settings= vars['NETWORK_SETTINGS']
71 raise BootManagerException, "No network settings found in vars."
74 hostname= network_settings['hostname']
75 domainname= network_settings['domainname']
76 method= network_settings['method']
77 ip= network_settings['ip']
78 gateway= network_settings['gateway']
79 network= network_settings['network']
80 netmask= network_settings['netmask']
81 dns1= network_settings['dns1']
82 mac= network_settings['mac']
84 raise BootManagerException, "Missing value %s in network settings." % str(e)
88 dns2= network_settings['dns2']
93 # Node Manager needs at least PLC_API_HOST and PLC_BOOT_HOST
94 log.write("Writing /etc/planetlab/plc_config\n")
95 utils.makedirs("%s/etc/planetlab" % SYSIMG_PATH)
96 plc_config = file("%s/etc/planetlab/plc_config" % SYSIMG_PATH, "w")
98 bs= BootServerRequest.BootServerRequest()
99 if bs.BOOTSERVER_CERTS:
100 print >> plc_config, "PLC_BOOT_HOST='%s'" % bs.BOOTSERVER_CERTS.keys()[0]
102 api_url = vars['BOOT_API_SERVER']
103 (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(api_url)
104 parts = netloc.split(':')
110 print >> plc_config, "PLC_API_HOST='%s'" % host
111 print >> plc_config, "PLC_API_PORT='%s'" % port
112 print >> plc_config, "PLC_API_PATH='%s'" % path
117 log.write( "Writing /etc/hosts\n" )
118 hosts_file= file("%s/etc/hosts" % SYSIMG_PATH, "w" )
119 hosts_file.write( "127.0.0.1 localhost\n" )
120 if method == "static":
121 hosts_file.write( "%s %s.%s\n" % (ip, hostname, domainname) )
126 log.write( "Writing /etc/sysconfig/network-scripts/ifcfg-eth0\n" )
127 eth0_file= file("%s/etc/sysconfig/network-scripts/ifcfg-eth0" %
129 eth0_file.write( "DEVICE=eth0\n" )
130 if method == "static":
131 eth0_file.write( "BOOTPROTO=static\n" )
132 eth0_file.write( "IPADDR=%s\n" % ip )
133 eth0_file.write( "NETMASK=%s\n" % netmask )
134 eth0_file.write( "GATEWAY=%s\n" % gateway )
136 eth0_file.write( "BOOTPROTO=dhcp\n" )
137 eth0_file.write( "DHCP_HOSTNAME=%s\n" % hostname )
139 eth0_file.write( "HWADDR=%s\n" % mac )
140 eth0_file.write( "ONBOOT=yes\n" )
141 eth0_file.write( "USERCTL=no\n" )
145 if method == "static":
146 log.write( "Writing /etc/resolv.conf\n" )
147 resolv_file= file("%s/etc/resolv.conf" % SYSIMG_PATH, "w" )
149 resolv_file.write( "nameserver %s\n" % dns1 )
151 resolv_file.write( "nameserver %s\n" % dns2 )
152 resolv_file.write( "search %s\n" % domainname )
156 log.write( "Writing /etc/sysconfig/network\n" )
157 network_file= file("%s/etc/sysconfig/network" % SYSIMG_PATH, "w" )
158 network_file.write( "NETWORKING=yes\n" )
159 network_file.write( "HOSTNAME=%s.%s\n" % (hostname, domainname) )
160 if method == "static":
161 network_file.write( "GATEWAY=%s\n" % gateway )