2010-05-14 20:43:05 +00:00
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::FSPcfg ;
use strict ;
use Getopt::Long ;
use xCAT::Usage ;
2011-06-17 07:29:17 +00:00
use xCAT::Utils ;
2012-05-03 05:00:28 +00:00
use xCAT::FSPUtils ;
2012-08-09 03:48:50 +00:00
use xCAT::TableUtils ;
2011-06-17 07:29:17 +00:00
use xCAT::PPCcfg ;
2011-04-08 05:21:44 +00:00
#use Data::Dumper;
2010-05-14 20:43:05 +00:00
#use xCAT::PPCcli;
2012-06-21 09:43:16 +00:00
use xCAT::MsgUtils qw( verbose_message ) ;
2010-05-14 20:43:05 +00:00
##########################################
# Globals
##########################################
2011-05-05 03:23:59 +00:00
my % rspconfig = (
frame = > \ & frame ,
2011-06-23 05:57:50 +00:00
cec_off_policy = > \ & cec_off_policy ,
2011-05-05 03:23:59 +00:00
) ;
2010-05-14 20:43:05 +00:00
2011-06-30 08:23:15 +00:00
my % default_passwd = (
HMC = > "" ,
admin = > "admin" ,
general = > "general" ,
) ;
2010-05-14 20:43:05 +00:00
##########################################################################
# Parse the command line for options and operands
##########################################################################
2011-08-29 09:04:01 +00:00
sub array_to_string {
my $ array = shift ;
my $ string = "" ;
my $ i = 0 ;
if ( ! scalar ( @$ array ) ) {
return undef ;
}
$ string . = "\'$array->[0]\'" ;
for ( $ i = 1 ; $ i < scalar ( @$ array ) - 1 ; $ i + + ) {
$ string . = ", " ;
$ string . = "\'$array->[$i]\'" ;
}
if ( $ i < scalar ( @$ array ) ) {
$ string . = " or \'$array->[$i]\'" ;
}
return $ string ;
}
2011-10-20 03:27:28 +00:00
sub check_command {
my $ cmd = shift ;
my $ rsp = shift ;
my @ type = ( ) ;
foreach my $ tmp_type ( keys %$ rsp ) {
if ( grep ( /^$cmd$/ , @ { $ rsp - > { $ tmp_type } } ) ) {
push @ type , $ tmp_type ;
}
}
if ( ! scalar ( @ type ) ) {
return undef ;
} else {
return & array_to_string ( \ @ type ) ;
}
}
2010-05-14 20:43:05 +00:00
sub parse_args {
my $ request = shift ;
my $ command = $ request - > { command } ;
my $ args = $ request - > { arg } ;
my % opt = ( ) ;
my % cmds = ( ) ;
my @ fsp = (
"HMC_passwd" ,
"admin_passwd" ,
"general_passwd" ,
2011-05-23 10:00:31 +00:00
"*_passwd" ,
"resetnet" ,
2012-02-07 09:32:58 +00:00
"cec_off_policy"
2010-05-14 20:43:05 +00:00
) ;
my @ bpa = (
2011-05-05 03:23:59 +00:00
"frame" ,
2010-05-14 20:43:05 +00:00
"HMC_passwd" ,
"admin_passwd" ,
"general_passwd" ,
2011-05-23 10:00:31 +00:00
"*_passwd" ,
"resetnet"
2010-05-14 20:43:05 +00:00
) ;
2010-12-17 03:07:08 +00:00
my @ cec = (
"HMC_passwd" ,
"admin_passwd" ,
"general_passwd" ,
2011-05-23 10:00:31 +00:00
"*_passwd" ,
2011-06-23 05:57:50 +00:00
"cec_off_policy" ,
2011-06-29 04:50:09 +00:00
"resetnet" ,
2011-07-27 09:11:37 +00:00
"sysname" ,
2011-08-29 09:04:01 +00:00
"pending_power_on_side" ,
2011-09-20 06:50:34 +00:00
"BSR" ,
"setup_failover" ,
2011-11-24 09:24:56 +00:00
"force_failover" ,
"huge_page"
2010-12-17 03:07:08 +00:00
) ;
my @ frame = (
2011-05-05 03:23:59 +00:00
"frame" ,
2010-12-17 03:07:08 +00:00
"HMC_passwd" ,
"admin_passwd" ,
"general_passwd" ,
2011-05-23 10:00:31 +00:00
"*_passwd" ,
2011-06-29 04:50:09 +00:00
"resetnet" ,
2011-07-27 09:11:37 +00:00
"sysname" ,
"pending_power_on_side"
2010-12-17 03:07:08 +00:00
) ;
2012-03-06 05:15:33 +00:00
my @ blade = (
"cec_off_policy" ,
"pending_power_on_side"
) ;
2010-12-17 03:07:08 +00:00
2010-05-14 20:43:05 +00:00
my % rsp = (
2010-12-17 03:07:08 +00:00
fsp = > \ @ fsp ,
bpa = > \ @ bpa ,
cec = > \ @ cec ,
2012-03-06 05:15:33 +00:00
blade = > \ @ blade ,
2010-12-17 03:07:08 +00:00
frame = > \ @ frame ,
2010-05-14 20:43:05 +00:00
) ;
#############################################
# Get support command list
#############################################
2011-06-07 05:59:56 +00:00
#my $typetab = xCAT::Table->new( 'nodetype' );
2011-06-03 07:55:28 +00:00
#my $nodes = $request->{node};
#foreach (@$nodes) {
2011-06-07 05:59:56 +00:00
# if ( defined( $typetab )) {
# my ($ent) = $typetab->getAttribs({ node=>$_},'nodetype');
2011-06-03 07:55:28 +00:00
# if ( defined($ent) ) {
# $request->{hwtype} = $ent->{nodetype};
# last;
# }
#
# }
#
#}
2010-05-14 20:43:05 +00:00
my $ nodes = $ request - > { node } ;
2012-02-13 01:56:34 +00:00
my $ typehash = xCAT::DBobjUtils - > getnodetype ( $ nodes , "ppc" ) ;
2011-06-03 07:55:28 +00:00
foreach my $ nn ( @$ nodes ) {
2012-02-10 09:14:40 +00:00
$ request - > { hwtype } = $$ typehash { $ nn } ;
2011-06-07 05:59:56 +00:00
last if ( $ request - > { hwtype } ) ;
2010-05-14 20:43:05 +00:00
}
my $ supported = $ rsp { $ request - > { hwtype } } ;
2012-03-06 05:15:33 +00:00
2010-05-14 20:43:05 +00:00
#############################################
# Responds with usage statement
#############################################
local * usage = sub {
my $ usage_string = xCAT::Usage - > getUsage ( $ command ) ;
return ( [ $ _ [ 0 ] , $ usage_string ] ) ;
} ;
#############################################
# 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" ) ;
$ request - > { method } = undef ;
2012-06-29 09:03:22 +00:00
if ( ! GetOptions ( \ % opt , qw( V|verbose resetnet ) ) ) {
2010-05-14 20:43:05 +00:00
return ( usage ( ) ) ;
}
####################################
# Check for "-" with no option
####################################
if ( grep ( /^-$/ , @ ARGV ) ) {
return ( usage ( "Missing option: -" ) ) ;
}
####################################
# Check for "=" with no argument
####################################
if ( my ( $ c ) = grep ( /=$/ , @ ARGV ) ) {
return ( usage ( "Missing argument: $c" ) ) ;
}
####################################
# Check for unsupported commands
####################################
2011-08-29 09:04:01 +00:00
my @ arg_array = @ ARGV ;
my @ fsp_cmds = ( ) ;
my @ ppc_cmds = ( ) ;
foreach my $ arg ( @ arg_array ) {
2010-05-14 20:43:05 +00:00
my ( $ command , $ value ) = split ( /=/ , $ arg ) ;
2011-05-23 10:00:31 +00:00
if ( ! grep ( /^$command$/ , @$ supported ) and ! $ opt { resetnet } ) {
2011-08-29 09:04:01 +00:00
$ request - > { arg } = [ $ arg ] ;
2012-03-06 05:15:33 +00:00
my $ res = xCAT::PPCcfg:: parse_args ( $ request , @ _ ) ;
2011-08-23 03:09:26 +00:00
if ( ref ( $ res ) eq 'ARRAY' ) {
2012-01-30 06:34:38 +00:00
my $ check_cmd = & check_command ( $ command , \ % rsp ) ;
if ( ! defined ( $ check_cmd ) ) {
2011-10-20 03:27:28 +00:00
return $ res ;
2012-01-30 06:34:38 +00:00
} else {
return ( [ $ _ [ 0 ] , "'$command' is only supported by type $check_cmd." ] ) ;
2011-10-20 03:27:28 +00:00
}
2011-08-23 03:09:26 +00:00
} else {
2011-08-29 09:04:01 +00:00
push @ ppc_cmds , $ command ;
2011-08-23 03:09:26 +00:00
}
2011-08-29 09:04:01 +00:00
} else {
push @ fsp_cmds , $ command ;
2011-08-23 03:09:26 +00:00
}
2010-05-14 20:43:05 +00:00
if ( exists ( $ cmds { $ command } ) ) {
return ( usage ( "Command multiple times: $command" ) ) ;
}
$ cmds { $ command } = $ value ;
2012-03-06 05:15:33 +00:00
}
2011-08-29 09:04:01 +00:00
$ request - > { arg } = \ @ arg_array ;
if ( scalar ( @ fsp_cmds ) && scalar ( @ ppc_cmds ) ) {
my $ fsp_cmds_string = & array_to_string ( \ @ fsp_cmds ) ;
my $ ppc_cmds_string = & array_to_string ( \ @ ppc_cmds ) ;
return ( usage ( "Invalid command array: $fsp_cmds_string can not execute with $ppc_cmds_string." ) ) ;
} elsif ( scalar ( @ ppc_cmds ) ) {
2012-08-09 03:48:50 +00:00
my @ enableASMI = xCAT::TableUtils - > get_site_attribute ( "enableASMI" ) ;
2011-08-29 09:04:01 +00:00
if ( defined ( $ enableASMI [ 0 ] ) ) {
$ enableASMI [ 0 ] =~ tr /a-z/ A - Z / ; # convert to upper
if ( ( $ enableASMI [ 0 ] eq "1" ) || ( $ enableASMI [ 0 ] eq "YES" ) ) {
$ request - > { enableASMI } = 1 ;
}
}
if ( $ request - > { enableASMI } ne '1' ) {
return ( usage ( "You should enable \"ASMI\" first for \'$command\'." ) ) ;
}
}
2010-05-14 20:43:05 +00:00
####################################
# Check command arguments
####################################
foreach ( keys % cmds ) {
if ( $ cmds { $ _ } ) {
my $ result = parse_option ( $ request , $ _ , $ cmds { $ _ } ) ;
if ( $ result ) {
return ( usage ( $ result ) ) ;
}
2012-01-30 06:34:38 +00:00
} elsif ( $ _ =~ /_passwd$/ ) {
return ( usage ( "No argument specified for '$_'" ) ) ;
2010-05-14 20:43:05 +00:00
}
}
2012-03-06 05:15:33 +00:00
2010-05-14 20:43:05 +00:00
####################################
# Return method to invoke
####################################
#if ( $request->{hwtype} =~ /(^hmc|ivm)$/ ) {
# $request->{method} = "cfg";
# return( \%opt );
#}
####################################
# Return method to invoke
####################################
2011-06-23 05:57:50 +00:00
if ( exists ( $ cmds { frame } ) or exists ( $ cmds { cec_off_policy } ) ) {
2011-07-27 09:11:37 +00:00
$ request - > { hcp } = ( exists ( $ cmds { frame } ) ) ? "bpa" : "fsp" ;
2012-03-06 05:15:33 +00:00
$ request - > { method } = "cfg" ;
2011-05-05 03:23:59 +00:00
return ( \ % opt ) ;
}
2011-05-23 10:00:31 +00:00
####################################
# Return method to invoke
####################################
if ( $ opt { resetnet } ) {
$ request - > { hcp } = "fsp" ;
$ request - > { method } = "resetnet" ;
return ( \ % opt ) ;
}
2011-09-20 06:50:34 +00:00
if ( exists ( $ cmds { sysname } ) or exists ( $ cmds { pending_power_on_side } ) or exists ( $ cmds { BSR } )
2011-11-24 09:24:56 +00:00
or exists ( $ cmds { setup_failover } ) or exists ( $ cmds { force_failover } ) or exists ( $ cmds { huge_page } ) ) {
2011-07-27 09:11:37 +00:00
$ request - > { hcp } = $ request - > { hwtype } eq 'frame' ? "bpa" : "fsp" ;
$ request - > { method } = "do_fspapi_function" ;
return ( \ % opt ) ;
}
2010-05-14 20:43:05 +00:00
####################################
# Return method to invoke
####################################
if ( exists ( $ cmds { HMC_passwd } ) or exists ( $ cmds { general_passwd } ) or exists ( $ cmds { admin_passwd } ) or exists ( $ cmds { "*_passwd" } ) ) {
$ request - > { hcp } = "fsp" ;
$ request - > { method } = "passwd" ;
return ( \ % opt ) ;
}
$ request - > { method } = \ % cmds ;
return ( \ % opt ) ;
}
##########################################################################
# Parse the command line optional arguments
##########################################################################
sub parse_option {
my $ request = shift ;
my $ command = shift ;
my $ value = shift ;
####################################
# Password
####################################
2011-06-30 08:23:15 +00:00
#if ( $command eq 'admin_passwd' or $command eq 'general_passwd' or $command eq "*_passwd"){
# my ($passwd,$newpasswd) = split /,/, $value;
# if ( !$passwd or !$newpasswd) {
# return( "Current password and new password couldn't be empty for user 'admin' and 'general'" );
# }
#}
2010-05-14 20:43:05 +00:00
2011-06-30 08:23:15 +00:00
if ( $ command eq 'HMC_passwd' or $ command eq 'admin_passwd' or $ command eq 'general_passwd' or $ command eq "*_passwd" ) {
2010-05-14 20:43:05 +00:00
my ( $ passwd , $ newpasswd ) = split /,/ , $ value ;
if ( ! $ newpasswd ) {
2011-06-30 08:23:15 +00:00
return ( "New password couldn't be empty for user 'HMC', 'admin' or 'general'" ) ;
2010-05-14 20:43:05 +00:00
}
}
2011-05-05 03:23:59 +00:00
if ( $ command eq 'frame' ) {
if ( $ value !~ /^\d+$/i && $ value ne '*' ) {
return ( "Invalid frame number '$value'" ) ;
}
}
2011-06-23 05:57:50 +00:00
if ( $ command eq 'cec_off_policy' ) {
if ( $ value !~ /^poweroff$/i && $ value !~ /^stayon$/i ) {
return ( "Invalid cec_off_policy '$value'" ) ;
}
}
2011-06-29 04:50:09 +00:00
if ( $ command eq 'sysname' ) {
if ( $ value ne '*' ) {
if ( $ value !~ /^[a-zA-Z0-9-_]+$/ ) {
2011-07-27 09:11:37 +00:00
return ( "Invalid sysname param '$value'" ) ;
2011-06-29 04:50:09 +00:00
} elsif ( scalar ( @ { $ request - > { node } } ) gt '1' ) {
2011-07-27 09:11:37 +00:00
return ( "Invalid sysname param '$value'" ) ;
2011-06-29 04:50:09 +00:00
}
my $ len = rindex $ value . "\$" , "\$" ;
if ( $ len > '31' ) {
2011-07-27 09:11:37 +00:00
return ( "Invalid sysname param '$value', name is too long, max 31 characters" ) ;
2011-06-29 04:50:09 +00:00
}
}
}
2011-07-27 09:11:37 +00:00
if ( $ command eq 'pending_power_on_side' ) {
if ( $ value !~ /^(temp|perm)$/ ) {
return ( "Invalid pending_power_on_side param '$value'" ) ;
}
}
2011-09-20 06:50:34 +00:00
if ( $ command eq 'setup_failover' ) {
if ( $ value !~ /^(enable|disable)$/ ) {
return ( "Invalid setup_failover param '$value'" ) ;
}
}
if ( $ command =~ /^(BSR|force_failover)$/ ) {
2011-08-29 09:04:01 +00:00
return ( "BSR value can not be set" ) ;
}
2011-11-24 09:24:56 +00:00
if ( $ command =~ /^huge_page$/ ) {
if ( $ value !~ /^[0-9]+$/ ) {
return ( "Invalid huge page param '$value'" ) ;
}
}
2010-05-14 20:43:05 +00:00
return undef ;
}
2011-07-27 09:11:37 +00:00
sub check_node_info {
2011-06-29 04:50:09 +00:00
my $ hash = shift ;
my $ invalid_node = undef ;
while ( my ( $ mtsm , $ h ) = each ( %$ hash ) ) {
while ( my ( $ name , $ d ) = each ( %$ h ) ) {
2012-03-06 05:15:33 +00:00
if ( @$ d [ 4 ] !~ /^(cec|frame|blade)$/ ) {
2011-06-29 04:50:09 +00:00
$ invalid_node = $ name ;
last ;
}
}
}
return $ invalid_node ;
}
2010-05-14 20:43:05 +00:00
2011-07-27 09:11:37 +00:00
my % fspapi_action = (
sysname = > {
2011-08-29 09:04:01 +00:00
query = > {
cec = > "get_cec_name" ,
frame = > "get_frame_name"
} ,
set = > {
cec = > "set_cec_name" ,
frame = > "set_frame_name"
}
2011-07-27 09:11:37 +00:00
} ,
pending_power_on_side = > {
2011-08-29 09:04:01 +00:00
query = > {
cec = > "list_firmware_level" ,
2012-03-06 05:15:33 +00:00
blade = > "list_firmware_level" ,
2011-08-29 09:04:01 +00:00
frame = > "list_firmware_level"
} ,
set = > {
cec = > "set_ipl_param" ,
2012-03-06 05:15:33 +00:00
blade = > "set_ipl_param" ,
2011-08-29 09:04:01 +00:00
frame = > "set_ipl_param"
}
2011-07-27 09:11:37 +00:00
} ,
2011-08-29 09:04:01 +00:00
BSR = > {
query = > {
cec = > "get_cec_bsr"
}
2011-09-20 06:50:34 +00:00
} ,
setup_failover = > {
query = > {
cec = > "cec_setup_failover"
} ,
set = > {
cec = > "cec_setup_failover"
}
} ,
force_failover = > {
query = > {
cec = > "cec_force_failover"
}
2011-11-24 09:24:56 +00:00
} ,
huge_page = > {
query = > {
cec = > "get_huge_page"
} ,
set = > {
cec = > "set_huge_page"
}
2011-07-27 09:11:37 +00:00
}
2011-06-29 04:50:09 +00:00
) ;
2011-07-27 09:11:37 +00:00
sub do_process_query_res {
my $ name = shift ;
my $ cmd = shift ;
my $ result = shift ;
my $ res = shift ;
2011-08-29 09:04:01 +00:00
if ( @$ res [ 2 ] != 0 ) {
push @$ result , $ res ;
return "Error" ;
}
2011-07-27 09:11:37 +00:00
if ( $ cmd =~ /^sysname$/ ) {
push @$ result , $ res ;
2011-08-29 09:04:01 +00:00
} elsif ( $ cmd =~ /^pending_power_on_side$/ ) {
my @ values = split ( /\n/ , @$ res [ 1 ] ) ;
foreach my $ v ( @ values ) {
if ( $ v =~ /pend_power_on_side_(\w+)=(temp|perm),/ ) {
push @$ result , [ $ name , "Pending Power On Side \L\u$1: $2" , '0' ] ;
} else {
push @$ result , [ $ name , $ v , '1' ] ;
return "Error" ;
2011-07-27 09:11:37 +00:00
}
}
2011-11-24 09:24:56 +00:00
} elsif ( $ cmd =~ /^(BSR|huge_page)$/ ) {
2011-08-29 09:04:01 +00:00
my @ values = split ( /\n/ , @$ res [ 1 ] ) ;
foreach my $ v ( @ values ) {
push @$ result , [ $ name , $ v , '0' ] ;
}
2011-09-20 06:50:34 +00:00
} else {
push @$ result , $ res ;
2011-07-27 09:11:37 +00:00
}
return undef ;
}
sub do_query {
2011-06-29 04:50:09 +00:00
my $ request = shift ;
my $ hash = shift ;
2011-07-27 09:11:37 +00:00
my $ cmd = shift ;
2011-06-29 04:50:09 +00:00
my @ result = ( ) ;
while ( my ( $ mtms , $ h ) = each ( %$ hash ) ) {
while ( my ( $ name , $ d ) = each ( %$ h ) ) {
2011-07-27 09:11:37 +00:00
my $ action = $ fspapi_action { $ cmd } { query } { @$ d [ 4 ] } ;
2012-06-21 09:43:16 +00:00
xCAT::MsgUtils - > verbose_message ( $ request , "rspconfig :$action for node:$name." ) ;
2012-04-28 09:26:49 +00:00
my $ values = xCAT::FSPUtils:: fsp_api_action ( $ request , $ name , $ d , $ action ) ;
2011-08-29 09:04:01 +00:00
& do_process_query_res ( $ name , $ cmd , \ @ result , $ values ) ;
#my $res = &do_process_query_res($name, $cmd, \@result, $values);
#if (defined($res)) {
# last;
#}
2011-06-29 04:50:09 +00:00
}
}
return ( \ @ result ) ;
}
2011-07-27 09:11:37 +00:00
sub do_set_get_para {
my $ node_name = shift ;
my $ cmd = shift ;
my $ value = shift ;
if ( $ cmd =~ /^sysname$/ ) {
return ( ( $ value eq '*' ) ? $ node_name : $ value ) ;
} elsif ( $ cmd =~ /^pending_power_on_side$/ ) {
return ( $ value =~ /^perm$/ ) ? '0' : '1' ;
2011-09-20 06:50:34 +00:00
} elsif ( $ cmd =~ /^setup_failover$/ ) {
return ( $ value =~ /^enable$/ ) ? '1' : '0' ;
2011-11-24 09:24:56 +00:00
} else {
return $ value ;
2011-07-27 09:11:37 +00:00
}
}
sub do_process_set_res {
my $ name = shift ;
my $ cmd = shift ;
my $ result = shift ;
my $ res = shift ;
if ( @$ res [ 1 ] && @$ res [ 1 ] !~ /success/i ) {
push @$ result , $ res ;
return "Error" ;
} else {
push @$ result , [ $ name , "Success" , 0 ] ;
}
}
sub do_set {
2011-06-29 04:50:09 +00:00
my $ request = shift ;
my $ hash = shift ;
2011-07-27 09:11:37 +00:00
my $ cmd = shift ;
2011-06-29 04:50:09 +00:00
my $ value = shift ;
my @ result = ( ) ;
while ( my ( $ mtms , $ h ) = each ( %$ hash ) ) {
while ( my ( $ name , $ d ) = each ( %$ h ) ) {
2011-07-27 09:11:37 +00:00
my $ action = $ fspapi_action { $ cmd } { set } { @$ d [ 4 ] } ;
2012-06-21 09:43:16 +00:00
xCAT::MsgUtils - > verbose_message ( $ request , "rspconfig :$action for node:$name, param:$value." ) ;
2011-07-27 09:11:37 +00:00
my $ para = & do_set_get_para ( $ name , $ cmd , $ value ) ;
2012-04-28 09:26:49 +00:00
my $ values = xCAT::FSPUtils:: fsp_api_action ( $ request , $ name , $ d , $ action , 0 , $ para ) ;
2011-07-27 09:11:37 +00:00
# print Dumper($values);
2011-08-29 09:04:01 +00:00
& do_process_set_res ( $ name , $ cmd , \ @ result , $ values ) ;
#my $res = &do_process_set_res($name, $cmd, \@result, $values);
#if (defined($res)) {
# last;
#}
2011-06-29 04:50:09 +00:00
}
}
return ( \ @ result ) ;
}
2011-07-27 09:11:37 +00:00
sub do_fspapi_function {
my $ request = shift ;
my $ hash = shift ;
my $ exp = shift ;
my @ ret = ( ) ;
my $ res ;
my $ args = $ request - > { arg } ;
2011-11-24 09:24:56 +00:00
my @ fspapi_array = qw/sysname pending_power_on_side BSR setup_failover force_failover huge_page/ ;
2011-07-27 09:11:37 +00:00
my $ invalid_node = & check_node_info ( $ hash ) ;
if ( defined ( $ invalid_node ) ) {
return ( [ [ $ invalid_node , "Node must be CEC or Frame" , '1' ] ] ) ;
}
foreach my $ arg ( @$ args ) {
my ( $ cmd , $ value ) = split /=/ , $ arg ;
2011-08-29 09:04:01 +00:00
if ( ! grep ( /^$cmd$/ , @ fspapi_array ) ) {
my $ fspapi_array_string = & array_to_string ( \ @ fspapi_array ) ;
return ( [ [ "Error" , "'$cmd' can not execute with $fspapi_array_string" , '1' ] ] ) ;
2011-07-27 09:11:37 +00:00
}
if ( $ value ) {
$ res = & do_set ( $ request , $ hash , $ cmd , $ value )
} else {
$ res = & do_query ( $ request , $ hash , $ cmd ) ;
}
push @ ret , @$ res ;
}
return \ @ ret ;
2011-06-29 04:50:09 +00:00
}
2010-05-14 20:43:05 +00:00
##########################################################################
# Update passwords for different users on FSP/BPA
##########################################################################
sub passwd {
my $ request = shift ;
my $ hash = shift ;
my $ exp = shift ;
my $ args = $ request - > { arg } ;
my $ user = ( ) ;
my $ users = ( ) ;
my @ output = ( ) ;
2011-06-30 08:23:15 +00:00
my $ default ;
2010-05-14 20:43:05 +00:00
foreach my $ arg ( @$ args ) {
my ( $ user , $ value ) = split /=/ , $ arg ;
2011-07-27 09:11:37 +00:00
if ( $ user !~ /_passwd$/ ) {
return ( [ [ "Error" , "'$user' can not execute with '*_passwd' commands" , '1' ] ] ) ;
}
2010-05-14 20:43:05 +00:00
my ( $ passwd , $ newpasswd ) = split /,/ , $ value ;
$ user =~ s/_passwd$// ;
#$user =~ s/^HMC$/access/g;
2011-06-30 08:23:15 +00:00
if ( ! $ passwd ) {
$ default = 1 ;
}
2010-05-14 20:43:05 +00:00
if ( $ user eq "*" ) {
push @$ users , "HMC" ;
push @$ users , "admin" ;
push @$ users , "general" ;
} else {
push @$ users , $ user ;
}
foreach my $ usr ( @$ users ) {
2011-06-30 08:23:15 +00:00
if ( $ default == 1 ) {
$ passwd = $ default_passwd { $ usr } ;
}
2010-05-14 20:43:05 +00:00
while ( my ( $ cec , $ h ) = each ( %$ hash ) ) {
while ( my ( $ node , $ d ) = each ( %$ h ) ) {
my $ type = @$ d [ 4 ] ;
my $ fsp_api = ( $ ::XCATROOT ) ? "$::XCATROOT/sbin/fsp-api" : "/opt/xcat/sbin/fsp-api" ;
2012-06-21 09:43:16 +00:00
xCAT::MsgUtils - > verbose_message ( $ request , "rspconfig :modify password of $usr for node:$node." ) ;
2012-04-28 09:26:49 +00:00
my $ cmd = xCAT::FSPcfg:: fsp_api_passwd ( $ request , $ node , $ d , $ usr , $ passwd , $ newpasswd ) ;
2010-05-14 20:43:05 +00:00
my $ Rc = @$ cmd [ 2 ] ;
my $ data = @$ cmd [ 1 ] ;
my $ usr_back = $ usr ;
$ usr_back =~ s/^access$/HMC/g ;
push @ output , [ $ node , "$usr_back: $data" , $ Rc ] ;
##################################
# Write the new password to table
##################################
if ( $ Rc == 0 ) {
2012-06-21 09:43:16 +00:00
xCAT::MsgUtils - > verbose_message ( $ request , "rspconfig :update xCATdb for node:$node,ID:$usr." ) ;
2010-05-14 20:43:05 +00:00
xCAT::PPCdb:: update_credentials ( $ node , $ type , $ usr , $ newpasswd ) ;
}
}
}
}
}
return ( \ @ output ) ;
}
2011-05-05 03:23:59 +00:00
##########################################################################
# Handles all PPC rspconfig commands
##########################################################################
sub cfg {
my $ request = shift ;
my $ hash = shift ;
my $ exp = shift ;
my $ args = $ request - > { arg } ;
my $ result ;
foreach ( @$ args ) {
##################################
# Ignore switches in command-line
##################################
unless ( /^-/ ) {
my ( $ cmd , $ value ) = split /=/ ;
2011-07-27 09:11:37 +00:00
if ( $ cmd !~ /(frame|cec_off_policy)/ ) {
return ( [ [ "Error" , "'$cmd' can not execute with 'frame' or 'cec_off_policy'" , '1' ] ] ) ;
}
2011-05-05 03:23:59 +00:00
no strict 'refs' ;
$ result = $ rspconfig { $ cmd } ( $ request , $ value , $ hash ) ;
use strict ;
}
}
return ( $ result ) ;
}
sub frame {
my $ request = shift ;
my $ value = shift ;
my $ hash = shift ;
my $ arg = $ request - > { arg } ;
foreach ( @$ arg ) {
my $ result ;
my $ Rc ;
my $ data ;
my ( $ cmd , $ value ) = split /=/ , $ _ ;
if ( $ cmd ne "frame" ) {
return ( [ [ "Error" , "Multiple option $cmd and frame is not accepted" , - 1 ] ] ) ;
}
#################################
# Open xCAT database to sync with
# the frame number between hcp
# and database
#################################
my $ tab = xCAT::Table - > new ( "ppc" ) ;
while ( my ( $ cec , $ h ) = each ( %$ hash ) ) {
while ( my ( $ node , $ d ) = each ( %$ h ) ) {
if ( ! defined ( $ value ) ) {
#################################
# Get frame number
#################################
#$data = xCAT::PPCcli::lssyscfg( $exp, @$d[4], @$d[2], 'frame_num' );
2012-06-21 09:43:16 +00:00
xCAT::MsgUtils - > verbose_message ( $ request , "rspconfig :get_frame_number for node:$node." ) ;
2012-04-28 09:26:49 +00:00
$ data = xCAT::FSPUtils:: fsp_api_action ( $ request , $ node , $ d , "get_frame_number" ) ;
2011-05-05 03:23:59 +00:00
$ Rc = pop ( @$ data ) ;
#################################
# Return error
#################################
2011-10-25 08:01:16 +00:00
if ( $ Rc != 0 || @$ data [ 1 ] =~ /Error/ ) {
return ( [ [ $ node , "@$data[1]. If just set the frame number, please wait for 5-10 minutes. Otherwise, maybe other problems cause this failure." , $ Rc ] ] ) ;
2011-05-05 03:23:59 +00:00
}
push @$ result , [ $ node , @$ data [ 1 ] , 0 ] ;
#################################
# Set frame number to database
#################################
$ tab - > setNodeAttribs ( $ node , { id = > @$ data [ 1 ] } ) ;
} elsif ( $ value eq '*' ) {
#################################
# Set frame number
# Read the settings from database
#################################
my $ ent = $ tab - > getNodeAttribs ( $ node , [ 'id' ] ) ;
#################################
# Return error
#################################
if ( ! defined ( $ ent ) or ! defined ( $ ent - > { id } ) ) {
return ( [ [ $ node , "Cannot find frame num in database" , - 1 ] ] ) ;
}
#$data = xCAT::PPCcli::chsyscfg( $exp, "bpa", $d, "frame_num=".$ent->{id} );
2012-06-21 09:43:16 +00:00
xCAT::MsgUtils - > verbose_message ( $ request , "rspconfig :set_frame_number for node:$node,id:$ent->{id}." ) ;
2012-04-28 09:26:49 +00:00
$ data = xCAT::FSPUtils:: fsp_api_action ( $ request , $ node , $ d , "set_frame_number" , 0 , $ ent - > { id } ) ;
2011-05-05 03:23:59 +00:00
$ Rc = pop ( @$ data ) ;
#################################
# Return error
#################################
if ( $ Rc != 0 ) {
return ( [ [ $ node , @$ data [ 1 ] , $ Rc ] ] ) ;
}
push @$ result , [ $ node , @$ data [ 1 ] , 0 ] ;
2011-10-25 08:01:16 +00:00
push @$ result , [ $ node , "It will take several minutes to complete. So please wait for 5-10 minutes, then the other operations could be done. Otherwise, the other operation will fail." , 0 ] ;
2011-05-05 03:23:59 +00:00
} else {
#################################
# Set frame number
# Read the frame number from opt
#################################
#$data = xCAT::PPCcli::chsyscfg( $exp, "bpa", $d, "frame_num=$value" );
2012-06-21 09:43:16 +00:00
xCAT::MsgUtils - > verbose_message ( $ request , "rspconfig :set_frame_number for node:$node,id:$value." ) ;
2012-04-28 09:26:49 +00:00
$ data = xCAT::FSPUtils:: fsp_api_action ( $ request , $ node , $ d , "set_frame_number" , 0 , $ value ) ;
2011-05-05 03:23:59 +00:00
$ Rc = pop ( @$ data ) ;
#################################
# Return error
#################################
if ( $ Rc != 0 ) {
return ( [ [ $ node , @$ data [ 1 ] , $ Rc ] ] ) ;
}
push @$ result , [ $ node , @$ data [ 1 ] , 0 ] ;
2011-06-08 07:39:28 +00:00
push @$ result , [ $ node , "It will take several minutes to complete. So please wait for several minutes, then the other operations could be done. Otherwise, the other operation will fail." , 0 ] ;
2011-05-05 03:23:59 +00:00
#################################
# Set frame number to database
#################################
$ tab - > setNodeAttribs ( $ node , { id = > $ value } ) ;
}
}
return ( [ @$ result ] ) ;
}
}
}
2011-06-23 05:57:50 +00:00
sub cec_off_policy {
my $ request = shift ;
my $ value = shift ;
my $ hash = shift ;
my $ arg = $ request - > { arg } ;
2012-03-06 05:15:33 +00:00
2011-06-23 05:57:50 +00:00
foreach ( @$ arg ) {
my $ result ;
my $ Rc ;
my $ data ;
my ( $ cmd , $ value ) = split /=/ , $ _ ;
if ( $ cmd ne "cec_off_policy" ) {
return ( [ [ "Error" , "Multiple option $cmd and cec is not accepted" , - 1 ] ] ) ;
}
while ( my ( $ cec , $ h ) = each ( %$ hash ) ) {
while ( my ( $ node , $ d ) = each ( %$ h ) ) {
if ( ! defined ( $ value ) ) {
#################################
# Get platform IPL parameters
#################################
2012-06-21 09:43:16 +00:00
xCAT::MsgUtils - > verbose_message ( $ request , "rspconfig :get_phyp_cfg_power_off_policy for node:$node." ) ;
2012-04-28 09:26:49 +00:00
$ data = xCAT::FSPUtils:: fsp_api_action ( $ request , $ node , $ d , "get_phyp_cfg_power_off_policy" ) ;
2011-06-23 05:57:50 +00:00
$ Rc = pop ( @$ data ) ;
#################################
# Return error
#################################
if ( $ Rc != 0 ) {
return ( [ [ $ node , @$ data [ 1 ] , $ Rc ] ] ) ;
}
@$ data [ 1 ] =~ /cec_off_policy=(\w*);/ ;
push @$ result , [ $ node , $ 1 , 0 ] ;
} else {
#################################
# Set cec off policy
#################################
2012-06-21 09:43:16 +00:00
xCAT::MsgUtils - > verbose_message ( $ request , "rspconfig :set power_off_policy for node:$node,policy:$value." ) ;
2011-06-23 05:57:50 +00:00
if ( $ value eq "poweroff" ) {
$ value = "cec_off_policy_poweroff" ;
} else {
$ value = "cec_off_policy_stayon" ;
}
2012-04-28 09:26:49 +00:00
$ data = xCAT::FSPUtils:: fsp_api_action ( $ request , $ node , $ d , $ value ) ;
2011-06-23 05:57:50 +00:00
$ Rc = pop ( @$ data ) ;
#################################
# Return error
#################################
if ( $ Rc != 0 ) {
return ( [ [ $ node , @$ data [ 1 ] , $ Rc ] ] ) ;
}
push @$ result , [ $ node , "Success" , 0 ] ;
}
}
return ( [ @$ result ] ) ;
}
}
}
2011-05-05 03:23:59 +00:00
2010-05-14 20:43:05 +00:00
##########################################################################
# Invoke fsp_api to change the passwords and store updated passwd in db
##########################################################################
sub fsp_api_passwd {
2012-04-28 09:26:49 +00:00
my $ request = shift ;
2010-05-14 20:43:05 +00:00
my $ node_name = shift ;
my $ attrs = shift ;
my $ user = shift ;
my $ passwd = shift ;
my $ newpasswd = shift ;
my $ id = 1 ;
my $ fsp_name = ( ) ;
my $ fsp_ip = ( ) ;
my $ type = ( ) ; # fsp|lpar -- 0. BPA -- 1
my @ result ;
my $ Rc = 0 ;
my % outhash = ( ) ;
my $ res = 0 ;
my $ fsp_api = ( $ ::XCATROOT ) ? "$::XCATROOT/sbin/fsp-api" : "/opt/xcat/sbin/fsp-api" ;
$ id = $$ attrs [ 0 ] ;
$ fsp_name = $$ attrs [ 3 ] ;
############################
# Set type for FSP or BPA
############################
2011-05-05 03:23:59 +00:00
if ( $$ attrs [ 4 ] =~ /^fsp$/ || $$ attrs [ 4 ] =~ /^lpar$/ || $$ attrs [ 4 ] =~ /^cec$/ ) {
2010-05-14 20:43:05 +00:00
$ type = 0 ;
} else {
$ type = 1 ;
}
############################
# Get IP address
############################
2012-08-09 03:48:50 +00:00
#$fsp_ip = xCAT::NetworkUtils::get_hdwr_ip($fsp_name);
#$fsp_ip = xCAT::NetworkUtils::getNodeIPaddress($fsp_name);
2012-04-28 09:26:49 +00:00
#$fsp_ip = xCAT::Utils::getIPaddress($fsp_name);
2012-05-02 06:31:36 +00:00
$ fsp_ip = xCAT::FSPUtils:: getIPaddress ( $ request , $$ attrs [ 4 ] , $ fsp_name ) ;
2011-12-15 07:28:02 +00:00
if ( ! defined ( $ fsp_ip ) or ( $ fsp_ip == - 3 ) ) {
$ res = "Failed to get IP address for $fsp_name." ;
2010-05-14 20:43:05 +00:00
return ( [ $ node_name , $ res , - 1 ] ) ;
}
#################################
# Create command and run command
#################################
my $ cmd ;
2010-11-22 07:54:02 +00:00
if ( $ passwd ne "" ) {
$ cmd = "$fsp_api -a set_fsp_pw -u $user -p $passwd -P $newpasswd -t $type:$fsp_ip:$id:$node_name: " ;
} else {
$ cmd = "$fsp_api -a set_fsp_pw -u $user -P $newpasswd -t $type:$fsp_ip:$id:$node_name: " ;
}
2010-05-14 20:43:05 +00:00
$ SIG { CHLD } = ( ) ;
$ res = xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
$ Rc = $ ::RUNCMD_RC ;
2010-11-22 07:54:02 +00:00
if ( $ Rc == 0 ) {
$ res = "Success" ;
}
2010-05-14 20:43:05 +00:00
##################
# output the prompt
##################
#$outhash{ $node_name } = $res;
return ( [ $ node_name , $ res , $ Rc ] ) ;
}
2011-05-23 10:00:31 +00:00
##########################################################################
# Do resetnet
##########################################################################
sub resetnet {
my $ request = shift ;
2012-07-01 03:19:10 +00:00
xCAT::PPCcfg:: doresetnet ( $ request ) ;
2012-08-02 07:05:09 +00:00
return 0 ;
2011-05-23 10:00:31 +00:00
}
2010-05-14 20:43:05 +00:00
1 ;