From b1ff94f270cc20f6979fb680e643d693e8ba9b30 Mon Sep 17 00:00:00 2001
From: jjhua <jjhua@8638fb3e-16cb-4fca-ae20-7b5d299a9bcd>
Date: Tue, 25 May 2010 05:15:41 +0000
Subject: [PATCH] enhance getmacs and rnetboot with -o option for p7 ih lpar

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6214 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
---
 perl-xCAT/xCAT/FSPboot.pm            | 11 +++--
 perl-xCAT/xCAT/FSPmac.pm             |  8 +++-
 perl-xCAT/xCAT/PPCboot.pm            |  2 +-
 perl-xCAT/xCAT/PPCmac.pm             |  2 +-
 xCAT-server/sbin/lpar_netboot.expect | 64 +++++++++++++++++++---------
 5 files changed, 61 insertions(+), 26 deletions(-)

diff --git a/perl-xCAT/xCAT/FSPboot.pm b/perl-xCAT/xCAT/FSPboot.pm
index 27c30f6aa..9c6ca7d86 100644
--- a/perl-xCAT/xCAT/FSPboot.pm
+++ b/perl-xCAT/xCAT/FSPboot.pm
@@ -33,7 +33,7 @@ sub do_rnetboot {
     my $pw      = @$exp[5];
     my $cmd;
     my $result;
-
+    
     #######################################
     # Disconnect Expect session
     #######################################
@@ -101,7 +101,9 @@ sub do_rnetboot {
     # Network specified
     #######################################
     $cmd.= " -s auto -d auto -m $opt->{m} -S $opt->{S} -G $opt->{G} -C $opt->{C}";
-   
+    if (  exists( $opt->{o} )) {
+        $cmd.= " -o";
+    }
     #######################################
     # Add command options
     #######################################
@@ -203,7 +205,10 @@ sub rnetboot {
     if ( exists( $options->{s} )) {
         $opt{s} = $options->{s};
     }
-
+    if ( exists( $options->{o} )) {
+        $opt{o} = $options->{o};
+    }
+     
     #####################################
     # Invalid target hardware 
     #####################################
diff --git a/perl-xCAT/xCAT/FSPmac.pm b/perl-xCAT/xCAT/FSPmac.pm
index db6725547..1e75cb980 100644
--- a/perl-xCAT/xCAT/FSPmac.pm
+++ b/perl-xCAT/xCAT/FSPmac.pm
@@ -107,12 +107,16 @@ sub do_getmacs {
             $cmd.= " -i";
         }
     }
-
+    
     #######################################
     # Network specified (-D ping test)
     #######################################
     if ( exists( $opt->{S} )) { 
-        $cmd.= " -D -s auto -d auto -S $opt->{S} -G $opt->{G} -C $opt->{C}";
+        if ( exists( $opt->{o} )) {
+            $cmd .=" -o";
+        }
+
+        $cmd.= " -D -s auto -d auto -S $opt->{S} -G $opt->{G} -C $opt->{C} ";
     } 
     #######################################
     # Add command options 
diff --git a/perl-xCAT/xCAT/PPCboot.pm b/perl-xCAT/xCAT/PPCboot.pm
index d05d65bee..14e26568a 100644
--- a/perl-xCAT/xCAT/PPCboot.pm
+++ b/perl-xCAT/xCAT/PPCboot.pm
@@ -43,7 +43,7 @@ sub parse_args {
     $Getopt::Long::ignorecase = 0;
     Getopt::Long::Configure( "bundling" );
 
-    if ( !GetOptions( \%opt, qw(h|help V|Verbose v|version I|iscsiboot F f s=s m:s@ r=s t=s) )) { 
+    if ( !GetOptions( \%opt, qw(h|help V|Verbose v|version I|iscsiboot F f o s=s m:s@ r=s t=s) )) { 
         return( usage() );
     }
 
diff --git a/perl-xCAT/xCAT/PPCmac.pm b/perl-xCAT/xCAT/PPCmac.pm
index 1e3888428..f4fa3aba9 100644
--- a/perl-xCAT/xCAT/PPCmac.pm
+++ b/perl-xCAT/xCAT/PPCmac.pm
@@ -44,7 +44,7 @@ sub parse_args {
     $Getopt::Long::ignorecase = 0;
     Getopt::Long::Configure( "bundling" );
 
-    if ( !GetOptions( \%opt,qw(h|help V|Verbose v|version C=s G=s S=s D d f F=s arp))) { 
+    if ( !GetOptions( \%opt,qw(h|help V|Verbose v|version C=s G=s S=s D d f o F=s arp))) { 
         return( usage() );
     }
     ####################################
diff --git a/xCAT-server/sbin/lpar_netboot.expect b/xCAT-server/sbin/lpar_netboot.expect
index f09a4cf36..08adba439 100644
--- a/xCAT-server/sbin/lpar_netboot.expect
+++ b/xCAT-server/sbin/lpar_netboot.expect
@@ -1391,6 +1391,7 @@ proc boot_network {} {
     global set_boot_order
     set rc 0
     set i 0
+     
 
     nc_msg "$PROGRAM Status: boot_network start\n"
 
@@ -1858,6 +1859,7 @@ set rc 0
 set debug_flag 0
 set rmvterm_flag 0
 set immed_flag 0
+set from_of 0
 set list_physical 0
 set set_boot_order 0
 set colon 0
@@ -1958,6 +1960,10 @@ while { [llength $argv] > 0} {
                set argv [lrange $argv 1 end]
              }
 
+        "-o" { set from_of 1
+               set argv [lrange $argv 1 end]
+             }
+
         "-w" { set set_boot_order [lindex $argv 1]
                set argv [lrange $argv 2 end]
              }
@@ -2038,7 +2044,7 @@ if { [llength $argv] < 1 } {
 set arg0 [lindex $argv 0]
 set arg1 [lindex $argv 1]
 
-if { [llength $argv] > 6 } {
+if { [llength $argv] > 8 } {
     send_user "$PROGRAM: Extraneous parameter(s)\n"
     usage
 }
@@ -2170,7 +2176,16 @@ if { [string compare "$msg" "Not Available"] == 0  } {
         exit 1
 }
 
+if { $from_of } {
+    if { ([string compare "$msg" "open-firmware"] != 0)  } {
+        send_user "$PROGRAM: You used the -o option. Please make sure the LPAR's initial state is open firmware\n"
+        set rc 1
+        exit 1
 
+    }
+}
+
+if { $from_of != 1 } {
 if { ([string compare "$msg" "Off"] == 0) || ([string compare "$msg" "off"] == 0)  || ([string compare "$msg" "Not Activated"] == 0) } {
     send_user "# Power off complete.\n"
 } else { 
@@ -2230,6 +2245,8 @@ if { ([string compare "$msg" "Off"] == 0) || ([string compare "$msg" "off"] == 0
     }
 }
 
+}
+
 set done 0
 set retry_count 0
 if { $set_boot_order > 1 } {
@@ -2488,24 +2505,27 @@ if { $noboot } { # Display information for all supported adapters
         }
     }
 
-    nc_msg "$PROGRAM Status: power off the node after noboot == 1\n"
-    set cmd "0"
+    if { $from_of != 1 } {  
+    
+      nc_msg "$PROGRAM Status: power off the node after noboot == 1\n"
+      set cmd "0"
 
-    if { $immed_flag } {
-        #set cmd "chsysstate -r lpar -o shutdown -m \"$manage\" --immed -n \"$node\""
-        set cmd [list exec $BINPATH/rpower $node off]
-    } else {
-        #set cmd "chsysstate -r lpar -o shutdown -m \"$manage\" -n \"$node\""
-        set cmd [list exec $BINPATH/rpower $node off]
-    }
-    set timeout 120
-    set rc [catch $cmd msg]
+      if { $immed_flag } {
+          #set cmd "chsysstate -r lpar -o shutdown -m \"$manage\" --immed -n \"$node\""
+          set cmd [list exec $BINPATH/rpower $node off]
+       } else {
+           #set cmd "chsysstate -r lpar -o shutdown -m \"$manage\" -n \"$node\""
+           set cmd [list exec $BINPATH/rpower $node off]
+       }
+       set timeout 120
+       set rc [catch $cmd msg]
        
-    if { $rc } {
-        send_user "$PROGRAM: Cannot power off $NODENAME\n"
-        nc_msg "$PROGRAM Status: error from rpower command\n"
-        send_user "$PROGRAM: Error : $msg\n"
-        exit 1
+       if { $rc } {
+          send_user "$PROGRAM: Cannot power off $NODENAME\n"
+          nc_msg "$PROGRAM Status: error from rpower command\n"
+          send_user "$PROGRAM: Error : $msg\n"
+          exit 1
+       }
     }
 } else {  # Do a network boot
 
@@ -2660,10 +2680,16 @@ if { !$noboot  } {
                                                                      
         #                                                            
         # separate the nodename from the query status                
-        #                                                            
+        #                 
+        if { $from_of != 1 } {                                                   
         if { ([string compare "$msg" "Off"] == 0) || ([string compare "$msg" "off"] == 0)  || ([string compare "$msg" "Not Activated"] == 0) } {
             set done 1                                               
-        }                                                            
+        }                     
+        } else { 
+            if { ([string compare "$msg" "open-firmware"] == 0)  } {
+                set done 1
+            }
+        }                                       
 
         incr query_count                                             
         if { $query_count > 60 } {