2008-10-21 18:23:18 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#Note, this ppping still frontends fping. I think it would be possible to write a perl equivalent, but
|
|
|
|
#I've not had the time. Net::Ping shows perl code I could see being adapted for a somewhat
|
|
|
|
#asynchronous ICMP ping (the tcp syn is interesting, but far too limited, and that is currently the only async
|
|
|
|
#method Net::Ping provides.
|
2009-08-11 20:29:13 +00:00
|
|
|
|
|
|
|
# This script starts with a noderange from the user, expands it using the
|
|
|
|
# xcat daemon, then sends a command to every node that can be pinged
|
|
|
|
# from the machine where it is run to ping all of the other nodes
|
|
|
|
# obtained from the user. It then prints out the result and exits.
|
2008-10-21 18:23:18 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
2009-08-11 20:29:13 +00:00
|
|
|
# XCATROOT must be set for this script to work
|
2008-10-21 18:23:18 +00:00
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
|
|
|
|
use IO::Socket::SSL;
|
|
|
|
use XML::Simple;
|
2009-08-11 20:29:13 +00:00
|
|
|
if ($^O =~ /^linux/i) {
|
|
|
|
$XML::Simple::PREFERRED_PARSER='XML::Parser';
|
|
|
|
}
|
2008-10-21 18:23:18 +00:00
|
|
|
use Data::Dumper;
|
|
|
|
use IO::Handle;
|
|
|
|
use IO::Select;
|
|
|
|
use xCAT::Utils;
|
|
|
|
use Getopt::Long;
|
|
|
|
my $interface;
|
2009-08-11 20:29:13 +00:00
|
|
|
my $DEBUG = 0;
|
|
|
|
my $VERBOSE = 0;
|
|
|
|
my $HIERARCHY = 0;
|
2008-10-21 18:23:18 +00:00
|
|
|
|
2009-08-11 20:29:13 +00:00
|
|
|
my $USAGE="Usage: ppping [-i|--interface interface] [-d|--debug] [-v|--verbose] [-s|--serial] noderange
|
2008-10-21 18:23:18 +00:00
|
|
|
ppping -h|--help
|
2009-08-11 20:29:13 +00:00
|
|
|
ppping -V|--version\n";
|
2008-10-21 18:23:18 +00:00
|
|
|
|
2009-08-11 20:29:13 +00:00
|
|
|
# Parse the options
|
2008-10-21 18:23:18 +00:00
|
|
|
if(!GetOptions(
|
|
|
|
'h|help' => \$::HELP,
|
2009-08-12 20:52:53 +00:00
|
|
|
'v|version' => \$::VERSION,
|
2008-10-21 18:23:18 +00:00
|
|
|
's|serial' => \$::SERIAL,
|
2009-08-11 20:29:13 +00:00
|
|
|
'd|debug' => \$DEBUG,
|
2009-08-12 20:52:53 +00:00
|
|
|
'V|verbose' => \$VERBOSE,
|
2009-08-11 20:29:13 +00:00
|
|
|
'H|hierarchical' => \$HIERARCHY,
|
2008-10-21 18:23:18 +00:00
|
|
|
'interface=s' => \$interface))
|
|
|
|
{
|
|
|
|
print "$USAGE";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($::HELP) { print "$USAGE"; exit 0}
|
|
|
|
if ($::VERSION) {print xCAT::Utils->Version() . "\n"; exit 0}
|
|
|
|
|
2009-08-11 20:29:13 +00:00
|
|
|
# A method to prefix and print debug information only if it is wanted.
|
|
|
|
sub debug {
|
|
|
|
$debug_text = shift;
|
|
|
|
if($DEBUG){
|
|
|
|
print("---$debug_text");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-21 18:23:18 +00:00
|
|
|
my $xcathost='localhost:3001';
|
|
|
|
if ($ENV{XCATHOST}) {
|
|
|
|
$xcathost=$ENV{XCATHOST};
|
|
|
|
}
|
|
|
|
|
|
|
|
unless (@ARGV) {
|
|
|
|
print "$USAGE";
|
|
|
|
exit 1;
|
|
|
|
}
|
2009-08-11 20:29:13 +00:00
|
|
|
|
|
|
|
## Connect to xcatd to expand a noderange
|
2008-10-21 18:23:18 +00:00
|
|
|
my $noderange = $ARGV[0];
|
|
|
|
my $client = IO::Socket::SSL->new(
|
|
|
|
PeerAddr=>$xcathost,
|
|
|
|
SSL_key_file=>$ENV{HOME}."/.xcat/client-cred.pem",
|
|
|
|
SSL_cert_file=>$ENV{HOME}."/.xcat/client-cred.pem",
|
|
|
|
SSL_ca_file => $ENV{HOME}."/.xcat/ca.pem",
|
|
|
|
SSL_use_cert => 1,
|
|
|
|
#SSL_verify_mode => 1,
|
|
|
|
);
|
|
|
|
die "Connection failure: $!\n" unless ($client);
|
|
|
|
my %cmdref = (command => 'noderange', noderange => $noderange);
|
2009-08-11 20:29:13 +00:00
|
|
|
# Request nodes from xcatd
|
|
|
|
debug("[start] - request nodes from xcatd\n");
|
2008-10-21 18:23:18 +00:00
|
|
|
$SIG{ALRM} = sub { die "No response getting noderange" };
|
|
|
|
alarm(15);
|
|
|
|
print $client XMLout(\%cmdref,RootName=>'xcatrequest', NoAttr=>1, KeyAttr => []);
|
|
|
|
alarm(15);
|
2009-08-11 20:29:13 +00:00
|
|
|
debug("[stop] - request nodes from xcatd\n");
|
|
|
|
|
|
|
|
## Recieve nodes from xcatd and place them in @nodes
|
2008-10-21 18:23:18 +00:00
|
|
|
my $response="";
|
|
|
|
my @nodes=();
|
2009-08-11 20:29:13 +00:00
|
|
|
debug("[start] - recieve nodes from xcatd\n");
|
2008-10-21 18:23:18 +00:00
|
|
|
while (<$client>) {
|
|
|
|
alarm(0);
|
|
|
|
$response .= $_;
|
|
|
|
if ($response =~ m/<\/xcatresponse>/) {
|
|
|
|
$rsp=XMLin($response, ForceArray => ['node']);
|
|
|
|
$response='';
|
|
|
|
if ($rsp->{warning}) {
|
|
|
|
printf "Warning: ".$rsp->{warning}."\n";
|
|
|
|
}
|
|
|
|
if ($rsp->{error}) {
|
|
|
|
die ("ERROR: ".$rsp->{error}."\n");
|
|
|
|
} elsif ($rsp->{node}) {
|
|
|
|
@nodes=@{$rsp->{node}};
|
|
|
|
}
|
|
|
|
if ($rsp->{serverdone}) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close($client);
|
2009-08-11 20:29:13 +00:00
|
|
|
debug("[stop] - recieve nodes from xcatd\n");
|
|
|
|
debug("\@nodes LENGTH:" . scalar @nodes . "\n");
|
|
|
|
|
2008-10-21 18:23:18 +00:00
|
|
|
my $children = 0;
|
|
|
|
my $inputs = new IO::Select;
|
|
|
|
$SIG{CHLD} = sub { while (waitpid(-1,WNOHANG) > 0) { $children--; } };
|
|
|
|
|
|
|
|
unless (scalar(@nodes)) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2009-08-11 20:29:13 +00:00
|
|
|
## Use pping to determine which nodes are reachable
|
2008-10-21 18:23:18 +00:00
|
|
|
my @reachable_nodes=();
|
|
|
|
my @unreachable_nodes=();
|
2009-08-11 20:29:13 +00:00
|
|
|
debug("[start] - find unreachable nodes\n");
|
2008-10-21 18:23:18 +00:00
|
|
|
open (PPING, "$::XCATROOT/bin/pping ".join(',',@nodes). " 2> /dev/null|") or die("Cannot open pping-internal pipe: $!");
|
|
|
|
while (<PPING>) {
|
|
|
|
if ($_ =~ / ping/) {
|
|
|
|
my @a_tmp=split(':', $_);
|
|
|
|
push(@reachable_nodes, $a_tmp[0]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my @a_tmp=split(':', $_);
|
|
|
|
push(@unreachable_nodes, $a_tmp[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(PPING);
|
2009-08-11 20:29:13 +00:00
|
|
|
debug("[stop] - find unreachable nodes\n");
|
2008-10-21 18:23:18 +00:00
|
|
|
|
2009-08-11 20:29:13 +00:00
|
|
|
## Dispose of the unreachable nodes now
|
2008-10-21 18:23:18 +00:00
|
|
|
foreach(@unreachable_nodes) {
|
|
|
|
print "$_: noping\n";
|
|
|
|
}
|
|
|
|
|
2009-08-11 20:29:13 +00:00
|
|
|
## If there are nodes in @reachable nodes, use xdsh to make each reachable
|
|
|
|
## node pping2 every other node, even the unreachable ones.
|
|
|
|
debug("[start] - deal with reachable nodes\n");
|
|
|
|
debug("REACHABLE_NODES:@reachable_nodes\n");
|
2008-10-21 18:23:18 +00:00
|
|
|
|
|
|
|
if (@reachable_nodes > 0) {
|
|
|
|
my $allnodes=join(',', @nodes);
|
2009-08-12 20:52:53 +00:00
|
|
|
|
|
|
|
# If verbose is set, take out the quiet flag
|
|
|
|
my $quiet = "-q";
|
|
|
|
if($VERBOSE){
|
|
|
|
$quiet = "";
|
|
|
|
}
|
|
|
|
# If hierarchical behavior is wanted, take out the bypass flag
|
|
|
|
my $bypass = "-B";
|
|
|
|
if($HIERARCHY){
|
|
|
|
$bypass = "";
|
|
|
|
}
|
|
|
|
my $i_string = "";
|
|
|
|
if($interface) {
|
|
|
|
$i_string = "-i $interface";
|
|
|
|
}
|
|
|
|
|
2009-08-11 20:29:13 +00:00
|
|
|
## If the serial option was set, pping2 one reachable node at a time.
|
2008-10-21 18:23:18 +00:00
|
|
|
if ($::SERIAL) {
|
2009-08-11 20:29:13 +00:00
|
|
|
debug("SERIAL:$::SERIAL\n");
|
|
|
|
debug("[start] - xdsh to each reachable node\n");
|
2008-10-21 18:23:18 +00:00
|
|
|
foreach(@reachable_nodes) {
|
2009-08-11 20:29:13 +00:00
|
|
|
my $result;
|
|
|
|
|
2009-08-12 20:52:53 +00:00
|
|
|
my $command = "$::XCATROOT/bin/xdsh $_ $bypass -e $::XCATROOT/sbin/pping2 \"$i_string $quiet $allnodes\" 2>&1";
|
|
|
|
|
2009-08-11 20:29:13 +00:00
|
|
|
debug("Running \'$command\'\n");
|
|
|
|
$result=`$command`;
|
2008-10-21 18:23:18 +00:00
|
|
|
print "$result";
|
|
|
|
}
|
2009-08-11 20:29:13 +00:00
|
|
|
debug("[stop] - xdsh to each reachable node\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
## If the serial option was not set, pping2 all the reachable nodes simultaneously.
|
|
|
|
else {
|
|
|
|
debug("SERIAL not set.\n");
|
2008-10-21 18:23:18 +00:00
|
|
|
my $node_string=join(',', @reachable_nodes);
|
2009-08-12 20:52:53 +00:00
|
|
|
my $command = "$::XCATROOT/bin/xdsh $node_string $bypass -s -e $::XCATROOT/sbin/pping2 \"$i_string $quiet $allnodes\" 2> /dev/null|";
|
2009-08-11 20:29:13 +00:00
|
|
|
debug("Running \'$command\'");
|
|
|
|
open (PPING2, "$command") or die("Cannot open pping-internal pipe: $!");
|
|
|
|
# Print out the result
|
2008-10-21 18:23:18 +00:00
|
|
|
while (<PPING2>) {
|
|
|
|
print "$_";
|
|
|
|
}
|
|
|
|
close(PPING2);
|
|
|
|
}
|
|
|
|
}
|
2009-08-11 20:29:13 +00:00
|
|
|
debug("[stop] - deal with reachable nodes\n");
|
2008-10-21 18:23:18 +00:00
|
|
|
|
|
|
|
exit 0;
|