From ad7dcb64356a8dd10efab3d7e178443bfe5dcecc Mon Sep 17 00:00:00 2001
From: Robert Ricci <ricci@cs.utah.edu>
Date: Thu, 7 Dec 2006 00:27:14 +0000
Subject: [PATCH] Fix so that this script should work correctly if any of the
 planet-* nodes have been removed from the topology.

---
 pelab/monitor/gen-ip-mapping.pl | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/pelab/monitor/gen-ip-mapping.pl b/pelab/monitor/gen-ip-mapping.pl
index c82ef522a9..ceb7d215c4 100644
--- a/pelab/monitor/gen-ip-mapping.pl
+++ b/pelab/monitor/gen-ip-mapping.pl
@@ -15,7 +15,7 @@ my %opt;
 getopts('p',\%opt);
 
 use strict;
-my (%elabips, %plabips);
+my (%elabips, %plabips, %planetnodes);
 
 open(HOSTS,"/etc/hosts") or die "Unable to open /etc/hosts: $!\n";
 
@@ -26,6 +26,10 @@ while (<HOSTS>) {
         $elabips{$1} = $IP;
     } elsif ($firstname =~ /^(.+)-(plink|plan|pcloud|plabc)$/) {
         $plabips{$1} = $IP;
+    } elsif ($firstname =~ /^(.+)-realinternet$/) {
+        # Note - we don't really get the planetlab node's IP address in the
+        # hosts file, so we just use this to find out if the node exists at all
+        $planetnodes{$1} = 1;
     }
 }
 
@@ -47,11 +51,18 @@ foreach my $elabnode (keys %elabips) {
         print "$elabips{$elabnode} $plabips{$planetnode} elabc-$elabnode\n";
         $lines_output++;
     } else {
+        # If there is not a corresponding planet-* node in the hosts file, it
+        # has probably been removed from the experiment, and we should skip ip
+        my $plabnode = $elabnode;
+        $plabnode =~ s/^elab/planet/;
+        if (! exists($planetnodes{$plabnode})){
+            warn "Skipping $plabnode, which doesn't exist\n";
+            next;
+        }
         # Let's hope this is an experiment with a real (not emulated) planetlab
         # half. Note - this should be run by something that has sourced
-        # common-env.sh so that these are set
-        my $plabhostname = "$elabnode.$ENV{EXPERIMENT}.$ENV{PROJECT}.emulab.net";
-        $plabhostname =~ s/^elab/planet/;
+        # common-env.sh so that these enviroment variables are set
+        my $plabhostname = "$plabnode.$ENV{EXPERIMENT}.$ENV{PROJECT}.emulab.net";
         # Find out the IP address for $plabhostname
         open(H,"host $plabhostname |") or die "Unable to run host\n";
         # Yuck. Why can't 'host' have a flag to spit out just the IP?
-- 
GitLab