- write all nodes' IP addresses into /etc/hosts in preparation for
authorMark Huang <mlhuang@cs.princeton.edu>
Fri, 19 May 2006 22:22:15 +0000 (22:22 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Fri, 19 May 2006 22:22:15 +0000 (22:22 +0000)
  dnsmasq support

api-config

index ff38b79..955afc1 100755 (executable)
@@ -6,7 +6,7 @@
 # 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
@@ -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',