-#!/usr/bin/python
+#!/usr/bin/env /usr/bin/plcsh
#
# Writes IP addresses and hostnames of PlanetLab nodes to
# /etc/plc_hosts. Useful for dnsmasq, specify "addn-hosts
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: api-config,v 1.10 2006/05/24 03:08:55 mlhuang Exp $
+# $Id$
#
-import plcapilib
-(plcapi, moreopts, argv) = plcapilib.plcapi(globals())
from plc_config import PLCConfiguration
import os, sys
# Get the primary IP address for each node
hosts = {}
- nodes = AdmGetNodes([], ['node_id', 'hostname'])
- plcapi.begin()
- for node in nodes:
- AdmGetAllNodeNetworks(node['node_id'])
- nodenetworks_list = plcapi.commit()
- if nodenetworks_list is not None:
- 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]
+
+ nodes = {}
+ for node in GetNodes():
+ nodes[node['node_id']] = node
+
+ interface_ids = set()
+ for node in nodes.values():
+ interface_ids.update(node['interface_ids'])
+
+ for interface in GetInterfaces(list(interface_ids)):
+ if not interface['ip']:
+ continue
+
+ if interface['hostname']:
+ hostname = interface['hostname']
+ else:
+ hostname = nodes[interface['node_id']]['hostname']
+
+ if hosts.has_key(interface['ip']):
+ if hostname not in hosts[interface['ip']]:
+ hosts[interface['ip']].append(hostname)
+ else:
+ hosts[interface['ip']] = [hostname]
# Write /etc/plc_hosts
plc_hosts = open("/etc/plc_hosts", "w")
+ plc_hosts.write("# DO NOT EDIT; File is writen and removed by automatic scripts\n")
for ip, hostnames in hosts.iteritems():
plc_hosts.write(ip + "\t" + " ".join(hostnames) + "\n")
plc_hosts.close()
domain-needed
bogus-priv
addn-hosts=/etc/plc_hosts
+resolv-file=/etc/resolv.conf
""".lstrip())
# Reload dnsmasq