4 # Copyright (c) 2003 Intel Corporation
7 # Copyright (c) 2004-2006 The Trustees of Princeton University
9 # expected /proc/partitions format
18 from Exceptions import *
19 import BootServerRequest
25 def __init__(self, vars):
27 def call(self, func, *args):
28 return BootAPI.call_api_function(self.vars, func, args)
29 def __getattr__(self, func):
30 return lambda *args: self.call(func, *args)
33 def __init__(self, log):
35 def log(self, msg, level=3):
36 self._log.write(msg + "\n")
37 def verbose(self, msg):
42 Write out the network configuration for this machine:
44 /etc/sysconfig/network-scripts/ifcfg-<ifname>
45 /etc/resolv.conf (if applicable)
46 /etc/sysconfig/network
48 The values to be used for the network settings are to be set in vars
49 in the variable 'INTERFACE_SETTINGS', which is a dictionary
52 Key Used by this function
53 -----------------------------------------------
68 Expect the following variables from the store:
69 SYSIMG_PATH the path where the system image will be mounted
70 (always starts with TEMP_PATH)
71 INTERFACES All the interfaces associated with this node
72 INTERFACE_SETTINGS dictionary
73 Sets the following variables:
77 log.write( "\n\nStep: Install: Writing Network Configuration files.\n" )
80 SYSIMG_PATH= vars["SYSIMG_PATH"]
82 raise ValueError, "SYSIMG_PATH"
85 raise BootManagerException, "Missing variable in vars: %s\n" % var
86 except ValueError, var:
87 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
91 INTERFACE_SETTINGS= vars['INTERFACE_SETTINGS']
93 raise BootManagerException, "No interface settings found in vars."
96 hostname= INTERFACE_SETTINGS['hostname']
97 domainname= INTERFACE_SETTINGS['domainname']
98 method= INTERFACE_SETTINGS['method']
99 ip= INTERFACE_SETTINGS['ip']
100 gateway= INTERFACE_SETTINGS['gateway']
101 network= INTERFACE_SETTINGS['network']
102 netmask= INTERFACE_SETTINGS['netmask']
103 dns1= INTERFACE_SETTINGS['dns1']
104 mac= INTERFACE_SETTINGS['mac']
106 raise BootManagerException, "Missing value %s in interface settings." % str(e)
108 # dns2 is not required to be set
109 dns2 = INTERFACE_SETTINGS.get('dns2','')
111 # Node Manager needs at least PLC_API_HOST and PLC_BOOT_HOST
112 log.write("Writing /etc/planetlab/plc_config\n")
113 utils.makedirs("%s/etc/planetlab" % SYSIMG_PATH)
114 plc_config = file("%s/etc/planetlab/plc_config" % SYSIMG_PATH, "w")
116 api_url = vars['BOOT_API_SERVER']
117 (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(api_url)
118 parts = netloc.split(':')
125 log.write("getting via https://%s/PlanetLabConf/get_plc_config.php " % host)
126 bootserver = httplib.HTTPSConnection(host, int(port))
128 bootserver.request("GET","https://%s/PlanetLabConf/get_plc_config.php" % host)
129 plc_config.write("%s" % bootserver.getresponse().read())
133 log.write(" .. Failed. Using old method. -- stack trace follows\n")
134 traceback.print_exc(file=log.OutputFile)
135 bs= BootServerRequest.BootServerRequest(vars)
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['INTERFACES']}
155 plnet.InitInterfaces(logger(log), BootAPIWrap(vars), data, SYSIMG_PATH,