2007-11-16 19:47:00 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT::PPCboot;
|
|
|
|
use strict;
|
|
|
|
use Getopt::Long;
|
|
|
|
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# 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 @VERSION = qw( 2.0 );
|
|
|
|
|
|
|
|
#############################################
|
|
|
|
# Responds with usage statement
|
|
|
|
#############################################
|
|
|
|
local *usage = sub {
|
|
|
|
return( [ $_[0],
|
|
|
|
"rnetboot -h|--help",
|
|
|
|
"rnetboot -v|--version",
|
2008-03-19 17:16:24 +00:00
|
|
|
"rnetboot [-V|--verbose] noderange",
|
2007-11-16 19:47:00 +00:00
|
|
|
" -h writes usage information to standard output",
|
|
|
|
" -v displays command version",
|
|
|
|
" -V verbose output" ]);
|
|
|
|
};
|
|
|
|
#############################################
|
|
|
|
# Process command-line arguments
|
|
|
|
#############################################
|
|
|
|
if ( !defined( $args )) {
|
|
|
|
return( usage() );
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# 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-03-19 17:16:24 +00:00
|
|
|
if ( !GetOptions( \%opt, qw(h|help V|Verbose v|version) )) {
|
2007-11-16 19:47:00 +00:00
|
|
|
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]" ));
|
|
|
|
}
|
|
|
|
$request->{method} = $cmd;
|
|
|
|
return( \%opt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-20 15:29:12 +00:00
|
|
|
##########################################################################
|
|
|
|
# IVM rnetboot
|
|
|
|
##########################################################################
|
|
|
|
sub ivm_rnetboot {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $d = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $name = shift;
|
2008-03-19 17:16:24 +00:00
|
|
|
my $opt = shift;
|
2007-12-20 15:29:12 +00:00
|
|
|
my $ssh = @$exp[0];
|
|
|
|
my $userid = @$exp[4];
|
|
|
|
my $pw = @$exp[5];
|
2008-02-14 19:11:31 +00:00
|
|
|
my $cmd;
|
2007-12-20 15:29:12 +00:00
|
|
|
my $result;
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Disconnect Expect session
|
|
|
|
#######################################
|
|
|
|
xCAT::PPCcli::disconnect( $exp );
|
2008-02-14 19:11:31 +00:00
|
|
|
|
2008-03-19 17:16:24 +00:00
|
|
|
#######################################
|
|
|
|
# Get node data
|
|
|
|
#######################################
|
|
|
|
my $id = @$d[0];
|
|
|
|
my $profile = @$d[1];
|
|
|
|
my $fsp = @$d[2];
|
|
|
|
my $hcp = @$d[3];
|
|
|
|
|
2008-02-14 19:11:31 +00:00
|
|
|
#######################################
|
|
|
|
# Find Expect script
|
|
|
|
#######################################
|
|
|
|
$cmd = ($::XCATROOT) ? "$::XCATROOT/sbin/" : "/opt/xcat/sbin/";
|
|
|
|
$cmd .= "lpar_netboot.expect";
|
2007-12-20 15:29:12 +00:00
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Check command installed
|
|
|
|
#######################################
|
|
|
|
if ( !-x $cmd ) {
|
|
|
|
return( [RC_ERROR,"Command not installed: $cmd"] );
|
|
|
|
}
|
|
|
|
#######################################
|
|
|
|
# Create random temporary userid/pw
|
|
|
|
# file between 1000000 and 2000000
|
|
|
|
#######################################
|
|
|
|
my $random = int( rand(1000001)) + 1000000;
|
|
|
|
my $fname = "/tmp/xCAT-$hcp-$random";
|
|
|
|
|
|
|
|
unless ( open( CRED, ">$fname" )) {
|
|
|
|
return( [RC_ERROR,"Error creating temporary password file '$fname'"]);
|
|
|
|
}
|
|
|
|
print CRED "$userid $pw\n";
|
|
|
|
close( CRED );
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Turn on verbose and debugging
|
|
|
|
#######################################
|
|
|
|
if ( exists($request->{verbose}) ) {
|
|
|
|
$cmd.= " -v -x";
|
|
|
|
}
|
|
|
|
#######################################
|
|
|
|
# Network specified
|
|
|
|
#######################################
|
2008-03-04 20:00:50 +00:00
|
|
|
$cmd.= " -s auto -d auto -m $opt->{m} -S $opt->{S} -G $opt->{G} -C $opt->{C}";
|
2007-12-20 15:29:12 +00:00
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Add command options
|
|
|
|
#######################################
|
|
|
|
$cmd.= " -t ent -f \"$name\" \"$profile\" \"$fsp\" $id $hcp $fname";
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Execute command
|
|
|
|
#######################################
|
|
|
|
if ( !open( OUTPUT, "$cmd 2>&1 |")) {
|
|
|
|
return( [RC_ERROR,"$cmd fork error: $!"] );
|
|
|
|
}
|
|
|
|
#######################################
|
|
|
|
# Get command output
|
|
|
|
#######################################
|
|
|
|
while ( <OUTPUT> ) {
|
|
|
|
$result.=$_;
|
|
|
|
}
|
|
|
|
close OUTPUT;
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# If command did not, remove file
|
|
|
|
#######################################
|
|
|
|
if ( -r $fname ) {
|
|
|
|
unlink( $fname );
|
|
|
|
}
|
2008-03-03 19:52:09 +00:00
|
|
|
#######################################
|
|
|
|
# Get command exit code
|
|
|
|
#######################################
|
2008-03-04 20:00:50 +00:00
|
|
|
my $Rc = SUCCESS;
|
|
|
|
|
|
|
|
foreach ( split /\n/, $result ) {
|
|
|
|
if ( /^lpar_netboot: / ) {
|
|
|
|
$Rc = RC_ERROR;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
2008-03-03 20:47:07 +00:00
|
|
|
return( [$Rc,$result] );
|
2007-12-20 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Get LPAR MAC addresses
|
|
|
|
##########################################################################
|
|
|
|
sub rnetboot {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $d = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $hwtype = @$exp[2];
|
2007-12-20 15:29:12 +00:00
|
|
|
my $result;
|
2008-03-06 16:35:42 +00:00
|
|
|
my $node;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Get node data
|
|
|
|
#####################################
|
2008-03-06 16:35:42 +00:00
|
|
|
my $lparid = @$d[0];
|
|
|
|
my $mtms = @$d[2];
|
|
|
|
my $type = @$d[4];
|
|
|
|
my $name = @$d[6];
|
2008-03-19 17:16:24 +00:00
|
|
|
my $o = @$d[7];
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2008-03-19 17:16:24 +00:00
|
|
|
#####################################
|
|
|
|
# Gateway (-G)
|
|
|
|
# Server (-S)
|
|
|
|
# Client (-C)
|
|
|
|
# mac (-m)
|
|
|
|
#####################################
|
|
|
|
my %opt = (
|
|
|
|
G => $o->{gateway},
|
|
|
|
S => $o->{server},
|
|
|
|
C => $o->{client},
|
|
|
|
m => $o->{mac}
|
|
|
|
);
|
2007-11-16 19:47:00 +00:00
|
|
|
#####################################
|
|
|
|
# Invalid target hardware
|
|
|
|
#####################################
|
|
|
|
if ( $type !~ /^lpar$/ ) {
|
2008-03-19 17:16:24 +00:00
|
|
|
return( [[$name,"Not supported",RC_ERROR]] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2007-12-20 15:29:12 +00:00
|
|
|
#########################################
|
2008-03-06 16:35:42 +00:00
|
|
|
# Get name known by HCP
|
|
|
|
#########################################
|
|
|
|
my $filter = "name,lpar_id";
|
|
|
|
my $values = xCAT::PPCcli::lssyscfg( $exp, $type, $mtms, $filter );
|
|
|
|
my $Rc = shift(@$values);
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Return error
|
|
|
|
#########################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( [[$name,@$values[0],$Rc]] );
|
|
|
|
}
|
|
|
|
#########################################
|
|
|
|
# Find LPARs by lpar_id
|
|
|
|
#########################################
|
|
|
|
foreach ( @$values ) {
|
|
|
|
if ( /^(.*),$lparid$/ ) {
|
|
|
|
$node = $1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#########################################
|
|
|
|
# Node not found by lpar_id
|
|
|
|
#########################################
|
|
|
|
if ( !defined( $node )) {
|
|
|
|
return( [[$name,"Node not found, lparid=$lparid",RC_ERROR]] );
|
|
|
|
}
|
|
|
|
#########################################
|
2007-12-20 15:29:12 +00:00
|
|
|
# IVM does not have lpar_netboot command
|
|
|
|
# so we have to manually perform boot.
|
|
|
|
#########################################
|
|
|
|
if ( $hwtype eq "ivm" ) {
|
2008-03-19 17:16:24 +00:00
|
|
|
$result = ivm_rnetboot( $request, $d, $exp, $node, \%opt );
|
2007-12-20 15:29:12 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$result = xCAT::PPCcli::lpar_netboot(
|
|
|
|
$exp,
|
|
|
|
$request->{verbose},
|
2008-03-06 16:35:42 +00:00
|
|
|
$node,
|
2007-11-16 19:47:00 +00:00
|
|
|
$d,
|
2008-03-19 17:16:24 +00:00
|
|
|
\%opt );
|
2007-12-20 15:29:12 +00:00
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
my $Rc = shift(@$result);
|
2007-12-20 15:29:12 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Form string from array results
|
|
|
|
##################################
|
|
|
|
if ( exists($request->{verbose}) ) {
|
2008-03-05 18:38:29 +00:00
|
|
|
return( [[$name,join( '', @$result ),$Rc]] );
|
2007-12-20 15:29:12 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Return error
|
2008-02-29 18:56:16 +00:00
|
|
|
# lpar_netboot returns (for example):
|
|
|
|
# # Connecting to lpar1
|
|
|
|
# # Connected
|
|
|
|
# # Checking for power off.
|
|
|
|
# # Power off the node
|
|
|
|
# # Wait for power off.
|
|
|
|
# # Power off complete.
|
|
|
|
# # Power on lpar1 to Open Firmware.
|
|
|
|
# # Power on complete.
|
|
|
|
# lpar_netboot: can not find mac address 42DAB.
|
|
|
|
#
|
2007-12-20 15:29:12 +00:00
|
|
|
##################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
2008-02-29 18:56:16 +00:00
|
|
|
if ( @$result[0] =~ /lpar_netboot: (.*)/ ) {
|
2008-03-05 18:38:29 +00:00
|
|
|
return( [[$name,$1,$Rc]] );
|
2008-02-29 18:56:16 +00:00
|
|
|
}
|
2008-03-05 18:38:29 +00:00
|
|
|
return( [[$name,join( '', @$result ),$Rc]] );
|
2007-12-20 15:29:12 +00:00
|
|
|
}
|
|
|
|
##################################
|
2008-02-29 18:56:16 +00:00
|
|
|
# Split array into string
|
2007-12-20 15:29:12 +00:00
|
|
|
##################################
|
2008-02-29 18:56:16 +00:00
|
|
|
my $data = @$result[0];
|
|
|
|
if ( $hwtype eq "hmc" ) {
|
|
|
|
$data = join( '', @$result );
|
2007-12-20 15:29:12 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# lpar_netboot returns:
|
|
|
|
#
|
2008-02-29 18:56:16 +00:00
|
|
|
# # Connecting to lpar1
|
2007-12-20 15:29:12 +00:00
|
|
|
# # Connected
|
2008-02-29 18:56:16 +00:00
|
|
|
# ...
|
|
|
|
# lpar_netboot Status: network boot initiated
|
|
|
|
# # bootp sent over network.
|
|
|
|
# lpar_netboot Status: waiting for the boot image to boot up.
|
|
|
|
# # Network boot proceeding, lpar_netboot is exiting.
|
|
|
|
# # Finished.
|
|
|
|
#
|
2007-12-20 15:29:12 +00:00
|
|
|
#####################################
|
2008-02-29 18:56:16 +00:00
|
|
|
if ( $data =~ /Finished/) {
|
2008-03-05 18:38:29 +00:00
|
|
|
return( [[$name,"Success",$Rc]] );
|
2007-12-20 15:29:12 +00:00
|
|
|
}
|
2008-03-19 17:16:24 +00:00
|
|
|
#####################################
|
2008-02-29 18:56:16 +00:00
|
|
|
# Can still be error w/ Rc=0:
|
|
|
|
#
|
|
|
|
# # Connecting to lpar1
|
|
|
|
# # Connected
|
|
|
|
# ...
|
|
|
|
# lpar_netboot Status: network boot initiated
|
|
|
|
# # bootp sent over network.
|
|
|
|
# lpar_netboot Status: waiting for the boot image to boot up.
|
|
|
|
# lpar_netboot: bootp operation failed.
|
|
|
|
#
|
|
|
|
#####################################
|
|
|
|
if ( $data =~ /lpar_netboot: (.*)/ ) {
|
2008-03-19 17:16:24 +00:00
|
|
|
return( [[$name,$1,RC_ERROR]] );
|
2008-02-29 18:56:16 +00:00
|
|
|
}
|
2008-03-19 17:16:24 +00:00
|
|
|
return( [[$name,$data,RC_ERROR]] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-02-29 18:56:16 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
1;
|
2007-12-20 15:29:12 +00:00
|
|
|
|
2008-03-04 20:00:50 +00:00
|
|
|
|
2008-03-05 18:38:29 +00:00
|
|
|
|
2008-03-06 16:35:42 +00:00
|
|
|
|