# Mark Huang <mlhuang@cs.princeton.edu>
# 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
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
# 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',