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 It is assumed the caller mounted the root partition and the vserver partition
27 starting on SYSIMG_PATH - it is not checked here.
29 The values to be used for the network settings are to be set in vars
30 in the variable 'NETWORK_SETTINGS', which is a dictionary
33 Key Used by this function
34 -----------------------------------------------
49 Expect the following variables from the store:
50 SYSIMG_PATH the path where the system image will be mounted
51 (always starts with TEMP_PATH)
52 NETWORK_SETTINGS A dictionary of the values from the network
54 Sets the following variables:
58 log.write( "\n\nStep: Install: Writing Network Configuration files.\n" )
61 SYSIMG_PATH= vars["SYSIMG_PATH"]
63 raise ValueError, "SYSIMG_PATH"
66 raise BootManagerException, "Missing variable in vars: %s\n" % var
67 except ValueError, var:
68 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
72 network_settings= vars['NETWORK_SETTINGS']
74 raise BootManagerException, "No network settings found in vars."
77 hostname= network_settings['hostname']
78 domainname= network_settings['domainname']
79 method= network_settings['method']
80 ip= network_settings['ip']
81 gateway= network_settings['gateway']
82 network= network_settings['network']
83 netmask= network_settings['netmask']
84 dns1= network_settings['dns1']
85 mac= network_settings['mac']
87 raise BootManagerException, "Missing value %s in network settings." % str(e)
91 dns2= network_settings['dns2']
96 # Node Manager needs at least PLC_API_HOST and PLC_BOOT_HOST
97 log.write("Writing /etc/planetlab/plc_config\n")
98 utils.makedirs("%s/etc/planetlab" % SYSIMG_PATH)
99 plc_config = file("%s/etc/planetlab/plc_config" % SYSIMG_PATH, "w")
101 bs= BootServerRequest.BootServerRequest()
102 if bs.BOOTSERVER_CERTS:
103 print >> plc_config, "PLC_BOOT_HOST='%s'" % bs.BOOTSERVER_CERTS.keys()[0]
105 api_url = vars['BOOT_API_SERVER']
106 (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(api_url)
107 parts = netloc.split(':')
113 print >> plc_config, "PLC_API_HOST='%s'" % host
114 print >> plc_config, "PLC_API_PORT='%s'" % port
115 print >> plc_config, "PLC_API_PATH='%s'" % path
120 log.write( "Writing /etc/hosts\n" )
121 hosts_file= file("%s/etc/hosts" % SYSIMG_PATH, "w" )
122 hosts_file.write( "127.0.0.1 localhost\n" )
123 if method == "static":
124 hosts_file.write( "%s %s.%s\n" % (ip, hostname, domainname) )
129 log.write( "Writing /etc/sysconfig/network-scripts/ifcfg-eth0\n" )
130 eth0_file= file("%s/etc/sysconfig/network-scripts/ifcfg-eth0" %
132 eth0_file.write( "DEVICE=eth0\n" )
133 if method == "static":
134 eth0_file.write( "BOOTPROTO=static\n" )
135 eth0_file.write( "IPADDR=%s\n" % ip )
136 eth0_file.write( "NETMASK=%s\n" % netmask )
137 eth0_file.write( "GATEWAY=%s\n" % gateway )
139 eth0_file.write( "BOOTPROTO=dhcp\n" )
140 eth0_file.write( "DHCP_HOSTNAME=%s\n" % hostname )
142 eth0_file.write( "HWADDR=%s\n" % mac )
143 eth0_file.write( "ONBOOT=yes\n" )
144 eth0_file.write( "USERCTL=no\n" )
148 if method == "static":
149 log.write( "Writing /etc/resolv.conf\n" )
150 resolv_file= file("%s/etc/resolv.conf" % SYSIMG_PATH, "w" )
152 resolv_file.write( "nameserver %s\n" % dns1 )
154 resolv_file.write( "nameserver %s\n" % dns2 )
155 resolv_file.write( "search %s\n" % domainname )
159 log.write( "Writing /etc/sysconfig/network\n" )
160 network_file= file("%s/etc/sysconfig/network" % SYSIMG_PATH, "w" )
161 network_file.write( "NETWORKING=yes\n" )
162 network_file.write( "HOSTNAME=%s.%s\n" % (hostname, domainname) )
163 if method == "static":
164 network_file.write( "GATEWAY=%s\n" % gateway )