hierarchy support for PPC commands and xCATWorld

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1081 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
linggao 2008-04-16 16:45:14 +00:00
parent d24245d3e4
commit e951b2e047
6 changed files with 173 additions and 30 deletions

View File

@ -802,6 +802,112 @@ sub runcmd {
}
##########################################################################
# Pre-process request from xCat daemon. Send the request to the the service
# nodes of the HCPs.
##########################################################################
sub preprocess_request {
my $package = shift;
my $req = shift;
if ($req->{_xcatdest}) { return [$req]; } #exit if preprocessed
my $callback = shift;
my @requests;
####################################
# Get hwtype
####################################
$package =~ s/xCAT_plugin:://;
####################################
# Prompt for usage if needed
####################################
my $noderange = $req->{node}; #Should be arrayref
my $command = $req->{command}->[0];
my $extrargs = $req->{arg};
my @exargs=($req->{arg});
if (ref($extrargs)) {
@exargs=@$extrargs;
}
my $usage_string=xCAT::Usage->parseCommand($command, @exargs);
if ($usage_string) {
$callback->({data=>$usage_string});
$req = {};
return;
}
if (!$noderange) {
$usage_string=xCAT::Usage->getUsage($command);
$callback->({data=>$usage_string});
$req = {};
return;
}
##################################################################
# get the HCPs for the LPARs in order to figure out which service
# nodes to send the requests to
###################################################################
my $hcptab_name = ($package eq "fsp") ? "ppcdirect" : "ppchcp";
my $hcptab = xCAT::Table->new( $hcptab_name );
unless ($hcptab ) {
$callback->({data=>"Cannot open $hcptab_name table"});
$req = {};
return;
}
# Check if each node is hcp
my %hcp_hash=();
my @missednodes=();
foreach ( @$noderange ) {
my ($ent) = $hcptab->getAttribs( {hcp=>$_},"hcp" );
if ( !defined( $ent )) {
push @missednodes, $_;
next;
}
push @{$hcp_hash{$_}{nodes}}, $_;
}
#check if the left-over nodes are lpars
if (@missednodes > 0) {
my $ppctab = xCAT::Table->new("ppc");
unless ($ppctab) {
$callback->({data=>"Cannot open ppc table"});
$req = {};
return;
}
foreach my $node (@missednodes) {
my $ent=$ppctab->getNodeAttribs($node,['hcp']);
if (defined($ent->{hcp})) { push @{$hcp_hash{$ent->{hcp}}{nodes}}, $node;}
else {
$callback->({data=>"The node $node is neither a hcp nor an lapr"});
$req = {};
return;
}
}
}
# find service nodes for the HCPs
# build an individual request for each service node
my $service = "xcat";
my @hcps=keys(%hcp_hash);
my $sn = xCAT::Utils->get_ServiceNode(\@hcps, $service, "MN");
# build each request for each service node
foreach my $snkey (keys %$sn)
{
#print "snkey=$snkey\n";
my $reqcopy = {%$req};
$reqcopy->{'_xcatdest'} = $snkey;
my $hcps1=$sn->{$snkey};
my @nodes=();
foreach (@$hcps1) {
push @nodes, @{$hcp_hash{$_}{nodes}};
}
$reqcopy->{node} = \@nodes;
#print "nodes=@nodes\n";
push @requests, $reqcopy;
}
return \@requests;
}
##########################################################################
# Process request from xCat daemon
@ -817,29 +923,6 @@ sub process_request {
####################################
$package =~ s/xCAT_plugin:://;
####################################
# Prompt for usage if needed
####################################
my $noderange = $req->{node}; #Should be arrayref
my $command = $req->{command}->[0];
my $extrargs = $req->{arg};
my @exargs=($req->{arg});
if (ref($extrargs)) {
@exargs=@$extrargs;
}
my $usage_string=xCAT::Usage->parseCommand($command, @exargs);
if ($usage_string) {
$callback->({data=>$usage_string});
$req = {};
return;
}
if (!$noderange) {
$usage_string=xCAT::Usage->getUsage($command);
$callback->({data=>$usage_string});
$req = {};
return;
}
####################################
# Build hash to pass around
####################################

View File

@ -1226,7 +1226,7 @@ sub preprocess_request {
#get the MMs for the nodes for the nodes in order to figure out which service nodes to send the requests to
my $mptab = xCAT::Table->new("mp");
unless ($mptab) {
$callback->("Cannot open mp table");
$callback->({data=>"Cannot open mp table"});
$request = {};
return;
}
@ -1235,7 +1235,7 @@ sub preprocess_request {
my $ent=$mptab->getNodeAttribs($node,['mpa', 'id']);
if (defined($ent->{mpa})) { push @{$mpa_hash{$ent->{mpa}}{nodes}}, $node;}
else {
$callback->("no mpa defined for node $node");
$callback->({data=>"no mpa defined for node $node"});
$request = {};
return;
}

View File

@ -16,11 +16,10 @@ sub handled_commands {
};
}
##########################################################################
# Process request from xCat daemon
# Pre-process request from xCat daemon
##########################################################################
sub process_request {
sub preprocess_request {
#######################################################
# IO::Socket::SSL apparently does not work with LWP.pm
@ -45,6 +44,13 @@ sub process_request {
$callback->( \%output );
return(1);
}
xCAT::PPC::preprocess_request(__PACKAGE__,@_);
}
##########################################################################
# Process request from xCat daemon
##########################################################################
sub process_request {
xCAT::PPC::process_request(__PACKAGE__,@_);
}

View File

@ -24,6 +24,13 @@ sub handled_commands {
}
##########################################################################
# Pre-process request from xCat daemon
##########################################################################
sub preprocess_request {
xCAT::PPC::preprocess_request(__PACKAGE__,@_);
}
##########################################################################
# Process request from xCat daemon
##########################################################################

View File

@ -23,6 +23,13 @@ sub handled_commands {
}
}
##########################################################################
# Pre-process request from xCat daemon
##########################################################################
sub preprocess_request {
xCAT::PPC::preprocess_request(__PACKAGE__,@_);
}
##########################################################################
# Process request from xCat daemon

View File

@ -11,6 +11,7 @@
#-------------------------------------------------------
package xCAT_plugin::xCATWorld;
use Sys::Hostname;
use xCAT::Table;
use xCAT::Utils;
@ -34,6 +35,44 @@ sub handled_commands
return {xCATWorld => "xCATWorld"};
}
#-------------------------------------------------------
=head3 preprocess_request
Check and setup for hierarchy
=cut
#-------------------------------------------------------
sub preprocess_request
{
my $req = shift;
my $cb = shift;
my %sn;
if ($req->{_xcatdest}) { return [$req]; } #exit if preprocessed
my $nodes = $req->{node};
my $service = "xcat";
# find service nodes for requested nodes
# build an individual request for each service node
$sn = xCAT::Utils->get_ServiceNode($nodes, $service, "MN");
# build each request for each service node
foreach my $snkey (keys %$sn)
{
my $n=$sn->{$snkey};
print "snkey=$snkey, nodes=@$n\n";
my $reqcopy = {%$req};
$reqcopy->{node} = $sn->{$snkey};
$reqcopy->{'_xcatdest'} = $snkey;
push @requests, $reqcopy;
}
return \@requests;
}
#-------------------------------------------------------
=head3 process_request
@ -57,12 +96,13 @@ sub process_request
my @nodes=@$nodes;
# do your processing here
# return info
my $host=hostname();
$rsp->{data}->[0] = "Hello World! Your node list is:\n";
$rsp->{data}->[0] = "Hello World from $host! I can process the following nodes:";
xCAT::MsgUtils->message("I", $rsp, $callback, 0);
foreach $node (@nodes)
{
$rsp->{data}->[$i] = "$node\n";
$rsp->{data}->[$i] = "$node";
$i++;
}
xCAT::MsgUtils->message("I", $rsp, $callback, 0);