2008-01-27 19:16:44 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
use IO::Socket::SSL;
|
|
|
|
use XML::Simple;
|
2009-07-29 16:05:42 +00:00
|
|
|
$XML::Simple::PREFERRED_PARSER='XML::Parser';
|
2011-04-11 16:17:08 +00:00
|
|
|
#use Data::Dumper;
|
2008-01-27 19:16:44 +00:00
|
|
|
use IO::Handle;
|
|
|
|
use IO::Select;
|
2008-05-05 13:29:10 +00:00
|
|
|
use Thread qw(yield);
|
2008-01-27 19:16:44 +00:00
|
|
|
use xCAT::Utils;
|
2008-05-14 19:30:45 +00:00
|
|
|
use Getopt::Long qw(:config pass_through require_order);
|
2008-01-27 19:16:44 +00:00
|
|
|
use POSIX qw(:signal_h :errno_h :sys_wait_h);
|
|
|
|
my $interface;
|
|
|
|
GetOptions(
|
|
|
|
"interface=s" => \$interface,
|
2012-06-08 11:38:07 +00:00
|
|
|
"f|fanout=s" => \$fanout,
|
2008-01-27 19:16:44 +00:00
|
|
|
);
|
|
|
|
my %nodehdl;
|
|
|
|
my $xcathost='localhost:3001';
|
|
|
|
if ($ENV{XCATHOST}) {
|
|
|
|
$xcathost=$ENV{XCATHOST};
|
|
|
|
}
|
|
|
|
|
2008-05-14 19:30:45 +00:00
|
|
|
sub usage
|
|
|
|
{
|
2008-05-15 16:22:47 +00:00
|
|
|
print $_[0];
|
2012-06-08 11:38:07 +00:00
|
|
|
print "Usage: pscp [ -f fanout] [-i <SUFFIX>] [SCP OPTIONS...] FILE... <NODERANGE>:<DESTINATION>\n";
|
2008-05-14 19:30:45 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2012-06-08 11:38:07 +00:00
|
|
|
my $pshmaxp = 64;
|
|
|
|
if ($fanout) { # see if they overroad the fanout from the command line
|
|
|
|
$pshmaxp=$fanout;
|
|
|
|
}
|
|
|
|
if ($ENV{XCATPSHFANOUT}) { # env variable rules
|
|
|
|
$pshmaxp=$ENV{XCATPSHFANOUT};
|
|
|
|
}
|
|
|
|
|
2008-05-14 19:30:45 +00:00
|
|
|
|
|
|
|
# Processing arguments
|
|
|
|
usage unless @ARGV;
|
|
|
|
my $dest = shift;
|
|
|
|
my @scpargs;
|
|
|
|
while (@ARGV)
|
|
|
|
{
|
|
|
|
push @scpargs, $dest;
|
|
|
|
$dest = shift;
|
2008-01-27 19:16:44 +00:00
|
|
|
}
|
2008-05-14 19:30:45 +00:00
|
|
|
my $noderange, $destloc;
|
|
|
|
if ($dest =~ /:/) { ($noderange, $destloc) = split(/:/, $dest); }
|
2008-05-15 16:22:47 +00:00
|
|
|
else { usage("No node range specified\n\n"); }
|
2008-05-14 19:30:45 +00:00
|
|
|
|
2012-03-22 13:57:17 +00:00
|
|
|
my @user = getpwuid($>);
|
|
|
|
my $homedir=$user[7];
|
|
|
|
|
2008-01-27 19:16:44 +00:00
|
|
|
my $client = IO::Socket::SSL->new(
|
|
|
|
PeerAddr=>$xcathost,
|
2012-03-22 13:57:17 +00:00
|
|
|
SSL_key_file=>$homedir."/.xcat/client-cred.pem",
|
|
|
|
SSL_cert_file=>$homedir."/.xcat/client-cred.pem",
|
|
|
|
SSL_ca_file => $homedir."/.xcat/ca.pem",
|
2008-01-27 19:16:44 +00:00
|
|
|
SSL_use_cert => 1,
|
|
|
|
#SSL_verify_mode => 1,
|
|
|
|
);
|
|
|
|
die "Connection failure: $!\n" unless ($client);
|
|
|
|
my %cmdref = (command => 'noderange', noderange => $noderange);
|
|
|
|
$SIG{ALRM} = sub { die "No response getting noderange" };
|
|
|
|
alarm(15);
|
|
|
|
print $client XMLout(\%cmdref,RootName=>'xcatrequest', NoAttr=>1, KeyAttr => []);
|
|
|
|
alarm(15);
|
|
|
|
my $response="";
|
|
|
|
my @nodes=();
|
|
|
|
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);
|
|
|
|
my $children = 0;
|
|
|
|
my $inputs = new IO::Select;
|
|
|
|
$SIG{CHLD} = sub { while (waitpid(-1,WNOHANG) > 0) { $children--; } };
|
|
|
|
if ($interface) {
|
|
|
|
foreach (@nodes) {
|
|
|
|
s/$/-$interface/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (@nodes) {
|
|
|
|
my $node=$_;
|
|
|
|
while ($children > $pshmaxp) { processoutput($inputs); }
|
|
|
|
my $child;
|
|
|
|
$children++;
|
2008-05-14 19:30:45 +00:00
|
|
|
#scpnode(\$child,$node,@ARGV[0],$destloc);
|
|
|
|
scpnode(\$child,$node,\@scpargs,$destloc);
|
2008-01-27 19:16:44 +00:00
|
|
|
$inputs->add($child);
|
|
|
|
$nodehdl{$child} = $node;
|
|
|
|
}
|
2008-05-02 21:19:42 +00:00
|
|
|
while ($inputs->count and $children) {
|
2008-01-27 19:16:44 +00:00
|
|
|
processoutput($inputs);
|
|
|
|
}
|
|
|
|
while (processoutput($inputs)) {};
|
2008-05-02 21:19:42 +00:00
|
|
|
wait;
|
2008-01-27 19:16:44 +00:00
|
|
|
exit(0);
|
|
|
|
|
|
|
|
sub processoutput { #This way, one arbiter handles output, no interrupting
|
|
|
|
my $inputs = shift;
|
|
|
|
my @readyins = $inputs->can_read(1);
|
|
|
|
my $rc = @readyins;
|
|
|
|
my $readyh;
|
|
|
|
foreach $readyh (@readyins) {
|
|
|
|
my $line = <$readyh>;
|
|
|
|
unless ($line) {
|
|
|
|
$inputs->remove($readyh);
|
|
|
|
print $nodehdl{$readyh}.": done\n";
|
|
|
|
close($readyh);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
chomp($line);
|
|
|
|
print $nodehdl{$readyh}.": ".$line."\n";
|
|
|
|
}
|
2008-05-03 13:49:33 +00:00
|
|
|
#yield;
|
2008-01-27 19:16:44 +00:00
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
sub scpnode {
|
|
|
|
my $out = shift;
|
|
|
|
my $node = shift;
|
|
|
|
my $in;
|
|
|
|
#my $args = join(" ",@_);
|
2008-05-14 19:30:45 +00:00
|
|
|
#my $file = shift;
|
|
|
|
my $scpargsr = shift;
|
|
|
|
my @scpargs = @{$scpargsr};
|
2008-01-27 19:16:44 +00:00
|
|
|
my $dest = shift;
|
2008-05-14 19:30:45 +00:00
|
|
|
open($$out, "scp -o BatchMode=yes @scpargs $node:$dest 2>&1 |");
|
2008-01-27 19:16:44 +00:00
|
|
|
}
|
2008-05-14 19:30:45 +00:00
|
|
|
|
|
|
|
# vim: set et sw=2 ts=2 sts=2:
|