2007-11-16 19:47:00 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT::PPCfsp;
|
|
|
|
use strict;
|
2008-01-11 16:53:54 +00:00
|
|
|
use Getopt::Long;
|
2007-11-16 19:47:00 +00:00
|
|
|
use LWP;
|
|
|
|
use HTTP::Cookies;
|
2007-12-11 20:35:07 +00:00
|
|
|
use HTML::Form;
|
2008-01-18 16:27:05 +00:00
|
|
|
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
##########################################
|
|
|
|
# Globals
|
|
|
|
##########################################
|
|
|
|
my %cmds = (
|
|
|
|
rpower => {
|
2008-01-18 16:27:05 +00:00
|
|
|
state => ["Power On/Off System", \&state],
|
|
|
|
on => ["Power On/Off System", \&on],
|
|
|
|
off => ["Power On/Off System", \&off],
|
|
|
|
reset => ["System Reboot", \&reset],
|
|
|
|
boot => ["Power On/Off System", \&boot] },
|
2007-11-16 19:47:00 +00:00
|
|
|
reventlog => {
|
2008-01-18 16:27:05 +00:00
|
|
|
all => ["Error/Event Logs", \&all],
|
|
|
|
all_clear => ["Error/Event Logs", \&all_clear],
|
|
|
|
entries => ["Error/Event Logs", \&entries],
|
|
|
|
clear => ["Error/Event Logs", \&clear] },
|
2008-01-11 16:53:54 +00:00
|
|
|
rfsp => {
|
2008-01-18 16:27:05 +00:00
|
|
|
iocap => ["I/O Adapter Enlarged Capacity", \&iocap],
|
|
|
|
time => ["Time Of Day", \&time],
|
|
|
|
date => ["Time Of Day", \&date],
|
|
|
|
autopower => ["Auto Power Restart", \&autopower],
|
|
|
|
sysdump => ["System Dump", \&sysdump],
|
|
|
|
spdump => ["Service Processor Dump", \&spdump] },
|
2007-11-16 19:47:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-11 16:53:54 +00:00
|
|
|
##########################################################################
|
|
|
|
# Parse the command line for options and operands
|
|
|
|
##########################################################################
|
|
|
|
sub parse_args {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $args = $request->{arg};
|
2008-01-18 16:27:05 +00:00
|
|
|
my @rsp = keys %{$cmds{rfsp}};
|
|
|
|
my $cmd = join('|',@rsp);
|
2008-01-11 16:53:54 +00:00
|
|
|
my %opt = ();
|
|
|
|
my @VERSION = qw( 2.0 );
|
2008-01-18 16:27:05 +00:00
|
|
|
|
|
|
|
#############################################
|
|
|
|
# Modify usage statement
|
|
|
|
#############################################
|
|
|
|
$cmd =~ s/time/time [hh:mm:ss]/;
|
|
|
|
$cmd =~ s/date/date [mm-dd-yyy]/;
|
|
|
|
$cmd =~ s/autopower/autopower [enable|disable]/;
|
|
|
|
$cmd =~ s/iocap/iocap [enable|disable]/;
|
2008-01-11 16:53:54 +00:00
|
|
|
|
|
|
|
#############################################
|
|
|
|
# Responds with usage statement
|
|
|
|
#############################################
|
|
|
|
local *usage = sub {
|
|
|
|
return( [ $_[0],
|
|
|
|
"rfsp -h|--help",
|
|
|
|
"rfsp -v|--version",
|
2008-01-18 16:27:05 +00:00
|
|
|
"rfsp [-V|--verbose] noderange ". $cmd,
|
2008-01-11 16:53:54 +00:00
|
|
|
" -h writes usage information to standard output",
|
|
|
|
" -v displays command version",
|
2008-01-18 16:27:05 +00:00
|
|
|
" -V verbose output"] );
|
2008-01-11 16:53:54 +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-01-14 15:05:14 +00:00
|
|
|
$request->{method} = undef;
|
2008-01-11 16:53:54 +00:00
|
|
|
|
2008-01-18 16:27:05 +00:00
|
|
|
if ( !GetOptions( \%opt, qw(h|help V|Verbose v|version) )) {
|
2008-01-11 16:53:54 +00:00
|
|
|
return( usage() );
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Option -h for Help
|
|
|
|
####################################
|
|
|
|
if ( exists( $opt{h} )) {
|
|
|
|
return( usage() );
|
|
|
|
}
|
|
|
|
####################################
|
2008-01-11 19:32:52 +00:00
|
|
|
# Option -v for version
|
|
|
|
####################################
|
|
|
|
if ( exists( $opt{v} )) {
|
|
|
|
return( \@VERSION );
|
|
|
|
}
|
|
|
|
####################################
|
2008-01-11 16:53:54 +00:00
|
|
|
# Check for "-" with no option
|
|
|
|
####################################
|
|
|
|
if ( grep(/^-$/, @ARGV )) {
|
|
|
|
return(usage( "Missing option: -" ));
|
|
|
|
}
|
|
|
|
####################################
|
2008-01-14 16:38:44 +00:00
|
|
|
# Check for unsupported commands
|
2008-01-11 16:53:54 +00:00
|
|
|
####################################
|
2008-01-18 16:27:05 +00:00
|
|
|
if ( !defined( $request->{method} )) {
|
2008-01-14 15:05:14 +00:00
|
|
|
my ($cmd) = grep(/^$ARGV[0]$/, @rsp );
|
|
|
|
if ( !defined( $cmd )) {
|
|
|
|
return(usage( "Invalid command: $ARGV[0]" ));
|
|
|
|
}
|
|
|
|
$request->{method} = $cmd;
|
2008-01-11 16:53:54 +00:00
|
|
|
}
|
|
|
|
####################################
|
2008-01-18 16:27:05 +00:00
|
|
|
# Check command arguments
|
|
|
|
####################################
|
|
|
|
if ( $request->{method} =~ /^date|time|iocap|autopower$/ ) {
|
|
|
|
shift @ARGV;
|
|
|
|
|
|
|
|
if ( defined( $ARGV[0] )) {
|
|
|
|
if ( $request->{method} =~ /^time$/ ) {
|
|
|
|
if ( $ARGV[0] !~
|
|
|
|
/^([0-1]?[0-9]|2[0-3]):(0?[0-9]|[1-5][0-9]):(0?[0-9]|[1-5][0-9])$/ ) {
|
|
|
|
return( usage("Invalid time format '$ARGV[0]'") );
|
|
|
|
}
|
|
|
|
$request->{op} = "$1-$2-$3";
|
|
|
|
}
|
|
|
|
if ( $request->{method} =~ /^date$/ ) {
|
|
|
|
if ( $ARGV[0] !~
|
|
|
|
/^(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])-(20[0-9]{2})$/){
|
|
|
|
return( usage("Invalid date format '$ARGV[0]'") );
|
|
|
|
}
|
|
|
|
$request->{op} = "$1-$2-$3";
|
|
|
|
}
|
|
|
|
if ( $request->{method} =~ /^autopower|iocap$/ ) {
|
|
|
|
if ( $ARGV[0] !~ /^enable|disable$/ ) {
|
|
|
|
return( usage("Invalid argument '$ARGV[0]'") );
|
|
|
|
}
|
|
|
|
$request->{op} = $ARGV[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
####################################
|
2008-01-11 16:53:54 +00:00
|
|
|
# Check for an extra argument
|
|
|
|
####################################
|
|
|
|
shift @ARGV;
|
|
|
|
if ( defined( $ARGV[0] )) {
|
|
|
|
return(usage( "Invalid Argument: $ARGV[0]" ));
|
|
|
|
}
|
|
|
|
return( \%opt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##########################################################################
|
|
|
|
# FSP command handler through HTTP interface
|
|
|
|
##########################################################################
|
|
|
|
sub handler {
|
|
|
|
|
|
|
|
my $server = shift;
|
|
|
|
my $request = shift;
|
2007-12-06 19:09:54 +00:00
|
|
|
my $exp = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Process FSP command
|
|
|
|
##################################
|
2007-12-06 19:09:54 +00:00
|
|
|
my $result = process_cmd( $exp, $request );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
my %output;
|
|
|
|
$output{node}->[0]->{name}->[0] = $server;
|
|
|
|
$output{node}->[0]->{data}->[0]->{contents}->[0] = $result;
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Disconnect from FSP
|
|
|
|
##################################
|
2007-12-06 19:09:54 +00:00
|
|
|
xCAT::PPCfsp::disconnect( $exp );
|
2008-01-14 15:05:14 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
return( [\%output] );
|
2008-01-14 15:05:14 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Logon through remote FSP HTTP-interface
|
|
|
|
##########################################################################
|
|
|
|
sub connect {
|
|
|
|
|
2007-12-06 19:09:54 +00:00
|
|
|
my $request = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $server = shift;
|
2007-12-06 19:09:54 +00:00
|
|
|
my $command = $request->{command};
|
|
|
|
my $verbose = $request->{verbose};
|
|
|
|
my $method = $request->{method};
|
|
|
|
my $lwp_log;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2007-12-06 19:09:54 +00:00
|
|
|
##################################
|
|
|
|
# Check command
|
|
|
|
##################################
|
|
|
|
if ( !exists( $cmds{$command}{$method} )) {
|
|
|
|
return( "$server: Unsupported command" );
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
|
|
|
# Get userid/password
|
|
|
|
##################################
|
|
|
|
my @cred = xCAT::PPCdb::credentials( $server, "fsp" );
|
|
|
|
|
2007-12-06 19:09:54 +00:00
|
|
|
##################################
|
|
|
|
# Redirect STDERR to variable
|
|
|
|
##################################
|
|
|
|
if ( $verbose ) {
|
|
|
|
close STDERR;
|
|
|
|
if ( !open( STDERR, '>', \$lwp_log )) {
|
|
|
|
return( "Unable to redirect STDERR: $!" );
|
|
|
|
}
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
|
|
|
# Turn on tracing
|
|
|
|
##################################
|
|
|
|
if ( $verbose ) {
|
|
|
|
LWP::Debug::level( '+' );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Create cookie
|
|
|
|
##################################
|
|
|
|
my $cookie = HTTP::Cookies->new();
|
|
|
|
$cookie->set_cookie( 0,'asm_session','0','cgi-bin','','443',0,0,3600,0 );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Create UserAgent
|
|
|
|
##################################
|
|
|
|
my $ua = LWP::UserAgent->new();
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Set options
|
|
|
|
##################################
|
|
|
|
my $url = "https://$server/cgi-bin/cgi?form=2";
|
|
|
|
$ua->cookie_jar( $cookie );
|
|
|
|
$ua->timeout(30);
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Submit logon
|
|
|
|
##################################
|
|
|
|
my $res = $ua->post( $url,
|
|
|
|
[ user => $cred[0],
|
|
|
|
password => $cred[1],
|
|
|
|
lang => "0",
|
|
|
|
submit => "Log in"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Logon failed
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
2007-12-06 19:09:54 +00:00
|
|
|
return( $lwp_log.$res->status_line );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# To minimize number of GET/POSTs,
|
|
|
|
# if we successfully logon, we should
|
|
|
|
# get back a valid cookie:
|
|
|
|
# Set-Cookie: asm_session=3038839768778613290
|
|
|
|
#
|
|
|
|
##################################
|
|
|
|
|
|
|
|
if ( $res->as_string =~ /Set-Cookie: asm_session=(\d+)/ ) {
|
|
|
|
##############################
|
|
|
|
# Successful logon....
|
|
|
|
# Return:
|
|
|
|
# UserAgent
|
|
|
|
# Server hostname
|
|
|
|
# UserId
|
2007-12-06 19:09:54 +00:00
|
|
|
# Redirected STDERR/STDOUT
|
2007-11-16 19:47:00 +00:00
|
|
|
##############################
|
2007-12-06 19:09:54 +00:00
|
|
|
return( $ua,
|
2007-11-16 19:47:00 +00:00
|
|
|
$server,
|
2007-12-06 19:09:54 +00:00
|
|
|
$cred[0],
|
|
|
|
\$lwp_log );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Logon error
|
|
|
|
##############################
|
|
|
|
$res = $ua->get( $url );
|
|
|
|
|
|
|
|
if ( !$res->is_success() ) {
|
2007-12-06 19:09:54 +00:00
|
|
|
return( $lwp_log.$res->status_line );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Check for specific failures
|
|
|
|
##############################
|
2008-01-14 15:05:14 +00:00
|
|
|
if ( $res->content =~ /(Invalid user ID or password|Too many users)/ ) {
|
|
|
|
return( $lwp_log.$1 );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2007-12-06 19:09:54 +00:00
|
|
|
return( $lwp_log."Logon failure" );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Logoff through remote FSP HTTP-interface
|
|
|
|
##########################################################################
|
|
|
|
sub disconnect {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
my $uid = @$exp[2];
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# POST Logoff
|
|
|
|
##################################
|
|
|
|
my $res = $ua->post(
|
|
|
|
"https://$server/cgi-bin/cgi?form=1",
|
|
|
|
[submit => "Log out"]);
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Logoff failed
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Execute FSP command
|
|
|
|
##########################################################################
|
|
|
|
sub process_cmd {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
my $uid = @$exp[2];
|
|
|
|
my $command = $request->{command};
|
|
|
|
my $method = $request->{method};
|
|
|
|
my %menu = ();
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# We have to expand the main
|
|
|
|
# menu since unfortunately, the
|
|
|
|
# the forms numbers are not the
|
|
|
|
# same across FSP models/firmware
|
|
|
|
# versions.
|
|
|
|
##################################
|
2008-01-11 16:53:54 +00:00
|
|
|
my $res = $ua->post( "https://$server/cgi-bin/cgi",
|
2007-11-16 19:47:00 +00:00
|
|
|
[form => "2",
|
|
|
|
e => "1" ]
|
|
|
|
);
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Build hash of expanded menus
|
|
|
|
##################################
|
|
|
|
foreach ( split /\n/, $res->content ) {
|
|
|
|
if ( /form=(\d+).*window.status='(.*)'/ ) {
|
|
|
|
$menu{$2} = $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Get form id
|
|
|
|
##################################
|
|
|
|
my $form = $menu{$cmds{$command}{$method}[0]};
|
|
|
|
|
|
|
|
if ( !defined( $form )) {
|
|
|
|
return( "Cannot find '$cmds{$command}{$method}[0]' menu" );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Run command
|
|
|
|
##################################
|
|
|
|
my $result = $cmds{$command}{$method}[1]($exp, $request, $form, \%menu);
|
|
|
|
return( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns current power state
|
|
|
|
##########################################################################
|
|
|
|
sub state {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $menu = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Get current power status
|
|
|
|
##################################
|
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$form" );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Get power state
|
|
|
|
##################################
|
|
|
|
if ( $res->content =~ /Current system power state: (.*)<br>/) {
|
|
|
|
return( $1 );
|
|
|
|
}
|
|
|
|
return( "unknown" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Powers FSP On
|
|
|
|
##########################################################################
|
|
|
|
sub on {
|
|
|
|
return( power(@_,"on","on") );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Powers FSP Off
|
|
|
|
##########################################################################
|
|
|
|
sub off {
|
|
|
|
return( power(@_,"off","of") );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Powers FSP On/Off
|
|
|
|
##########################################################################
|
|
|
|
sub power {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $menu = shift;
|
|
|
|
my $state = shift;
|
|
|
|
my $button = shift;
|
|
|
|
my $command = $request->{command};
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Send Power On command
|
|
|
|
##################################
|
|
|
|
my $res = $ua->post( "https://$server/cgi-bin/cgi",
|
|
|
|
[form => $form,
|
|
|
|
sp => "255", # System boot speed: Fast
|
|
|
|
is => "1", # Firmware boot side for the next boot: Temporary
|
|
|
|
om => "4", # System operating mode: Normal
|
|
|
|
ip => "2", # Boot to system server firmware: Running
|
|
|
|
plt => "3", # System power off policy: Stay on
|
|
|
|
$button => "Save settings and power $state"]
|
|
|
|
);
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
if ( $res->content =~
|
|
|
|
/(Powering on or off not allowed: invalid system state)/) {
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check current power state
|
|
|
|
##############################
|
|
|
|
my $state = xCAT::PPCfsp::state(
|
|
|
|
$exp,
|
|
|
|
$request,
|
|
|
|
$menu->{$cmds{$command}{state}[0]},
|
|
|
|
$menu );
|
|
|
|
|
|
|
|
if ( $state eq $state ) {
|
|
|
|
return( "Success" );
|
|
|
|
}
|
|
|
|
return( $1 );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Success
|
|
|
|
##################################
|
|
|
|
if ( $res->content =~ /(Operation completed successfully)/ ) {
|
|
|
|
return( $1 );
|
|
|
|
}
|
|
|
|
return( "Unknown error" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Reset FSP
|
|
|
|
##########################################################################
|
|
|
|
sub reset {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $menu = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Send Reset command
|
|
|
|
##################################
|
|
|
|
my $res = $ua->post( "https://$server/cgi-bin/cgi",
|
|
|
|
[form => $form,
|
|
|
|
submit => "Continue" ]
|
|
|
|
);
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success()) {
|
2007-12-06 19:09:54 +00:00
|
|
|
return( $res->status_line );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
if ( $res->content =~
|
|
|
|
/(This feature is only available when the system is powered on)/ ) {
|
|
|
|
return( $1 );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Success
|
|
|
|
##################################
|
|
|
|
if ( $res->content =~ /(Operation completed successfully)/ ) {
|
|
|
|
return( $1 );
|
|
|
|
}
|
|
|
|
return( "Unknown error" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Boots FSP (Off->On, On->Reset)
|
|
|
|
##########################################################################
|
|
|
|
sub boot {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $menu = shift;
|
|
|
|
my $command = $request->{command};
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Check current power state
|
|
|
|
##################################
|
|
|
|
my $state = xCAT::PPCfsp::state(
|
|
|
|
$exp,
|
|
|
|
$request,
|
|
|
|
$menu->{$cmds{$command}{state}[0]},
|
|
|
|
$menu );
|
|
|
|
|
|
|
|
if ( $state !~ /^on|off$/ ) {
|
|
|
|
return( "Unable to boot in state: '$state'" );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Get command
|
|
|
|
##################################
|
|
|
|
my $method = ($state eq "on") ? "reset" : "off";
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Get command form id
|
|
|
|
##################################
|
|
|
|
$form = $menu->{$cmds{$command}{$method}[0]};
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Run command
|
|
|
|
##################################
|
|
|
|
my $result = $cmds{$method}[1]( $exp, $state, $form );
|
|
|
|
return( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Clears Error/Event Logs
|
|
|
|
##########################################################################
|
|
|
|
sub clear {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $menu = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
##################################
|
2007-12-11 20:35:07 +00:00
|
|
|
# Get Error/Event Logs URL
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
2007-12-11 20:35:07 +00:00
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$form" );
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
2007-12-11 20:35:07 +00:00
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
2008-01-25 15:57:14 +00:00
|
|
|
##################################
|
|
|
|
# Clear all error/event log entries:
|
|
|
|
# Are you sure? (OK/Cancel)
|
|
|
|
##################################
|
|
|
|
my $form = HTML::Form->parse( $res->content, $res->base );
|
|
|
|
|
2007-12-11 20:35:07 +00:00
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !defined( $form )) {
|
|
|
|
return( "No Error/Event Logs form found" );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Send Clear to JavaScript
|
|
|
|
##################################
|
|
|
|
my $request = $form->click( 'clear' );
|
|
|
|
$res = $ua->request( $request );
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
return( "Success" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets the number of Error/Event Logs entries specified
|
|
|
|
##########################################################################
|
|
|
|
sub entries {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $menu = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
my $opt = $request->{opt};
|
|
|
|
my $count = (exists($opt->{e})) ? $opt->{e} : 9999;
|
|
|
|
my $result;
|
|
|
|
my $i = 1;
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Get log entries
|
|
|
|
##################################
|
2008-01-11 16:53:54 +00:00
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$form" );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
my @entries = split /\n/, $res->content;
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Prepend header
|
|
|
|
##################################
|
|
|
|
$result = (@entries) ?
|
2008-01-18 16:27:05 +00:00
|
|
|
"\n#Log ID Time Failing subsystem Severity SRC\n" :
|
2007-11-16 19:47:00 +00:00
|
|
|
"No entries";
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Parse log entries
|
|
|
|
##################################
|
|
|
|
foreach ( @entries ) {
|
2008-01-18 16:27:05 +00:00
|
|
|
if ( /tabindex=\d+><\/td><td>(.*)<\/td><td / ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
my $values = $1;
|
|
|
|
$values =~ s/<\/td><td>/ /g;
|
|
|
|
$result.= "$values\n";
|
|
|
|
|
|
|
|
if ( $i++ == $count ) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( $result );
|
2008-01-14 15:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-18 16:27:05 +00:00
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets system time of day
|
|
|
|
##########################################################################
|
|
|
|
sub time {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $menu = shift;
|
|
|
|
my $option = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Send command
|
|
|
|
##############################
|
|
|
|
my $result = xCAT::PPCfsp::tod( $exp, $request, $form );
|
|
|
|
my $Rc = shift(@$result);
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Return error
|
|
|
|
##############################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( @$result[0] );
|
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Get time
|
|
|
|
##############################
|
|
|
|
if ( !defined( $request->{op} )) {
|
|
|
|
@$result[0] =~ /(\d+) (\d+) (\d+) $/;
|
|
|
|
return( "$1:$2:$3 UTC" );
|
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Set time
|
|
|
|
##############################
|
|
|
|
my @t = split / /, @$result[0];
|
|
|
|
my @new = split /-/, $request->{op};
|
|
|
|
splice( @t,3,3,@new );
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Send command
|
|
|
|
##############################
|
|
|
|
my $result = xCAT::PPCfsp::tod( $exp, $request, $form, \@t );
|
|
|
|
my $Rc = shift(@$result);
|
|
|
|
|
|
|
|
return( @$result[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets system date
|
|
|
|
##########################################################################
|
|
|
|
sub date {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $menu = shift;
|
|
|
|
my $option = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Send command
|
|
|
|
##############################
|
|
|
|
my $result = xCAT::PPCfsp::tod( $exp, $request, $form );
|
|
|
|
my $Rc = shift(@$result);
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Return error
|
|
|
|
##############################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( @$result[0] );
|
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Get date
|
|
|
|
##############################
|
|
|
|
if ( !defined( $request->{op} )) {
|
|
|
|
@$result[0] =~ /^(\d+) (\d+) (\d+)/;
|
|
|
|
return( "$1-$2-$3" );
|
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Set date
|
|
|
|
##############################
|
|
|
|
my @t = split / /, @$result[0];
|
|
|
|
my @new = split /-/, $request->{op};
|
|
|
|
splice( @t,0,3,@new );
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Send command
|
|
|
|
##############################
|
|
|
|
my $result = xCAT::PPCfsp::tod( $exp, $request, $form, \@t );
|
|
|
|
my $Rc = shift(@$result);
|
|
|
|
|
|
|
|
return( @$result[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets system time/date
|
|
|
|
##########################################################################
|
|
|
|
sub tod {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $d = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Get time/date
|
|
|
|
######################################
|
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$form" );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
if ( $res->content =~ /(only when the system is powered off)/ ) {
|
|
|
|
return( [RC_ERROR,$1] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Get time/date fields
|
|
|
|
######################################
|
|
|
|
my $result;
|
|
|
|
my @regex = (
|
|
|
|
"name='omo' value='(\\d+)'",
|
|
|
|
"name='od' value='(\\d+)'",
|
|
|
|
"name='oy' value='(\\d+)'",
|
|
|
|
"name='oh' value='(\\d+)'",
|
|
|
|
"name='omi' value='(\\d+)'",
|
|
|
|
"name='os' value='(\\d+)'",
|
|
|
|
);
|
|
|
|
foreach ( @regex ) {
|
|
|
|
if ( $res->content !~ /$_/ ) {
|
|
|
|
return( [RC_ERROR,"Error getting time of day"] );
|
|
|
|
}
|
|
|
|
$result.= "$1 ";
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Return time/date
|
|
|
|
######################################
|
|
|
|
if ( !defined( $d )) {
|
|
|
|
return( [SUCCESS,$result] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Set time/date
|
|
|
|
######################################
|
|
|
|
my $res = $ua->post( "https://$server/cgi-bin/cgi",
|
|
|
|
[ form => $form,
|
|
|
|
mo => @$d[0],
|
|
|
|
d => @$d[1],
|
|
|
|
y => @$d[2],
|
|
|
|
h => @$d[3],
|
|
|
|
mi => @$d[4],
|
|
|
|
s => @$d[5],
|
|
|
|
submit => "Save settings" ]
|
|
|
|
);
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
if ( $res->content =~ /(not allowed when the system is powered on)/ ) {
|
|
|
|
return( [RC_ERROR,$1] );
|
|
|
|
}
|
|
|
|
if ( $res->content =~ /(Invalid entry)/ ) {
|
|
|
|
return( [RC_ERROR,$1] );
|
|
|
|
}
|
|
|
|
return( [SUCCESS,"Success"] );
|
|
|
|
}
|
|
|
|
|
2008-01-14 16:38:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets I/O Adapter Enlarged Capacity
|
2008-01-14 15:05:14 +00:00
|
|
|
##########################################################################
|
2008-01-14 16:38:44 +00:00
|
|
|
sub iocap {
|
|
|
|
return( option( @_,"pe" ));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-14 15:05:14 +00:00
|
|
|
##########################################################################
|
2008-01-14 16:38:44 +00:00
|
|
|
# Gets/Sets Auto Power Restart
|
|
|
|
##########################################################
|
2008-01-14 15:05:14 +00:00
|
|
|
sub autopower {
|
2008-01-14 16:38:44 +00:00
|
|
|
return( option( @_,"apor" ));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets options
|
|
|
|
##########################################################################
|
|
|
|
sub option {
|
2008-01-14 15:05:14 +00:00
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $menu = shift;
|
2008-01-14 16:38:44 +00:00
|
|
|
my $option = shift;
|
2008-01-14 15:05:14 +00:00
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
my $op = $request->{op};
|
|
|
|
|
|
|
|
######################################
|
2008-01-14 16:38:44 +00:00
|
|
|
# Get option URL
|
2008-01-14 15:05:14 +00:00
|
|
|
######################################
|
|
|
|
if ( !defined( $op )) {
|
2008-01-18 16:27:05 +00:00
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$form" );
|
2008-01-14 15:05:14 +00:00
|
|
|
|
|
|
|
##################################
|
2008-01-18 16:27:05 +00:00
|
|
|
# Return errors
|
2008-01-14 15:05:14 +00:00
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
2008-01-18 16:27:05 +00:00
|
|
|
if ( $res->content !~ /selected value='\d+'>(Enabled|Disabled)</ ) {
|
|
|
|
return( "Unknown" );
|
2008-01-14 15:05:14 +00:00
|
|
|
}
|
2008-01-18 16:27:05 +00:00
|
|
|
return($1);
|
2008-01-14 15:05:14 +00:00
|
|
|
}
|
|
|
|
######################################
|
2008-01-14 16:38:44 +00:00
|
|
|
# Set option
|
2008-01-14 15:05:14 +00:00
|
|
|
######################################
|
|
|
|
my $res = $ua->post( "https://$server/cgi-bin/cgi",
|
2008-01-14 16:38:44 +00:00
|
|
|
[form => $form,
|
|
|
|
$option => ($op eq "disable") ? "0" : "1",
|
|
|
|
submit => "Save settings" ]
|
2008-01-14 15:05:14 +00:00
|
|
|
);
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
if ( $res->content !~ /Operation completed successfully/ ) {
|
2008-01-14 16:38:44 +00:00
|
|
|
return( "Error setting option" );
|
2008-01-14 15:05:14 +00:00
|
|
|
}
|
|
|
|
return( "Success" );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-11 16:53:54 +00:00
|
|
|
##########################################################################
|
|
|
|
# Performs a Service Processor Dump
|
|
|
|
##########################################################################
|
|
|
|
sub spdump {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $menu = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
my $dump_setting = 1;
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Get Dump URL
|
|
|
|
######################################
|
|
|
|
my $url = "https://$server/cgi-bin/cgi?form=$form";
|
|
|
|
my $res = $ua->get( $url );
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Dump disabled - enable it
|
|
|
|
######################################
|
|
|
|
if ( $res->content =~ /<option selected value='0'>Disabled/ ) {
|
|
|
|
$res = $ua->post( "https://$server/cgi-bin/cgi",
|
2008-01-18 16:27:05 +00:00
|
|
|
[ form => $form,
|
|
|
|
bdmp => "1",
|
|
|
|
save => "Save settings" ]
|
2008-01-11 16:53:54 +00:00
|
|
|
);
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
if ( $res->content !~ /Operation completed successfully/ ) {
|
|
|
|
return( "Error enabling dump setting" );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Get Dump URL again
|
|
|
|
##################################
|
|
|
|
$res = $ua->get( $url );
|
|
|
|
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Restore setting after dump
|
|
|
|
##################################
|
|
|
|
$dump_setting = 0;
|
|
|
|
}
|
|
|
|
if ( $res->content !~ /(Save settings and initiate dump)/ ) {
|
|
|
|
return( "'$1' button not found" );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# We will lose conection after dump
|
|
|
|
######################################
|
|
|
|
$ua->timeout(5);
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Send dump command
|
|
|
|
######################################
|
|
|
|
$res = $ua->post( "https://$server/cgi-bin/cgi",
|
|
|
|
[form => $form,
|
|
|
|
bdmp => $dump_setting,
|
|
|
|
dump => "Save settings and initiate dump"]
|
|
|
|
);
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
if ( $res->code ne "500" ) {
|
|
|
|
return( $res->status_line );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( "Success" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##########################################################################
|
|
|
|
# Gets all Error/Event Logs entries
|
|
|
|
##########################################################################
|
|
|
|
sub all {
|
|
|
|
return( entries(@_) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets all Error/Event Logs entries then clears the logs
|
|
|
|
##########################################################################
|
|
|
|
sub all_clear {
|
|
|
|
|
|
|
|
my $result = entries( @_ );
|
|
|
|
clear( @_);
|
|
|
|
return( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
1;
|
2007-12-06 19:09:54 +00:00
|
|
|
|
2007-12-11 20:35:07 +00:00
|
|
|
|