2007-10-26 22:44:33 +00:00
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
2008-02-14 14:25:49 +00:00
# Used as a standard client cmd that can be used for many of the xcat cmds.
# It grabs the arguments, noderange, and stdin and then submits the request to
# xcatd and waits for responses. Most of the client/server communication is
# contained in Client.pm.
# To use this, sym link your cmd name to this script.
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
2007-12-11 19:15:28 +00:00
use lib "$::XCATROOT/lib/perl";
2008-01-10 13:41:31 +00:00
use Cwd;
2008-02-14 14:25:49 +00:00
#use IO::Socket::SSL;
#use IO::Socket::INET;
2007-10-26 22:44:33 +00:00
use File::Basename;
2008-02-14 14:25:49 +00:00
#use Data::Dumper;
use xCAT::Client;
2011-12-12 19:54:30 +00:00
use strict;
2008-02-14 14:25:49 +00:00
my $bname = basename($0);
2007-10-26 22:44:33 +00:00
my $cmdref;
2008-02-14 14:25:49 +00:00
if ($bname =~ /xcatclient/) { $cmdref->{command}->[0]=shift @ARGV; } # xcatclient was invoked directly and the 1st arg is cmd name that is used to locate the plugin
else { $cmdref->{command}->[0] = $bname; } # the cmd was sym linked to xcatclient
2008-01-10 13:41:31 +00:00
$cmdref->{cwd}->[0] = cwd();
2007-10-26 22:44:33 +00:00
2011-12-12 19:54:30 +00:00
my $data;
2011-12-12 16:25:53 +00:00
# allows our plugins to get the stdin of the cmd that invoked the plugin
2011-12-12 20:01:42 +00:00
if ( (($^O =~ /^linux/i) && ($ENV{'SHELL'} =~ /\/ksh$/)) || !defined($ENV{'TERM'}) )
2011-12-12 16:25:53 +00:00
{
my $rin="";
2011-12-12 19:54:30 +00:00
my $rout;
2011-12-12 16:25:53 +00:00
vec($rin,fileno(STDIN),1)=1;
my $nfound=select($rout=$rin,"","",1);
if ($nfound)
{
while ( <STDIN> ) { $data.=$_; }
$cmdref->{stdin}->[0]=$data;
}
}
else
{
if (-p STDIN) {
while ( <STDIN> ) { $data.=$_; }
$cmdref->{stdin}->[0]=$data;
}
2007-10-26 22:44:33 +00:00
}
2011-12-12 16:25:53 +00:00
2010-08-18 03:15:38 +00:00
my $arg;
my @tmpargv = @ARGV;
# lslite needs to handle imagename besides noderange
# so do not fill {noderange} if imagename given
my $str = join(',', @tmpargv);
if (($bname =~ /lslite/) && $str =~ /-i/)
{
$arg = "NO_NODE_RANGE";
}
else
{ # Consider the 1st non-hyphen arg to be the noderange. All others (before and after) go on the arg list.
$arg=shift(@ARGV);
while ($arg =~ /^-/) {
push (@{$cmdref->{arg}}, $arg);
$arg=shift(@ARGV);
}
2007-10-26 22:44:33 +00:00
}
2010-08-18 03:15:38 +00:00
2008-02-14 14:25:49 +00:00
if ($arg ne "NO_NODE_RANGE") {
2010-01-20 07:47:07 +00:00
# The noderange can be specified through a noderange file,
# the noderange file can be a relative path,
# convert the relative path to a full path.
# an ideal way is converting the relative path in xCAT::Noderange::noderange,
# but the existing xCAT::Noderange::noderange can not get the cwd(),
# needs to change all the callers to pass the cwd(),
# there are more than 100 callers.
my @tempnr = ();
foreach my $nr (split(/,/, $arg)) {
if ($nr =~ /^\^(.*)$/) {
my $nrf = $1;
if ($nrf !~ /^\//) { #relative path
$nrf = Cwd::abs_path($nrf);
}
$nrf = "\^" . $nrf;
push @tempnr, $nrf;
} else {
push @tempnr, $nr;
}
}
$arg = join(',',@tempnr);
2007-10-26 22:44:33 +00:00
$cmdref->{noderange}->[0]=$arg;
}
2013-06-18 17:45:17 +00:00
if (@ARGV) {
push (@{$cmdref->{arg}}, @ARGV);
}
2010-03-02 21:54:37 +00:00
foreach (keys %ENV) {
if (/^XCAT_/) {
$cmdref->{environment}->{$_} = $ENV{$_};
}
}
2007-10-26 22:44:33 +00:00
2008-02-14 14:25:49 +00:00
xCAT::Client::submit_request($cmdref,\&xCAT::Client::handle_response);
exit $xCAT::Client::EXITCODE;