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
22 def __init__(self, vars):
24 def call(self, func, *args):
25 BootAPI.call_api_function(self.vars, func, args)
26 def __getattr__(self, func):
27 return lambda *args: self.call(func, *args)
30 def __init__(self, log):
32 def log(self, msg, level=3):
33 self._log.write(msg + "\n")
34 def verbose(self, msg):
39 Write out the network configuration for this machine:
41 /etc/sysconfig/network-scripts/ifcfg-eth0
42 /etc/resolv.conf (if applicable)
43 /etc/sysconfig/network
45 The values to be used for the network settings are to be set in vars
46 in the variable 'NETWORK_SETTINGS', which is a dictionary
49 Key Used by this function
50 -----------------------------------------------
65 Expect the following variables from the store:
66 SYSIMG_PATH the path where the system image will be mounted
67 (always starts with TEMP_PATH)
68 NETWORK_SETTINGS A dictionary of the values from the network
70 NODE_NETWORKS All the network associated with this node
71 Sets the following variables:
75 log.write( "\n\nStep: Install: Writing Network Configuration files.\n" )
78 SYSIMG_PATH= vars["SYSIMG_PATH"]
80 raise ValueError, "SYSIMG_PATH"
83 raise BootManagerException, "Missing variable in vars: %s\n" % var
84 except ValueError, var:
85 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
89 network_settings= vars['NETWORK_SETTINGS']
91 raise BootManagerException, "No network settings found in vars."
94 hostname= network_settings['hostname']
95 domainname= network_settings['domainname']
96 method= network_settings['method']
97 ip= network_settings['ip']
98 gateway= network_settings['gateway']
99 network= network_settings['network']
100 netmask= network_settings['netmask']
101 dns1= network_settings['dns1']
102 mac= network_settings['mac']
104 raise BootManagerException, "Missing value %s in network settings." % str(e)
108 dns2= network_settings['dns2']
113 # Node Manager needs at least PLC_API_HOST and PLC_BOOT_HOST
114 log.write("Writing /etc/planetlab/plc_config\n")
115 utils.makedirs("%s/etc/planetlab" % SYSIMG_PATH)
116 plc_config = file("%s/etc/planetlab/plc_config" % SYSIMG_PATH, "w")
118 api_url = vars['BOOT_API_SERVER']
119 (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(api_url)
120 parts = netloc.split(':')
127 log.write("getting via https://%s/PlanetLabConf/get_plc_config.php" % host)
128 bootserver = httplib.HTTPSConnection(host, int(port))
130 bootserver.request("GET","https://%s/PlanetLabConf/get_plc_config.php" % host)
131 plc_config.write("%s" % bootserver.getresponse().read())
134 log.write("Failed. Using old method.")
135 bs= BootServerRequest.BootServerRequest()
136 if bs.BOOTSERVER_CERTS:
137 print >> plc_config, "PLC_BOOT_HOST='%s'" % bs.BOOTSERVER_CERTS.keys()[0]
138 print >> plc_config, "PLC_API_HOST='%s'" % host
139 print >> plc_config, "PLC_API_PORT='%s'" % port
140 print >> plc_config, "PLC_API_PATH='%s'" % path
145 log.write( "Writing /etc/hosts\n" )
146 hosts_file= file("%s/etc/hosts" % SYSIMG_PATH, "w" )
147 hosts_file.write( "127.0.0.1 localhost\n" )
148 if method == "static":
149 hosts_file.write( "%s %s.%s\n" % (ip, hostname, domainname) )
153 data = {'hostname': '%s.%s' % (hostname, domainname),
154 'networks': vars['NODE_NETWORKS']}
155 plnet.InitInterfaces(logger(log), BootAPIWrap(vars), data, SYSIMG_PATH,