2007-11-16 19:47:00 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT::PPC;
|
|
|
|
use strict;
|
|
|
|
use xCAT::Table;
|
2008-01-21 19:49:59 +00:00
|
|
|
use xCAT::Utils;
|
2007-11-16 19:47:00 +00:00
|
|
|
use POSIX "WNOHANG";
|
|
|
|
use Storable qw(freeze thaw);
|
|
|
|
use Time::HiRes qw(gettimeofday);
|
|
|
|
use IO::Select;
|
2008-03-10 19:08:34 +00:00
|
|
|
use xCAT::PPCcli;
|
2008-02-14 19:47:42 +00:00
|
|
|
use xCAT::GlobalDef;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
##########################################
|
|
|
|
# Globals
|
|
|
|
##########################################
|
|
|
|
my %modules = (
|
|
|
|
rinv => "xCAT::PPCinv",
|
|
|
|
rpower => "xCAT::PPCpower",
|
|
|
|
rvitals => "xCAT::PPCvitals",
|
|
|
|
rscan => "xCAT::PPCscan",
|
|
|
|
mkvm => "xCAT::PPCvm",
|
|
|
|
rmvm => "xCAT::PPCvm",
|
|
|
|
lsvm => "xCAT::PPCvm",
|
|
|
|
chvm => "xCAT::PPCvm",
|
|
|
|
rnetboot => "xCAT::PPCboot",
|
|
|
|
getmacs => "xCAT::PPCmac",
|
2008-01-11 16:15:51 +00:00
|
|
|
reventlog => "xCAT::PPClog",
|
|
|
|
rfsp => "xCAT::PPCfsp"
|
2007-11-16 19:47:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
##########################################
|
|
|
|
# Database errors
|
|
|
|
##########################################
|
|
|
|
my %errmsg = (
|
|
|
|
NODE_UNDEF =>"Node not defined in '%s' database",
|
|
|
|
NO_ATTR =>"'%s' not defined in '%s' database",
|
|
|
|
DB_UNDEF =>"'%s' database not defined"
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Invokes the callback with the specified message
|
|
|
|
##########################################################################
|
2008-02-18 20:26:39 +00:00
|
|
|
sub send_msg {
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
my $request = shift;
|
2008-02-18 20:26:39 +00:00
|
|
|
my $ecode = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
my %output;
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
# Called from child process - send to parent
|
|
|
|
#################################################
|
|
|
|
if ( exists( $request->{pipe} )) {
|
|
|
|
my $out = $request->{pipe};
|
|
|
|
|
2008-02-18 20:26:39 +00:00
|
|
|
$output{errorcode} = $ecode;
|
2007-11-16 19:47:00 +00:00
|
|
|
$output{data} = \@_;
|
|
|
|
print $out freeze( [\%output] );
|
2007-12-06 16:36:32 +00:00
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
#################################################
|
|
|
|
# Called from parent - invoke callback directly
|
|
|
|
#################################################
|
|
|
|
elsif ( exists( $request->{callback} )) {
|
|
|
|
my $callback = $request->{callback};
|
|
|
|
|
2008-02-18 20:26:39 +00:00
|
|
|
$output{errorcode} = $ecode;
|
2007-11-16 19:47:00 +00:00
|
|
|
$output{data} = \@_;
|
|
|
|
$callback->( \%output );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Fork child to execute remote commands
|
|
|
|
##########################################################################
|
|
|
|
sub process_command {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $maxp = 64;
|
|
|
|
my %nodes = ();
|
|
|
|
my $callback = $request->{callback};
|
|
|
|
my $start;
|
|
|
|
|
2007-12-04 15:39:28 +00:00
|
|
|
#######################################
|
|
|
|
# Get max processes to fork
|
|
|
|
#######################################
|
|
|
|
my $sitetab = xCAT::Table->new('site');
|
|
|
|
if ( defined( $sitetab )) {
|
2007-12-04 15:41:44 +00:00
|
|
|
my ($ent) = $sitetab->getAttribs({'key'=>'ppcmaxp'},'value');
|
2007-12-04 15:39:28 +00:00
|
|
|
if ( defined($ent) ) {
|
|
|
|
$maxp = $ent->{value};
|
|
|
|
}
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
if ( exists( $request->{verbose} )) {
|
|
|
|
$start = Time::HiRes::gettimeofday();
|
|
|
|
}
|
|
|
|
#######################################
|
|
|
|
# Group nodes based on command
|
|
|
|
#######################################
|
|
|
|
my $nodes = preprocess_nodes( $request );
|
|
|
|
if ( !defined( $nodes )) {
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
#######################################
|
|
|
|
# Fork process
|
|
|
|
#######################################
|
|
|
|
my $children = 0;
|
|
|
|
$SIG{CHLD} = sub { while (waitpid(-1, WNOHANG) > 0) { $children--; } };
|
|
|
|
my $fds = new IO::Select;
|
|
|
|
|
|
|
|
foreach ( @$nodes ) {
|
|
|
|
while ( $children > $maxp ) {
|
2008-02-11 20:14:51 +00:00
|
|
|
Time::HiRes::sleep(0.1);
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
my $pipe = fork_cmd( @$_[0], @$_[1], $request );
|
|
|
|
if ( $pipe ) {
|
|
|
|
$fds->add( $pipe );
|
|
|
|
$children++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#######################################
|
|
|
|
# Process responses from children
|
|
|
|
#######################################
|
|
|
|
while ( $children > 0 ) {
|
|
|
|
child_response( $callback, $fds );
|
2008-02-18 20:00:34 +00:00
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
if ( exists( $request->{verbose} )) {
|
2008-02-18 20:00:34 +00:00
|
|
|
trace( $request, $start );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-06 16:36:32 +00:00
|
|
|
##########################################################################
|
|
|
|
# Verbose mode (-V)
|
|
|
|
##########################################################################
|
|
|
|
sub trace {
|
|
|
|
|
|
|
|
my $request = shift;
|
2008-02-18 20:00:34 +00:00
|
|
|
my $start = shift;
|
2007-12-06 16:36:32 +00:00
|
|
|
my $msg = shift;
|
2008-02-18 20:00:34 +00:00
|
|
|
my %output;
|
2007-12-06 16:36:32 +00:00
|
|
|
|
2008-02-18 20:00:34 +00:00
|
|
|
my $elapsed = Time::HiRes::gettimeofday() - $start;
|
|
|
|
my $time = sprintf( "Total Elapsed Time: %.3f sec\n", $elapsed );
|
2007-12-06 16:36:32 +00:00
|
|
|
my ($sec,$min,$hour,$mday,$mon,$yr,$wday,$yday,$dst) = localtime(time);
|
2008-02-18 20:00:34 +00:00
|
|
|
my $msg = sprintf "%02d:%02d:%02d %5d %s", $hour,$min,$sec,$$,$time;
|
|
|
|
|
|
|
|
my $callback = $request->{callback};
|
|
|
|
$output{data} = \@_;
|
|
|
|
$callback->( \%output );
|
2007-12-06 16:36:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##########################################################################
|
|
|
|
# Send response from child process back to xCAT client
|
|
|
|
##########################################################################
|
|
|
|
sub child_response {
|
|
|
|
|
|
|
|
my $callback = shift;
|
|
|
|
my $fds = shift;
|
|
|
|
my @ready_fds = $fds->can_read(1);
|
|
|
|
|
|
|
|
foreach my $rfh (@ready_fds) {
|
|
|
|
my $data;
|
|
|
|
|
|
|
|
#################################
|
2007-12-06 16:36:32 +00:00
|
|
|
# Read from child process
|
2007-11-16 19:47:00 +00:00
|
|
|
#################################
|
2007-12-06 16:36:32 +00:00
|
|
|
if ( $data = <$rfh> ) {
|
|
|
|
while ($data !~ /ENDOFFREEZE6sK4ci/) {
|
|
|
|
$data .= <$rfh>;
|
|
|
|
}
|
|
|
|
my $responses = thaw($data);
|
|
|
|
foreach ( @$responses ) {
|
|
|
|
$callback->( $_ );
|
|
|
|
}
|
|
|
|
next;
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
#################################
|
2007-12-06 16:36:32 +00:00
|
|
|
# Done - close handle
|
2007-11-16 19:47:00 +00:00
|
|
|
#################################
|
|
|
|
$fds->remove($rfh);
|
|
|
|
close($rfh);
|
2007-12-06 16:36:32 +00:00
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Group nodes depending on command
|
|
|
|
##########################################################################
|
|
|
|
sub preprocess_nodes {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $noderange = $request->{node};
|
|
|
|
my $method = $request->{method};
|
|
|
|
my %nodehash = ();
|
|
|
|
my @nodegroup = ();
|
|
|
|
my %tabs = ();
|
|
|
|
|
|
|
|
########################################
|
|
|
|
# Special cases
|
|
|
|
# rscan - Nodes are hardware control pts
|
|
|
|
# Direct-attached FSP
|
|
|
|
########################################
|
|
|
|
if (( $request->{command} eq "rscan" ) or
|
|
|
|
( $request->{hwtype} eq "fsp" )) {
|
|
|
|
|
2007-11-26 16:07:00 +00:00
|
|
|
my $tab = ($request->{hwtype} eq "fsp") ? "ppcdirect" : "ppchcp";
|
2007-11-16 19:47:00 +00:00
|
|
|
my $db = xCAT::Table->new( $tab );
|
|
|
|
|
|
|
|
if ( !defined( $db )) {
|
2008-02-18 20:26:39 +00:00
|
|
|
send_msg( $request, 1, sprintf( $errmsg{DB_UNDEF}, $tab ));
|
2007-11-16 19:47:00 +00:00
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Process each node
|
|
|
|
####################################
|
|
|
|
foreach ( @$noderange ) {
|
|
|
|
my ($ent) = $db->getAttribs( {hcp=>$_},"hcp" );
|
|
|
|
|
|
|
|
if ( !defined( $ent )) {
|
|
|
|
my $msg = sprintf( "$_: $errmsg{NODE_UNDEF}", $tab );
|
2008-02-18 20:26:39 +00:00
|
|
|
send_msg( $request, 1, $msg );
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
################################
|
|
|
|
# Save values
|
|
|
|
################################
|
|
|
|
push @nodegroup,[$_];
|
|
|
|
}
|
|
|
|
return( \@nodegroup );
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################################
|
|
|
|
# Open databases needed
|
|
|
|
##########################################
|
|
|
|
foreach ( qw(ppc vpd nodelist) ) {
|
|
|
|
$tabs{$_} = xCAT::Table->new($_);
|
|
|
|
|
|
|
|
if ( !exists( $tabs{$_} )) {
|
2008-02-18 20:26:39 +00:00
|
|
|
send_msg( $request, 1, sprintf( $errmsg{DB_UNDEF}, $_ ));
|
2007-11-16 19:47:00 +00:00
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##########################################
|
|
|
|
# Group nodes
|
|
|
|
##########################################
|
|
|
|
foreach my $node ( @$noderange ) {
|
|
|
|
my $d = resolve( $request, $node, \%tabs );
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Error locating node attributes
|
|
|
|
######################################
|
|
|
|
if ( ref($d) ne 'ARRAY' ) {
|
2008-02-18 20:26:39 +00:00
|
|
|
send_msg( $request, 1, "$node: $d");
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Get data values
|
|
|
|
######################################
|
|
|
|
my $hcp = @$d[3];
|
|
|
|
my $mtms = @$d[2];
|
|
|
|
|
|
|
|
$nodehash{$hcp}{$mtms}{$node} = $d;
|
|
|
|
}
|
|
|
|
##########################################
|
|
|
|
# Group the nodes - we will fork one
|
|
|
|
# process per nodegroup array element.
|
|
|
|
##########################################
|
|
|
|
|
|
|
|
##########################################
|
|
|
|
# These commands are grouped on an
|
|
|
|
# LPAR-by-LPAR basis - fork one process
|
|
|
|
# per LPAR.
|
|
|
|
##########################################
|
|
|
|
if ( $method =~ /^getmacs|rnetboot$/ ) {
|
|
|
|
while (my ($hcp,$hash) = each(%nodehash) ) {
|
|
|
|
while (my ($mtms,$h) = each(%$hash) ) {
|
|
|
|
while (my ($lpar,$d) = each(%$h)) {
|
|
|
|
push @$d, $lpar;
|
|
|
|
push @nodegroup,[$hcp,$d];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( \@nodegroup );
|
|
|
|
}
|
|
|
|
##########################################
|
|
|
|
# Power control commands are grouped
|
|
|
|
# by CEC which is the smallest entity
|
|
|
|
# that commands can be sent to in parallel.
|
|
|
|
# If commands are sent in parallel to a
|
|
|
|
# single CEC, the CEC itself will serialize
|
|
|
|
# them - fork one process per CEC.
|
|
|
|
##########################################
|
|
|
|
elsif ( $method =~ /^powercmd/ ) {
|
|
|
|
while (my ($hcp,$hash) = each(%nodehash) ) {
|
|
|
|
while (my ($mtms,$h) = each(%$hash) ) {
|
|
|
|
push @nodegroup,[$hcp,$h];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( \@nodegroup );
|
|
|
|
}
|
|
|
|
##########################################
|
|
|
|
# All other commands are grouped by
|
|
|
|
# hardware control point - fork one
|
|
|
|
# process per hardware control point.
|
|
|
|
##########################################
|
|
|
|
while (my ($hcp,$hash) = each(%nodehash) ) {
|
|
|
|
push @nodegroup,[$hcp,$hash];
|
|
|
|
}
|
|
|
|
return( \@nodegroup );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Findis attributes for given node is various databases
|
|
|
|
##########################################################################
|
|
|
|
sub resolve {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $node = shift;
|
|
|
|
my $tabs = shift;
|
2007-11-19 16:39:20 +00:00
|
|
|
my @attribs = qw(id profile parent hcp);
|
2007-11-16 19:47:00 +00:00
|
|
|
my @values = ();
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Get node type
|
|
|
|
#################################
|
|
|
|
my ($ent) = $tabs->{nodelist}->getAttribs({'node'=>$node}, "nodetype" );
|
|
|
|
if ( !defined( $ent )) {
|
|
|
|
return( sprintf( $errmsg{NODE_UNDEF}, "nodelist" ));
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Check for type
|
|
|
|
#################################
|
|
|
|
if ( !exists( $ent->{nodetype} )) {
|
|
|
|
return( sprintf( $errmsg{NO_ATTR}, $ent->{nodetype}, "nodelist" ));
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Check for valid "type"
|
|
|
|
#################################
|
2008-02-14 19:47:42 +00:00
|
|
|
my ($type) = grep(
|
|
|
|
/^$::NODETYPE_LPAR|$::NODETYPE_OSI|$::NODETYPE_BPA|$::NODETYPE_FSP$/,
|
|
|
|
split /,/, $ent->{nodetype} );
|
2008-02-13 19:26:13 +00:00
|
|
|
|
|
|
|
if ( !defined( $type )) {
|
2007-11-16 19:47:00 +00:00
|
|
|
return( "Invalid node type: $ent->{nodetype}" );
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Get attributes
|
|
|
|
#################################
|
|
|
|
my ($att) = $tabs->{ppc}->getAttribs({'node'=>$node}, @attribs );
|
|
|
|
|
|
|
|
if ( !defined( $att )) {
|
|
|
|
return( sprintf( $errmsg{NODE_UNDEF}, "ppc" ));
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Special lpar processing
|
|
|
|
#################################
|
2008-02-14 19:47:42 +00:00
|
|
|
if ( $type =~ /^$::NODETYPE_OSI|$::NODETYPE_LPAR$/ ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
$att->{bpa} = 0;
|
|
|
|
$att->{type} = "lpar";
|
2007-11-19 16:39:20 +00:00
|
|
|
$att->{node} = $att->{parent};
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2007-11-19 16:39:20 +00:00
|
|
|
if ( !exists( $att->{parent} )) {
|
|
|
|
return( sprintf( $errmsg{NO_ATTR}, "parent", "ppc" ));
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
#############################
|
|
|
|
# Get BPA (if any)
|
|
|
|
#############################
|
|
|
|
if (( $request->{command} eq "rvitals" ) &&
|
|
|
|
( $request->{method} =~ /^all|temp$/ )) {
|
2007-11-19 16:39:20 +00:00
|
|
|
my ($ent) = $tabs->{ppc}->getAttribs(
|
|
|
|
{node=>$att->{parent}}, "parent" );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
#############################
|
|
|
|
# Find MTMS in vpd database
|
|
|
|
#############################
|
2007-11-19 16:39:20 +00:00
|
|
|
if (( defined( $ent )) && exists( $ent->{parent} )) {
|
2007-11-16 19:47:00 +00:00
|
|
|
my @attrs = qw(mtm serial);
|
2007-11-19 16:39:20 +00:00
|
|
|
my ($vpd) = $tabs->{vpd}->getAttribs(
|
|
|
|
{node=>$ent->{parent}},@attrs );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
if ( !defined( $vpd )) {
|
|
|
|
return( sprintf( $errmsg{NO_UNDEF}, "vpd" ));
|
|
|
|
}
|
|
|
|
########################
|
|
|
|
# Verify attributes
|
|
|
|
########################
|
|
|
|
foreach ( @attrs ) {
|
|
|
|
if ( !exists( $vpd->{$_} )) {
|
|
|
|
return( sprintf( $errmsg{NO_ATTR}, $_, "vpd" ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$att->{bpa} = "$vpd->{mtm}*$vpd->{serial}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Optional and N/A fields
|
|
|
|
#################################
|
2008-02-14 19:47:42 +00:00
|
|
|
elsif ( $type =~ /^$::NODETYPE_FSP$/ ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
$att->{profile} = 0;
|
|
|
|
$att->{id} = 0;
|
|
|
|
$att->{fsp} = 0;
|
|
|
|
$att->{node} = $node;
|
|
|
|
$att->{type} = $type;
|
2007-11-19 16:39:20 +00:00
|
|
|
$att->{parent} = exists($att->{parent}) ? $att->{parent} : 0;
|
|
|
|
$att->{bpa} = $att->{parent};
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-03-06 15:17:30 +00:00
|
|
|
elsif ( $type =~ /^$::NODETYPE_BPA$/ ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
$att->{profile} = 0;
|
|
|
|
$att->{id} = 0;
|
|
|
|
$att->{bpa} = 0;
|
2007-11-19 16:39:20 +00:00
|
|
|
$att->{parent} = 0;
|
2007-11-16 19:47:00 +00:00
|
|
|
$att->{fsp} = 0;
|
|
|
|
$att->{node} = $node;
|
|
|
|
$att->{type} = $type;
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Find MTMS in vpd database
|
|
|
|
#################################
|
|
|
|
my @attrs = qw(mtm serial);
|
|
|
|
my ($vpd) = $tabs->{vpd}->getAttribs({node=>$att->{node}}, @attrs );
|
|
|
|
|
|
|
|
if ( !defined( $vpd )) {
|
|
|
|
return( sprintf( $errmsg{NODE_UNDEF}, "vpd" ));
|
|
|
|
}
|
|
|
|
################################
|
|
|
|
# Verify both vpd attributes
|
|
|
|
################################
|
|
|
|
foreach ( @attrs ) {
|
|
|
|
if ( !exists( $vpd->{$_} )) {
|
|
|
|
return( sprintf( $errmsg{NO_ATTR}, $_, "vpd" ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$att->{fsp} = "$vpd->{mtm}*$vpd->{serial}";
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Verify required attributes
|
|
|
|
#################################
|
|
|
|
foreach my $at ( @attribs ) {
|
|
|
|
if ( !exists( $att->{$at} )) {
|
|
|
|
return( sprintf( $errmsg{NO_ATTR}, $at, "ppc" ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Build array of data
|
|
|
|
#################################
|
|
|
|
foreach ( qw(id profile fsp hcp type bpa) ) {
|
|
|
|
push @values, $att->{$_};
|
|
|
|
}
|
|
|
|
return( \@values );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Forks a process to run the ssh command
|
|
|
|
##########################################################################
|
|
|
|
sub fork_cmd {
|
|
|
|
|
|
|
|
my $host = shift;
|
|
|
|
my $nodes = shift;
|
|
|
|
my $request = shift;
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Pipe childs output back to parent
|
|
|
|
#######################################
|
|
|
|
my $parent;
|
|
|
|
my $child;
|
|
|
|
pipe $parent, $child;
|
2008-01-21 19:49:59 +00:00
|
|
|
my $pid = xCAT::Utils->xfork;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
if ( !defined($pid) ) {
|
|
|
|
###################################
|
|
|
|
# Fork error
|
|
|
|
###################################
|
2008-02-18 20:26:39 +00:00
|
|
|
send_msg( $request, 1, "Fork error: $!" );
|
2007-11-16 19:47:00 +00:00
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
elsif ( $pid == 0 ) {
|
|
|
|
###################################
|
|
|
|
# Child process
|
|
|
|
###################################
|
|
|
|
close( $parent );
|
|
|
|
$request->{pipe} = $child;
|
|
|
|
|
|
|
|
invoke_cmd( $host, $nodes, $request );
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
###################################
|
|
|
|
# Parent process
|
|
|
|
###################################
|
|
|
|
close( $child );
|
|
|
|
return( $parent );
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Run the command, process the response, and send to parent
|
|
|
|
##########################################################################
|
|
|
|
sub invoke_cmd {
|
|
|
|
|
|
|
|
my $host = shift;
|
|
|
|
my $nodes = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $hwtype = $request->{hwtype};
|
|
|
|
my $verbose = $request->{verbose};
|
|
|
|
my @exp;
|
2007-12-07 16:10:10 +00:00
|
|
|
my $verbose_log;
|
2007-11-16 19:47:00 +00:00
|
|
|
my @outhash;
|
2007-12-07 16:10:10 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
########################################
|
|
|
|
# Direct-attached FSP handler
|
|
|
|
########################################
|
|
|
|
if ( $hwtype eq "fsp" ) {
|
2008-03-10 19:08:34 +00:00
|
|
|
|
|
|
|
####################################
|
|
|
|
# Dynamically load FSP module
|
|
|
|
####################################
|
|
|
|
eval { require xCAT::PPCfsp };
|
|
|
|
if ( $@ ) {
|
|
|
|
send_msg( $request, 1, $@ );
|
|
|
|
return;
|
|
|
|
}
|
2007-12-06 19:09:40 +00:00
|
|
|
my @exp = xCAT::PPCfsp::connect( $request, $host );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2007-12-06 19:09:40 +00:00
|
|
|
####################################
|
|
|
|
# Error connecting
|
|
|
|
####################################
|
|
|
|
if ( ref($exp[0]) ne "LWP::UserAgent" ) {
|
2008-02-18 20:26:39 +00:00
|
|
|
send_msg( $request, 1, $exp[0] );
|
2007-12-06 19:09:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
my $result = xCAT::PPCfsp::handler( $host, $request, \@exp );
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Output verbose Perl::LWP
|
|
|
|
####################################
|
|
|
|
if ( $verbose ) {
|
2007-12-07 16:10:10 +00:00
|
|
|
$verbose_log = $exp[3];
|
|
|
|
|
|
|
|
my %output;
|
|
|
|
$output{data} = [$$verbose_log];
|
|
|
|
unshift @$result, \%output;
|
2007-12-06 19:09:40 +00:00
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
my $out = $request->{pipe};
|
|
|
|
print $out freeze( $result );
|
2007-12-06 16:36:32 +00:00
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
2007-11-16 19:47:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-12-07 16:10:10 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
########################################
|
2007-12-07 16:10:10 +00:00
|
|
|
# HMC and IVM-managed handler
|
2007-11-16 19:47:00 +00:00
|
|
|
# Connect to list of remote servers
|
|
|
|
########################################
|
|
|
|
foreach ( split /,/, $host ) {
|
|
|
|
@exp = xCAT::PPCcli::connect( $hwtype, $_, $verbose );
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Successfully connected
|
|
|
|
####################################
|
|
|
|
if ( ref($exp[0]) eq "Expect" ) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
########################################
|
|
|
|
# Error connecting
|
|
|
|
########################################
|
|
|
|
if ( ref($exp[0]) ne "Expect" ) {
|
2008-02-18 20:26:39 +00:00
|
|
|
send_msg( $request, 1, $exp[0] );
|
2007-11-16 19:47:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
########################################
|
|
|
|
# Process specific command
|
|
|
|
########################################
|
|
|
|
my $result = runcmd( $request, $nodes, \@exp );
|
|
|
|
|
2007-12-06 19:09:40 +00:00
|
|
|
########################################
|
|
|
|
# Close connection to remote server
|
|
|
|
########################################
|
|
|
|
xCAT::PPCcli::disconnect( \@exp );
|
|
|
|
|
2007-12-06 16:36:32 +00:00
|
|
|
########################################
|
2007-12-07 16:10:10 +00:00
|
|
|
# Get verbose Expect output
|
2007-12-06 16:36:32 +00:00
|
|
|
########################################
|
|
|
|
if ( $verbose ) {
|
2007-12-07 16:10:10 +00:00
|
|
|
$verbose_log = $exp[6];
|
2007-12-06 16:36:32 +00:00
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
########################################
|
|
|
|
# Return error
|
|
|
|
########################################
|
|
|
|
if ( ref($result) ne 'ARRAY' ) {
|
2008-02-18 20:26:39 +00:00
|
|
|
send_msg( $request, 1, $$verbose_log.$result );
|
2007-11-16 19:47:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
########################################
|
2007-12-07 16:10:10 +00:00
|
|
|
# Prepend verbose output
|
|
|
|
########################################
|
|
|
|
if ( defined( $verbose_log )) {
|
|
|
|
my %output;
|
|
|
|
$output{data} = [$$verbose_log];
|
|
|
|
push @outhash, \%output;
|
|
|
|
}
|
|
|
|
########################################
|
2007-11-16 19:47:00 +00:00
|
|
|
# Send result back to parent process
|
|
|
|
########################################
|
2007-12-06 16:36:32 +00:00
|
|
|
if ( @$result[0] eq "FORMATDATA6sK4ci" ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
my $out = $request->{pipe};
|
2007-12-07 16:10:10 +00:00
|
|
|
|
|
|
|
push @outhash, @$result[1];
|
|
|
|
print $out freeze( [@outhash] );
|
2007-12-06 16:36:32 +00:00
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
2007-11-16 19:47:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
########################################
|
|
|
|
# Format and send back to parent
|
|
|
|
########################################
|
|
|
|
foreach ( @$result ) {
|
|
|
|
my %output;
|
|
|
|
$output{node}->[0]->{name}->[0] = @$_[0];
|
|
|
|
$output{node}->[0]->{data}->[0]->{contents}->[0] = @$_[1];
|
2008-03-04 20:16:35 +00:00
|
|
|
$output{errorcode} = @$_[2];
|
2007-11-16 19:47:00 +00:00
|
|
|
push @outhash, \%output;
|
|
|
|
}
|
|
|
|
my $out = $request->{pipe};
|
|
|
|
print $out freeze( [@outhash] );
|
2007-12-06 16:36:32 +00:00
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Run the command method specified
|
|
|
|
##########################################################################
|
|
|
|
sub runcmd {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $cmd = $request->{command};
|
|
|
|
my $method = $request->{method};
|
2007-11-30 20:04:17 +00:00
|
|
|
my $hwtype = $request->{hwtype};
|
2007-11-16 19:47:00 +00:00
|
|
|
my $modname = $modules{$cmd};
|
2007-11-30 20:04:17 +00:00
|
|
|
|
|
|
|
######################################
|
|
|
|
# Command not supported
|
|
|
|
######################################
|
|
|
|
if ( !defined( $modname )) {
|
|
|
|
return( ["$cmd not a supported command by $hwtype method"] );
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
######################################
|
|
|
|
# Load specific module
|
|
|
|
######################################
|
2008-01-10 14:34:34 +00:00
|
|
|
eval "require $modname";
|
|
|
|
if ( $@ ) {
|
|
|
|
return( [$@] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Invoke method
|
|
|
|
######################################
|
|
|
|
no strict 'refs';
|
|
|
|
my $result = ${$modname."::"}{$method}->($request,@_);
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
return( $result );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Process request from xCat daemon
|
|
|
|
##########################################################################
|
|
|
|
sub process_request {
|
|
|
|
|
|
|
|
my $package = shift;
|
|
|
|
my $req = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Get hwtype
|
|
|
|
####################################
|
|
|
|
$package =~ s/xCAT_plugin:://;
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Build hash to pass around
|
|
|
|
####################################
|
|
|
|
my %request;
|
|
|
|
$request{command} = $req->{command}->[0];
|
|
|
|
$request{arg} = $req->{arg};
|
|
|
|
$request{node} = $req->{node};
|
|
|
|
$request{stdin} = $req->{stdin}->[0];
|
|
|
|
$request{hwtype} = $package;
|
|
|
|
$request{callback} = $callback;
|
|
|
|
$request{method} = "parse_args";
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Process command-specific options
|
|
|
|
####################################
|
|
|
|
my $opt = runcmd( \%request );
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Return error
|
|
|
|
####################################
|
|
|
|
if ( ref($opt) eq 'ARRAY' ) {
|
2008-02-18 20:26:39 +00:00
|
|
|
send_msg( \%request, 1, @$opt );
|
2007-11-16 19:47:00 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Option -V for verbose output
|
|
|
|
####################################
|
|
|
|
if ( exists( $opt->{V} )) {
|
|
|
|
$request{verbose} = 1;
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Process remote command
|
|
|
|
####################################
|
|
|
|
$request{opt} = $opt;
|
|
|
|
process_command( \%request );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1;
|
2007-11-19 16:39:20 +00:00
|
|
|
|
2007-12-04 15:39:28 +00:00
|
|
|
|
2007-12-06 16:36:32 +00:00
|
|
|
|
2008-02-13 19:26:13 +00:00
|
|
|
|
2008-02-14 19:47:42 +00:00
|
|
|
|
2008-02-18 20:00:34 +00:00
|
|
|
|
2008-02-18 20:26:39 +00:00
|
|
|
|