2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
=head1
|
2007-10-26 22:44:33 +00:00
|
|
|
xCAT plugin package to handle xdsh
|
|
|
|
|
|
|
|
Supported command:
|
|
|
|
xdsh-> dsh
|
|
|
|
xdcp-> dcp
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
package xCAT_plugin::xdsh;
|
|
|
|
use xCAT::Table;
|
|
|
|
|
|
|
|
use xCAT::Utils;
|
|
|
|
|
|
|
|
use xCAT::MsgUtils;
|
2007-12-12 13:24:36 +00:00
|
|
|
use Getopt::Long;
|
|
|
|
require xCAT::DSHCLI;
|
2007-10-26 22:44:33 +00:00
|
|
|
1;
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
=head3 handled_commands
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
Return list of commands handled by this plugin
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
sub handled_commands
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
xdsh => "xdsh",
|
|
|
|
xdcp => "xdsh"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
=head3 process_request
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
Process the command
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub process_request
|
|
|
|
{
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $nodes = $request->{node};
|
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my $args = $request->{arg};
|
2007-12-12 13:24:36 +00:00
|
|
|
my $envs = $request->{env};
|
2007-10-26 22:44:33 +00:00
|
|
|
my %rsp;
|
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
# get the Environment Variables and set them in the current environment
|
|
|
|
foreach my $envar (@{$request->{env}}) {
|
|
|
|
my ($var, $value) = split(/=/, $envar, 2);
|
|
|
|
$ENV{$var} = $value;
|
2007-12-12 13:24:36 +00:00
|
|
|
}
|
|
|
|
if ($command eq "xdsh")
|
|
|
|
{
|
|
|
|
xdsh($nodes, $args, $callback, $command, $request->{noderange}->[0]);
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-12 13:24:36 +00:00
|
|
|
if ($command eq "xdcp")
|
2007-10-26 22:44:33 +00:00
|
|
|
{
|
2007-12-12 13:24:36 +00:00
|
|
|
xdcp($nodes, $args, $callback, $command,
|
|
|
|
$request->{noderange}->[0]);
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
else
|
2007-12-12 13:24:36 +00:00
|
|
|
{
|
|
|
|
my %rsp;
|
2007-10-26 22:44:33 +00:00
|
|
|
$rsp->{data}->[0] =
|
2008-02-18 15:57:25 +00:00
|
|
|
"Unknown command $command. Cannot process the command.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
|
|
|
return;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
=head3 xdsh
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
Parses Builds and runs the dsh
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub xdsh
|
|
|
|
{
|
2007-12-12 13:24:36 +00:00
|
|
|
my ($nodes, $args, $callback, $command, $noderange) = @_;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2007-12-12 13:24:36 +00:00
|
|
|
# parse dsh input
|
|
|
|
@local_results =
|
|
|
|
xCAT::DSHCLI->parse_and_run_dsh($nodes, $args, $callback,
|
|
|
|
$command, $noderange);
|
2008-02-18 15:57:25 +00:00
|
|
|
push @{$rsp->{data}}, @local_results;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2007-12-12 13:24:36 +00:00
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
return;
|
2007-12-12 13:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
=head3 xdcp
|
2007-12-12 13:24:36 +00:00
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
Parses, Builds and runs the dcp command
|
2007-12-12 13:24:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub xdcp
|
|
|
|
{
|
|
|
|
my ($nodes, $args, $callback, $command, $noderange) = @_;
|
|
|
|
|
|
|
|
# parse dcp input
|
|
|
|
@local_results =
|
|
|
|
xCAT::DSHCLI->parse_and_run_dcp($nodes, $args, $callback,
|
|
|
|
$command, $noderange);
|
|
|
|
my %rsp;
|
|
|
|
my $i = 0;
|
|
|
|
## process return data
|
2007-10-26 22:44:33 +00:00
|
|
|
foreach my $line (@local_results)
|
|
|
|
{
|
|
|
|
$rsp->{data}->[$i] = $line;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
return;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|