2010-12-13 05:18:12 +00:00
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::FSPbootseq ;
use Socket ;
use strict ;
use Getopt::Long ;
use xCAT::PPCcli qw( SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR ) ;
use xCAT::NetworkUtils ;
use xCAT::FSPUtils ;
2011-04-08 05:20:32 +00:00
#use Data::Dumper;
2010-12-13 05:18:12 +00:00
##########################################################################
# Parse the command line for options and operands
##########################################################################
sub parse_args {
my $ request = shift ;
my % opt = ( ) ;
my $ cmd = $ request - > { command } ;
my $ args = $ request - > { arg } ;
my $ node = $ request - > { node } ;
my $ vers =
my @ VERSION = qw( 2.6 ) ;
my @ dev = qw( hfi net ) ;
#############################################
# Responds with usage statement
#############################################
local * usage = sub {
my $ usage_string = xCAT::Usage - > getUsage ( $ cmd ) ;
return ( [ $ _ [ 0 ] , $ usage_string ] ) ;
} ;
#############################################
# Process command-line arguments
#############################################
if ( ! defined ( $ args ) ) {
2011-11-01 03:18:46 +00:00
return ( usage ( "Missing command with rbootseq in DFM, net or hfi ?" ) ) ;
2010-12-13 05:18:12 +00:00
}
2011-11-01 03:18:46 +00:00
2010-12-13 05:18:12 +00:00
#############################################
# 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" ) ;
if ( ! GetOptions ( \ % opt , qw( h|help V|Verbose v|version ) ) ) {
return ( usage ( ) ) ;
}
####################################
# Option -h for Help
####################################
#if ( exists( $opt{h} )) {
# return( usage() );
#}
####################################
# Option -v for version
####################################
if ( exists ( $ opt { v } ) ) {
return ( \ @ VERSION ) ;
}
####################################
# Check for "-" with no option
####################################
#if ( grep(/^-$/, @ARGV )) {
# return(usage( "Missing option: -" ));
#}
####################################
# Check for an extra argument
####################################
#if ( defined( $ARGV[0] )) {
# return(usage( "Invalid Argument: $ARGV[0]" ));
#}
my $ command = grep ( /^$ARGV[0]$/ , @ dev ) ;
if ( ! defined ( $ command ) ) {
return ( usage ( "Invalid command: $ARGV[0]" ) ) ;
}
if ( $ ARGV [ 0 ] =~ /^hfi$/ ) {
2011-04-19 07:03:38 +00:00
$ opt { hfi } = 1 ;
} elsif ( $ ARGV [ 0 ] =~ /^net$/ ) {
$ opt { net } = 1 ;
} else {
return ( usage ( "Invalid Argument: $ARGV[0]" ) ) ;
2010-12-13 05:18:12 +00:00
}
shift @ ARGV ;
if ( defined ( $ ARGV [ 0 ] ) ) {
return ( usage ( "Invalid Argument: $ARGV[0]" ) ) ;
}
2011-04-08 05:20:32 +00:00
#print "in parse_args:\n";
#print $command;
#print Dumper(\%opt);
2012-05-03 06:28:18 +00:00
my $ nodetype = xCAT::DBobjUtils - > getnodetype ( $$ node [ 0 ] , "ppc" ) ;
if ( $ nodetype =~ /^blade$/ ) {
$ request - > { callback } - > ( { data = > [ "After running rebootseq on the nodes successfully, it's required to run <rpower noderange reset> to make the setting be permanent" ] } ) ;
}
2010-12-13 05:18:12 +00:00
####################################
# Set method to invoke
####################################
$ request - > { method } = $ cmd ;
return ( \ % opt ) ;
}
##########################################################################
# set hfi/eth boot string
##########################################################################
sub rbootseq {
my $ request = shift ;
my $ d = shift ;
my $ opt = $ request - > { opt } ;
my @ output ;
my $ tooltype = 0 ;
my $ parameter ;
my $ bootp_retries = 5 ;
my $ tftp_retries = 5 ;
my $ blksize = 512 ;
my $ hash ;
my $ node_name = @$ d [ 6 ] ;
my $ o = @$ d [ 7 ] ;
2011-02-28 07:05:25 +00:00
#print "in setbootseq:\n";
#print "request\n";
#print Dumper($request);
#print "d";
#print Dumper($d);
2010-12-13 05:18:12 +00:00
2012-03-05 10:25:08 +00:00
if ( ! ( $$ d [ 4 ] =~ /^(lpar|blade)$/ ) ) {
2010-12-13 05:18:12 +00:00
push @ output , [ $ node_name , "\'boot\' command not supported for CEC or BPA" , - 1 ] ;
return ( \ @ output ) ;
}
2012-03-05 10:25:08 +00:00
# add checking the power state of the cec
2012-04-28 09:26:49 +00:00
my $ power_state = xCAT::FSPUtils:: fsp_api_action ( $ request , $ node_name , $ d , "cec_state" , $ tooltype ) ;
2012-03-09 10:20:05 +00:00
if ( @$ power_state [ 2 ] != 0 ) {
push @ output , [ $ node_name , @$ power_state [ 1 ] , - 1 ] ;
return ( \ @ output ) ;
}
unless ( @$ power_state [ 1 ] and @$ power_state [ 1 ] =~ /operating|standby/ ) {
2012-03-05 10:25:08 +00:00
my $ machine ;
my $ state ;
if ( $$ d [ 4 ] eq 'blade' ) {
$ machine = "blade" ;
$ state = "on" ;
} else {
$ machine = "CEC" ;
$ state = "power on" ;
}
2012-03-09 10:20:05 +00:00
push @ output , [ $ node_name , "\'boot\' command can only support while the $machine is in the \'$state\' state" , - 1 ] ;
2012-03-05 10:25:08 +00:00
return ( \ @ output ) ;
}
2010-12-13 05:18:12 +00:00
if ( $ opt - > { net } ) {
my $ mactab = xCAT::Table - > new ( 'mac' ) ;
unless ( $ mactab ) {
push @ output , [ $ node_name , "Cannot open mac table" , - 1 ] ;
return ( \ @ output ) ;
}
my $ mac_hash = $ mactab - > getNodeAttribs ( $ node_name , [ qw( mac ) ] ) ;
my $ mac = $ mac_hash - > { mac } ;
2011-02-28 07:05:25 +00:00
if ( ! defined ( $ mac ) ) {
2010-12-13 05:18:12 +00:00
push @ output , [ $ node_name , "No mac address in mac table" , - 1 ] ;
}
$ mactab - > close ( ) ;
if ( $ mac =~ /\| / ) {
#01:02:03:04:05:0E!node5|01:02:03:05:0F!node6-eth1
my @ mac_t = split ( /\|/ , $ mac ) ;
my $ m ;
my $ m_t ;
foreach $ m ( @ mac_t ) {
2011-11-09 09:09:21 +00:00
if ( ( $ m =~ /([\w:]{12})!$node_name/ ) || ( $ m =~ /([\w:]{17})!$node_name/ ) ) {
2010-12-13 05:18:12 +00:00
$ m_t = $ 1 ;
last ;
2011-11-09 09:09:21 +00:00
}
}
2010-12-13 05:18:12 +00:00
if ( ! defined ( $ m_t ) ) {
$ mac = $ mac_t [ 0 ] ;
} else {
$ mac = $ m_t ;
}
}
2011-11-09 09:09:21 +00:00
if ( $ mac =~ /\:/ ) {
$ mac =~ s/\://g ;
}
if ( $ mac =~ /^(\w{12})$/ ) {
$ parameter = "mac=$mac:speed=auto,duplex=auto,$o->{server},,$o->{client},$o->{gateway},$bootp_retries,$tftp_retries,$o->{netmask},$blksize" ;
} else {
push @ output , [ $ node_name , "The mac address in mac table could NOT be used for rbootseq with -net. HFI mac , or other wrong format?" , - 1 ] ;
return ( \ @ output ) ;
}
2010-12-13 05:18:12 +00:00
}
if ( $ opt - > { hfi } ) {
2011-02-28 10:35:22 +00:00
$ parameter = "/hfi-iohub/hfi-ethernet:$o->{server},,$o->{client},$o->{gateway},$bootp_retries,$tftp_retries,$o->{netmask},$blksize" ;
2010-12-13 05:18:12 +00:00
}
2012-04-28 09:26:49 +00:00
my $ res = xCAT::FSPUtils:: fsp_api_action ( $ request , $ node_name , $ d , "set_lpar_bootstring" , $ tooltype , $ parameter ) ;
2010-12-13 05:18:12 +00:00
#print "In boot, state\n";
#print Dumper($res);
my $ Rc = @$ res [ 2 ] ;
my $ data = @$ res [ 1 ] ;
##################################
# Output error
##################################
if ( $ Rc != SUCCESS ) {
push @ output , [ $ node_name , $ data , $ Rc ] ;
2011-11-09 09:09:21 +00:00
} else {
2010-12-13 05:18:12 +00:00
push @ output , [ $ node_name , "Success" , 0 ] ;
2011-11-09 09:09:21 +00:00
}
2010-12-13 05:18:12 +00:00
return ( \ @ output ) ;
}
1 ;