From b5dd66ff03e520b6ed29658d7c978b87d3643d0d Mon Sep 17 00:00:00 2001
From: jbjohnso <jbjohnso@8638fb3e-16cb-4fca-ae20-7b5d299a9bcd>
Date: Sat, 21 Feb 2009 14:25:06 +0000
Subject: [PATCH] -Speed up nodestat -Additionally, provide list of all known
 detected states rather than making value judgements as to what is most
 important

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2792 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
---
 xCAT-server/lib/xcat/plugins/nodestat.pm | 58 ++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/xCAT-server/lib/xcat/plugins/nodestat.pm b/xCAT-server/lib/xcat/plugins/nodestat.pm
index 94017910d..ef70e8652 100644
--- a/xCAT-server/lib/xcat/plugins/nodestat.pm
+++ b/xCAT-server/lib/xcat/plugins/nodestat.pm
@@ -130,12 +130,66 @@ sub preprocess_request
     return \@requests;
 }
 
+sub interrogate_node { #Meant to run against confirmed up nodes
+    my $node=shift;
+    my $doreq=shift;
+    my $status = "";
+    if (nodesockopen($node,15002)) {
+        $status.="pbs,"
+    }
+    if (nodesockopen($node,8002)) {
+        $status.="xend,"
+    }
+    if (nodesockopen($node,22)) {
+        $status.="sshd,"
+    }
+    $status =~ s/,$//;
+    if ($status) {
+        return $status;
+    }
+    if ($status = installer_query($node)) {
+        return  $status;
+    } else { #pingable, but no *clue* as to what the state may be
+         $doreq->({command=>['nodeset'],
+                  node=>[$node],
+                  arg=>['stat']},
+                  \&getstat);
+         return 'ping '.$stat;
+     }
+}
+
 sub process_request {
    my $request = shift;
    my $callback = shift;
    my $doreq = shift;
    my @nodes = @{$request->{node}};
+   my %unknownnodes;
+   foreach (@nodes) {
+	$unknownnodes{$_}=1;
+   }
    my $node;
+   my $fping;
+   open($fping,"fping ".join(' ',@nodes). " 2> /dev/null|") or die("Can't start fping: $!");
+   while (<$fping>) {
+      my %rsp;
+      my $node=$_;
+      $node =~ s/ .*//;
+      chomp $node;
+       if (/ is alive/) {
+           $rsp{name}=[$node];
+           $rsp{data} = [ interrogate_node($node,$doreq) ];
+           $callback->({node=>[\%rsp]});
+       } elsif (/is unreachable/) {
+         $rsp{name}=[$node];
+         $rsp{data} = [ 'noping' ];
+         $callback->({node=>[\%rsp]});
+       } elsif (/ address not found/) {
+         $rsp{name}=[$node];
+         $rsp{data} = [ 'nosuchhost' ];
+         $callback->({node=>[\%rsp]});
+       }
+    }
+    @nodes=();
    foreach $node (@nodes) {
       my %rsp;
       my $text="";
@@ -149,6 +203,10 @@ sub process_request {
          $rsp{data} = [ 'pbs' ];
          $callback->({node=>[\%rsp]});
          next;
+      } elsif (nodesockopen($node,8002)) {
+         $rsp{data} = [ 'xend' ];
+         $callback->({node=>[\%rsp]});
+         next;
       } elsif (nodesockopen($node,22)) {
          $rsp{data} = [ 'sshd' ];
          $callback->({node=>[\%rsp]});