diff --git a/perl-xCAT-2.0/xCAT/PPC.pm b/perl-xCAT-2.0/xCAT/PPC.pm index 3a63dda2a..c92dc13a8 100644 --- a/perl-xCAT-2.0/xCAT/PPC.pm +++ b/perl-xCAT-2.0/xCAT/PPC.pm @@ -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 #################################### diff --git a/xCAT-server-2.0/lib/xcat/plugins/blade.pm b/xCAT-server-2.0/lib/xcat/plugins/blade.pm index f861524b7..1997c9d7d 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/blade.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/blade.pm @@ -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; } diff --git a/xCAT-server-2.0/lib/xcat/plugins/fsp.pm b/xCAT-server-2.0/lib/xcat/plugins/fsp.pm index e6811fef1..65e67dcf1 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/fsp.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/fsp.pm @@ -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__,@_); } diff --git a/xCAT-server-2.0/lib/xcat/plugins/hmc.pm b/xCAT-server-2.0/lib/xcat/plugins/hmc.pm index 2bd1b3a45..65b34d5ef 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/hmc.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/hmc.pm @@ -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 ########################################################################## diff --git a/xCAT-server-2.0/lib/xcat/plugins/ivm.pm b/xCAT-server-2.0/lib/xcat/plugins/ivm.pm index 611b538ce..b832ecd23 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/ivm.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/ivm.pm @@ -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 diff --git a/xCAT-server-2.0/lib/xcat/plugins/xCATWorld.pm b/xCAT-server-2.0/lib/xcat/plugins/xCATWorld.pm index 61bdc6c20..230d525f5 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/xCATWorld.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/xCATWorld.pm @@ -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);