From: Mark Huang Date: Fri, 19 May 2006 22:22:15 +0000 (+0000) Subject: - write all nodes' IP addresses into /etc/hosts in preparation for X-Git-Tag: myplc-0_4-rc1~31 X-Git-Url: http://git.onelab.eu/?p=myplc.git;a=commitdiff_plain;h=490e47f745d02879fd7744ad7e66f17aa23ff8ca - write all nodes' IP addresses into /etc/hosts in preparation for dnsmasq support --- diff --git a/api-config b/api-config index ff38b79..955afc1 100755 --- a/api-config +++ b/api-config @@ -6,7 +6,7 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: api-config,v 1.6 2006/05/02 15:09:08 mlhuang Exp $ +# $Id: api-config,v 1.7 2006/05/09 19:52:01 mlhuang Exp $ # import plcapilib @@ -94,6 +94,40 @@ def main(): AdmGrantRoleToPerson(admin['person_id'], 10) AdmGrantRoleToPerson(admin['person_id'], 20) + # Read and parse /etc/hosts + hosts = {} + for line in file("/etc/hosts"): + line = line.strip() + words = line.split() + if len(words) > 1 and words[0] != "#": + hosts[words[0]] = words[1:] + + nodes = AdmGetNodes([], ['node_id', 'hostname']) + + # Get the primary IP address for each node + plcapi.begin() + for node in nodes: + AdmGetAllNodeNetworks(node['node_id']) + nodenetworks_list = plcapi.commit() + for i, nodenetworks in enumerate(nodenetworks_list): + for nodenetwork in nodenetworks: + if nodenetwork['hostname']: + hostname = nodenetwork['hostname'] + else: + hostname = nodes[i]['hostname'] + + if hosts.has_key(nodenetwork['ip']): + if hostname not in hosts[nodenetwork['ip']]: + hosts[nodenetwork['ip']].append(hostname) + else: + hosts[nodenetwork['ip']] = [hostname] + + # Rewrite /etc/hosts + etc_hosts = open("/etc/hosts", "w") + for ip, hostnames in hosts.iteritems(): + etc_hosts.write(ip + "\t" + " ".join(hostnames) + "\n") + etc_hosts.close() + # Setup default PlanetLabConf entries default_conf_files = [ # NTP configuration @@ -196,7 +230,7 @@ def main(): # YUM configuration {'enabled': 1, - 'source': 'PlanetLabConf/yum.conf.php', + 'source': 'PlanetLabConf/yum.conf.php?gpgcheck=1', 'dest': '/etc/yum.conf', 'file_permissions': '644', 'file_owner': 'root',