HMC alternative: FSPinv.pm, FSPpower.pm, fsp for rcons

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4750 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jjhua 2009-12-10 02:19:40 +00:00
parent 163102fa18
commit 366fdd26a0
9 changed files with 585 additions and 259 deletions

View File

@ -1,10 +1,11 @@
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::Directinv;
package xCAT::FSPinv;
use strict;
use Getopt::Long;
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
use xCAT::Usage;
use xCAT::PPCinv;
use Data::Dumper;
##########################################
@ -25,6 +26,15 @@ my @licmap = (
["curr_level_secondary", "Level Secondary"]
);
##########################################################################
# Parse the command line for options and operands
##########################################################################
sub parse_args {
xCAT::PPCinv::parse_args(@_);
}
##########################################################################
# Returns FSP/BPA firmware information
@ -35,13 +45,13 @@ sub firmware {
my $hash = shift;
my @result;
# print "in Directinv \n";
# print "in FSPinv \n";
#print Dumper($request);
#print Dumper($hash);
####################################
# Power commands are grouped by hardware control point
# In Direct attach support, the hcp is the related fsp.
# FSPinv with firm command is grouped by hardware control point
# In FSPinv, the hcp is the related fsp.
####################################
# Example of $hash.
@ -50,12 +60,12 @@ sub firmware {
# 'Server-9110-51A-SN1075ECF' => [
# 0,
# 0,
# '9110-51A*1075ECF',
# 'fsp1_name',
# 'fsp',
# 0
# ]
# }
# '9110-51A*1075ECF',
# 'fsp1_name',
# 'fsp',
# 0
# ]
# }
# };
while (my ($mtms,$h) = each(%$hash) ) {
@ -91,9 +101,10 @@ sub firmware {
#####################################
# Format fsp-api results
#####################################
foreach ( @licmap ) {
if ( $data->{$name} =~ /@$_[0]=(\w+)/ ) {
push @result, [$name,"@$_[1]: $1",$Rc];
my $val;
foreach $val ( @licmap ) {
if ( $data->{$name} =~ /@$val[0]=(\w+)/ ) {
push @result, [$name,"@$val[1]: $1",$Rc];
}
}
}
@ -101,13 +112,15 @@ sub firmware {
return( \@result );
}
##########################################################################
# invoke the fsp-api command
##########################################################################
sub action {
my $node_name = shift;
my $d = shift;
my $attrs = shift;
my $action = shift;
# my $user = "HMC";
# my $password = "abc123";
my $fsp_api ="/opt/xcat/sbin/fsp-api";
# my $fsp_api ="/opt/xcat/sbin/fsp-api";
my $fsp_api = ($::XCATROOT) ? "$::XCATROOT/sbin/fsp-api" : "/opt/xcat/sbin/fsp-api";
my $id = 1;
my $fsp_name = ();
my $fsp_ip = ();
@ -117,17 +130,17 @@ sub action {
my $Rc = 0 ;
my %outhash = ();
$id = $$d[0];
$fsp_name = $$d[3];
$id = $$attrs[0];
$fsp_name = $$attrs[3];
my %objhash = ();
$objhash{$fsp_name} = "node";
my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash);
my $password = $myhash{$fsp_name}{"passwd.HMC"};
my $password = $myhash{$fsp_name}{"passwd.hscroot"};
#print "fspname:$fsp_name password:$password\n";
#print Dumper(%myhash);
if(!$password ) {
$outhash{$node_name} = "The password.HMC of $fsp_name in ppcdirect table is empty";
$outhash{$node_name} = "The password.hscroot of $fsp_name in ppcdirect table is empty";
return ([-1, \%outhash]);
}
# my $user = "HMC";
@ -136,10 +149,10 @@ sub action {
# my $user = @$cred[0];
# my $password = @$cred[1];
if($$d[4] =~ /^lpar$/) {
if($$attrs[4] =~ /^lpar$/) {
$type = 0;
$id = 1;
} elsif($$d[4] =~ /^fsp$/) {
} elsif($$attrs[4] =~ /^fsp$/) {
$type = 0;
} else {
$type = 1;
@ -148,24 +161,13 @@ sub action {
############################
# Get IP address
############################
my $hosttab = xCAT::Table->new( 'hosts' );
if ( $hosttab)
{
my $node_ip_hash = $hosttab->getNodeAttribs( $fsp_name,[qw(ip)]);
$fsp_ip = $node_ip_hash->{ip};
}
if (!$fsp_ip)
{
my $ip_tmp_res = xCAT::Utils::toIP($fsp_name);
($Rc, $fsp_ip) = @$ip_tmp_res;
if ( $Rc )
{
$outhash{$node_name} = "Failed to get the $fsp_name\'s ip";
return ([-1, \%outhash]);
}
$fsp_ip = xCAT::Utils::get_hdwr_ip($fsp_name);
if($fsp_ip == -1) {
$outhash{$node_name} = "Failed to get the $fsp_name\'s ip";
return ([-1, \%outhash]);
}
print "fsp name: $fsp_name\n";
print "fsp ip: $fsp_ip\n";
@ -173,19 +175,14 @@ sub action {
print "cmd: $cmd\n";
$SIG{CHLD} = ();
my @res = xCAT::Utils->runcmd($cmd, -1);
my $res = xCAT::Utils->runcmd($cmd, -1);
if($::RUNCMD_RC != 0){
$Rc = -1;
} else {
$Rc = SUCCESS;
}
my $r = ();
foreach $r (@res) {
chomp $r;
print "r:$r\n";
$outhash{ $node_name } = $r;
}
$outhash{ $node_name } = $res;
return( [$Rc,\%outhash] );

View File

@ -1,6 +1,6 @@
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::Directpower;
package xCAT::FSPpower;
use strict;
#use Getopt::Long;
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
@ -8,6 +8,17 @@ use xCAT::Usage;
use xCAT::MsgUtils;
use Data::Dumper;
use xCAT::DBobjUtils;
use xCAT::PPCpower;
##########################################################################
# Parse the command line for options and operands
##########################################################################
sub parse_args {
xCAT::PPCpower::parse_args(@_);
}
##########################################################################
# Performs boot operation (Off->On, On->Reset)
@ -27,51 +38,51 @@ sub powercmd_boot {
#Example of $hash
# $VAR1 = {
# 'Server-9110-51A-SN1075ECF' => [
# 0,
# 0,
# '9110-51A*1075ECF',
# 'Server-9110-51A-SN1075ECF',
# 'fsp',
# 0
# ]
# 0,
# 0,
# '9110-51A*1075ECF',
# 'Server-9110-51A-SN1075ECF',
# 'fsp',
# 0
# ]
# }
foreach my $node_name ( keys %$hash)
{
my $d = $hash->{$node_name};
my $stat = action ($node_name, $d, "state");
my $d = $hash->{$node_name};
my $stat = action ($node_name, $d, "state");
print "In boot, state\n";
print Dumper($stat);
my $Rc = shift(@$stat);
my $data = @$stat[0];
my $type = @$d[4];
my $id = ($type=~/^(fsp|bpa)$/) ? $type : @$d[0];
my $Rc = shift(@$stat);
my $data = @$stat[0];
my $type = @$d[4];
my $id = ($type=~/^(fsp|bpa)$/) ? $type : @$d[0];
##################################
# Output error
##################################
if ( $Rc != SUCCESS ) {
push @output, [$node_name,$data,$Rc];
next;
}
my $t = $data->{$node_name};
print "boot: $t \n";
##################################
# Convert state to on/off
##################################
my $state = power_status($data->{$node_name});
print "boot:state:$state\n";
my $op = ($state =~ /^off$/) ? "on" : "reset";
$stat = action ($node_name, $d, $op);
# Output error
##################################
if ( $Rc != SUCCESS ) {
push @output, [$node_name,$data,$Rc];
next;
}
my $t = $data->{$node_name};
print "boot: $t \n";
##################################
# Convert state to on/off
##################################
my $state = power_status($data->{$node_name});
print "boot:state:$state\n";
my $op = ($state =~ /^off$/) ? "on" : "reset";
$stat = action ($node_name, $d, $op);
# @output ...
$Rc = shift(@$stat);
$data = @$stat[0];
if ( $Rc != SUCCESS ) {
push @output, [$node_name,$data->{$node_name},$Rc];
next;
}
push @output,[$node_name, "SUCCESS", 0];
# @output ...
$Rc = shift(@$stat);
$data = @$stat[0];
if ( $Rc != SUCCESS ) {
push @output, [$node_name,$data->{$node_name},$Rc];
next;
}
push @output,[$node_name, "SUCCESS", 0];
}
return( \@output );
@ -111,25 +122,25 @@ sub powercmd {
foreach my $node_name ( keys %$hash)
{
my $d = $hash->{$node_name};
my $res = action ($node_name, $d, $request->{'op'});
print "In boot, state\n";
print Dumper($res);
my $Rc = shift(@$res);
my $data = @$res[0];
my $t = $data->{$node_name};
my $type = @$d[4];
my $id = ($type=~/^(fsp|bpa)$/) ? $type : @$d[0];
my $d = $hash->{$node_name};
my $res = action ($node_name, $d, $request->{'op'});
print "In boot, state\n";
print Dumper($res);
my $Rc = shift(@$res);
my $data = @$res[0];
my $t = $data->{$node_name};
my $type = @$d[4];
my $id = ($type=~/^(fsp|bpa)$/) ? $type : @$d[0];
##################################
# Output error
##################################
if ( $Rc != SUCCESS ) {
push @output, [$node_name,$t,$Rc];
next;
}
##################################
# Output error
##################################
if ( $Rc != SUCCESS ) {
push @output, [$node_name,$t,$Rc];
next;
}
push @output, [$node_name,$t,$Rc];
push @output, [$node_name,$t,$Rc];
}
return( \@output );
@ -138,7 +149,7 @@ sub powercmd {
##########################################################################
# Queries CEC/LPAR power status (On or Off)
# Queries CEC/LPAR power status (On or Off) for powercmd_boot
##########################################################################
sub power_status {
@ -155,6 +166,9 @@ sub power_status {
return("off");
}
##########################################################################
# Queries CEC/LPAR power status
##########################################################################
sub state {
my $request = shift;
@ -168,7 +182,7 @@ sub state {
#print Dumper($hash);
####################################
# Power commands are grouped by hardware control point
# In Direct attach support, the hcp is the related fsp.
# In FSPpower, the hcp is the related fsp.
####################################
# Example of $hash.
@ -177,12 +191,12 @@ sub state {
# 'Server-9110-51A-SN1075ECF' => [
# 0,
# 0,
# '9110-51A*1075ECF',
# 'fsp1_name',
# 'fsp',
# 0
# ]
# }
# '9110-51A*1075ECF',
# 'fsp1_name',
# 'fsp',
# 0
# ]
# }
# };
@ -216,13 +230,15 @@ sub state {
}
##########################################################################
# invoke the fsp-api command.
##########################################################################
sub action {
my $node_name = shift;
my $d = shift;
my $attrs = shift;
my $action = shift;
# my $user = "HMC";
# my $password = "abc123";
my $fsp_api ="/home/fsp-api";
# my $fsp_api ="/opt/xcat/sbin/fsp-api";
my $fsp_api = ($::XCATROOT) ? "$::XCATROOT/sbin/fsp-api" : "/opt/xcat/sbin/fsp-api";
my $id = 1;
my $fsp_name = ();
my $fsp_ip = ();
@ -232,17 +248,17 @@ sub action {
my $Rc = 0 ;
my %outhash = ();
$id = $$d[0];
$fsp_name = $$d[3];
$id = $$attrs[0];
$fsp_name = $$attrs[3];
my %objhash = ();
$objhash{$fsp_name} = "node";
my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash);
my $password = $myhash{$fsp_name}{"passwd.HMC"};
my $password = $myhash{$fsp_name}{"passwd.hscroot"};
#print "fspname:$fsp_name password:$password\n";
print Dumper(%myhash);
# print Dumper(%myhash);
if(!$password ) {
$outhash{$node_name} = "The password.HMC of $fsp_name in ppcdirect table is empty";
$outhash{$node_name} = "The password.hscroot of $fsp_name in ppcdirect table is empty";
return ([-1, \%outhash]);
}
# my $user = "HMC";
@ -251,60 +267,48 @@ sub action {
# my $user = @$cred[0];
# my $password = @$cred[1];
if($$d[4] =~ /^lpar$/) {
$type = 0;
} elsif($$d[4] =~ /^fsp$/) {
if($$attrs[4] =~ /^lpar$/) {
$type = 0;
} elsif($$attrs[4] =~ /^fsp$/) {
$type = 0;
if($action =~ /^state$/) {$action = "cec_state"; }
if($action =~ /^on$/) { $action = "cec_on_autostart"; }
if($action =~ /^off$/) { $action = "cec_off"; }
if($action =~ /^of$/ ) {
$outhash{$node_name} = "\'$action\' command not supported";
if($action =~ /^state$/) {$action = "cec_state"; }
if($action =~ /^on$/) { $action = "cec_on_autostart"; }
if($action =~ /^off$/) { $action = "cec_off"; }
if($action =~ /^of$/ ) {
$outhash{$node_name} = "\'$action\' command not supported";
return ([-1, \%outhash]);
}
}
} else {
$type = 1;
if($action =~ /^state$/) {
$action = "cec_state";
} else {
$type = 1;
if($action =~ /^state$/) {
$action = "cec_state";
} else {
$outhash{$node_name} = "$node_name\'s type isn't fsp or lpar. Not allow doing this operation";
return ([-1, \%outhash]);
}
}
############################
# Get IP address
############################
my $hosttab = xCAT::Table->new( 'hosts' );
if ( $hosttab)
{
my $node_ip_hash = $hosttab->getNodeAttribs( $fsp_name,[qw(ip)]);
$fsp_ip = $node_ip_hash->{ip};
}
if (!$fsp_ip)
{
my $ip_tmp_res = xCAT::Utils::toIP($fsp_name);
($Rc, $fsp_ip) = @$ip_tmp_res;
if ( $Rc )
{
$outhash{$node_name} = "Failed to get the $fsp_name\'s ip";
$outhash{$node_name} = "$node_name\'s type isn't fsp or lpar. Not allow doing this operation";
return ([-1, \%outhash]);
}
}
}
}
############################
# Get IP address
############################
$fsp_ip = xCAT::Utils::get_hdwr_ip($fsp_name);
if($fsp_ip == -1) {
$outhash{$node_name} = "Failed to get the $fsp_name\'s ip";
return ([-1, \%outhash]);
}
print "fsp name: $fsp_name\n";
print "fsp ip: $fsp_ip\n";
print "fsp name: $fsp_name\n";
print "fsp ip: $fsp_ip\n";
my $cmd = "$fsp_api -a $action -u $user -p $password -t $type:$fsp_ip:$id:$node_name:";
my $cmd = "$fsp_api -a $action -u $user -p $password -t $type:$fsp_ip:$id:$node_name:";
print "cmd: $cmd\n";
$SIG{CHLD} = ();
my @res = xCAT::Utils->runcmd($cmd, -1);
if($::RUNCMD_RC != 0){
print "cmd: $cmd\n";
$SIG{CHLD} = ();
my $res = xCAT::Utils->runcmd($cmd, -1);
if($::RUNCMD_RC != 0){
$Rc = -1;
} else {
} else {
$Rc = SUCCESS;
####################
# on,off, of, reset, cec_onstandby,cec_off, if $? == 0, it will return sucess
@ -313,18 +317,14 @@ sub action {
$outhash{$node_name} = "Sucess";
return ([$Rc, \%outhash]);
}
}
##################
# state cec_state
#################
my $r = ();
foreach $r (@res) {
chomp $r;
print "jhhg:$r\n";
$outhash{ $node_name } = $r;
}
}
##################
# state cec_state
#################
$outhash{ $node_name } = $res;
return( [$Rc,\%outhash] );
return( [$Rc,\%outhash] );
}

View File

@ -5,7 +5,6 @@ use strict;
use Getopt::Long;
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
use xCAT::Usage;
use xCAT::Directinv;
##########################################
@ -432,11 +431,6 @@ sub firmware {
my $hwtype = @$exp[2];
my @result;
if($request->{direct_attach_support} == 1) {
my $res = xCAT::Directinv::firmware($request, $hash);
return( \$res );
}
while (my ($mtms,$h) = each(%$hash) ) {
while (my ($name,$d) = each(%$h) ) {
@ -448,12 +442,12 @@ sub firmware {
[$name,"Information only available for CEC/BPA/LPAR",RC_ERROR];
next;
}
#################
#For support on Lpars, the flag need to be changed.
##########
if(@$d[4] eq "lpar") {
@$d[4] = "fsp";
}
#################
#For support on Lpars, the flag need to be changed.
##########
if(@$d[4] eq "lpar") {
@$d[4] = "fsp";
}
my $values = xCAT::PPCcli::lslic( $exp, $d );
my $Rc = shift(@$values);

View File

@ -6,7 +6,7 @@ use Getopt::Long;
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
use xCAT::Usage;
use xCAT::MsgUtils;
use xCAT::Directpower;
use xCAT::FSPpower;
##########################################################################
# Parse the command line for options and operands
@ -146,10 +146,6 @@ sub powercmd_boot {
my @output = ();
my $callback = $request->{'callback'};
if($request->{direct_attach_support} == 1) {
my $res = xCAT::Directpower::powercmd_boot($request, $hash);
return( \$res );
}
######################################
# Power commands are grouped by CEC
@ -276,10 +272,6 @@ sub powercmd {
my @result = ();
my $callback = $request->{'callback'};
if($request->{direct_attach_support} == 1) {
my $res = xCAT::Directpower::powercmd($request, $hash);
return( \$res );
}
####################################
# Power commands are grouped by CEC
@ -380,10 +372,6 @@ sub state {
my $convert = shift;
my @result = ();
if($request->{direct_attach_support} == 1) {
my $res = xCAT::Directpower::state($request, $hash);
return( \$res );
}
if ( !defined( $prefix )) {
$prefix = "";

View File

@ -11,7 +11,7 @@ use xCAT::Table;
use Getopt::Long;
use File::Spec;
use POSIX qw(tmpnam);
use xCAT::FSPflash.pm
my $packages_dir= ();
@ -247,15 +247,15 @@ sub noderange_validate {
#my $t = print_var($exargs, "exargs");
#print $t;
if ( grep(/commit/,@$exargs) != 0 || grep(/recover/,@$exargs) != 0) {
#send_msg( $request, 1, "When run \"rflash\" with the \"commit\" or \"recover\" operation, the noderange cannot be BPA and can only be CEC or LPAR.");
#send_msg( $request, 1, "And then, it will do the operation for both managed systems and power subsystems.");
send_msg( $request, 1, "When run \"rflash\" with the \"commit\" or \"recover\" operation, the noderange cannot be BPA and can only be CEC or LPAR.");
send_msg( $request, 1, "And then, it will do the operation for both managed systems and power subsystems.");
return -1;
}
}
}
if($f1 * $f2) {
#send_msg( $request, 1, "The argument noderange of rflash can't be BPA and CEC(or LPAR) at the same time");
send_msg( $request, 1, "The argument noderange of rflash can't be BPA and CEC(or LPAR) at the same time");
return -1;
}
}
@ -264,7 +264,7 @@ sub noderange_validate {
sub preprocess_for_rflash {
my $request = shift;
my $opt = shift;
my $callback = $request->{callback};
my $callback = $request->{callback};
my $packages_fw = "/install/packages_fw";
my $c = 0;
my $packages_d;

View File

@ -1162,6 +1162,11 @@ my @nodeattrs = (
only_if => 'mgt=fsp',
tabentry => 'ppcdirect.password',
access_tabentry => 'ppcdirect.hcp=attr:node::ppcdirect.username=str:HMC',
},
{attr_name => 'passwd.hscroot',
only_if => 'mgt=fsp',
tabentry => 'ppcdirect.password',
access_tabentry => 'ppcdirect.hcp=attr:node::ppcdirect.username=str:hscroot',
},
{attr_name => 'passwd.admin',
only_if => 'mgt=fsp',
@ -1172,6 +1177,26 @@ my @nodeattrs = (
only_if => 'mgt=fsp',
tabentry => 'ppcdirect.password',
access_tabentry => 'ppcdirect.hcp=attr:node::ppcdirect.username=str:general',
},
{attr_name => 'passwd.HMC',
only_if => 'mgt=bpa',
tabentry => 'ppcdirect.password',
access_tabentry => 'ppcdirect.hcp=attr:node::ppcdirect.username=str:HMC',
},
{attr_name => 'passwd.hscroot',
only_if => 'mgt=bpa',
tabentry => 'ppcdirect.password',
access_tabentry => 'ppcdirect.hcp=attr:node::ppcdirect.username=str:hscroot',
},
{attr_name => 'passwd.admin',
only_if => 'mgt=bpa',
tabentry => 'ppcdirect.password',
access_tabentry => 'ppcdirect.hcp=attr:node::ppcdirect.username=str:admin',
},
{attr_name => 'passwd.general',
only_if => 'mgt=bpa',
tabentry => 'ppcdirect.password',
access_tabentry => 'ppcdirect.hcp=attr:node::ppcdirect.username=str:general',
},
####################

View File

@ -5333,6 +5333,50 @@ sub get_unique_members
#-------------------------------------------------------------------------------
=head3 get_hdwr_ip
Description:
Get hardware(CEC, BPA) IP from the hosts table, and then /etc/hosts.
Arguments:
node: the nodename(cec, or bpa)
Returns:
Return the node IP
-1 - Failed to get the IP.
Globals:
none
Error:
none
Example:
my $ip = xCAT::Utils::get_hdwr_ip('node1');
Comments:
Used in FSPpower FSPflash, FSPinv.
=cut
#-------------------------------------------------------------------------------
sub get_hdwr_ip
{
my $node = shift;
my $ip = undef;
my $Rc = undef;
my $hosttab = xCAT::Table->new( 'hosts' );
if ( $hosttab) {
my $node_ip_hash = $hosttab->getNodeAttribs( $node,[qw(ip)]);
$ip = $node_ip_hash->{ip};
}
if (!$ip) {
my $ip_tmp_res = xCAT::Utils::toIP($node);
($Rc, $ip) = @$ip_tmp_res;
if ( $Rc ) {
return -1;
}
}
return $ip;
}
#-------------------------------------------------------------------------------
=head3 updateEtcHosts
Description:
Add nodes and their IP addresses into /etc/hosts.

View File

@ -23,25 +23,49 @@ use Thread qw(yield);
# 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",
reventlog => "xCAT::PPClog",
rspconfig => "xCAT::PPCcfg",
rflash => "xCAT::PPCrflash",
mkhwconn => "xCAT::PPCconn",
rmhwconn => "xCAT::PPCconn",
lshwconn => "xCAT::PPCconn",
renergy => "xCAT::PPCenergy"
rinv => { hmc => "xCAT::PPCinv",
fsp => "xCAT::FSPinv",
bpa => "xCAT::FSPinv",
},
rpower => { hmc => "xCAT::PPCpower",
fsp => "xCAT::FSPpower",
bpa => "xCAT::FSPpower",
},
rvitals => { hmc => "xCAT::PPCvitals",
},
rscan => { hmc => "xCAT::PPCscan",
},
mkvm => { hmc => "xCAT::PPCvm",
},
rmvm => { hmc => "xCAT::PPCvm",
},
lsvm => { hmc => "xCAT::PPCvm",
},
chvm => { hmc => "xCAT::PPCvm",
},
rnetboot => { hmc => "xCAT::PPCboot",
},
getmacs => { hmc => "xCAT::PPCmac",
},
reventlog => { hmc => "xCAT::PPClog",
},
rspconfig => { hmc => "xCAT::PPCcfg",
},
rflash => { hmc => "xCAT::PPCrflash",
fsp => "xCAT::FSPflash",
bpa => "xCAT::FSPflash",
},
mkhwconn => { hmc => "xCAT::PPCconn",
},
rmhwconn => { hmc => "xCAT::PPCconn",
},
lshwconn => { hmc => "xCAT::PPCconn",
},
renergy => { hmc => "xCAT::PPCenergy",
},
);
##########################################
# Database errors
##########################################
@ -121,18 +145,18 @@ sub process_command {
$start = Time::HiRes::gettimeofday();
}
#xCAT doesn't support direct attach by default
$request->{direct_attach_support} = 0;
#xCAT doesn't support FSPpower,FSPinv and FSPrflash by default
$request->{fsp_api} = 0;
#######################################
# Direct-attached FSP handler
# FSPpower, FSPinv and FSPrflash handler
#########################################
my $hwtype = $request->{hwtype};
if ( $hwtype eq "fsp" or $hwtype eq "bpa") {
my $direct_attach_support = check_direct_attach($request);
if($direct_attach_support == 0 &&
($request->{command} =~ /^(rpower)$/ || $request->{command} =~ /^rinv$/ || $request->{command} =~ /^rflash$/)) {
#direct-attached fsp commands: such as rpower and so on.
$request->{direct_attach_support} = 1;
my $fsp_api = check_fsp_api($request);
if($fsp_api == 0 &&
($request->{command} =~ /^(rpower)$/ || $request->{command} =~ /^rinv$/ || $request->{command} =~ /^rflash$/)) {
#support FSPpower, FSPinv and FSPrflash
$request->{fsp_api} = 1;
}
}
@ -652,13 +676,13 @@ sub preprocess_nodes {
########################################
# Special cases
# rscan - Nodes are hardware control pts
# Direct-attached FSP
# FSPpower, FSPinv and FSPrflash
########################################
if (( !$request->{hcp} && ($request->{hcp} ne "hmc" ))
and ($request->{command} !~ /^renergy$/)
and (( $request->{command} =~ /^(rscan|rspconfig)$/ )
or ($request->{hwtype} eq "fsp" or $request->{hwtype} eq "bpa" )
or ($request->{command} eq 'lshwconn' and $request->{nodetype} eq 'hmc')) and ($request->{direct_attach_support} != 1)
or ($request->{command} eq 'lshwconn' and $request->{nodetype} eq 'hmc')) and ($request->{fsp_api} != 1)
) {
my $result = resolve_hcp( $request, $noderange );
return( $result );
@ -1119,31 +1143,7 @@ sub invoke_cmd {
########################################
# Direct-attached FSP handler
########################################
if ( ($power ne "hmc") && ( $hwtype eq "fsp" or $hwtype eq "bpa")) {
if($request->{direct_attach_support} == 1 ) {
# direct-attached fsp commands: such as rpower and so on. Using fsp-api.
########################################
#Process specific command
#########################################
print "in invoke cmd node: $nodes\n";
my $result = runcmd( $request, $nodes );
#print '------after runcmd----\n';
#print Dumper($result);
my $r;
foreach $r ( @$$result ) {
my %output;
$output{node}->[0]->{name}->[0] = @$r[0];
$output{node}->[0]->{data}->[0]->{contents}->[0] = @$r[1];
$output{errorcode} = @$r[2];
push @outhash, \%output;
}
my $out = $request->{pipe};
print $out freeze( [@outhash] );
print $out "\nENDOFFREEZE6sK4ci\n";
return;
}
if ( ($power ne "hmc") && ( $hwtype eq "fsp" or $hwtype eq "bpa") && $request->{fsp_api} == 0) {
####################################
# Dynamically load FSP module
@ -1271,7 +1271,8 @@ sub runcmd {
my $cmd = $request->{command};
my $method = $request->{method};
my $hwtype = $request->{hwtype};
my $modname = $modules{$cmd};
#my $modname = $modules{$cmd};
my $modname = $modules{$cmd}{$hwtype};
######################################
# Command not supported
@ -1647,13 +1648,15 @@ sub updconf_in_asm
return ([0, undef, \@data]);
}
sub check_direct_attach
sub check_fsp_api
{
my $request = shift;
my $fsp_api = "/opt/xcat/sbin/fsp-api";
my $libfsp = "/usr/lib/libfsp.a";
# my $libfsp = "/opt/xcat/lib/libfsp.a";
# my $fsp_api = "/opt/xcat/sbin/fsp-api";
my $fsp_api = ($::XCATROOT) ? "$::XCATROOT/sbin/fsp-api" : "/opt/xcat/sbin/fsp-api";
# my $libfsp = "/usr/lib/libfsp.a";
my $libfsp = "/opt/xcat/lib/libfsp.a";
# my $libfsp = ($::XCATROOT) ? "$::XCATROOT/lib/libfsp.a" : "/opt/xcat/lib/libfsp.a";
# my $hw_svr = "/opt/csm/csmbin/hdwr_svr";
my $msg = ();

275
xCAT-server/share/xcat/cons/fsp Executable file
View File

@ -0,0 +1,275 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
BEGIN
{
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
}
use lib "$::XCATROOT/lib/perl";
use strict;
use Getopt::Long;
use xCAT::Table;
use xCAT::PPCdb;
use Expect;
use xCAT::DBobjUtils;
use Data::Dumper;
##############################################
# Globals
##############################################
my $verbose = 0;
my $node;
##########################################
# 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"
);
##########################################################################
# Parse the command line for options and operands
##########################################################################
sub parse_args {
my %opt = ();
my @VERSION = qw( 2.0 );
#############################################
# Responds with usage statement
#############################################
local *usage = sub {
my $cmd = __FILE__;
$cmd =~ s/.*([\w]{3}$)/$1/;
if ( defined( $_[0] )) {
print STDERR "$_[0]\n";
}
my @msg = (
"$cmd -h|--help\n",
"$cmd -v|--version\n",
"$cmd singlenode [-V|-Verbose]\n" );
print STDERR @msg;
};
#############################################
# Process command-line arguments
#############################################
if ( !defined( @ARGV )) {
usage( "No node specified" );
return(1);
}
#############################################
# Checks case in GetOptions, allows opts
# to be grouped (e.g. -vx), and terminates
# at the first unrecognized option.
#############################################
$Getopt::Long::ignorecase = 0;
Getopt::Long::Configure( "bundling" );
if ( !GetOptions( \%opt, qw(h|help V|Verbose v|version) )) {
usage();
return(1);
}
#######################################
# Option -h for Help
#######################################
if ( exists( $opt{h} )) {
usage();
return(1);
}
#######################################
# Option -v for version
#######################################
if ( exists( $opt{v} )) {
print STDERR \@VERSION;
return(1);
}
#######################################
# Option -V for verbose output
#######################################
if ( exists( $opt{V} )) {
$verbose = 1;
}
#######################################
# Check for "-" with no option
#######################################
if ( grep(/^-$/, @ARGV )) {
usage( "Missing option: -" );
return(1);
}
#######################################
# Get node
#######################################
if ( !defined( $ARGV[0] )) {
usage( "No node specified" );
return(1);
}
#######################################
# Check for extra argument
#######################################
$node = shift @ARGV;
if ( defined( $ARGV[0] )) {
usage( "Invalid Argument: $ARGV[0]" );
return(1);
}
return(0);
}
##########################################################################
# Open remote console
##########################################################################
sub invoke_cmd {
my @attribs = qw(id parent hcp);
my %tabs = ();
##################################
# Open databases needed
##################################
foreach ( qw(ppc vpd nodetype) ) {
$tabs{$_} = xCAT::Table->new($_);
if ( !exists( $tabs{$_} )) {
return( sprintf( $errmsg{DB_UNDEF}, $_ ));
}
}
##################################
# Get node power type
##################################
my $hwtype = __FILE__;
$hwtype =~ s/.*([\w]{3})$/$1/;
#################################
# Get node type
#################################
my ($ent) = $tabs{nodetype}->getNodeAttribs($node, ["nodetype"] );
if ( !defined( $ent )) {
return( sprintf( $errmsg{NODE_UNDEF}, "nodetype" ));
}
#################################
# Check for type
#################################
if ( !exists( $ent->{nodetype} )) {
return( sprintf( $errmsg{NO_ATTR}, $ent->{nodetype},"nodetype" ));
}
#################################
# Check for valid "type"
#################################
my @types = split /,/, $ent->{nodetype};
my ($type) = grep( /^(lpar|osi)$/, @types );
if ( !defined( $type )) {
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" ));
}
#################################
# Verify required attributes
#################################
foreach my $at ( @attribs ) {
if ( !exists( $att->{$at} )) {
return( sprintf( $errmsg{NO_ATTR}, $at, "ppc" ));
}
}
my $fsp_name = $att->{hcp};
my $id = $att->{id};
my %objhash = ();
$objhash{$fsp_name} = "node";
my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash);
my $password = $myhash{$fsp_name}{"passwd.hscroot"};
if(!$password ) {
return "The password.hscroot of $fsp_name in ppcdirect table is empty";
}
my $username = "hscroot";
# my $fsp_api ="/opt/xcat/sbin/fsp-api";
my $fsp_api = ($::XCATROOT) ? "$::XCATROOT/sbin/fsp-api" : "/opt/xcat/sbin/fsp-api";
my $action = "console";
my $type = "0";
my $fsp_ip = ();
my $Rc = 0;
my $hosttab = xCAT::Table->new( 'hosts' );
if ( $hosttab) {
my $node_ip_hash = $hosttab->getNodeAttribs( $fsp_name,[qw(ip)]);
$fsp_ip = $node_ip_hash->{ip};
}
if (!$fsp_ip) {
my $ip_tmp_res = xCAT::Utils::toIP($fsp_name);
($Rc, $fsp_ip) = @$ip_tmp_res;
if ( $Rc ) {
return "Failed to get the $fsp_name\'s ip";
}
}
my $cmd = "$fsp_api -a $action -u $username -p $password -t $type:$fsp_ip:$id:$node:\r";
# print "cmd: $cmd\n";
my $running_failed_code = "Reason code: 0x1000000";
my $fsp_standby_msg = "Reason code: 0x1300";
my $timeout = 30;
my $failed = 0;
my $exp = new Expect;
$exp->log_stdout( 1 );
$exp->spawn( $cmd ) or die "Can't spawn $cmd\r\n";
my @result = $exp->expect( $timeout,
[ "$running_failed_code",
sub {
$failed = 1;
} ],
[ "$fsp_standby_msg",
sub {
$failed = 2;
}]
);
if($failed == 1) {
$exp->hard_close();
return("Virtual terminal is already connected");
}
if($failed == 2) {
$exp->hard_close();
return("Failed to open the console. Please check the related FSP's status");
}
my $escape = "\030";
$exp->send( "\r" );
$exp->interact( \*STDIN, $escape );
$exp->hard_close();
return(0);
}
##############################################
# Start main body of code
##############################################
if ( parse_args() ) {
exit(1);
}
my $result = invoke_cmd();
if ( $result ne "0" ) {
print STDERR "$node: $result\n";
exit(1);
}
exit(0);