2008-03-27 19:48:28 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head1
|
|
|
|
xCAT plugin package to handle xCATWorld
|
|
|
|
|
|
|
|
Supported command:
|
|
|
|
xCATWorld->xCATWorld
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
package xCAT_plugin::xCATWorld;
|
2008-04-16 16:45:14 +00:00
|
|
|
use Sys::Hostname;
|
2008-03-27 19:48:28 +00:00
|
|
|
use xCAT::Table;
|
|
|
|
|
|
|
|
use xCAT::Utils;
|
2012-08-09 04:07:40 +00:00
|
|
|
use xCAT::TableUtils;
|
|
|
|
use xCAT::ServiceNodeUtils;
|
2008-03-27 19:48:28 +00:00
|
|
|
use xCAT::MsgUtils;
|
|
|
|
use Getopt::Long;
|
|
|
|
1;
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 handled_commands
|
|
|
|
|
|
|
|
Return list of commands handled by this plugin
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
sub handled_commands
|
|
|
|
{
|
|
|
|
return {xCATWorld => "xCATWorld"};
|
|
|
|
}
|
|
|
|
|
2008-04-16 16:45:14 +00:00
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 preprocess_request
|
|
|
|
|
2012-08-15 11:36:24 +00:00
|
|
|
Check and setup for hierarchy , if your command must run
|
|
|
|
on service nodes. Otherwise preprocess_request not necessary
|
2008-04-16 16:45:14 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub preprocess_request
|
|
|
|
{
|
|
|
|
my $req = shift;
|
2009-03-16 13:24:16 +00:00
|
|
|
my $callback = shift;
|
2008-04-16 16:45:14 +00:00
|
|
|
my %sn;
|
2009-03-16 13:24:16 +00:00
|
|
|
#if already preprocessed, go straight to request
|
2009-11-23 18:00:40 +00:00
|
|
|
if (($req->{_xcatpreprocessed}) and ($req->{_xcatpreprocessed}->[0] == 1) ) { return [$req]; }
|
2008-04-16 16:45:14 +00:00
|
|
|
my $nodes = $req->{node};
|
|
|
|
my $service = "xcat";
|
|
|
|
|
|
|
|
# find service nodes for requested nodes
|
|
|
|
# build an individual request for each service node
|
2009-03-16 13:24:16 +00:00
|
|
|
if ($nodes) {
|
2012-08-09 04:07:40 +00:00
|
|
|
$sn = xCAT::ServiceNodeUtils->get_ServiceNode($nodes, $service, "MN");
|
2008-04-16 16:45:14 +00:00
|
|
|
|
2009-03-16 13:24:16 +00:00
|
|
|
# build each request for each service node
|
2008-04-16 16:45:14 +00:00
|
|
|
|
2009-03-16 13:24:16 +00:00
|
|
|
foreach my $snkey (keys %$sn)
|
|
|
|
{
|
2012-08-15 11:36:24 +00:00
|
|
|
my $n=$sn->{$snkey};
|
2008-04-16 16:45:14 +00:00
|
|
|
my $reqcopy = {%$req};
|
|
|
|
$reqcopy->{node} = $sn->{$snkey};
|
|
|
|
$reqcopy->{'_xcatdest'} = $snkey;
|
2009-03-16 13:24:16 +00:00
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
2008-04-16 16:45:14 +00:00
|
|
|
push @requests, $reqcopy;
|
|
|
|
|
2009-03-16 13:24:16 +00:00
|
|
|
}
|
2012-08-15 11:36:24 +00:00
|
|
|
return \@requests; # return requests for all Service nodes
|
|
|
|
} else {
|
|
|
|
return [$req]; # just return original request
|
2008-04-16 16:45:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-27 19:48:28 +00:00
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 process_request
|
|
|
|
|
|
|
|
Process the command
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub process_request
|
|
|
|
{
|
|
|
|
|
|
|
|
my $request = shift;
|
2012-08-15 11:36:24 +00:00
|
|
|
$::CALLBACK = shift;
|
2008-03-27 19:48:28 +00:00
|
|
|
my $nodes = $request->{node};
|
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my $args = $request->{arg};
|
|
|
|
my $envs = $request->{env};
|
|
|
|
my %rsp;
|
|
|
|
my @nodes=@$nodes;
|
2012-08-15 11:36:24 +00:00
|
|
|
@ARGV = @{$args}; # get arguments
|
2008-03-27 19:48:28 +00:00
|
|
|
# do your processing here
|
|
|
|
# return info
|
2012-08-15 11:36:24 +00:00
|
|
|
Getopt::Long::Configure("posix_default");
|
|
|
|
Getopt::Long::Configure("no_gnu_compat");
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
my %options = ();
|
|
|
|
if (
|
|
|
|
!GetOptions(
|
|
|
|
'h|help' => \$options{'help'},
|
|
|
|
'v|version' => \$options{'version'},
|
|
|
|
'V|Verbose' => \$options{'verbose'}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
xCAT::DSHCLI->usage_dsh;
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
if ($options{'help'})
|
|
|
|
{
|
|
|
|
&usage;
|
|
|
|
exit 0;
|
|
|
|
}
|
2008-03-28 11:57:26 +00:00
|
|
|
|
2012-08-15 11:36:24 +00:00
|
|
|
if ($options{'version'})
|
|
|
|
{
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
#$version .= "\n";
|
|
|
|
my $rsp={};
|
|
|
|
$rsp->{data}->[0] = $version;
|
|
|
|
xCAT::MsgUtils->message("I",$rsp,$::CALLBACK, 0);
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $host=hostname();
|
|
|
|
my $rsp={};
|
2008-04-16 16:45:14 +00:00
|
|
|
$rsp->{data}->[0] = "Hello World from $host! I can process the following nodes:";
|
2012-08-15 11:36:24 +00:00
|
|
|
xCAT::MsgUtils->message("I", $rsp, $::CALLBACK, 0);
|
2008-03-27 19:48:28 +00:00
|
|
|
foreach $node (@nodes)
|
|
|
|
{
|
2012-08-15 11:36:24 +00:00
|
|
|
$rsp->{data}->[0] .= "$node\n";
|
2008-03-27 19:48:28 +00:00
|
|
|
}
|
2012-08-15 11:36:24 +00:00
|
|
|
xCAT::MsgUtils->message("I", $rsp, $::CALLBACK, 0);
|
2008-03-27 19:48:28 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
2012-08-15 11:36:24 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3
|
|
|
|
usage
|
|
|
|
|
|
|
|
puts out usage message for help
|
2008-03-27 19:48:28 +00:00
|
|
|
|
2012-08-15 11:36:24 +00:00
|
|
|
Arguments:
|
|
|
|
None
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
Globals:
|
|
|
|
|
|
|
|
Error:
|
|
|
|
None
|
|
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sub usage
|
|
|
|
{
|
|
|
|
## usage message
|
|
|
|
my $usagemsg = " xCATWorld -h \n xCATWorld -v \n xCATWorld -V \n";
|
|
|
|
$usagemsg .= " xCATWorld <noderange> ";
|
|
|
|
### end usage mesage
|
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = $usagemsg;
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $::CALLBACK);
|
|
|
|
return;
|
|
|
|
}
|