enhance plugin processing to ensure correct table-driven plugin is called, moved common usage preprocessing to new plugin
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4663 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
d489563c4f
commit
2aa3876007
@ -168,7 +168,7 @@ sub submit_request {
|
||||
|
||||
#add ESC back
|
||||
foreach my $key (keys %$rsp) {
|
||||
if (ref($rsp->{$key}) eq 'ARRAY') { foreach my $text (@{$rsp->{$key}}) { next unless defined $text; $text =~ s/xxxxESCxxxx/\e/g; } }
|
||||
if (ref($rsp->{$key}) eq 'ARRAY') { foreach my $text (@{$rsp->{$key}}) { next unless defined $text; $text =~ s/xxxxESCxxxx/\e/g; } }
|
||||
else { $rsp->{$key} =~ s/xxxxESCxxxx/\e/g; }
|
||||
}
|
||||
|
||||
@ -207,20 +207,7 @@ sub scan_plugins {
|
||||
foreach (keys %$cmd_adds) {
|
||||
my $value = $_;
|
||||
if (defined($cmd_handlers{$_})) {
|
||||
my $add=1;
|
||||
#This next bit of code iterates through the handlers.
|
||||
#If the value doesn't contain an equal, and has an equivalent entry added by
|
||||
# another plugin already, don't add (otherwise would hit the DB multiple times)
|
||||
#referring to having redundant nodehm:mgt handlers registered, for example
|
||||
# a better idea, restructure the cmd_handlers as a multi-level hash
|
||||
# prove out this idea real quick before doing that
|
||||
foreach (@{$cmd_handlers{$_}}) {
|
||||
if (($_->[1] eq $cmd_adds->{$value}) and (($cmd_adds->{$value} !~ /=/) or ($_->[0] eq $modname))) {
|
||||
$add = 0;
|
||||
}
|
||||
}
|
||||
if ($add) { push @{$cmd_handlers{$_}},[$modname,$cmd_adds->{$_}]; }
|
||||
#die "Conflicting handler information from $modname";
|
||||
push @{$cmd_handlers{$_}},[$modname,$cmd_adds->{$_}];
|
||||
} else {
|
||||
$cmd_handlers{$_} = [ [$modname,$cmd_adds->{$_}] ];
|
||||
}
|
||||
@ -312,61 +299,69 @@ sub plugin_command {
|
||||
}
|
||||
}
|
||||
} elsif ($hdlspec =~ /:/) { #Specificed a table lookup path for plugin name
|
||||
$useglobals = 0; #Only contemplate nodes that aren't caught through searching below in the global handler
|
||||
$useunhandled=1;
|
||||
my $table;
|
||||
my $cols;
|
||||
($table,$cols) = split(/:/,$hdlspec);
|
||||
my @colmns=split(/,/,$cols);
|
||||
my @columns;
|
||||
my $hdlrtable=xCAT::Table->new($table);
|
||||
unless ($hdlrtable) {
|
||||
#TODO: proper error handling
|
||||
}
|
||||
my $node;
|
||||
my $colvals = {};
|
||||
foreach my $colu (@colmns) {
|
||||
if ($colu =~ /=/) { #a value redirect to a pattern/specific name
|
||||
my $coln; my $colv;
|
||||
($coln,$colv) = split(/=/,$colu,2);
|
||||
$colvals->{$coln} = $colv;
|
||||
push (@columns,$coln);
|
||||
} else {
|
||||
push (@columns,$colu);
|
||||
if (@nodes) { # only use table lookup plugin if nodelist exists
|
||||
# Usage will be handled in common AAAhelp plugin
|
||||
|
||||
$useglobals = 0; #Only contemplate nodes that aren't caught through searching below in the global handler
|
||||
$useunhandled=1;
|
||||
my $table;
|
||||
my $cols;
|
||||
($table,$cols) = split(/:/,$hdlspec);
|
||||
my @colmns=split(/,/,$cols);
|
||||
my @columns;
|
||||
my $hdlrtable=xCAT::Table->new($table);
|
||||
unless ($hdlrtable) {
|
||||
#TODO: proper error handling
|
||||
}
|
||||
my $node;
|
||||
my $colvals = {};
|
||||
foreach my $colu (@colmns) {
|
||||
if ($colu =~ /=/) { #a value redirect to a pattern/specific name
|
||||
my $coln; my $colv;
|
||||
($coln,$colv) = split(/=/,$colu,2);
|
||||
$colvals->{$coln} = $colv;
|
||||
push (@columns,$coln);
|
||||
} else {
|
||||
push (@columns,$colu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unless (@nodes) { #register the plugin in the event of usage
|
||||
$handler_hash{$ownmod} = 1;
|
||||
$useglobals = 1;
|
||||
}
|
||||
my $hdlrcache;
|
||||
if ($hdlrtable) {
|
||||
$hdlrcache = $hdlrtable->getNodesAttribs(\@nodes,\@columns);
|
||||
}
|
||||
foreach $node (@nodes) {
|
||||
unless ($hdlrcache) { next; }
|
||||
my $attribs = $hdlrcache->{$node}->[0]; #$hdlrtable->getNodeAttribs($node,\@columns);
|
||||
unless (defined($attribs)) { next; }
|
||||
foreach (@columns) {
|
||||
my $col=$_;
|
||||
if (defined($attribs->{$col})) {
|
||||
if ($colvals->{$col}) { #A pattern match style request.
|
||||
if ($attribs->{$col} =~ /$colvals->{$col}/) {
|
||||
$handler_hash{$ownmod}->{$node} = 1;
|
||||
delete $unhandled_nodes{$node};
|
||||
last;
|
||||
unless (@nodes) { #register the plugin in the event of usage
|
||||
$handler_hash{$ownmod} = 1;
|
||||
$useglobals = 1;
|
||||
}
|
||||
my $hdlrcache;
|
||||
if ($hdlrtable) {
|
||||
$hdlrcache = $hdlrtable->getNodesAttribs(\@nodes,\@columns);
|
||||
}
|
||||
foreach $node (@nodes) {
|
||||
unless ($hdlrcache) { next; }
|
||||
my $attribs = $hdlrcache->{$node}->[0]; #$hdlrtable->getNodeAttribs($node,\@columns);
|
||||
unless (defined($attribs)) { next; }
|
||||
foreach (@columns) {
|
||||
my $col=$_;
|
||||
if (defined($attribs->{$col})) {
|
||||
if ($colvals->{$col}) { #A pattern match style request.
|
||||
if ($attribs->{$col} =~ /$colvals->{$col}/) {
|
||||
$handler_hash{$ownmod}->{$node} = 1;
|
||||
delete $unhandled_nodes{$node};
|
||||
last;
|
||||
}
|
||||
} else {
|
||||
# call the plugin that matches the table value for that node
|
||||
if ($attribs->{$col} =~ /$ownmod/) {
|
||||
$handler_hash{$attribs->{$col}}->{$node} = 1;
|
||||
delete $unhandled_nodes{$node};
|
||||
last;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$handler_hash{$attribs->{$col}}->{$node} = 1;
|
||||
delete $unhandled_nodes{$node};
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$hdlrtable->close;
|
||||
$hdlrtable->close;
|
||||
} # end if (@nodes)
|
||||
|
||||
} else {
|
||||
push @globalhandlers,$hdlspec;
|
||||
}
|
||||
@ -403,13 +398,13 @@ sub plugin_command {
|
||||
}
|
||||
if ($useunhandled) {
|
||||
my $queuelist;
|
||||
foreach (@{$cmd_handlers{$req->{command}->[0]}->[0]}) {
|
||||
unless (/:/) {
|
||||
next;
|
||||
}
|
||||
$queuelist .= "$_,";
|
||||
foreach (@{$cmd_handlers{$req->{command}->[0]}}) {
|
||||
my $queueitem = $_->[1];
|
||||
if (($queueitem =~ /:/) and !($queuelist =~ /($queueitem)/)) {
|
||||
$queuelist .= "$_->[1];";
|
||||
}
|
||||
}
|
||||
$queuelist =~ s/,$//;
|
||||
$queuelist =~ s/;$//;
|
||||
$queuelist =~ s/:/./g;
|
||||
foreach (keys %unhandled_nodes) {
|
||||
# if ($sock) {
|
||||
|
81
xCAT-server/lib/xcat/plugins/AAAusage.pm
Normal file
81
xCAT-server/lib/xcat/plugins/AAAusage.pm
Normal file
@ -0,0 +1,81 @@
|
||||
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
package xCAT_plugin::AAAusage;
|
||||
use strict;
|
||||
##########################################################################
|
||||
# Common help plugin for table-driven commands
|
||||
##########################################################################
|
||||
|
||||
##########################################################################
|
||||
# Command handler method from tables
|
||||
##########################################################################
|
||||
sub handled_commands {
|
||||
return {
|
||||
rnetboot => 'AAAusage',
|
||||
rpower => 'AAAusage',
|
||||
rbeacon => 'AAAusage',
|
||||
rvitals => 'AAAusage',
|
||||
reventlog => 'AAAusage',
|
||||
rinv => 'AAAusage',
|
||||
rsetboot => 'AAAusage',
|
||||
rbootseq => 'AAAusage',
|
||||
rscan => 'AAAusage',
|
||||
rspconfig => 'AAAusage',
|
||||
getmacs => 'AAAusage',
|
||||
mkvm => 'AAAusage',
|
||||
lsvm => 'AAAusage',
|
||||
chvm => 'AAAusage',
|
||||
rmvm => 'AAAusage',
|
||||
lsslp => 'AAAusage',
|
||||
rflash => 'AAAusage',
|
||||
mkhwconn => 'AAAusage',
|
||||
rmhwconn => 'AAAusage',
|
||||
lshwconn => 'AAAusage',
|
||||
renergy => 'AAAusage'
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
# Pre-process request from xCat daemon
|
||||
##########################################################################
|
||||
sub preprocess_request {
|
||||
my $request = shift;
|
||||
#if ($request->{_xcatdest}) { return [$request]; } #exit if preprocessed
|
||||
|
||||
if (($request->{_xcatpreprocessed}) and ($request->{_xcatpreprocessed}->[0] == 1) ) { return [$request]; }
|
||||
my $callback=shift;
|
||||
my @requests;
|
||||
|
||||
#display usage statement if -h is present or no noderage is specified
|
||||
my $noderange = $request->{node}; #Should be arrayref
|
||||
my $command = $request->{command}->[0];
|
||||
my $extrargs = $request->{arg};
|
||||
my @exargs=($request->{arg});
|
||||
if (ref($extrargs)) {
|
||||
@exargs=@$extrargs;
|
||||
}
|
||||
if (($#exargs==-1) or (($#exargs==0) and ($exargs[0] =~ /^\s*$/)) ) {
|
||||
$exargs[0] = "--help"; # force help if no args
|
||||
}
|
||||
|
||||
my $usage_string=xCAT::Usage->parseCommand($command, @exargs);
|
||||
if ($usage_string) {
|
||||
$callback->({data=>[$usage_string]});
|
||||
$request = {};
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Process request from xCat daemon
|
||||
##########################################################################
|
||||
sub process_request {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
1;
|
@ -443,20 +443,8 @@ sub scan_plugins {
|
||||
foreach (keys %$cmd_adds) {
|
||||
my $value = $_;
|
||||
if (defined($cmd_handlers{$_})) {
|
||||
my $add=1;
|
||||
#This next bit of code iterates through the handlers.
|
||||
#If the value doesn't contain an equal, and has an equivalent entry added by
|
||||
# another plugin already, don't add (otherwise would hit the DB multiple times)
|
||||
#referring to having redundant nodehm:mgt handlers registered, for example
|
||||
# a better idea, restructure the cmd_handlers as a multi-level hash
|
||||
# prove out this idea real quick before doing that
|
||||
foreach (@{$cmd_handlers{$_}}) {
|
||||
if (($_->[1] eq $cmd_adds->{$value}) and (($cmd_adds->{$value} !~ /=/) or ($_->[0] eq $modname))) {
|
||||
$add = 0;
|
||||
}
|
||||
}
|
||||
if ($add) { push @{$cmd_handlers{$_}},[$modname,$cmd_adds->{$_}]; }
|
||||
#die "Conflicting handler information from $modname";
|
||||
# Add every plugin registration to cmd_handlers
|
||||
push @{$cmd_handlers{$_}},[$modname,$cmd_adds->{$_}];
|
||||
} else {
|
||||
$cmd_handlers{$_} = [ [$modname,$cmd_adds->{$_}] ];
|
||||
}
|
||||
@ -737,61 +725,68 @@ sub plugin_command {
|
||||
}
|
||||
}
|
||||
} elsif ($hdlspec =~ /:/) { #Specificed a table lookup path for plugin name
|
||||
$useglobals = 0; #Only contemplate nodes that aren't caught through searching below in the global handler
|
||||
$useunhandled=1;
|
||||
my $table;
|
||||
my $cols;
|
||||
($table,$cols) = split(/:/,$hdlspec);
|
||||
my @colmns=split(/,/,$cols);
|
||||
my @columns;
|
||||
my $hdlrtable=xCAT::Table->new($table);
|
||||
unless ($hdlrtable) {
|
||||
#TODO: proper error handling
|
||||
}
|
||||
my $node;
|
||||
my $colvals = {};
|
||||
foreach my $colu (@colmns) {
|
||||
if ($colu =~ /=/) { #a value redirect to a pattern/specific name
|
||||
my $coln; my $colv;
|
||||
($coln,$colv) = split(/=/,$colu,2);
|
||||
$colvals->{$coln} = $colv;
|
||||
push (@columns,$coln);
|
||||
} else {
|
||||
push (@columns,$colu);
|
||||
if (@nodes) { # only use table lookup plugin if nodelist exists
|
||||
# Usage will be handled in common AAAhelp plugin
|
||||
$useglobals = 0; #Only contemplate nodes that aren't caught through searching below in the global handler
|
||||
$useunhandled=1;
|
||||
my $table;
|
||||
my $cols;
|
||||
($table,$cols) = split(/:/,$hdlspec);
|
||||
my @colmns=split(/,/,$cols);
|
||||
my @columns;
|
||||
my $hdlrtable=xCAT::Table->new($table);
|
||||
unless ($hdlrtable) {
|
||||
#TODO: proper error handling
|
||||
}
|
||||
my $node;
|
||||
my $colvals = {};
|
||||
foreach my $colu (@colmns) {
|
||||
if ($colu =~ /=/) { #a value redirect to a pattern/specific name
|
||||
my $coln; my $colv;
|
||||
($coln,$colv) = split(/=/,$colu,2);
|
||||
$colvals->{$coln} = $colv;
|
||||
push (@columns,$coln);
|
||||
} else {
|
||||
push (@columns,$colu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unless (@nodes) { #register the plugin in the event of usage
|
||||
$handler_hash{$ownmod} = 1;
|
||||
$useglobals = 1;
|
||||
}
|
||||
my $hdlrcache;
|
||||
if ($hdlrtable) {
|
||||
$hdlrcache = $hdlrtable->getNodesAttribs(\@nodes,\@columns);
|
||||
}
|
||||
foreach $node (@nodes) {
|
||||
unless ($hdlrcache) { next; }
|
||||
my $attribs = $hdlrcache->{$node}->[0]; #$hdlrtable->getNodeAttribs($node,\@columns);
|
||||
unless (defined($attribs)) { next; }
|
||||
foreach (@columns) {
|
||||
my $col=$_;
|
||||
if (defined($attribs->{$col})) {
|
||||
if ($colvals->{$col}) { #A pattern match style request.
|
||||
if ($attribs->{$col} =~ /$colvals->{$col}/) {
|
||||
$handler_hash{$ownmod}->{$node} = 1;
|
||||
delete $unhandled_nodes{$node};
|
||||
last;
|
||||
unless (@nodes) { #register the plugin in the event of usage
|
||||
$handler_hash{$ownmod} = 1;
|
||||
$useglobals = 1;
|
||||
}
|
||||
my $hdlrcache;
|
||||
if ($hdlrtable) {
|
||||
$hdlrcache = $hdlrtable->getNodesAttribs(\@nodes,\@columns);
|
||||
}
|
||||
foreach $node (@nodes) {
|
||||
unless ($hdlrcache) { next; }
|
||||
my $attribs = $hdlrcache->{$node}->[0]; #$hdlrtable->getNodeAttribs($node,\@columns);
|
||||
unless (defined($attribs)) { next; }
|
||||
foreach (@columns) {
|
||||
my $col=$_;
|
||||
if (defined($attribs->{$col})) {
|
||||
if ($colvals->{$col}) { #A pattern match style request.
|
||||
if ($attribs->{$col} =~ /$colvals->{$col}/) {
|
||||
$handler_hash{$ownmod}->{$node} = 1;
|
||||
delete $unhandled_nodes{$node};
|
||||
last;
|
||||
}
|
||||
} else {
|
||||
# call the plugin that matches the table value for that node
|
||||
if ($attribs->{$col} =~ /$ownmod/) {
|
||||
$handler_hash{$attribs->{$col}}->{$node} = 1;
|
||||
delete $unhandled_nodes{$node};
|
||||
last;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$handler_hash{$attribs->{$col}}->{$node} = 1;
|
||||
delete $unhandled_nodes{$node};
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$hdlrtable->close;
|
||||
$hdlrtable->close;
|
||||
} # end if (@nodes)
|
||||
|
||||
} else {
|
||||
push @globalhandlers,$hdlspec;
|
||||
}
|
||||
@ -827,14 +822,14 @@ sub plugin_command {
|
||||
return 1; #TODO: error back that request has no known plugin for it
|
||||
}
|
||||
if ($useunhandled) {
|
||||
my $queuelist;
|
||||
foreach (@{$cmd_handlers{$req->{command}->[0]}->[0]}) {
|
||||
unless (/:/) {
|
||||
next;
|
||||
}
|
||||
$queuelist .= "$_,";
|
||||
my $queuelist='';
|
||||
foreach (@{$cmd_handlers{$req->{command}->[0]}}) {
|
||||
my $queueitem = $_->[1];
|
||||
if (($queueitem =~ /:/) and !($queuelist =~ /($queueitem)/)) {
|
||||
$queuelist .= "$_->[1];";
|
||||
}
|
||||
}
|
||||
$queuelist =~ s/,$//;
|
||||
$queuelist =~ s/;$//;
|
||||
$queuelist =~ s/:/./g;
|
||||
foreach (keys %unhandled_nodes) {
|
||||
if ($sock) {
|
||||
|
Loading…
Reference in New Issue
Block a user