3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
8 # expected /proc/partitions format
17 from Exceptions import *
18 import BootServerRequest
24 def __init__(self, vars):
26 def call(self, func, *args):
27 return BootAPI.call_api_function(self.vars, func, args)
28 def __getattr__(self, func):
29 return lambda *args: self.call(func, *args)
32 def __init__(self, log):
34 def log(self, msg, level=3):
35 self._log.write(msg + "\n")
36 def verbose(self, msg):
41 Write out the network configuration for this machine:
43 /etc/sysconfig/network-scripts/ifcfg-<ifname>
44 /etc/resolv.conf (if applicable)
45 /etc/sysconfig/network
47 The values to be used for the network settings are to be set in vars
48 in the variable 'INTERFACE_SETTINGS', which is a dictionary
51 Key Used by this function
52 -----------------------------------------------
67 Expect the following variables from the store:
68 SYSIMG_PATH the path where the system image will be mounted
69 (always starts with TEMP_PATH)
70 INTERFACES All the interfaces associated with this node
71 INTERFACE_SETTINGS dictionary
72 Sets the following variables:
76 log.write( "\n\nStep: Install: Writing Network Configuration files.\n" )
79 SYSIMG_PATH= vars["SYSIMG_PATH"]
81 raise ValueError, "SYSIMG_PATH"
84 raise BootManagerException, "Missing variable in vars: %s\n" % var
85 except ValueError, var:
86 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
90 INTERFACE_SETTINGS= vars['INTERFACE_SETTINGS']
92 raise BootManagerException, "No interface settings found in vars."
95 hostname= INTERFACE_SETTINGS['hostname']
96 domainname= INTERFACE_SETTINGS['domainname']
97 method= INTERFACE_SETTINGS['method']
98 ip= INTERFACE_SETTINGS['ip']
99 gateway= INTERFACE_SETTINGS['gateway']
100 network= INTERFACE_SETTINGS['network']
101 netmask= INTERFACE_SETTINGS['netmask']
102 dns1= INTERFACE_SETTINGS['dns1']
103 mac= INTERFACE_SETTINGS['mac']
105 raise BootManagerException, "Missing value %s in interface settings." % str(e)
107 # dns2 is not required to be set
108 dns2 = INTERFACE_SETTINGS.get('dns2','')
110 # Node Manager needs at least PLC_API_HOST and PLC_BOOT_HOST
111 log.write("Writing /etc/planetlab/plc_config\n")
112 utils.makedirs("%s/etc/planetlab" % SYSIMG_PATH)
113 plc_config = file("%s/etc/planetlab/plc_config" % SYSIMG_PATH, "w")
115 api_url = vars['BOOT_API_SERVER']
116 (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(api_url)
117 parts = netloc.split(':')
124 log.write("getting via https://%s/PlanetLabConf/get_plc_config.php " % host)
125 bootserver = httplib.HTTPSConnection(host, int(port))
127 bootserver.request("GET","https://%s/PlanetLabConf/get_plc_config.php" % host)
128 plc_config.write("%s" % bootserver.getresponse().read())
132 log.write(" .. Failed. Using old method. -- stack trace follows\n")
133 traceback.print_exc(file=log.OutputFile)
134 bs= BootServerRequest.BootServerRequest(vars)
135 if bs.BOOTSERVER_CERTS:
136 print >> plc_config, "PLC_BOOT_HOST='%s'" % bs.BOOTSERVER_CERTS.keys()[0]
137 print >> plc_config, "PLC_API_HOST='%s'" % host
138 print >> plc_config, "PLC_API_PORT='%s'" % port
139 print >> plc_config, "PLC_API_PATH='%s'" % path
144 log.write( "Writing /etc/hosts\n" )
145 hosts_file= file("%s/etc/hosts" % SYSIMG_PATH, "w" )
146 hosts_file.write( "127.0.0.1 localhost\n" )
147 if method == "static":
148 hosts_file.write( "%s %s.%s\n" % (ip, hostname, domainname) )
152 data = {'hostname': '%s.%s' % (hostname, domainname),
153 'networks': vars['INTERFACES']}
154 plnet.InitInterfaces(logger(log), BootAPIWrap(vars), data, SYSIMG_PATH,