2009-03-30 08:36:36 +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);
|
|
|
|
use xCAT::Usage;
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Parse the command line for options and operands
|
|
|
|
##########################################################################
|
|
|
|
sub parse_args {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my %opt = ();
|
|
|
|
my $cmd = $request->{command};
|
|
|
|
my $args = $request->{arg};
|
|
|
|
|
|
|
|
#############################################
|
|
|
|
# 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 )) {
|
|
|
|
$request->{method} = $cmd;
|
|
|
|
return( \%opt );
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# 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" );
|
|
|
|
|
2009-05-11 04:13:35 +00:00
|
|
|
if ( !GetOptions( \%opt, qw(V|Verbose f s=s) )) {
|
2009-03-30 08:36:36 +00:00
|
|
|
return( usage() );
|
|
|
|
}
|
2009-05-11 04:13:35 +00:00
|
|
|
|
|
|
|
if ( exists( $opt{s} ) ){
|
|
|
|
my @boot_devices = split(/,/, $opt{s});
|
|
|
|
foreach (@boot_devices) {
|
|
|
|
if ( (!/^net$/) && (!/^hd$/) ) {
|
|
|
|
return(usage( "boot device $_ is not supported" ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-30 08:36:36 +00:00
|
|
|
####################################
|
|
|
|
# Check for "-" with no option
|
|
|
|
####################################
|
|
|
|
if ( grep(/^-$/, @ARGV )) {
|
|
|
|
return(usage( "Missing option: -" ));
|
|
|
|
}
|
2009-05-11 04:13:35 +00:00
|
|
|
|
2009-03-30 08:36:36 +00:00
|
|
|
####################################
|
|
|
|
# Check for an extra argument
|
|
|
|
####################################
|
|
|
|
if ( defined( $ARGV[0] )) {
|
|
|
|
return(usage( "Invalid Argument: $ARGV[0]" ));
|
|
|
|
}
|
|
|
|
$request->{method} = $cmd;
|
|
|
|
return( \%opt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2009-04-20 05:03:07 +00:00
|
|
|
# Netboot the lpar
|
2009-03-30 08:36:36 +00:00
|
|
|
##########################################################################
|
2009-04-20 05:03:07 +00:00
|
|
|
sub do_rnetboot {
|
2009-03-30 08:36:36 +00:00
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $d = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $name = shift;
|
|
|
|
my $node = shift;
|
|
|
|
my $opt = shift;
|
|
|
|
my $ssh = @$exp[0];
|
|
|
|
my $userid = @$exp[4];
|
|
|
|
my $pw = @$exp[5];
|
|
|
|
my $cmd;
|
|
|
|
my $result;
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Disconnect Expect session
|
|
|
|
#######################################
|
|
|
|
xCAT::PPCcli::disconnect( $exp );
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Get node data
|
|
|
|
#######################################
|
|
|
|
my $id = @$d[0];
|
|
|
|
my $pprofile = @$d[1];
|
|
|
|
my $fsp = @$d[2];
|
|
|
|
my $hcp = @$d[3];
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Find Expect script
|
|
|
|
#######################################
|
|
|
|
$cmd = ($::XCATROOT) ? "$::XCATROOT/sbin/" : "/opt/xcat/sbin/";
|
|
|
|
$cmd .= "lpar_netboot.expect";
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Check command installed
|
|
|
|
#######################################
|
|
|
|
if ( !-x $cmd ) {
|
|
|
|
return( [RC_ERROR,"Command not installed: $cmd"] );
|
|
|
|
}
|
|
|
|
#######################################
|
2009-04-09 09:32:55 +00:00
|
|
|
# Save user name and passwd of hcp to
|
|
|
|
# environment variables.
|
|
|
|
# lpar_netboot.expect depends on it
|
2009-03-30 08:36:36 +00:00
|
|
|
#######################################
|
2009-04-09 09:32:55 +00:00
|
|
|
$ENV{HCP_USERID} = $userid;
|
|
|
|
$ENV{HCP_PASSWD} = $pw;
|
2009-03-30 08:36:36 +00:00
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Turn on verbose and debugging
|
|
|
|
#######################################
|
|
|
|
if ( exists($request->{verbose}) ) {
|
|
|
|
$cmd.= " -v -x";
|
|
|
|
}
|
|
|
|
#######################################
|
|
|
|
# Force LPAR shutdown
|
|
|
|
#######################################
|
|
|
|
if ( exists( $opt->{f} )) {
|
|
|
|
$cmd.= " -i";
|
|
|
|
}
|
2009-05-11 04:13:35 +00:00
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Write boot order
|
|
|
|
#######################################
|
|
|
|
if ( exists( $opt->{s} )) {
|
|
|
|
foreach ($opt->{s}) {
|
|
|
|
if ( /^net$/ ) {
|
|
|
|
$cmd.= " -w 1";
|
|
|
|
} elsif ( /^net,hd$/ ) {
|
|
|
|
$cmd.= " -w 2";
|
|
|
|
} elsif ( /^hd,net$/ ) {
|
|
|
|
$cmd.= " -w 3";
|
|
|
|
} elsif ( /^hd$/ ) {
|
|
|
|
$cmd.= " -w 4";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-30 08:36:36 +00:00
|
|
|
#######################################
|
|
|
|
# Network specified
|
|
|
|
#######################################
|
|
|
|
$cmd.= " -s auto -d auto -m $opt->{m} -S $opt->{S} -G $opt->{G} -C $opt->{C}";
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Add command options
|
|
|
|
#######################################
|
2009-04-09 09:32:55 +00:00
|
|
|
$cmd.= " -t ent -f \"$name\" \"$pprofile\" \"$fsp\" $id $hcp \"$node\"";
|
2009-03-30 08:36:36 +00:00
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Execute command
|
|
|
|
#######################################
|
|
|
|
if ( !open( OUTPUT, "$cmd 2>&1 |")) {
|
|
|
|
return( [RC_ERROR,"$cmd fork error: $!"] );
|
|
|
|
}
|
|
|
|
#######################################
|
|
|
|
# Get command output
|
|
|
|
#######################################
|
|
|
|
while ( <OUTPUT> ) {
|
|
|
|
$result.=$_;
|
|
|
|
}
|
|
|
|
close OUTPUT;
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Get command exit code
|
|
|
|
#######################################
|
|
|
|
my $Rc = SUCCESS;
|
|
|
|
|
|
|
|
foreach ( split /\n/, $result ) {
|
|
|
|
if ( /^lpar_netboot: / ) {
|
|
|
|
$Rc = RC_ERROR;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( [$Rc,$result] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Get LPAR MAC addresses
|
|
|
|
##########################################################################
|
|
|
|
sub rnetboot {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $d = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $options = $request->{opt};
|
|
|
|
my $hwtype = @$exp[2];
|
|
|
|
my $result;
|
|
|
|
my $name;
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Get node data
|
|
|
|
#####################################
|
|
|
|
my $lparid = @$d[0];
|
|
|
|
my $mtms = @$d[2];
|
|
|
|
my $type = @$d[4];
|
|
|
|
my $node = @$d[6];
|
|
|
|
my $o = @$d[7];
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Gateway (-G)
|
|
|
|
# Server (-S)
|
|
|
|
# Client (-C)
|
|
|
|
# mac (-m)
|
|
|
|
#####################################
|
|
|
|
my %opt = (
|
|
|
|
G => $o->{gateway},
|
|
|
|
S => $o->{server},
|
|
|
|
C => $o->{client},
|
|
|
|
m => $o->{mac}
|
|
|
|
);
|
|
|
|
#####################################
|
|
|
|
# Strip colons from mac address
|
|
|
|
#####################################
|
|
|
|
$opt{m} =~ s/://g;
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Force LPAR shutdown
|
|
|
|
#####################################
|
|
|
|
if ( exists( $options->{f} )) {
|
|
|
|
$opt{f} = 1;
|
|
|
|
}
|
2009-05-11 04:13:35 +00:00
|
|
|
#####################################
|
|
|
|
# Write boot device order
|
|
|
|
#####################################
|
|
|
|
if ( exists( $options->{s} )) {
|
|
|
|
$opt{s} = $options->{s};
|
|
|
|
}
|
|
|
|
|
2009-03-30 08:36:36 +00:00
|
|
|
#####################################
|
|
|
|
# Invalid target hardware
|
|
|
|
#####################################
|
|
|
|
if ( $type !~ /^lpar$/ ) {
|
|
|
|
return( [[$name,"Not supported",RC_ERROR]] );
|
|
|
|
}
|
|
|
|
#########################################
|
|
|
|
# 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( [[$node,@$values[0],$Rc]] );
|
|
|
|
}
|
|
|
|
#########################################
|
|
|
|
# Find LPARs by lpar_id
|
|
|
|
#########################################
|
|
|
|
foreach ( @$values ) {
|
|
|
|
if ( /^(.*),$lparid$/ ) {
|
|
|
|
$name = $1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#########################################
|
|
|
|
# Node not found by lpar_id
|
|
|
|
#########################################
|
|
|
|
if ( !defined( $name )) {
|
|
|
|
return( [[$node,"Node not found, lparid=$lparid",RC_ERROR]] );
|
|
|
|
}
|
|
|
|
#########################################
|
|
|
|
# Manually perform boot.
|
|
|
|
#########################################
|
2009-04-20 05:03:07 +00:00
|
|
|
$result = do_rnetboot( $request, $d, $exp, $name, $node, \%opt );
|
2009-03-30 08:36:36 +00:00
|
|
|
$Rc = shift(@$result);
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Form string from array results
|
|
|
|
##################################
|
|
|
|
if ( exists($request->{verbose}) ) {
|
2009-04-20 05:03:07 +00:00
|
|
|
return( [[$node,join( '', @$result ),$Rc]] );
|
2009-03-30 08:36:36 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
##################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
if ( @$result[0] =~ /lpar_netboot: (.*)/ ) {
|
2009-04-20 05:03:07 +00:00
|
|
|
return( [[$node,$1,$Rc]] );
|
2009-03-30 08:36:36 +00:00
|
|
|
}
|
2009-04-20 05:03:07 +00:00
|
|
|
return( [[$node,join( '', @$result ),$Rc]] );
|
2009-03-30 08:36:36 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Split array into string
|
|
|
|
##################################
|
|
|
|
my $data = @$result[0];
|
|
|
|
if ( $hwtype eq "hmc" ) {
|
|
|
|
$data = join( '', @$result );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# lpar_netboot returns:
|
|
|
|
#
|
|
|
|
# # 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.
|
|
|
|
# # Network boot proceeding, lpar_netboot is exiting.
|
|
|
|
# # Finished.
|
|
|
|
#
|
|
|
|
#####################################
|
|
|
|
if ( $data =~ /Finished/) {
|
2009-04-20 05:03:07 +00:00
|
|
|
return( [[$node,"Success",$Rc]] );
|
2009-03-30 08:36:36 +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: (.*)/ ) {
|
2009-04-20 05:03:07 +00:00
|
|
|
return( [[$node,$1,RC_ERROR]] );
|
2009-03-30 08:36:36 +00:00
|
|
|
}
|
2009-04-20 05:03:07 +00:00
|
|
|
return( [[$node,$data,RC_ERROR]] );
|
2009-03-30 08:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|