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")
83 except KeyError as var:
84 raise BootManagerException("Missing variable in vars: {}\n".format(var))
85 except ValueError as var:
86 raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(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']
104 except KeyError as e:
105 raise BootManagerException("Missing value {} in interface settings.".format(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("{}/etc/planetlab".format(SYSIMG_PATH))
113 with open("{}/etc/planetlab/plc_config".format(SYSIMG_PATH), "w") as plc_config:
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://{}/PlanetLabConf/get_plc_config.php ".format(host))
125 bootserver = httplib.HTTPSConnection(host, int(port))
127 bootserver.request("GET","https://{}/PlanetLabConf/get_plc_config.php".format(host))
128 plc_config.write("{}".format(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 plc_config.write("PLC_BOOT_HOST='{}'\n".format(bs.BOOTSERVER_CERTS.keys()[0]))
137 plc_config.write("PLC_API_HOST='{}'\n".format(host))
138 plc_config.write("PLC_API_PORT='{}'\n".format(port))
139 plc_config.write("PLC_API_PATH='{}'\n".format(path))
141 log.write("Writing /etc/hosts\n")
142 with open("{}/etc/hosts".format(SYSIMG_PATH), "w") as hosts_file:
143 hosts_file.write("127.0.0.1 localhost\n")
144 if method == "static":
145 hosts_file.write("{} {}.{}\n".format(ip, hostname, domainname))
147 data = {'hostname': '{}.{}'.format(hostname, domainname),
148 'networks': vars['INTERFACES']}
149 plnet.InitInterfaces(logger(log), BootAPIWrap(vars), data, SYSIMG_PATH,