2007-11-16 19:47:00 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT::PPCvitals;
|
|
|
|
use strict;
|
|
|
|
use Getopt::Long;
|
|
|
|
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
|
|
|
|
use xCAT::PPCpower;
|
2008-04-12 14:53:11 +00:00
|
|
|
use xCAT::Usage;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Parse the command line for options and operands
|
|
|
|
##########################################################################
|
|
|
|
sub parse_args {
|
|
|
|
|
|
|
|
my $request = shift;
|
2008-04-12 14:53:11 +00:00
|
|
|
my $command = $request->{command};
|
2007-11-16 19:47:00 +00:00
|
|
|
my $args = $request->{arg};
|
|
|
|
my %opt = ();
|
2009-03-05 03:21:20 +00:00
|
|
|
my @rvitals = qw(temp voltage power lcds state all);
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
#############################################
|
|
|
|
# Responds with usage statement
|
|
|
|
#############################################
|
|
|
|
local *usage = sub {
|
2008-04-16 18:05:54 +00:00
|
|
|
my $usage_string = xCAT::Usage->getUsage($command);
|
|
|
|
return( [ $_[0], $usage_string] );
|
2007-11-16 19:47:00 +00:00
|
|
|
};
|
|
|
|
#############################################
|
|
|
|
# Process command-line arguments
|
|
|
|
#############################################
|
|
|
|
if ( !defined( $args )) {
|
|
|
|
return(usage( "No command specified" ));
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Checks case in GetOptions, allows opts
|
|
|
|
# to be grouped (e.g. -vx), and terminates
|
|
|
|
# at the first unrecognized option.
|
|
|
|
#############################################
|
|
|
|
@ARGV = @$args;
|
|
|
|
$Getopt::Long::ignorecase = 0;
|
|
|
|
Getopt::Long::Configure( "bundling" );
|
|
|
|
|
2008-04-12 14:53:11 +00:00
|
|
|
if ( !GetOptions( \%opt, qw(V|Verbose) )) {
|
2007-11-16 19:47:00 +00:00
|
|
|
return( usage() );
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Check for "-" with no option
|
|
|
|
####################################
|
|
|
|
if ( grep(/^-$/, @ARGV )) {
|
|
|
|
return(usage( "Missing option: -" ));
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Unsupported command
|
|
|
|
####################################
|
|
|
|
my ($cmd) = grep(/^$ARGV[0]$/, @rvitals );
|
|
|
|
if ( !defined( $cmd )) {
|
|
|
|
return(usage( "Invalid command: $ARGV[0]" ));
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Check for an extra argument
|
|
|
|
####################################
|
|
|
|
shift @ARGV;
|
|
|
|
if ( defined( $ARGV[0] )) {
|
|
|
|
return(usage( "Invalid Argument: $ARGV[0]" ));
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Set method to invoke
|
|
|
|
####################################
|
|
|
|
$request->{method} = $cmd;
|
|
|
|
return( \%opt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns Frame voltages/currents
|
|
|
|
##########################################################################
|
|
|
|
sub enumerate_volt {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $d = shift;
|
|
|
|
|
|
|
|
my $mtms = @$d[2];
|
|
|
|
my $volt = xCAT::PPCcli::lshwinfo( $exp, "frame", $mtms );
|
|
|
|
my $Rc = shift(@$volt);
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Return error
|
|
|
|
####################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( [RC_ERROR, @$volt[0]] );
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Success - return voltages
|
|
|
|
####################################
|
|
|
|
return( [SUCCESS, @$volt[0]] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns cage temperatures
|
|
|
|
##########################################################################
|
|
|
|
sub enumerate_temp {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $frame = shift;
|
|
|
|
my %outhash = ();
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Get cage information for frame
|
|
|
|
####################################
|
|
|
|
my $filter = "type_model_serial_num,temperature";
|
|
|
|
my $cages = xCAT::PPCcli::lshwinfo( $exp, "sys", $frame, $filter );
|
|
|
|
my $Rc = shift(@$cages);
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Expect error
|
|
|
|
####################################
|
|
|
|
if ( $Rc == EXPECT_ERROR ) {
|
|
|
|
return( [$Rc,@$cages[0]] );
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Save frame by CEC MTMS in cage
|
|
|
|
####################################
|
|
|
|
foreach ( @$cages ) {
|
|
|
|
my ($mtms,$temp) = split /,/;
|
|
|
|
$outhash{$mtms} = $temp;
|
|
|
|
}
|
|
|
|
return( [SUCCESS,\%outhash] );
|
|
|
|
}
|
|
|
|
|
2009-03-05 03:21:20 +00:00
|
|
|
##########################################################################
|
|
|
|
# Returns refcode
|
|
|
|
##########################################################################
|
|
|
|
sub enumerate_lcds {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $d = shift;
|
|
|
|
my $mtms = @$d[2];
|
|
|
|
my $Rc = undef;
|
|
|
|
my $value = undef;
|
|
|
|
my $nodetype = @$d[4];
|
|
|
|
my $lpar_id = @$d[0];
|
|
|
|
my @refcode = ();
|
|
|
|
|
|
|
|
my $values = xCAT::PPCcli::lsrefcode($exp, $nodetype, $mtms, $lpar_id);
|
|
|
|
foreach $value (@$values){
|
|
|
|
#Return error
|
|
|
|
$Rc = shift @$value;
|
|
|
|
if ($Rc != SUCCESS){
|
|
|
|
push @refcode, ( [$Rc, @$value[0]] );
|
|
|
|
} else {
|
|
|
|
if( @$value[0] =~ /refcode=(\w+)/){
|
|
|
|
push @refcode, ( [$Rc, $1] );
|
|
|
|
} else {
|
|
|
|
push @refcode, ( [$Rc, @$value[0]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return \@refcode;
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns voltages/currents
|
|
|
|
##########################################################################
|
|
|
|
sub voltage {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $hash = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $hwtype = @$exp[2];
|
|
|
|
my @result = ();
|
|
|
|
my $text = "Frame Voltages: ";
|
|
|
|
my @prefix = (
|
|
|
|
"Frame Voltage (Vab): %sV",
|
|
|
|
"Frame Voltage (Vbc): %sV",
|
|
|
|
"Frame Voltage (Vca): %sV",
|
|
|
|
"Frame Current (Ia): %sA",
|
|
|
|
"Frame Current (Ib): %sA",
|
|
|
|
"Frame Current (Ic): %sA",
|
|
|
|
);
|
|
|
|
|
|
|
|
while (my ($mtms,$h) = each(%$hash) ) {
|
|
|
|
while (my ($name,$d) = each(%$h) ) {
|
|
|
|
#################################
|
|
|
|
# No frame command on IVM
|
|
|
|
#################################
|
|
|
|
if ( $hwtype eq "ivm" ) {
|
2008-03-05 19:15:28 +00:00
|
|
|
push @result, [$name,"$text Not available",1];
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Voltages available in frame
|
|
|
|
#################################
|
|
|
|
if ( @$d[4] ne "bpa" ) {
|
2008-03-05 19:15:28 +00:00
|
|
|
push @result, [$name,"$text Only available for BPA",1];
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
my $volt = enumerate_volt( $exp, $d );
|
|
|
|
my $Rc = shift(@$volt);
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Output error
|
|
|
|
#################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
2008-03-05 19:15:28 +00:00
|
|
|
push @result, [$name,"$text @$volt[0]",$Rc];
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Output value
|
|
|
|
#################################
|
|
|
|
my @values = split /,/, @$volt[0];
|
|
|
|
my $i = 0;
|
|
|
|
|
|
|
|
foreach ( @prefix ) {
|
|
|
|
my $value = sprintf($_, $values[$i++]);
|
2008-03-05 19:15:28 +00:00
|
|
|
push @result, [$name,$value,$Rc];
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( \@result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns temperatures for CEC
|
|
|
|
##########################################################################
|
|
|
|
sub temp {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $hash = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $hwtype = @$exp[2];
|
|
|
|
my @result = ();
|
|
|
|
my %frame = ();
|
|
|
|
my $prefix = "System Temperature:";
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Group by frame
|
|
|
|
#########################################
|
|
|
|
while (my ($mtms,$h) = each(%$hash) ) {
|
|
|
|
while (my ($name,$d) = each(%$h) ) {
|
|
|
|
my $mtms = @$d[5];
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# No frame commands for IVM
|
|
|
|
#################################
|
|
|
|
if ( $hwtype eq "ivm" ) {
|
2008-03-05 19:15:28 +00:00
|
|
|
push @result, [$name,"$prefix Not available (No BPA)",1];
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Temperatures not available
|
|
|
|
#################################
|
2008-04-16 18:05:54 +00:00
|
|
|
if ( @$d[4] !~ /^(fsp|lpar)$/ ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
my $text = "$prefix Only available for CEC/LPAR";
|
2008-03-05 19:15:28 +00:00
|
|
|
push @result, [$name,$text,1];
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Error - No frame
|
|
|
|
#################################
|
|
|
|
if ( $mtms eq "0" ) {
|
2008-03-05 19:15:28 +00:00
|
|
|
push @result, [$name,"$prefix Not available (No BPA)",1];
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Save node
|
|
|
|
#################################
|
|
|
|
$frame{$mtms}{$name} = $d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (my ($mtms,$h) = each(%frame) ) {
|
|
|
|
#################################
|
|
|
|
# Get temperatures this frame
|
|
|
|
#################################
|
|
|
|
my $temp = enumerate_temp( $exp, $mtms );
|
|
|
|
my $Rc = shift(@$temp);
|
|
|
|
my $data = @$temp[0];
|
|
|
|
|
|
|
|
while (my ($name,$d) = each(%$h) ) {
|
|
|
|
my $mtms = @$d[2];
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# Output error
|
|
|
|
#############################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
2008-03-05 19:15:28 +00:00
|
|
|
push @result, [$name,"$prefix $data",$Rc];
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
#############################
|
|
|
|
# CEC not in frame
|
|
|
|
#############################
|
|
|
|
if ( !exists( $data->{$mtms} )) {
|
2008-03-05 19:15:28 +00:00
|
|
|
push @result, [$name,"$prefix CEC '$mtms' not found",1];
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
#############################
|
|
|
|
# Output value
|
|
|
|
#############################
|
|
|
|
my $cel = $data->{$mtms};
|
|
|
|
my $fah = ($cel * 1.8) + 32;
|
|
|
|
my $value = "$prefix $cel C ($fah F)";
|
2008-03-05 19:15:28 +00:00
|
|
|
push @result, [$name,$value,$Rc];
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return( \@result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns system power status (on or off)
|
|
|
|
##########################################################################
|
|
|
|
sub power {
|
|
|
|
return( xCAT::PPCpower::state(@_,"Current Power Status: ",1));
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns system state
|
|
|
|
##########################################################################
|
|
|
|
sub state {
|
|
|
|
return( xCAT::PPCpower::state(@_,"System State: "));
|
|
|
|
}
|
2009-03-05 03:21:20 +00:00
|
|
|
###########################################################################
|
|
|
|
# Returns system LCD status (LCD1, LCD2)
|
|
|
|
##########################################################################
|
|
|
|
sub lcds {
|
|
|
|
my $request = shift;
|
|
|
|
my $hash = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $hwtype = @$exp[2];
|
|
|
|
my @result = ();
|
|
|
|
my $text = "Current LCD:";
|
|
|
|
my $prefix = "Current LCD%d: %s";
|
|
|
|
my $rcode = undef;
|
|
|
|
my $refcodes = undef;
|
|
|
|
my $Rc = undef;
|
|
|
|
my $num = undef;
|
|
|
|
my $value = undef;
|
|
|
|
|
|
|
|
while (my ($mtms,$h) = each(%$hash) ) {
|
|
|
|
while(my ($name, $d) = each(%$h) ){
|
|
|
|
#Support HMC only
|
|
|
|
if($hwtype ne 'hmc'){
|
|
|
|
push @result, [$name, "$text Not available(NO HMC)", 1];
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$refcodes = enumerate_lcds($exp, $d);
|
|
|
|
$num = 1;
|
|
|
|
foreach $rcode (@$refcodes){
|
|
|
|
$Rc = shift(@$rcode);
|
|
|
|
$value = sprintf($prefix, $num, @$rcode[0]);
|
|
|
|
push @result, [$name, $value, $Rc];
|
|
|
|
$num = $num + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return \@result;
|
|
|
|
}
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns all vitals
|
|
|
|
##########################################################################
|
|
|
|
sub all {
|
|
|
|
|
|
|
|
my @values = (
|
|
|
|
@{temp(@_)},
|
|
|
|
@{voltage(@_)},
|
|
|
|
@{state(@_)},
|
2009-03-05 03:21:20 +00:00
|
|
|
@{power(@_)},
|
|
|
|
@{lcds(@_)},
|
2007-11-16 19:47:00 +00:00
|
|
|
);
|
|
|
|
return( \@values );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
1;
|
2008-03-05 19:15:28 +00:00
|
|
|
|