From 32b38b76920c683a15f21fa0e1f9b047d01c889a Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Mon, 3 Aug 2020 14:54:32 -0400 Subject: [PATCH 1/2] Secured OF prompt --- perl-xCAT/xCAT/LparNetbootExp.pm | 731 ++++++++++++++++++++++++++++--- 1 file changed, 660 insertions(+), 71 deletions(-) diff --git a/perl-xCAT/xCAT/LparNetbootExp.pm b/perl-xCAT/xCAT/LparNetbootExp.pm index e5f1284ac..62dd9d2ce 100755 --- a/perl-xCAT/xCAT/LparNetbootExp.pm +++ b/perl-xCAT/xCAT/LparNetbootExp.pm @@ -4,6 +4,7 @@ package xCAT::LparNetbootExp; + #----------------------------------------------------------------------------- =head1 LparNetbootExp @@ -33,6 +34,7 @@ Usage: Return macaddress 3: Set disk as 1st boot device, network as 2nd boot device 4: set disk as boot device -M Discovery ethernet adapter mac address and location code + -a Use Secure OF --help Prints this help @@ -62,6 +64,7 @@ my $client_ip; my $gateway_ip; my $device_type; my $server_ip; +my $secOF=1; # List supported network adapters here. dev_pat is an array of regexp patterns # the script searches for in the device tree listing. dev_type is the type @@ -425,8 +428,144 @@ sub get_phandle { my $expect_out; my $retry_count; my %path; - my $rc = 0; + my $rc; + if ($secOF == 1) { + nc_msg($verbose, "Status: get_phandle: Using Secured OF..............\n"); + + send_command($verbose, $rconsole, "\r"); + + @result = $rconsole->expect( + $timeout, + [ qr/ok/ => + sub { + nc_msg($verbose, "Status: at root\n"); + $rconsole->clear_accum(); + } + ], + [ qr/]/ => + sub { + nc_msg($verbose, "Unexpected prompt\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + $rconsole->send("\r"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); + + send_command($verbose, $rconsole, "DISPLAY_BOOT_DEVICES #network\r"); + + $timeout = 60; + $done = 0; + while (!$done) { + + @result = (); + @result = $rconsole->expect( + $timeout, + [ qr/.*1GbE.*/ => + sub { + nc_msg($verbose, "Parsing network adapters... \n"); + } + ], + [ qr/.*25\/10 Gb.*/ => + sub { + nc_msg($verbose, "Parsing network adapters 25G \n"); + } + ], + [ qr/.*Interpartition Logical LAN.*/ => + sub { + nc_msg($verbose, "Parsing network adapters... \n"); + } + ], + [ qr/>/ => + sub { + nc_msg($verbose, "finished \n"); + $rconsole->clear_accum(); + $done = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout isolating single line of ls output\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); + + if ($result[2] =~ /1GbE/) { + my $j = 0; + for ($j = 0 ; $j < $dev_count ; $j++) { + my @values1 = split('=', $result[2]); + my @values2 = split('\)', $values1[1]); + $full_path_name_array[$adapter_found] = $values2[0]; + $phandle_array[$adapter_found] = $values2[0]; + $adap_type[$adapter_found] = $dev_type[$j]; + $adapter_found++; + last; + }; + }; + + if ($result[2] =~ /25\/10 Gb/) { + my $j = 0; + for ($j = 0 ; $j < $dev_count ; $j++) { + my @values1 = split('=', $result[2]); + my @values2 = split('\)', $values1[1]); + $full_path_name_array[$adapter_found] = $values2[0]; + $phandle_array[$adapter_found] = $values2[0]; + $adap_type[$adapter_found] = $dev_type[$j]; + $adapter_found++; + last; + }; + }; + + if ($result[2] =~ /Interpartition Logical LAN/) { + my $j = 0; + for ($j = 0 ; $j < $dev_count ; $j++) { + my @values1 = split('=', $result[2]); + my @values2 = split('\)', $values1[1]); + $full_path_name_array[$adapter_found] = $values2[0]; + $phandle_array[$adapter_found] = $values2[0]; + $adap_type[$adapter_found] = $dev_type[$j]; + $adapter_found++; + last; + }; + }; + }; + + # Did we find one or more adapters? + if ($adapter_found > 0) { + return 0; + } else { + nc_msg($verbose, "No network adapters found\n"); + return 1; + }; + + } + else + { # This is the first procedure entered after getting to the ok prompt. On entry # the current device is not root. The command 'dev /' is sent to get to the @@ -436,6 +575,7 @@ sub get_phandle { # The pwd command can be used to determine what the current device is. # + send_command($verbose, $rconsole, "dev /\r"); @result = $rconsole->expect( @@ -588,8 +728,8 @@ sub get_phandle { } else { nc_msg($verbose, "No network adapters found\n"); return 1; - } - + }; + }; } #------------------------------------------------------------------------------- @@ -627,9 +767,30 @@ sub get_adap_prop { my $nw_speed; my $nw_conn; my $nw_duplex; + my $vtag; + nc_msg($verbose, " Status: get_adap_prop start\n"); + if ($secOF == 1) { + nc_msg($verbose, " Status: get_adap_prop: Secured OF\n"); + + $nw_type="ethernet"; + $nw_speed="100"; + $nw_conn="rj45"; + $nw_duplex="duplex"; + + push @adap_prop_array, $nw_speed . "," . $nw_conn . "," . $nw_duplex; + nc_msg($verbose, "Status: Adding adapter properties to list\n"); + + if (scalar(@adap_prop_array) != 0) { + return \@adap_prop_array; + } else { + return 0; + }; + } + else { + # state 0, stack count 0 $done[0] = 0; $cmd[0] = "\" supported-network-types\" " . $phandle . " get-package-property\r"; @@ -794,7 +955,8 @@ sub get_adap_prop { return \@adap_prop_array; } else { return 0; - } + }; + }; } #------------------------------------------------------------------------------- @@ -826,12 +988,14 @@ sub get_mac_addr { my $rconsole = shift; my $node = shift; my $verbose = shift; - my $timeout = 60; + my $timeout = 120; my $state = 0; + my $nowdone = 0; my @result; my $mac_rc; my @cmd; my @done; + my $newdone; my @msg; my @pattern; my @newstate; @@ -839,6 +1003,70 @@ sub get_mac_addr { my $rc = 0; + if ($secOF == 1) { + nc_msg($verbose, " Status: get_mac_addr: Secured OF\n"); + + my $loc = substr($phandle,0,-1); + $rconsole->clear_accum(); + + while (!$newdone) { + @result = (); + send_command($verbose, $rconsole, "DISPLAY_MAC_ADDRESS $loc\r"); + @result = $rconsole->expect( + $timeout, + # [ qr/25\/10 Gb/ => + # sub { + # nc_msg($verbose, "Parsing MAC Address 25/10 Gb... \n"); + # $rconsole->clear_accum(); + # } + #], + [ qr/(\n)([^\r]*)(\r)/ => + sub { + nc_msg($verbose, "Parsing MAC Address... \n"); + #$rconsole->clear_accum(); + } + ], + [ qr/>/ => + sub { + nc_msg($verbose, "finished \n"); + $rconsole->clear_accum(); + $newdone = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout isolating single line of ls output\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); + + my @lines = grep(/MAC/, @result); + my @values1 = split(' ', $lines[1]); + $mac_address = $values1[2]; + + #nc_msg($verbose, "1GbE Adapter MAC Address: $mac_address \n"); + nc_msg($verbose, "Ethernet Adapter MAC Address: $mac_address \n"); + + # Return mac address + if ($mac_address) { + return $mac_address; + } else { + return undef; + }; + } + } + else { + nc_msg($verbose, "Status: get_mac_addr start\n"); # cmd(0) could have been sent as 3 commands. " mac-address" (tcl forces @@ -1001,7 +1229,8 @@ sub get_mac_addr { return $mac_address; } else { return undef; - } + }; + }; } @@ -1044,6 +1273,13 @@ sub get_adaptr_loc { my $loc_code; my $rc = 0; + if ($secOF == 1) { + nc_msg($verbose, " Status: get_adaptr_loc: Secured OF\n"); + + return $phandle; + } + else { + nc_msg($verbose, "Status: get_adaptr_loc start\n"); # cmd(0) could have been sent as 3 commands. " ibm,loc-code" (tcl forces @@ -1196,7 +1432,8 @@ sub get_adaptr_loc { return $loc_code; } else { return undef; - } + }; + }; } #------------------------------------------------------------------------------- @@ -1238,6 +1475,7 @@ sub ping_server { my $linklocal_ip; my @result; my @done; + my $newdone=0; my @cmd; my @msg; my @pattern; @@ -1245,11 +1483,7 @@ sub ping_server { my $state = 0; my $timeout; - nc_msg($verbose, "Status: ping_server start\n"); - #if (exists($env{'FIRMWARE_DUMP'})) { - # $full_path_name = Firmware_Dump($phandle); - #} my $j = 0; my $tty_do_ping = 0; my $stack_level = 0; @@ -1262,6 +1496,67 @@ sub ping_server { my $ping_debug; my $ping_rc; my $rc = 0; + my $netmask="255.255.255.0"; + + nc_msg($verbose, "Status: ping_server start\n"); + + if ($secOF == 1) { + nc_msg($verbose, " Status: ping_server: Secured OF\n"); + nc_msg($verbose, " Adapter Location: \n"); + + + my $loc = substr($phandle,0,-1); + $rconsole->clear_accum(); + send_command($verbose, $rconsole, "PING $loc $server_ip,$client_ip,$gateway_ip,,$netmask \r"); + + while (!$newdone) { + @result = (); + @result = $rconsole->expect( + $timeout, + [ qr/(\n)([^\r]*)(\r)/ => + sub { + nc_msg($verbose, "Pinging... \n"); + #$rconsole->clear_accum(); + } + ], + [ qr/>/ => + sub { + nc_msg($verbose, "finished \n"); + $rconsole->clear_accum(); + $newdone = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout isolating single line of ls output\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); + + my $line = grep(/SMS Macro Operation Succeeded./, @result); + + if ($line eq 1) { + nc_msg($verbose, "# $full_path_name ping successful.\n"); + $ping_rc=0; + last; + } else { + nc_msg($verbose, "# $full_path_name ping unsuccessful.\n"); + $ping_rc=1; + }; + }; + return $ping_rc; + } + else { # If the adapter type chosen is ethernet, need to set the speed and duplex # of the adapter before we perform the ping. If token ring or fddi, @@ -1328,6 +1623,7 @@ sub ping_server { } $cmd[3] = "ping $full_path_name:ipv6,$server_ip,$linklocal_ip,$gateway_ip$to4pt\r"; } else { + ###$cmd[3] = "ping $full_path_name:$server_ip,$client_ip,$gateway_ip$to4pt\r"; $cmd[3] = "ping $full_path_name:$server_ip,$client_ip,$gateway_ip$to4pt\r"; } $pattern[3] = ".*ping(.*)ok(.*)0 >(.*)"; @@ -1462,35 +1758,6 @@ sub ping_server { $stack_level = length($result[4]); } elsif (($state == 4) && ($tty_do_ping != 1) && ($result[2] =~ /PING SUCCESS/)) { $ping_rc = 0; - - #} elsif ( $result[2] =~ /unknown word/ ) { - # nc_msg($verbose, "Status: try tty-do-ping.\n"); - # $ping_rc = 1; - # $tty_do_ping = 1; - # $state = 3 ; - # $cmd[3] = "\"" . $full_path_name . ":" . $client_ip . "," . $server_ip . "," . $gateway_ip . "\" tty-do-ping\r"; - # $pattern[3] = "(.*)ok(.*)(\[1-2\]) >(.*)"; - # - # # state 4, get the return code off the stack - # $done[4] = 0; - # $cmd[4] = ".\r"; - # $msg[4] = "Status: return code displayed, stack empty\n"; - # $pattern[4] = "(\[0-9\]*) ok(.*)(\[0-1\]) >(.*)"; - # $newstate[4] = 5; - # - # # this command is used to work around a default catch problem in open - # # firmware. Without it, a default catch occurs if we try to set - # # adapter properties again after a ping - # # - # # state 5, re$pointer - # $done[5] = 0; - # $cmd[5] = "0 to my-self\r"; - # $msg[5] = "Status: resetting pointer\n" ; - # $pattern[5] = "(.*)ok(.*)0 >(.*)"; - # $newstate[5] = 6 ; - # - # # state 6, all done - # $done[6] = 1; } else { $ping_rc = 1; } @@ -1583,6 +1850,7 @@ sub ping_server { } } return $ping_rc; + }; } @@ -1623,6 +1891,69 @@ sub set_disk_boot { my $state; my $rc = 0; + if ($secOF == 1) { + nc_msg($verbose, " Status: set_disk_boot: Secured OF\n"); + + # state 0, get SMS screen + $done[0] = 0; + $cmd[0] = "DISPLAY_BOOTSEQ\r"; + $msg[0] = "Status: sending return to repaint SMS screen\n"; + $pattern[0] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Storage(\r)"; + $newstate[0] = 1; + + # state 1, Set Default Boot Seq + $done[1] = 0; + $cmd[1] = "SET_DEFAULT_BOOTSEQ\r"; + $msg[1] = "Status: Set default boot sequence\n"; + $pattern[1] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Your default boot sequence has been restored(\r)"; + $newstate[1] = 2; + + # state 2, all done + $done[2] = 1; + + $timeout = 30; + $state = 0; + + while ($done[$state] eq 0) { + send_command($verbose, $rconsole, $cmd[$state]); + $rconsole->expect( + [ qr/$pattern[$state]/ => + sub { + $rconsole->clear_accum(); + $state = $newstate[$state]; + } + ], + [ qr/THE SELECTED DEVICES WERE NOT DETECTED IN THE SYSTEM/ => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, " Status: THE hard disk WERE NOT DETECTED IN THE SYSTEM!\n"); + $rc = 1; + } + ], + [ timeout => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Timeout in settin boot order\n"); + $rc = 1; + } + ], + [ eof => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Cannot connect to $node\n"); + $rc = 1; + } + ], + ); + if ($rc == 1) { + return 1; + } else { + return 0; + } + } + return 0; + } + else { # state 0, get SMS screen $done[0] = 0; if ($expect_out[0] =~ /(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Select Boot Options(\r)/) { @@ -1751,7 +2082,7 @@ sub set_disk_boot { } } return 0; - + }; } @@ -1798,7 +2129,131 @@ sub boot_network { my $boot_device_bk; my $rc = 0; + if ($secOF == 1) + { + nc_msg($verbose, " Status: boot_network: Secured OF\n"); + + + $done[0] = 0; + if ($dump_target ne "") { + + + $net_device[0] = "$full_path_name:iscsi,ciaddr=$client_ip,subnet-mask=$netmask,itname=dummy,iport=$dump_port,ilun=$dump_lun,iname=$dump_target,siaddr=$server_ip,2"; + $pattern[0] = "iSCSI"; + } else { + + if ($extra_args ne "") { + + if ($server_ip =~ /:/) { #ipv6 + $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node,$extra_args"; + } else { + + $net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip $extra_args"; + } + } else { + if ($server_ip =~ /:/) { #ipv6 + $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node"; + } else { + $net_device[0] = "$full_path_name speed=$speed,duplex=$duplex,$server_ip,,$client_ip,$gateway_ip"; + } + } + $pattern[0] = "BOOTP"; + } + + $cmd[0] = "\rPING $full_path_name $server_ip,$client_ip,$gateway_ip,,$netmask \r"; + send_command($verbose, $rconsole, $cmd[0]); + + sleep 10; + + $cmd[0] = "\r\rBOOT_FROM_DEVICE #network $net_device[0]\r\r\n"; + $msg[0] = "Status: network boot initiated\n"; + $newstate[0] = 99; + + # state 99, all done + $done[99] = 1; + + # state -1, all done + $done[100] = 2; #-1??? + + if ($speed eq "" || $duplex eq "") { + nc_msg($verbose, "Cannot set speed or duplex for network boot\n"); + return 1; + } + + $timeout = 30; # shouldn't take long + while ($done[$state] eq 0) { + send_command($verbose, $rconsole, $cmd[$state]); + $rconsole->expect( + [ qr/$pattern[$state]/ => + sub { + $rconsole->clear_accum(); + my @expect_out = shift; + if ($state == 2) { + if ($set_boot_order == 1) { + ######################################## + # Set network as boot device + ######################################## + $cmd[3] = "setenv boot-device $net_device[$newstate[3]]\r"; + } elsif ($set_boot_order == 2) { + ######################################## + # Set network as 1st boot device,disk as 2nd boot device + ######################################## + $boot_device_bk = $expect_out[1]; + $cmd[3] = "setenv boot-device $net_device[$newstate[3]] $boot_device_bk\r"; + } elsif ($set_boot_order == 3) { + ######################################## + # Set disk as 1st boot device,network as 2nd boot device + ######################################## + $boot_device_bk = $expect_out[1]; + $cmd[3] = "setenv boot-device $boot_device_bk $net_device[$newstate[3]]\r"; + } elsif ($set_boot_order == 4) { + ######################################## + # set disk as boot device + ######################################## + $boot_device_bk = $expect_out[1]; + $cmd[3] = "setenv boot-device $boot_device_bk\r"; + } + } + nc_msg($verbose, $msg[$state]); + $state = $newstate[$state]; + } + ], + [ qr/----/ => + sub { + nc_msg($verbose, $msg[$state]); + $rconsole->clear_accum(); + $state = $newstate[$state]; + } + ], + [ qr/(.*)DEFAULT(.*)/ => + sub { + nc_msg($verbose, "Default catch error\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout when openning console\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to the $node\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); + } + return 0; + } + else + { nc_msg($verbose, "Status: boot_network start\n"); ################################################################### # Variables associated with each of the commands sent by this routine @@ -1835,6 +2290,7 @@ sub boot_network { if ($server_ip =~ /:/) { #ipv6 $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node"; } else { + ####$net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip"; $net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip"; } } @@ -1976,6 +2432,7 @@ sub boot_network { return 1 if ($rc == 1); } return 0; + }; } # # PROCEDURE @@ -2004,21 +2461,12 @@ sub Boot { $rc = 1; } ], - - #[!(qr/[0-9A-F]+/)=> - # sub { - # nc_msg($verbose, "The network boot ended in an error.\n"); - # #nc_msg($verbose, $expect_out[buffer]); - # $rc = 1; - # } - #], [ qr/BOOTP/ => #-ex sub { nc_msg($verbose, "# Network boot proceeding - matched BOOTP, exiting.\n"); $rconsole->clear_accum(); } ], - # Welcome to AIX - some old firmware does not output BOOTP or ---- [ qr/Welcome/ => #-ex sub { @@ -2026,7 +2474,6 @@ sub Boot { $rconsole->clear_accum(); } ], - # tftp file download - some old firmware does not output BOOTP or ---- [ qr/FILE/ => #-ex sub { @@ -2034,7 +2481,6 @@ sub Boot { $rconsole->clear_accum(); } ], - # some old firmware does not output BOOTP or ---- [ qr/Elapsed/ => #-ex sub { @@ -2097,6 +2543,14 @@ sub multiple_open_dev { my $timeout; my $rc = 0; + if ($secOF == 1) { + + nc_msg($verbose, " Status: multiple_open_dev: Secured OF\n"); + return $rc; + + } + else + { send_command($verbose, $rconsole, "dev /packages/net \r"); send_command($verbose, $rconsole, "FALSE value OPEN-DEV_DEBUG \r"); @@ -2213,8 +2667,8 @@ sub multiple_open_dev { } ], ); - return $rc; + }; } ################################################################### # @@ -2419,7 +2873,7 @@ sub lparnetbootexp my $discover_all = 0; my $discoverynoping = 0; my $discoverytimeout = 0; - my $verbose = 0; + my $verbose = 1; my $discover_macaddr = 0; my $rc = 0; my $debug_flag = 0; @@ -2583,7 +3037,7 @@ sub lparnetbootexp if (exists($opt->{v})) { $verbose = 1; } else { - $verbose = 0; + $verbose = 1; } if (exists($opt->{x})) { $debug_flag = 1; @@ -2621,7 +3075,6 @@ sub lparnetbootexp my $hcp = $opt->{hcp}; - if ($dev_type_found) { nc_msg($verbose, "$PROGRAM Status: List only $list_type adapters\n"); } if ($noboot) { nc_msg($verbose, "$PROGRAM Status: -n (no boot) flag detected\n"); } if ($discovery) { nc_msg($verbose, "$PROGRAM Status: -D (discovery) flag detected\n"); } @@ -2660,7 +3113,6 @@ sub lparnetbootexp # decide if need to do the connect #################################### - #################################### # open the console #################################### @@ -2716,8 +3168,45 @@ sub lparnetbootexp $rconsole->send("\005c?"); # for some reason the ctrl-e is not being sent for confluent, just getting c? - $timeout = 10; + + if ($secOF == 1) { + nc_msg($verbose, " Status: lparnetboot - console check: Secured OF\n"); + + $rconsole->expect( + $timeout, + [ qr/c?/i => + sub { + $rc = 0; + $rconsole->clear_accum(); + nc_msg($verbose, "Confluent -> Connected.\n"); + } + ], + [ qr/macro_help.*/i => + sub { + $rc = 0; + $rconsole->clear_accum(); + nc_msg($verbose, "Conserver -> Connected.\n"); + } + ], + [ timeout => + sub { + $rc = 1; + $rconsole->clear_accum(); + nc_msg($verbose, "Timeout waiting for console connection.\n"); + } + ], + [ eof => + sub { + $rc = 2; + $rconsole->clear_accum(); + nc_msg(1, "Please make sure rcons $node works.\n"); + } + ], + ); + } + else + { $rconsole->expect( $timeout, [ qr/c?/i => @@ -2749,6 +3238,7 @@ sub lparnetbootexp } ], ); + }; unless ($rc eq 0) { return [1]; @@ -2821,7 +3311,6 @@ sub lparnetbootexp } - ################################################# # if set_boot_order is set, set the boot order # if not set, power the node to open firmware @@ -2934,14 +3423,14 @@ sub lparnetbootexp nc_msg($verbose, "Check for active console.\n"); $done = 0; $retry_count = 0; - $timeout = 10; + if ($secOF == 1) { + nc_msg($verbose, " Status: lparnetboot - check for active console: Secured OF\n"); + while (!$done) { my @result = $rconsole->expect( $timeout, - - #[qr/ok(.*)0 >/=> [ qr/0(.*)ok/ => sub { nc_msg($verbose, " at ok prompt\n"); @@ -3005,9 +3494,76 @@ sub lparnetbootexp ); return [1] if ($rc == 1); } - - - + } + else + { + while (!$done) { + my @result = $rconsole->expect( + $timeout, + [ qr/0(.*)ok/ => + sub { + nc_msg($verbose, " at ok prompt\n"); + $rconsole->clear_accum(); + $done = 1; + } + ], + [ qr/(.*)elect this consol(.*)/ => + sub { + nc_msg($verbose, " selecting active console\n"); + $rconsole->clear_accum(); + $rconsole->send("0\r"); + } + ], + [ qr/English|French|German|Italian|Spanish|Portuguese|Chinese|Japanese|Korean/ => + sub { + nc_msg($verbose, "Languagae Selection Panel received\n"); + $rconsole->clear_accum(); + $rconsole->send("2\r"); + } + ], + [ qr/admin/ => + sub { + nc_msg($verbose, "No password specified\n"); + $rconsole->soft_close(); + $rc = 1; + } + ], + [ qr/Invalid Password/ => + sub { + nc_msg($verbose, "FSP password is invalid.\n"); + $rconsole->soft_close(); + $rc = 1; + } + ], + [ qr/SMS(.*)Navigation Keys/ => + sub { + nc_msg($verbose, "SMS\n"); + $rconsole->clear_accum(); + $done = 1; + } + ], + [ timeout => + sub { + $rconsole->send("\r"); + $retry_count++; + if ($retry_count == 9) { + nc_msg($verbose, "Timeout waiting for ok prompt; exiting.\n"); + $rconsole->soft_close(); + $rc = 1; + } + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->soft_close(); + $rc = 1; + } + ], + ); + return [1] if ($rc == 1); + } + }; ############################## # Set the node boot order @@ -3036,7 +3592,7 @@ sub lparnetbootexp if ($result == 1) { $retry_count++; $rconsole->send("\r"); - if ($retry_count == 3) { + if ($retry_count == 4) { nc_msg($verbose, "Unable to obtain network adapter information. Quitting.\n"); return [1]; } @@ -3068,12 +3624,12 @@ sub lparnetbootexp nc_msg($verbose, "# Gateway IP address is $gateway_ip\n"); } - ############################## # Display information for all # supported adapters ############################## if ($noboot) { #if not do net boot + if ($list_type) { $match_pat = $list_type; } else { @@ -3082,10 +3638,12 @@ sub lparnetbootexp if ($colon) { + nc_msg($verbose, "#Type:Location_Code:MAC_Address:Full_Path_Name:Ping_Result:Device_Type:Size_MB:OS:OS_Version:\n"); $outputarrayindex++; # start from 1, 0 is used to set as 0 $outputarray[$outputarrayindex] = "#Type:Location_Code:MAC_Address:Full_Path_Name:Ping_Result:Device_Type:Size_MB:OS:OS_Version:"; } else { + if ($discoverynoping) { nc_msg($verbose, "# Type \tLocation Code \tMAC Address\t Full Path Name\t Device Type\n"); $outputarrayindex++; @@ -3093,19 +3651,22 @@ sub lparnetbootexp } else { nc_msg($verbose, "# Type \tLocation Code \tMAC Address\t Full Path Name\t Ping Result\t Device Type\n"); $outputarrayindex++; - $outputarray[$outputarrayindex] = "# Type \tLocation Code \tMAC Address\t Full Path Name\t Ping Result\t Device Type"; + $outputarray[$outputarrayindex] = "# Type \tLocation Code \tMAC Address\t Full Path Name\t Ping Result\t Device Type\n"; } } if ($discover_all) { #getmacs here + for ($i = 0 ; $i < $adapter_found ; $i++) { if ($adap_type[$i] =~ /$match_pat/) { if (!($adap_type[$i] eq "hfi-ent")) { + $mac_address = get_mac_addr($phandle_array[$i], $rconsole, $node, $verbose); $loc_code = get_adaptr_loc($phandle_array[$i], $rconsole, $node, $verbose); } $ping_result = ""; if ($discovery && !$discoverynoping) { + $ping_rc = ping_server($phandle_array[$i], $full_path_name_array[$i], $rconsole, $node, $mac_address, $verbose, $adap_speed, $adap_duplex, $list_type, $server_ip, $client_ip, $gateway_ip); nc_msg($verbose, "ping_server returns $ping_rc\n"); unless ($ping_rc eq 0) { @@ -3121,12 +3682,15 @@ sub lparnetbootexp } if ($full_path_name_array[$i] =~ /vdevice/) { + $device_type = "virtual"; } else { + $device_type = "physical"; } if (defined($mac_address)) { + my @newmacs = (); my @allmacs = split /\|/, $mac_address; if (!xCAT::Utils->isAIX()) { @@ -3153,14 +3717,18 @@ sub lparnetbootexp } } } else { + for ($i = 0 ; $i < $adapter_found ; $i++) { if ($adap_type[$i] =~ /$match_pat/) { + if (!($adap_type[$i] eq "hfi-ent")) { + $mac_address = get_mac_addr($phandle_array[$i], $rconsole, $node, $verbose); $loc_code = get_adaptr_loc($phandle_array[$i], $rconsole, $node, $verbose); } $ping_result = ""; if ($discovery && !$discoverynoping) { + $ping_rc = ping_server($phandle_array[$i], $full_path_name_array[$i], $rconsole, $node, $mac_address, $verbose, $adap_speed, $adap_duplex, $list_type, $server_ip, $client_ip, $gateway_ip); nc_msg($verbose, "ping_server returns $ping_rc\n"); unless ($ping_rc eq 0) { @@ -3176,8 +3744,10 @@ sub lparnetbootexp } if ($full_path_name_array[$i] =~ /vdevice/) { + $device_type = "virtual"; } else { + $device_type = "physical"; } @@ -3208,9 +3778,12 @@ sub lparnetbootexp } } } else { # Do a network boot - # Loop throught the adapters and perform a ping test to discover an - # adapter that pings successfully, then use that adapter to network boot. + + # Loop throught the adapters and perform a ping test to discover an + # adapter that pings successfully, then use that adapter to network boot. + if ($discover_all) { #rnetboot should not use -A + for ($i = 0 ; $i < $adapter_found ; $i++) { $ping_rc = ping_server($phandle_array[$i], $full_path_name_array[$i], $rconsole, $node, $mac_address, $verbose, $adap_speed, $adap_duplex, $list_type, $server_ip, $client_ip, $gateway_ip); @@ -3223,14 +3796,18 @@ sub lparnetbootexp } } } elsif ($macaddress ne "") { #rnetboot here + $match = 0; for ($i = 0 ; $i < $adapter_found ; $i++) { if ($adap_type[$i] =~ /hfi-ent/) { $ping_rc = ping_server($phandle_array[$i], $full_path_name_array[$i], $rconsole, $node, $mac_address, $verbose, $adap_speed, $adap_duplex, $list_type, $server_ip, $client_ip, $gateway_ip); } + $mac_address = get_mac_addr($phandle_array[$i], $rconsole, $node, $verbose); if ($macaddress =~ /$mac_address/) { + if (($discovery == 1) && !$discoverynoping) { + unless ($adap_type[$i] eq "hfi-ent") { $ping_rc = ping_server($phandle_array[$i], $full_path_name_array[$i], $rconsole, $node, $mac_address, $verbose, $adap_speed, $adap_duplex, $list_type, $server_ip, $client_ip, $gateway_ip); } @@ -3243,6 +3820,7 @@ sub lparnetbootexp $full_path_name = $full_path_name_array[$i]; $chosen_adap_type = $adap_type[$i]; $match = 1; + last; } } @@ -3250,11 +3828,15 @@ sub lparnetbootexp nc_msg($verbose, "Can not find mac address '$macaddress'\n"); return [1]; } + } elsif ($phys_loc ne "") { + + $match = 0; for ($i = 0 ; $i < $adapter_found ; $i++) { $loc_code = get_adaptr_loc($phandle_array[$i], $rconsole, $node, $verbose); if ($loc_code =~ /$phys_loc/) { + if ($discovery && !$discoverynoping) { $ping_rc = ping_server($phandle_array[$i], $full_path_name_array[$i], $rconsole, $node, $mac_address, $verbose, $adap_speed, $adap_duplex, $list_type, $server_ip, $client_ip, $gateway_ip); unless ($ping_rc eq 0) { @@ -3278,10 +3860,13 @@ sub lparnetbootexp # Use the first ethernet adapter in the # device tree. # + for ($i = 0 ; $i < $adapter_found ; $i++) { nc_msg($verbose, " begint to boot from first adapter in the device tree \n"); if ($adap_type[$i] eq $list_type) { + if (($discovery == 1) && !$discoverynoping) { + $ping_rc = ping_server($phandle_array[$i], $full_path_name_array[$i], $rconsole, $node, $mac_address, $verbose, $adap_speed, $adap_duplex, $list_type, $server_ip, $client_ip, $gateway_ip); unless ($ping_rc eq 0) { return [1]; @@ -3294,11 +3879,16 @@ sub lparnetbootexp } } } + + my $result; + + if ($full_path_name eq "") { nc_msg($verbose, "Unable to boot network adapter.\n"); return [1]; } else { + nc_msg($verbose, "# Network booting install adapter.\n"); $result = xCAT::LparNetbootExp->boot_network($rconsole, $full_path_name, $adap_speed, $adap_duplex, $chosen_adap_type, $server_ip, $client_ip, $gateway_ip, $netmask, $dump_target, $dump_lun, $dump_port, $verbose, $extra_args, $node, $set_boot_order); } @@ -3414,4 +4004,3 @@ sub lparnetbootexp return \@outputarray; } - From 3b4434c8c652757ccd9dabfdda1dfa106c4409f2 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Wed, 12 Aug 2020 16:09:44 -0400 Subject: [PATCH 2/2] perltidy for better readability --- perl-xCAT/xCAT/LparNetbootExp.pm | 3680 +++++++++++++++--------------- 1 file changed, 1843 insertions(+), 1837 deletions(-) diff --git a/perl-xCAT/xCAT/LparNetbootExp.pm b/perl-xCAT/xCAT/LparNetbootExp.pm index 62dd9d2ce..76c861322 100755 --- a/perl-xCAT/xCAT/LparNetbootExp.pm +++ b/perl-xCAT/xCAT/LparNetbootExp.pm @@ -64,7 +64,7 @@ my $client_ip; my $gateway_ip; my $device_type; my $server_ip; -my $secOF=1; +my $secOF = 1; # List supported network adapters here. dev_pat is an array of regexp patterns # the script searches for in the device tree listing. dev_type is the type @@ -431,76 +431,28 @@ sub get_phandle { my $rc; if ($secOF == 1) { - nc_msg($verbose, "Status: get_phandle: Using Secured OF..............\n"); + nc_msg($verbose, "Status: get_phandle: Using Secured OF..............\n"); - send_command($verbose, $rconsole, "\r"); + send_command($verbose, $rconsole, "\r"); - @result = $rconsole->expect( - $timeout, - [ qr/ok/ => - sub { - nc_msg($verbose, "Status: at root\n"); - $rconsole->clear_accum(); - } - ], - [ qr/]/ => - sub { - nc_msg($verbose, "Unexpected prompt\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - $rconsole->send("\r"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to $node"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - return 1 if ($rc == 1); - - send_command($verbose, $rconsole, "DISPLAY_BOOT_DEVICES #network\r"); - - $timeout = 60; - $done = 0; - while (!$done) { - - @result = (); @result = $rconsole->expect( $timeout, - [ qr/.*1GbE.*/ => + [ qr/ok/ => sub { - nc_msg($verbose, "Parsing network adapters... \n"); - } - ], - [ qr/.*25\/10 Gb.*/ => - sub { - nc_msg($verbose, "Parsing network adapters 25G \n"); - } - ], - [ qr/.*Interpartition Logical LAN.*/ => - sub { - nc_msg($verbose, "Parsing network adapters... \n"); - } - ], - [ qr/>/ => - sub { - nc_msg($verbose, "finished \n"); + nc_msg($verbose, "Status: at root\n"); $rconsole->clear_accum(); - $done = 1; + } + ], + [ qr/]/ => + sub { + nc_msg($verbose, "Unexpected prompt\n"); + $rconsole->clear_accum(); + $rc = 1; } ], [ timeout => sub { - nc_msg($verbose, "Timeout isolating single line of ls output\n"); + $rconsole->send("\r"); $rconsole->clear_accum(); $rc = 1; } @@ -515,221 +467,269 @@ sub get_phandle { ); return 1 if ($rc == 1); - if ($result[2] =~ /1GbE/) { - my $j = 0; - for ($j = 0 ; $j < $dev_count ; $j++) { - my @values1 = split('=', $result[2]); - my @values2 = split('\)', $values1[1]); - $full_path_name_array[$adapter_found] = $values2[0]; - $phandle_array[$adapter_found] = $values2[0]; - $adap_type[$adapter_found] = $dev_type[$j]; - $adapter_found++; - last; - }; - }; + send_command($verbose, $rconsole, "DISPLAY_BOOT_DEVICES #network\r"); - if ($result[2] =~ /25\/10 Gb/) { - my $j = 0; - for ($j = 0 ; $j < $dev_count ; $j++) { - my @values1 = split('=', $result[2]); - my @values2 = split('\)', $values1[1]); - $full_path_name_array[$adapter_found] = $values2[0]; - $phandle_array[$adapter_found] = $values2[0]; - $adap_type[$adapter_found] = $dev_type[$j]; - $adapter_found++; - last; - }; - }; + $timeout = 60; + $done = 0; + while (!$done) { - if ($result[2] =~ /Interpartition Logical LAN/) { - my $j = 0; - for ($j = 0 ; $j < $dev_count ; $j++) { - my @values1 = split('=', $result[2]); - my @values2 = split('\)', $values1[1]); - $full_path_name_array[$adapter_found] = $values2[0]; - $phandle_array[$adapter_found] = $values2[0]; - $adap_type[$adapter_found] = $dev_type[$j]; - $adapter_found++; - last; - }; - }; - }; + @result = (); + @result = $rconsole->expect( + $timeout, + [ qr/.*1GbE.*/ => + sub { + nc_msg($verbose, "Parsing network adapters... \n"); + } + ], + [ qr/.*25\/10 Gb.*/ => + sub { + nc_msg($verbose, "Parsing network adapters 25G \n"); + } + ], + [ qr/.*Interpartition Logical LAN.*/ => + sub { + nc_msg($verbose, "Parsing network adapters... \n"); + } + ], + [ qr/>/ => + sub { + nc_msg($verbose, "finished \n"); + $rconsole->clear_accum(); + $done = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout isolating single line of ls output\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); - # Did we find one or more adapters? - if ($adapter_found > 0) { - return 0; - } else { - nc_msg($verbose, "No network adapters found\n"); - return 1; - }; + if ($result[2] =~ /1GbE/) { + my $j = 0; + for ($j = 0 ; $j < $dev_count ; $j++) { + my @values1 = split('=', $result[2]); + my @values2 = split('\)', $values1[1]); + $full_path_name_array[$adapter_found] = $values2[0]; + $phandle_array[$adapter_found] = $values2[0]; + $adap_type[$adapter_found] = $dev_type[$j]; + $adapter_found++; + last; + } + } - } - else - { + if ($result[2] =~ /25\/10 Gb/) { + my $j = 0; + for ($j = 0 ; $j < $dev_count ; $j++) { + my @values1 = split('=', $result[2]); + my @values2 = split('\)', $values1[1]); + $full_path_name_array[$adapter_found] = $values2[0]; + $phandle_array[$adapter_found] = $values2[0]; + $adap_type[$adapter_found] = $dev_type[$j]; + $adapter_found++; + last; + } + } - # This is the first procedure entered after getting to the ok prompt. On entry - # the current device is not root. The command 'dev /' is sent to get to the - # root of the device tree. There is no output from the dev command. The expected - # output is the ok prompt ('>'). - # - # The pwd command can be used to determine what the current device is. - # - - - send_command($verbose, $rconsole, "dev /\r"); - - @result = $rconsole->expect( - $timeout, - [ qr/ok/ => - sub { - nc_msg($verbose, "Status: at root\n"); - $rconsole->clear_accum(); - } - ], - [ qr/]/ => - sub { - nc_msg($verbose, "Unexpected prompt\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - $rconsole->send("\r"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to $node"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - return 1 if ($rc == 1); - - # Next, the 'ls' command is sent. The result is a display of the entire - # device tree. The code then looks at the - # output from the ls command one line at a time, trying to match it with the - # regexp pattern in dev_pat, an array that contains all the supported network - # adapters. When found, the adapter type, the phandle and path name are saved - # in array variables. - # - # The complicated part is that the full path name may be spread over more than - # one line. Each line contains information about a node. If the supported - # network adapter is found on an nth level node, the full path name is the - # concatenation of the node information from the 0th level to the nth level. - # Hence, the path name from each level of the device tree needs to be saved. - # - # The pattern "\n(\[^\r]*)\r" is worth a second look. It took - # many hours of debug and reading the expect book to get it right. When more - # than one line of data is returned to expect at once, it is tricky getting - # exactly one line of data to look at. This pattern works because it looks - # for a newline(\n), any character other than a carriage return(\[^\r]*), and - # then for a carriage return. This causes expect to match a single line. - # If (.*) is used instead of (\[^\r]*), multiple lines are matched. (that was - # attempt number 1) - # - # Once a single line is found, it tries to determine what level in the device - # tree this line is. - # searching through subsequent lines and subsequent levels until an - # adapter is found. - # The level of the current line, which - # is calculated based on the assumption of "Level = (Leading Spaces - 1)/2". - # Leading Spaces is the number of spaces between the first colon ':' and the - # first non-space character of each line. - # - # Using the -d flag helped a lot in finding the correct pattern. - # - - send_command($verbose, $rconsole, "ls \r"); - - $timeout = 60; - $done = 0; - while (!$done) { - - # this expect call isolates single lines - # This code uses the tcl regexp to parse the single line - # isolated by expect. - # - # When the ok prompt ('>') is matched, this indicates the end of - # the ls output, at which point the done variable is set, to break - # out of the loop. - # - # All other lines are ignored. - # - @result = (); - @result = $rconsole->expect( - $timeout, - [ qr/(\n)([^\r]*)(\r)/ => - sub { - nc_msg($verbose, "Parsing network adapters... \n"); - - #$rconsole->clear_accum(); - } - ], - [ qr/>/ => - sub { - nc_msg($verbose, "finished \n"); - $rconsole->clear_accum(); - $done = 1; - } - ], - [ timeout => - sub { - nc_msg($verbose, "Timeout isolating single line of ls output\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to $node"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - return 1 if ($rc == 1); - if ($result[2] =~ /(\w*)\:(\s*)\/(\S*)/) { - - my $x1 = $1; - my $x2 = $2; #number of space - my $x3 = $3; #device - # Each level is inspected for a match - my $level = (length($x2) - 1) / 2; - $path{$level} = $x3; - my $j = 0; - - for ($j = 0 ; $j < $dev_count ; $j++) { - if ($x3 =~ /$dev_pat[$j]/) { - if ($x3 =~ /hfi-ethernet/ and $dev_pat[$j] eq "ethernet") { - next; - } - my $i = 0; - for ($i = 0 ; $i <= $level ; $i++) - { - $full_path_name_array[$adapter_found] .= "/" . $path{$i}; - } - $phandle_array[$adapter_found] = $x1; - $adap_type[$adapter_found] = $dev_type[$j]; + if ($result[2] =~ /Interpartition Logical LAN/) { + my $j = 0; + for ($j = 0 ; $j < $dev_count ; $j++) { + my @values1 = split('=', $result[2]); + my @values2 = split('\)', $values1[1]); + $full_path_name_array[$adapter_found] = $values2[0]; + $phandle_array[$adapter_found] = $values2[0]; + $adap_type[$adapter_found] = $dev_type[$j]; $adapter_found++; last; } } } - } - # Did we find one or more adapters? - if ($adapter_found > 0) { - return 0; - } else { - nc_msg($verbose, "No network adapters found\n"); - return 1; - }; - }; + # Did we find one or more adapters? + if ($adapter_found > 0) { + return 0; + } else { + nc_msg($verbose, "No network adapters found\n"); + return 1; + } + + } + else + { + + # This is the first procedure entered after getting to the ok prompt. On entry + # the current device is not root. The command 'dev /' is sent to get to the + # root of the device tree. There is no output from the dev command. The expected + # output is the ok prompt ('>'). + # + # The pwd command can be used to determine what the current device is. + # + + + send_command($verbose, $rconsole, "dev /\r"); + + @result = $rconsole->expect( + $timeout, + [ qr/ok/ => + sub { + nc_msg($verbose, "Status: at root\n"); + $rconsole->clear_accum(); + } + ], + [ qr/]/ => + sub { + nc_msg($verbose, "Unexpected prompt\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + $rconsole->send("\r"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); + + # Next, the 'ls' command is sent. The result is a display of the entire + # device tree. The code then looks at the + # output from the ls command one line at a time, trying to match it with the + # regexp pattern in dev_pat, an array that contains all the supported network + # adapters. When found, the adapter type, the phandle and path name are saved + # in array variables. + # + # The complicated part is that the full path name may be spread over more than + # one line. Each line contains information about a node. If the supported + # network adapter is found on an nth level node, the full path name is the + # concatenation of the node information from the 0th level to the nth level. + # Hence, the path name from each level of the device tree needs to be saved. + # + # The pattern "\n(\[^\r]*)\r" is worth a second look. It took + # many hours of debug and reading the expect book to get it right. When more + # than one line of data is returned to expect at once, it is tricky getting + # exactly one line of data to look at. This pattern works because it looks + # for a newline(\n), any character other than a carriage return(\[^\r]*), and + # then for a carriage return. This causes expect to match a single line. + # If (.*) is used instead of (\[^\r]*), multiple lines are matched. (that was + # attempt number 1) + # + # Once a single line is found, it tries to determine what level in the device + # tree this line is. + # searching through subsequent lines and subsequent levels until an + # adapter is found. + # The level of the current line, which + # is calculated based on the assumption of "Level = (Leading Spaces - 1)/2". + # Leading Spaces is the number of spaces between the first colon ':' and the + # first non-space character of each line. + # + # Using the -d flag helped a lot in finding the correct pattern. + # + + send_command($verbose, $rconsole, "ls \r"); + + $timeout = 60; + $done = 0; + while (!$done) { + + # this expect call isolates single lines + # This code uses the tcl regexp to parse the single line + # isolated by expect. + # + # When the ok prompt ('>') is matched, this indicates the end of + # the ls output, at which point the done variable is set, to break + # out of the loop. + # + # All other lines are ignored. + # + @result = (); + @result = $rconsole->expect( + $timeout, + [ qr/(\n)([^\r]*)(\r)/ => + sub { + nc_msg($verbose, "Parsing network adapters... \n"); + + #$rconsole->clear_accum(); + } + ], + [ qr/>/ => + sub { + nc_msg($verbose, "finished \n"); + $rconsole->clear_accum(); + $done = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout isolating single line of ls output\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); + if ($result[2] =~ /(\w*)\:(\s*)\/(\S*)/) { + + my $x1 = $1; + my $x2 = $2; #number of space + my $x3 = $3; #device + # Each level is inspected for a match + my $level = (length($x2) - 1) / 2; + $path{$level} = $x3; + my $j = 0; + + for ($j = 0 ; $j < $dev_count ; $j++) { + if ($x3 =~ /$dev_pat[$j]/) { + if ($x3 =~ /hfi-ethernet/ and $dev_pat[$j] eq "ethernet") { + next; + } + my $i = 0; + for ($i = 0 ; $i <= $level ; $i++) + { + $full_path_name_array[$adapter_found] .= "/" . $path{$i}; + } + $phandle_array[$adapter_found] = $x1; + $adap_type[$adapter_found] = $dev_type[$j]; + $adapter_found++; + last; + } + } + } + } + + # Did we find one or more adapters? + if ($adapter_found > 0) { + return 0; + } else { + nc_msg($verbose, "No network adapters found\n"); + return 1; + } + } } #------------------------------------------------------------------------------- @@ -773,190 +773,190 @@ sub get_adap_prop { nc_msg($verbose, " Status: get_adap_prop start\n"); if ($secOF == 1) { - nc_msg($verbose, " Status: get_adap_prop: Secured OF\n"); + nc_msg($verbose, " Status: get_adap_prop: Secured OF\n"); - $nw_type="ethernet"; - $nw_speed="100"; - $nw_conn="rj45"; - $nw_duplex="duplex"; + $nw_type = "ethernet"; + $nw_speed = "100"; + $nw_conn = "rj45"; + $nw_duplex = "duplex"; - push @adap_prop_array, $nw_speed . "," . $nw_conn . "," . $nw_duplex; - nc_msg($verbose, "Status: Adding adapter properties to list\n"); - - if (scalar(@adap_prop_array) != 0) { - return \@adap_prop_array; - } else { - return 0; - }; - } - else { - - # state 0, stack count 0 - $done[0] = 0; - $cmd[0] = "\" supported-network-types\" " . $phandle . " get-package-property\r"; - $msg[0] = "Status: rc and all supported network types now on stack\n"; - - #$pattern[0] = "(.*)3 >(.*)"; - #$pattern[0] = "3 >"; - $pattern[0] = "ok"; - $newstate[0] = 1; - - # state 1, return code and string on stack - $done[1] = 0; - $cmd[1] = ".\r"; - $msg[1] = "Status: All supported network types now on stack\n"; - - #$pattern[1] = "(.*)2 >(.*)"; - #$pattern[1] = "2 >"; - $pattern[1] = "ok"; - $newstate[1] = 2; - - # state 2, data ready to decode - $done[2] = 0; - $cmd[2] = "decode-string\r"; - $msg[2] = "Status: supported network type isolated on stack\n"; - - #$pattern[2] = "(.*)ok(.*)4 >(.*)"; - $pattern[2] = "4 >"; - $newstate[2] = 3; - - # state 3, decoded string on stack - $done[3] = 0; - $cmd[3] = "dump\r"; - $msg[3] = "Status: supported network type off stack\n"; - - #$pattern[3] = ".*:.*:(.*):.*:.*:(.*):.*(2 >)(.*)"; - $pattern[3] = "ok"; - $newstate[3] = 4; - - # state 4, need to check for more data to decode - $done[4] = 0; - $cmd[4] = ".s\r"; - $msg[4] = "Status: checking for more supported network types\n"; - - #$pattern[4] = ".s (\[0-9a-f]* )(.*)>"; - $pattern[4] = "ok"; - $newstate[4] = 5; - - # state 5, done decoding string, clear stack - $done[5] = 0; - $cmd[5] = ".\r"; - $msg[5] = "Status: one entry on stack cleared\n"; - - #$pattern[5] = "(.*)ok(.*)1 >(.*)"; - $pattern[5] = "ok"; - $newstate[5] = 6; - - # state 6, finish clearing stack, choose correct adapter type - $done[6] = 0; - $cmd[6] = ".\r"; - $msg[6] = "Status: finished clearing stack\n"; - - #$pattern[6] = "(.*)ok(.*)0 >(.*)"; - $pattern[6] = "ok"; - $newstate[6] = 7; - - # state 7, done - $done[7] = 1; - - while ($done[$state] == 0) { - nc_msg($verbose, "Status: command is $cmd[$state]\n"); - send_command($verbose, $rconsole, $cmd[$state]); - @result = (); - @result = $rconsole->expect( - $timeout, - [ qr/$pattern[$state]/i, - sub { - if ($state == 1) { - if ($rconsole->before() =~ /-\d+/) { - nc_msg($verbose, "Status: Error getting adapter property for phandle=$phandle.\n"); - $state = 7; - $rconsole->clear_accum(); - $rc = 1; - return 1; - } - } - - nc_msg($verbose, $msg[$state]); - $state = $newstate[$state]; - $rconsole->clear_accum(); - } - ], - [ qr/]/, - sub { - nc_msg($verbose, "Unexpected prompt\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ qr/(.*)DEFAULT(.*)/, - sub { - nc_msg($verbose, " Default catch error\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - nc_msg($verbose, "Timeout in getting adapter properpties\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to $node\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ] - ); - return 1 if ($rc == 1); - - # After state 3, the network type is parsed and the connector - # type extracted. If the type hasn't been found, add it to - # the list of supported connector types. - if ($state == 4) { - - # Build the adapter properties from the string - #regexp .*,(.*),(.*),(.*) $nw_type dummy nw_speed nw_conn nw_duplex - #set adap_prop "$nw_speed,$nw_conn,$nw_duplex" - #nc_msg "Status: Adapter properties are $adap_prop\n" - - # if it's not in the list, add it, otherwise continue - if ($result[3] =~ /(\w*):(.*):(\w*)\,(\w*)\,(\w*):/) { - $nw_type = $3; - $nw_speed = $4; - $nw_conn = $5; - nc_msg($verbose, "nwtype is $3, nwspeed is $4, nwconn is $5\n"); - } - if ($result[3] =~ /(\w*):(.*):(\w*)\,(\w*):/) { - $nw_duplex = $4; - nc_msg($verbose, "nwduplex is $4\n"); - } - } - - #push @adap_prop_array, $nw_type.",".$nw_speed.",".$nw_conn.",".$nw_duplex; push @adap_prop_array, $nw_speed . "," . $nw_conn . "," . $nw_duplex; nc_msg($verbose, "Status: Adding adapter properties to list\n"); - # After state 4, a test is done to see if all of the supported - # network types have been decoded. If they have been, the - # state variable is left alone. if not, the state variable is - # set to 2, causing a loop back to the step where the - # decode-string command is sent. - if ($state == 5) { - if ($result[3] =~ /2 > \.s \w+ (\w*)/) { - $state = 2 if ($1 != 0); - } + if (scalar(@adap_prop_array) != 0) { + return \@adap_prop_array; + } else { + return 0; + } + } + else { + + # state 0, stack count 0 + $done[0] = 0; + $cmd[0] = "\" supported-network-types\" " . $phandle . " get-package-property\r"; + $msg[0] = "Status: rc and all supported network types now on stack\n"; + + #$pattern[0] = "(.*)3 >(.*)"; + #$pattern[0] = "3 >"; + $pattern[0] = "ok"; + $newstate[0] = 1; + + # state 1, return code and string on stack + $done[1] = 0; + $cmd[1] = ".\r"; + $msg[1] = "Status: All supported network types now on stack\n"; + + #$pattern[1] = "(.*)2 >(.*)"; + #$pattern[1] = "2 >"; + $pattern[1] = "ok"; + $newstate[1] = 2; + + # state 2, data ready to decode + $done[2] = 0; + $cmd[2] = "decode-string\r"; + $msg[2] = "Status: supported network type isolated on stack\n"; + + #$pattern[2] = "(.*)ok(.*)4 >(.*)"; + $pattern[2] = "4 >"; + $newstate[2] = 3; + + # state 3, decoded string on stack + $done[3] = 0; + $cmd[3] = "dump\r"; + $msg[3] = "Status: supported network type off stack\n"; + + #$pattern[3] = ".*:.*:(.*):.*:.*:(.*):.*(2 >)(.*)"; + $pattern[3] = "ok"; + $newstate[3] = 4; + + # state 4, need to check for more data to decode + $done[4] = 0; + $cmd[4] = ".s\r"; + $msg[4] = "Status: checking for more supported network types\n"; + + #$pattern[4] = ".s (\[0-9a-f]* )(.*)>"; + $pattern[4] = "ok"; + $newstate[4] = 5; + + # state 5, done decoding string, clear stack + $done[5] = 0; + $cmd[5] = ".\r"; + $msg[5] = "Status: one entry on stack cleared\n"; + + #$pattern[5] = "(.*)ok(.*)1 >(.*)"; + $pattern[5] = "ok"; + $newstate[5] = 6; + + # state 6, finish clearing stack, choose correct adapter type + $done[6] = 0; + $cmd[6] = ".\r"; + $msg[6] = "Status: finished clearing stack\n"; + + #$pattern[6] = "(.*)ok(.*)0 >(.*)"; + $pattern[6] = "ok"; + $newstate[6] = 7; + + # state 7, done + $done[7] = 1; + + while ($done[$state] == 0) { + nc_msg($verbose, "Status: command is $cmd[$state]\n"); + send_command($verbose, $rconsole, $cmd[$state]); + @result = (); + @result = $rconsole->expect( + $timeout, + [ qr/$pattern[$state]/i, + sub { + if ($state == 1) { + if ($rconsole->before() =~ /-\d+/) { + nc_msg($verbose, "Status: Error getting adapter property for phandle=$phandle.\n"); + $state = 7; + $rconsole->clear_accum(); + $rc = 1; + return 1; + } + } + + nc_msg($verbose, $msg[$state]); + $state = $newstate[$state]; + $rconsole->clear_accum(); + } + ], + [ qr/]/, + sub { + nc_msg($verbose, "Unexpected prompt\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ qr/(.*)DEFAULT(.*)/, + sub { + nc_msg($verbose, " Default catch error\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout in getting adapter properpties\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ] + ); + return 1 if ($rc == 1); + + # After state 3, the network type is parsed and the connector + # type extracted. If the type hasn't been found, add it to + # the list of supported connector types. + if ($state == 4) { + + # Build the adapter properties from the string + #regexp .*,(.*),(.*),(.*) $nw_type dummy nw_speed nw_conn nw_duplex + #set adap_prop "$nw_speed,$nw_conn,$nw_duplex" + #nc_msg "Status: Adapter properties are $adap_prop\n" + + # if it's not in the list, add it, otherwise continue + if ($result[3] =~ /(\w*):(.*):(\w*)\,(\w*)\,(\w*):/) { + $nw_type = $3; + $nw_speed = $4; + $nw_conn = $5; + nc_msg($verbose, "nwtype is $3, nwspeed is $4, nwconn is $5\n"); + } + if ($result[3] =~ /(\w*):(.*):(\w*)\,(\w*):/) { + $nw_duplex = $4; + nc_msg($verbose, "nwduplex is $4\n"); + } + } + + #push @adap_prop_array, $nw_type.",".$nw_speed.",".$nw_conn.",".$nw_duplex; + push @adap_prop_array, $nw_speed . "," . $nw_conn . "," . $nw_duplex; + nc_msg($verbose, "Status: Adding adapter properties to list\n"); + + # After state 4, a test is done to see if all of the supported + # network types have been decoded. If they have been, the + # state variable is left alone. if not, the state variable is + # set to 2, causing a loop back to the step where the + # decode-string command is sent. + if ($state == 5) { + if ($result[3] =~ /2 > \.s \w+ (\w*)/) { + $state = 2 if ($1 != 0); + } + } + } + if (scalar(@adap_prop_array) != 0) { + return \@adap_prop_array; + } else { + return 0; } } - if (scalar(@adap_prop_array) != 0) { - return \@adap_prop_array; - } else { - return 0; - }; - }; } #------------------------------------------------------------------------------- @@ -1004,106 +1004,108 @@ sub get_mac_addr { if ($secOF == 1) { - nc_msg($verbose, " Status: get_mac_addr: Secured OF\n"); + nc_msg($verbose, " Status: get_mac_addr: Secured OF\n"); - my $loc = substr($phandle,0,-1); - $rconsole->clear_accum(); + my $loc = substr($phandle, 0, -1); + $rconsole->clear_accum(); - while (!$newdone) { - @result = (); - send_command($verbose, $rconsole, "DISPLAY_MAC_ADDRESS $loc\r"); - @result = $rconsole->expect( - $timeout, - # [ qr/25\/10 Gb/ => - # sub { - # nc_msg($verbose, "Parsing MAC Address 25/10 Gb... \n"); - # $rconsole->clear_accum(); - # } - #], - [ qr/(\n)([^\r]*)(\r)/ => - sub { - nc_msg($verbose, "Parsing MAC Address... \n"); - #$rconsole->clear_accum(); - } - ], - [ qr/>/ => - sub { - nc_msg($verbose, "finished \n"); - $rconsole->clear_accum(); - $newdone = 1; - } - ], - [ timeout => - sub { - nc_msg($verbose, "Timeout isolating single line of ls output\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to $node"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - return 1 if ($rc == 1); + while (!$newdone) { + @result = (); + send_command($verbose, $rconsole, "DISPLAY_MAC_ADDRESS $loc\r"); + @result = $rconsole->expect( + $timeout, - my @lines = grep(/MAC/, @result); - my @values1 = split(' ', $lines[1]); - $mac_address = $values1[2]; + # [ qr/25\/10 Gb/ => + # sub { + # nc_msg($verbose, "Parsing MAC Address 25/10 Gb... \n"); + # $rconsole->clear_accum(); + # } + #], + [ qr/(\n)([^\r]*)(\r)/ => + sub { + nc_msg($verbose, "Parsing MAC Address... \n"); - #nc_msg($verbose, "1GbE Adapter MAC Address: $mac_address \n"); - nc_msg($verbose, "Ethernet Adapter MAC Address: $mac_address \n"); + #$rconsole->clear_accum(); + } + ], + [ qr/>/ => + sub { + nc_msg($verbose, "finished \n"); + $rconsole->clear_accum(); + $newdone = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout isolating single line of ls output\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); - # Return mac address - if ($mac_address) { - return $mac_address; - } else { - return undef; - }; - } + my @lines = grep(/MAC/, @result); + my @values1 = split(' ', $lines[1]); + $mac_address = $values1[2]; + + #nc_msg($verbose, "1GbE Adapter MAC Address: $mac_address \n"); + nc_msg($verbose, "Ethernet Adapter MAC Address: $mac_address \n"); + + # Return mac address + if ($mac_address) { + return $mac_address; + } else { + return undef; + } + } } else { - nc_msg($verbose, "Status: get_mac_addr start\n"); + nc_msg($verbose, "Status: get_mac_addr start\n"); - # cmd(0) could have been sent as 3 commands. " mac-address" (tcl forces - # the use of \") is the first command on this line. The result of entering - # " mac-address" is that 2 stack entries are created, and address and a length. - # - # The next command in cmd(0) is the phandle with no quotes. This results in - # one stack entry because the phandle is an address. - # - # the third command in cmd(0) is get-package-property. After this command, there - # are 3 stack entries (return code, address and length of mac-address). - # state 0, stack count 0, send command - $done[0] = 0; - $cmd[0] = "\" local-mac-address\" " . $phandle . " get-package-property\r"; - $msg[0] = "Status: return code and mac-address now on stack\n"; - $pattern[0] = "local-mac-address.*ok"; #"\s*3 >"; - $newstate[0] = 1; + # cmd(0) could have been sent as 3 commands. " mac-address" (tcl forces + # the use of \") is the first command on this line. The result of entering + # " mac-address" is that 2 stack entries are created, and address and a length. + # + # The next command in cmd(0) is the phandle with no quotes. This results in + # one stack entry because the phandle is an address. + # + # the third command in cmd(0) is get-package-property. After this command, there + # are 3 stack entries (return code, address and length of mac-address). + # state 0, stack count 0, send command + $done[0] = 0; + $cmd[0] = "\" local-mac-address\" " . $phandle . " get-package-property\r"; + $msg[0] = "Status: return code and mac-address now on stack\n"; + $pattern[0] = "local-mac-address.*ok"; #"\s*3 >"; + $newstate[0] = 1; - # cmd(1) is a dot (.). This is a stack manipulation command that removes one - # thing from the stack. pattern(1) is looking for a prompt with the 2 indicating - # that there are 2 things left on the stack. - # state 1, return code and mac-address on stack - $done[1] = 0; - $cmd[1] = ".\r"; - $msg[1] = "Status: mac-address now on stack\n"; + # cmd(1) is a dot (.). This is a stack manipulation command that removes one + # thing from the stack. pattern(1) is looking for a prompt with the 2 indicating + # that there are 2 things left on the stack. + # state 1, return code and mac-address on stack + $done[1] = 0; + $cmd[1] = ".\r"; + $msg[1] = "Status: mac-address now on stack\n"; - #$pattern[1] = "(.*)2 >(.*)"; - $pattern[1] = "ok"; #"2 >"; - $newstate[1] = 2; + #$pattern[1] = "(.*)2 >(.*)"; + $pattern[1] = "ok"; #"2 >"; + $newstate[1] = 2; - # cmd(2) is the dump command. This takes an address and a length off the stack - # and displays the contents of that storage in ascii and hex. The long pattern - # puts the hex into the variable expect_out(3,string). The tcl verb 'join' is - # used to eliminate the spaces put in by the dump command. - # state 2, mac-address on stack - $done[2] = 0; - $cmd[2] = ": dump-mac ( prop-addr prop-len -- ) \ + # cmd(2) is the dump command. This takes an address and a length off the stack + # and displays the contents of that storage in ascii and hex. The long pattern + # puts the hex into the variable expect_out(3,string). The tcl verb 'join' is + # used to eliminate the spaces put in by the dump command. + # state 2, mac-address on stack + $done[2] = 0; + $cmd[2] = ": dump-mac ( prop-addr prop-len -- ) \ cr \ dup decode-bytes 2swap 2drop ( data-addr data-len ) \ ( data-len ) 0 ?do \ @@ -1113,124 +1115,124 @@ sub get_mac_addr { drop \ cr \ ; \r"; - $msg[2] = "Status: set command\n"; - $pattern[2] = "ok"; - $newstate[2] = 3; + $msg[2] = "Status: set command\n"; + $pattern[2] = "ok"; + $newstate[2] = 3; - $done[3] = 0; - $cmd[3] = "dump-mac\r"; - $msg[3] = "Status: mac-address displayed, stack empty\n"; - $pattern[3] = "dump-mac(\\s*)(\\w*)(\\s*)ok"; - $newstate[3] = 4; + $done[3] = 0; + $cmd[3] = "dump-mac\r"; + $msg[3] = "Status: mac-address displayed, stack empty\n"; + $pattern[3] = "dump-mac(\\s*)(\\w*)(\\s*)ok"; + $newstate[3] = 4; - # state 4, all done - $done[4] = 1; + # state 4, all done + $done[4] = 1; - while ($done[$state] == 0) { - @result = (); - send_command($verbose, $rconsole, $cmd[$state]); - @result = $rconsole->expect( - $timeout, - [ qr/$pattern[$state]/ => - sub { - if ($state == 1) { - if ($rconsole->before() =~ /-\d+/) { - nc_msg($verbose, "Status: Error getting MAC address for phandle=$phandle.\n"); - $rconsole->clear_accum(); - $state = 4; - $rc = 1; - return undef; + while ($done[$state] == 0) { + @result = (); + send_command($verbose, $rconsole, $cmd[$state]); + @result = $rconsole->expect( + $timeout, + [ qr/$pattern[$state]/ => + sub { + if ($state == 1) { + if ($rconsole->before() =~ /-\d+/) { + nc_msg($verbose, "Status: Error getting MAC address for phandle=$phandle.\n"); + $rconsole->clear_accum(); + $state = 4; + $rc = 1; + return undef; + } } - } - nc_msg($verbose, $msg[$state]); - $state = $newstate[$state]; - $rconsole->clear_accum(); - } - ], - [ qr/1 > / => - sub { - $rconsole->clear_accum(); - if ($state eq 0) { + nc_msg($verbose, $msg[$state]); + $state = $newstate[$state]; + $rconsole->clear_accum(); + } + ], + [ qr/1 > / => + sub { + $rconsole->clear_accum(); + if ($state eq 0) { - # An error occurred while obtaining the mac address. Log the error, - # but don't quit nodecond. instead, return NA for the address - # - send_command($verbose, $rconsole, ".\r"); - $rconsole->expect( - $timeout, + # An error occurred while obtaining the mac address. Log the error, + # but don't quit nodecond. instead, return NA for the address + # + send_command($verbose, $rconsole, ".\r"); + $rconsole->expect( + $timeout, - #[ qr/(-*\[0-9\]*) ok(.*)0 >(.*)/i, - [ qr/0 >/i, - sub { - #$mac_rc = $expect_out; - nc_msg($verbose, "Status: Error getting MAC address for phandle=$phandle. RC=$mac_rc.\n"); - nc_msg($verbose, "Could not obtain MAC address; setting MAX to NA\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - nc_msg($verbose, "Timeout when getting mac address\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, " Cannot connect to $node\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ] - ); - } - } - ], - [ qr/]/ => - sub { - nc_msg($verbose, "Unexpected prompt\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ qr/(.*)DEFAULT(.*)/ => - sub { - nc_msg($verbose, "Default catch error\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - nc_msg($verbose, "Timeout in getting mac address\n"); - nc_msg($verbose, "timeout state is $state\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to $node"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - return undef if ($rc == 1); - } - - # if the state is 0, 1, or 2, an error occurred and the join will fail - if ($state == 4) { - if ($result[2] =~ /dump-mac\s*(\w*)\s*ok/) { - $mac_address = $1; + #[ qr/(-*\[0-9\]*) ok(.*)0 >(.*)/i, + [ qr/0 >/i, + sub { + #$mac_rc = $expect_out; + nc_msg($verbose, "Status: Error getting MAC address for phandle=$phandle. RC=$mac_rc.\n"); + nc_msg($verbose, "Could not obtain MAC address; setting MAX to NA\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout when getting mac address\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, " Cannot connect to $node\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ] + ); + } + } + ], + [ qr/]/ => + sub { + nc_msg($verbose, "Unexpected prompt\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ qr/(.*)DEFAULT(.*)/ => + sub { + nc_msg($verbose, "Default catch error\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout in getting mac address\n"); + nc_msg($verbose, "timeout state is $state\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return undef if ($rc == 1); } - return $mac_address; - } else { - return undef; - }; - }; + + # if the state is 0, 1, or 2, an error occurred and the join will fail + if ($state == 4) { + if ($result[2] =~ /dump-mac\s*(\w*)\s*ok/) { + $mac_address = $1; + } + return $mac_address; + } else { + return undef; + } + } } @@ -1274,166 +1276,166 @@ sub get_adaptr_loc { my $rc = 0; if ($secOF == 1) { - nc_msg($verbose, " Status: get_adaptr_loc: Secured OF\n"); + nc_msg($verbose, " Status: get_adaptr_loc: Secured OF\n"); - return $phandle; + return $phandle; } else { - nc_msg($verbose, "Status: get_adaptr_loc start\n"); + nc_msg($verbose, "Status: get_adaptr_loc start\n"); - # cmd(0) could have been sent as 3 commands. " ibm,loc-code" (tcl forces - # the use of \") is the first command on this line. The result of entering - # " ibm,loc-code" is that 2 stack entries are created, and address and a length. - # - # The next command in cmd(0) is the phandle with no quotes. This results in - # one stack entry because the phandle is an address. - # - # the third command in cmd(0) is get-package-property. After this command, there - # are 3 stack entries (return code, address and length of mac-address). - # state 0, stack count 0, send command - $done[0] = 0; - $cmd[0] = "\" ibm,loc-code\" $phandle get-package-property\r"; - $msg[0] = "Status: return code and loc-code now on stack\n"; + # cmd(0) could have been sent as 3 commands. " ibm,loc-code" (tcl forces + # the use of \") is the first command on this line. The result of entering + # " ibm,loc-code" is that 2 stack entries are created, and address and a length. + # + # The next command in cmd(0) is the phandle with no quotes. This results in + # one stack entry because the phandle is an address. + # + # the third command in cmd(0) is get-package-property. After this command, there + # are 3 stack entries (return code, address and length of mac-address). + # state 0, stack count 0, send command + $done[0] = 0; + $cmd[0] = "\" ibm,loc-code\" $phandle get-package-property\r"; + $msg[0] = "Status: return code and loc-code now on stack\n"; - #$pattern[0] = "(.*)3 >(.*)"; - #$pattern[0] = "3 >"; - $pattern[0] = "ok"; - $newstate[0] = 1; + #$pattern[0] = "(.*)3 >(.*)"; + #$pattern[0] = "3 >"; + $pattern[0] = "ok"; + $newstate[0] = 1; - # cmd(1) is a dot (.). This is a stack manipulation command that removes one - # thing from the stack. pattern(1) is looking for a prompt with the 2 indicating - # that there are 2 things left on the stack. - # state 1, return code and loc-code on stack - $done[1] = 0; - $cmd[1] = ".\r"; - $msg[1] = "Status: loc-code now on stack\n"; + # cmd(1) is a dot (.). This is a stack manipulation command that removes one + # thing from the stack. pattern(1) is looking for a prompt with the 2 indicating + # that there are 2 things left on the stack. + # state 1, return code and loc-code on stack + $done[1] = 0; + $cmd[1] = ".\r"; + $msg[1] = "Status: loc-code now on stack\n"; - #$pattern[1] = "(.*)2 >(.*)"; - $pattern[1] = "ok"; #"2 >"; - $newstate[1] = 2; + #$pattern[1] = "(.*)2 >(.*)"; + $pattern[1] = "ok"; #"2 >"; + $newstate[1] = 2; - # state 2, loc-code on stack - $done[2] = 0; - $cmd[2] = "dump\r"; - $msg[2] = "Status: loc-code displayed, stack empty\n"; + # state 2, loc-code on stack + $done[2] = 0; + $cmd[2] = "dump\r"; + $msg[2] = "Status: loc-code displayed, stack empty\n"; - #$pattern[2] = "(.*)(: )(.*)( :)(.*)(\.: ok)"; - $pattern[2] = "ok"; - $newstate[2] = 3; + #$pattern[2] = "(.*)(: )(.*)( :)(.*)(\.: ok)"; + $pattern[2] = "ok"; + $newstate[2] = 3; - # state 3, all done - $done[3] = 1; + # state 3, all done + $done[3] = 1; - while ($done[$state] eq 0) { - @result = (); - nc_msg($verbose, "PROGRAM Status: command is $cmd[$state]\n"); - send_command($verbose, $rconsole, $cmd[$state]); - @result = $rconsole->expect( - $timeout, - [ qr/$pattern[$state]/ => - sub { - if ($state == 1) { - if ($rconsole->before() =~ /-\d+/) { - nc_msg($verbose, "Status: Error getting adapter location for phandle=$phandle."); - $rconsole->clear_accum(); - $state = 3; - $rc = 1; - return undef; + while ($done[$state] eq 0) { + @result = (); + nc_msg($verbose, "PROGRAM Status: command is $cmd[$state]\n"); + send_command($verbose, $rconsole, $cmd[$state]); + @result = $rconsole->expect( + $timeout, + [ qr/$pattern[$state]/ => + sub { + if ($state == 1) { + if ($rconsole->before() =~ /-\d+/) { + nc_msg($verbose, "Status: Error getting adapter location for phandle=$phandle."); + $rconsole->clear_accum(); + $state = 3; + $rc = 1; + return undef; + } } - } - nc_msg($verbose, $msg[$state]); - $rconsole->clear_accum(); - $state = $newstate[$state]; - } - ], - [ qr/1 >/ => - sub { - $rconsole->clear_accum(); - my $exp = shift; - if ($state eq 0) { - send_command($verbose, $rconsole, ".\r"); - $exp->expect( + nc_msg($verbose, $msg[$state]); + $rconsole->clear_accum(); + $state = $newstate[$state]; + } + ], + [ qr/1 >/ => + sub { + $rconsole->clear_accum(); + my $exp = shift; + if ($state eq 0) { + send_command($verbose, $rconsole, ".\r"); + $exp->expect( - #[qr/(-*\[0-9\]*) ok(.*)0 >(.*)/=> - [ qr/0 >/ => - sub { - $rconsole->clear_accum(); - my $loc_rc = shift; - nc_msg($verbose, "Error getting adapter physical location.\n"); - nc_msg($verbose, "Status: Error getting physical location for phandle=$phandle. RC=$loc_rc.\n"); - $rc = 1; - } - ], - [ timeout => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, "Timeout when openning console\n"); - $rc = 1; - } - ], - [ eof => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, "Cannot connect to the $node\n"); - $rc = 1; - } - ], - ); + #[qr/(-*\[0-9\]*) ok(.*)0 >(.*)/=> + [ qr/0 >/ => + sub { + $rconsole->clear_accum(); + my $loc_rc = shift; + nc_msg($verbose, "Error getting adapter physical location.\n"); + nc_msg($verbose, "Status: Error getting physical location for phandle=$phandle. RC=$loc_rc.\n"); + $rc = 1; + } + ], + [ timeout => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Timeout when openning console\n"); + $rc = 1; + } + ], + [ eof => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Cannot connect to the $node\n"); + $rc = 1; + } + ], + ); - } - } - ], - [ qr/]/ => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, "Unexpected prompt\n"); - $rc = 1; - } - ], - [ qr/(.*)DEFAULT(.*)/ => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, "Default catch error\n"); - $rc = 1; - } - ], - [ timeout => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, "Timeout when openning console\n"); - $rc = 1; - } - ], - [ eof => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, "Cannot connect to the $node\n"); - $rc = 1; - } - ], - ); - return undef if ($rc == 1); - } + } + } + ], + [ qr/]/ => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Unexpected prompt\n"); + $rc = 1; + } + ], + [ qr/(.*)DEFAULT(.*)/ => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Default catch error\n"); + $rc = 1; + } + ], + [ timeout => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Timeout when openning console\n"); + $rc = 1; + } + ], + [ eof => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Cannot connect to the $node\n"); + $rc = 1; + } + ], + ); + return undef if ($rc == 1); + } - # Did we find one or more adapters? - my @loc_array = split /\n/, $result[3]; - my $found = 0; - $loc_code = ''; - foreach my $line (@loc_array) { - if ($line =~ /(\w*):(.*):([\w|\.|-]*):/) { - $loc_code .= $3; - $found = 1; + # Did we find one or more adapters? + my @loc_array = split /\n/, $result[3]; + my $found = 0; + $loc_code = ''; + foreach my $line (@loc_array) { + if ($line =~ /(\w*):(.*):([\w|\.|-]*):/) { + $loc_code .= $3; + $found = 1; + } + } + if ($found) { + $loc_code =~ s/\.$//; + return $loc_code; + } else { + return undef; } } - if ($found) { - $loc_code =~ s/\.$//; - return $loc_code; - } else { - return undef; - }; - }; } #------------------------------------------------------------------------------- @@ -1475,7 +1477,7 @@ sub ping_server { my $linklocal_ip; my @result; my @done; - my $newdone=0; + my $newdone = 0; my @cmd; my @msg; my @pattern; @@ -1495,8 +1497,8 @@ sub ping_server { my $i; my $ping_debug; my $ping_rc; - my $rc = 0; - my $netmask="255.255.255.0"; + my $rc = 0; + my $netmask = "255.255.255.0"; nc_msg($verbose, "Status: ping_server start\n"); @@ -1505,352 +1507,353 @@ sub ping_server { nc_msg($verbose, " Adapter Location: \n"); - my $loc = substr($phandle,0,-1); - $rconsole->clear_accum(); - send_command($verbose, $rconsole, "PING $loc $server_ip,$client_ip,$gateway_ip,,$netmask \r"); + my $loc = substr($phandle, 0, -1); + $rconsole->clear_accum(); + send_command($verbose, $rconsole, "PING $loc $server_ip,$client_ip,$gateway_ip,,$netmask \r"); - while (!$newdone) { - @result = (); - @result = $rconsole->expect( - $timeout, - [ qr/(\n)([^\r]*)(\r)/ => - sub { - nc_msg($verbose, "Pinging... \n"); - #$rconsole->clear_accum(); - } - ], - [ qr/>/ => - sub { - nc_msg($verbose, "finished \n"); - $rconsole->clear_accum(); - $newdone = 1; - } - ], - [ timeout => - sub { - nc_msg($verbose, "Timeout isolating single line of ls output\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to $node"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - return 1 if ($rc == 1); + while (!$newdone) { + @result = (); + @result = $rconsole->expect( + $timeout, + [ qr/(\n)([^\r]*)(\r)/ => + sub { + nc_msg($verbose, "Pinging... \n"); - my $line = grep(/SMS Macro Operation Succeeded./, @result); + #$rconsole->clear_accum(); + } + ], + [ qr/>/ => + sub { + nc_msg($verbose, "finished \n"); + $rconsole->clear_accum(); + $newdone = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout isolating single line of ls output\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); - if ($line eq 1) { - nc_msg($verbose, "# $full_path_name ping successful.\n"); - $ping_rc=0; - last; - } else { - nc_msg($verbose, "# $full_path_name ping unsuccessful.\n"); - $ping_rc=1; - }; - }; - return $ping_rc; + my $line = grep(/SMS Macro Operation Succeeded./, @result); + + if ($line eq 1) { + nc_msg($verbose, "# $full_path_name ping successful.\n"); + $ping_rc = 0; + last; + } else { + nc_msg($verbose, "# $full_path_name ping unsuccessful.\n"); + $ping_rc = 1; + } + } + return $ping_rc; } else { - # If the adapter type chosen is ethernet, need to set the speed and duplex - # of the adapter before we perform the ping. If token ring or fddi, - # this is not required, so begin with state 2. - # - # cmd(0) sets the given adapter as active, to allow setting of speed - # and duplex - # - # cmd(1) writes the settings to the current adapter - # - # cmd(2) selects the /packages/net node as the active package to access the - # ping command. - # - # The next command in cmd(3) is the ping command. This places the return code - # on the stack. A return code of 0 indicates success. - # - # state 0, set the current adapter - $done[0] = 0; - $cmd[0] = "dev $full_path_name\r"; - $msg[0] = "Status: selected $full_path_name as the active adapter\n"; + # If the adapter type chosen is ethernet, need to set the speed and duplex + # of the adapter before we perform the ping. If token ring or fddi, + # this is not required, so begin with state 2. + # + # cmd(0) sets the given adapter as active, to allow setting of speed + # and duplex + # + # cmd(1) writes the settings to the current adapter + # + # cmd(2) selects the /packages/net node as the active package to access the + # ping command. + # + # The next command in cmd(3) is the ping command. This places the return code + # on the stack. A return code of 0 indicates success. + # + # state 0, set the current adapter + $done[0] = 0; + $cmd[0] = "dev $full_path_name\r"; + $msg[0] = "Status: selected $full_path_name as the active adapter\n"; - #$pattern[0] = ".*dev(.*)0 >(.*)"; - $pattern[0] = "0 >"; - $newstate[0] = 1; + #$pattern[0] = ".*dev(.*)0 >(.*)"; + $pattern[0] = "0 >"; + $newstate[0] = 1; - # state 1, send property command to $selected type; - $done[1] = 0; - $cmd[1] = "\" ethernet,$adap_speed,$adap_conn,$adap_duplex\" encode-string \" chosen-network-type\" property\r"; - $msg[1] = "Status: chosen network type set\n"; + # state 1, send property command to $selected type; + $done[1] = 0; + $cmd[1] = "\" ethernet,$adap_speed,$adap_conn,$adap_duplex\" encode-string \" chosen-network-type\" property\r"; + $msg[1] = "Status: chosen network type set\n"; - #$pattern[1] =".*ethernet(.*)0 >(.*)"; - $pattern[1] = "0 >"; - $newstate[1] = 2; + #$pattern[1] =".*ethernet(.*)0 >(.*)"; + $pattern[1] = "0 >"; + $newstate[1] = 2; - # state 2, activate /packages/net - $done[2] = 0; - $cmd[2] = "dev /packages/net\r"; - $msg[2] = "Status: selected the /packages/net node as the active package\n"; - $pattern[2] = ".*dev.*packages.*net(.*)ok(.*)0 >(.*)"; + # state 2, activate /packages/net + $done[2] = 0; + $cmd[2] = "dev /packages/net\r"; + $msg[2] = "Status: selected the /packages/net node as the active package\n"; + $pattern[2] = ".*dev.*packages.*net(.*)ok(.*)0 >(.*)"; - #$pattern[2] = "ok"; - $newstate[2] = 3; + #$pattern[2] = "ok"; + $newstate[2] = 3; - # state 3, ping the server - $done[3] = 0; - $msg[3] = "Status: ping return code now on stack\n"; - $newstate[3] = 4; + # state 3, ping the server + $done[3] = 0; + $msg[3] = "Status: ping return code now on stack\n"; + $newstate[3] = 4; - # get the timeout for ping test - my $to4pt; - if ($ENV{TIMEOUT4PINGTEST} =~ /^\d+$/) { - $to4pt = ",$ENV{TIMEOUT4PINGTEST}"; - } + # get the timeout for ping test + my $to4pt; + if ($ENV{TIMEOUT4PINGTEST} =~ /^\d+$/) { + $to4pt = ",$ENV{TIMEOUT4PINGTEST}"; + } - #IPv6 - if ($server_ip =~ /:/) { + #IPv6 + if ($server_ip =~ /:/) { - #::1, calculate link local address - if ($client_ip eq "::1") { - my $command = "/opt/xcat/share/xcat/tools/mac2linklocal -m $mac_address"; - $linklocal_ip = $rconsole->send($command); + #::1, calculate link local address + if ($client_ip eq "::1") { + my $command = "/opt/xcat/share/xcat/tools/mac2linklocal -m $mac_address"; + $linklocal_ip = $rconsole->send($command); + } else { + $linklocal_ip = $client_ip; + } + $cmd[3] = "ping $full_path_name:ipv6,$server_ip,$linklocal_ip,$gateway_ip$to4pt\r"; } else { - $linklocal_ip = $client_ip; + ###$cmd[3] = "ping $full_path_name:$server_ip,$client_ip,$gateway_ip$to4pt\r"; + $cmd[3] = "ping $full_path_name:$server_ip,$client_ip,$gateway_ip$to4pt\r"; } - $cmd[3] = "ping $full_path_name:ipv6,$server_ip,$linklocal_ip,$gateway_ip$to4pt\r"; - } else { - ###$cmd[3] = "ping $full_path_name:$server_ip,$client_ip,$gateway_ip$to4pt\r"; - $cmd[3] = "ping $full_path_name:$server_ip,$client_ip,$gateway_ip$to4pt\r"; - } - $pattern[3] = ".*ping(.*)ok(.*)0 >(.*)"; + $pattern[3] = ".*ping(.*)ok(.*)0 >(.*)"; - # state 4, all done - $done[4] = 0; - $cmd[4] = "0 to my-self\r"; - $msg[4] = "Status: resetting pointer\n"; + # state 4, all done + $done[4] = 0; + $cmd[4] = "0 to my-self\r"; + $msg[4] = "Status: resetting pointer\n"; - #$pattern[4] = "(.*)ok(.*)0 >(.*)"; - $pattern[4] = "ok"; - $newstate[4] = 5; + #$pattern[4] = "(.*)ok(.*)0 >(.*)"; + $pattern[4] = "ok"; + $newstate[4] = 5; - # state 5, all done - $done[5] = 1; + # state 5, all done + $done[5] = 1; - # for ping, only need to set speed and duplex for ethernet adapters - # - if ($list_type eq "ent") { - $state = 0; - - # Get the list of properties for this adapter + # for ping, only need to set speed and duplex for ethernet adapters # - $adap_prop_list_array = get_adap_prop($phandle, $rconsole, $node, $verbose); - if ($adap_prop_list_array == 1) { - nc_msg($verbose, "ERROR return from get_adap_prop\n"); - return 1; - } + if ($list_type eq "ent") { + $state = 0; - if ($adap_prop_list_array eq 0) { - nc_msg($verbose, "No properties found for adapter '$full_path_name'\n"); - return 1; - } - - # Now need to verify that the network params we were passed are valid for - # the given adapter - # - my $a_speed; - my $a_conn; - my $a_duplex; - for my $prop (@$adap_prop_list_array) { - if ($prop =~ /(.*),(.*),(.*)/) { - $a_speed = $1; - $a_conn = $2; - $a_duplex = $3; - if (($a_speed eq $adap_speed) && ($a_duplex eq $adap_duplex)) { - $properties_matched = 1; - if (grep { $_ eq $a_conn } @adap_conn_list) { - push @adap_conn_list, $a_conn; - } - } - } - } - - if ($properties_matched eq 0) { - $adap_speed = $a_speed; - $adap_duplex = $a_duplex; - $properties_matched = 1; - push @adap_conn_list, $a_conn; - } - - $i = scalar(@adap_conn_list); - - if ($properties_matched eq 0) { - nc_msg($verbose, "'$adap_speed/$adap_duplex' settings are not supported on this adapter\n"); - return 1; - } - } else { - $state = 2; - } - - $timeout = 300; - while ($done[$state] eq 0) { - - send_command($verbose, $rconsole, $cmd[$state]); - @result = $rconsole->expect( - - $timeout, - [ qr/$pattern[$state]/s => - sub { - nc_msg($verbose, $msg[$state]); - $rconsole->clear_accum(); - $state = $newstate[$state]; - } - ], - [ qr/]/ => - sub { - nc_msg($verbose, "Unexpected prompt\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ qr/(.*)DEFAULT(.*)/ => - sub { - nc_msg($verbose, "Default catch error\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - nc_msg($verbose, "Timeout when openning console\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to the $node\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - - return 1 if ($rc == 1); - - if ($state == 1) { - $adap_conn = $adap_conn_list[$j]; - $cmd[1] = "\" ethernet,$adap_speed,$adap_conn,$adap_duplex\" encode-string \" chosen-network-type\" property\r"; - nc_msg($verbose, "Status: Trying connector type $adap_conn\n"); - $j++; - } - if ((($tty_do_ping == 1) && ($state == 4)) || ($tty_do_ping != 1) && ($state == 3)) { - $ping_debug = $result[2]; - } - if ((($tty_do_ping == 1) && ($state == 5)) || ($tty_do_ping != 1) && ($state == 4)) { - if (($tty_do_ping == 1) && ($state == 5)) { - - #$ping_rc = $result[2]; - $stack_level = length($result[4]); - } elsif (($state == 4) && ($tty_do_ping != 1) && ($result[2] =~ /PING SUCCESS/)) { - $ping_rc = 0; - } else { - $ping_rc = 1; - } - - if ($ping_rc eq 0) { - nc_msg($verbose, "# $full_path_name ping successful.\n"); - } elsif ($ping_rc == 1) { - nc_msg($verbose, "# $full_path_name ping unsuccessful.\n"); - nc_msg($verbose, "# $full_path_name ping unsuccessful.\n"); - nc_msg($verbose, "$ping_debug\n"); - - # An unsuccessful return may leave another item on the stack to - # be removed. Check for it, and remove if necessary - my $matchexp = 0; - my @exp_out; - while ($stack_level != 0) { - @exp_out = (); - send_command($verbose, $rconsole, ".\r"); - @exp_out = $rconsole->expect( - [ qr/(\[0-9\]*) ok(.*)(\[0-1\]) >(.*)/s => - sub { - $rconsole->clear_accum(); - $matchexp = 1; - } - ], - [ qr/]/ => - sub { - nc_msg($verbose, "Unexpected prompt\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ qr/(.*)DEFAULT(.*)/ => - sub { - nc_msg($verbose, "Default catch error\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - nc_msg($verbose, "Timeout in ping server\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to $node\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - if ($matchexp) { - $matchexp = 0; - $stack_level = length($exp_out[4]); - nc_msg($verbose, "Status: stack_level is <$stack_level>\n"); - } - } - - # Check if there are any more adapter connector types - # to try - # - if (($list_type eq "ent") && ($j < $i)) { - $adap_conn = $adap_conn_list[$j]; - nc_msg($verbose, "Status: Trying connector type $adap_conn\n"); - $j++; - - # Need to work around a default catch problem in open - # firmware by sending a "0 to my-self" instruction - # following the ping. To make sure this happens in - # this rare case where we have an adapter with multiple connectors, - # we have to force the instruction into the 0th slot in - # the array. This is OK, since we only set the current - # adapter once, upon entering this procedure. - # - $done[0] = 0; - $cmd[0] = "0 to my-self\r"; - $msg[0] = "Status: resetting pointer\n"; - $pattern[0] = "(.*)ok(.*)0 >(.*)"; - $newstate[0] = 1; - - $state = 0; - } - } else { - nc_msg($verbose, "Unexpected ping return code\n"); + # Get the list of properties for this adapter + # + $adap_prop_list_array = get_adap_prop($phandle, $rconsole, $node, $verbose); + if ($adap_prop_list_array == 1) { + nc_msg($verbose, "ERROR return from get_adap_prop\n"); return 1; } + + if ($adap_prop_list_array eq 0) { + nc_msg($verbose, "No properties found for adapter '$full_path_name'\n"); + return 1; + } + + # Now need to verify that the network params we were passed are valid for + # the given adapter + # + my $a_speed; + my $a_conn; + my $a_duplex; + for my $prop (@$adap_prop_list_array) { + if ($prop =~ /(.*),(.*),(.*)/) { + $a_speed = $1; + $a_conn = $2; + $a_duplex = $3; + if (($a_speed eq $adap_speed) && ($a_duplex eq $adap_duplex)) { + $properties_matched = 1; + if (grep { $_ eq $a_conn } @adap_conn_list) { + push @adap_conn_list, $a_conn; + } + } + } + } + + if ($properties_matched eq 0) { + $adap_speed = $a_speed; + $adap_duplex = $a_duplex; + $properties_matched = 1; + push @adap_conn_list, $a_conn; + } + + $i = scalar(@adap_conn_list); + + if ($properties_matched eq 0) { + nc_msg($verbose, "'$adap_speed/$adap_duplex' settings are not supported on this adapter\n"); + return 1; + } + } else { + $state = 2; } + + $timeout = 300; + while ($done[$state] eq 0) { + + send_command($verbose, $rconsole, $cmd[$state]); + @result = $rconsole->expect( + + $timeout, + [ qr/$pattern[$state]/s => + sub { + nc_msg($verbose, $msg[$state]); + $rconsole->clear_accum(); + $state = $newstate[$state]; + } + ], + [ qr/]/ => + sub { + nc_msg($verbose, "Unexpected prompt\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ qr/(.*)DEFAULT(.*)/ => + sub { + nc_msg($verbose, "Default catch error\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout when openning console\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to the $node\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + + return 1 if ($rc == 1); + + if ($state == 1) { + $adap_conn = $adap_conn_list[$j]; + $cmd[1] = "\" ethernet,$adap_speed,$adap_conn,$adap_duplex\" encode-string \" chosen-network-type\" property\r"; + nc_msg($verbose, "Status: Trying connector type $adap_conn\n"); + $j++; + } + if ((($tty_do_ping == 1) && ($state == 4)) || ($tty_do_ping != 1) && ($state == 3)) { + $ping_debug = $result[2]; + } + if ((($tty_do_ping == 1) && ($state == 5)) || ($tty_do_ping != 1) && ($state == 4)) { + if (($tty_do_ping == 1) && ($state == 5)) { + + #$ping_rc = $result[2]; + $stack_level = length($result[4]); + } elsif (($state == 4) && ($tty_do_ping != 1) && ($result[2] =~ /PING SUCCESS/)) { + $ping_rc = 0; + } else { + $ping_rc = 1; + } + + if ($ping_rc eq 0) { + nc_msg($verbose, "# $full_path_name ping successful.\n"); + } elsif ($ping_rc == 1) { + nc_msg($verbose, "# $full_path_name ping unsuccessful.\n"); + nc_msg($verbose, "# $full_path_name ping unsuccessful.\n"); + nc_msg($verbose, "$ping_debug\n"); + + # An unsuccessful return may leave another item on the stack to + # be removed. Check for it, and remove if necessary + my $matchexp = 0; + my @exp_out; + while ($stack_level != 0) { + @exp_out = (); + send_command($verbose, $rconsole, ".\r"); + @exp_out = $rconsole->expect( + [ qr/(\[0-9\]*) ok(.*)(\[0-1\]) >(.*)/s => + sub { + $rconsole->clear_accum(); + $matchexp = 1; + } + ], + [ qr/]/ => + sub { + nc_msg($verbose, "Unexpected prompt\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ qr/(.*)DEFAULT(.*)/ => + sub { + nc_msg($verbose, "Default catch error\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout in ping server\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + if ($matchexp) { + $matchexp = 0; + $stack_level = length($exp_out[4]); + nc_msg($verbose, "Status: stack_level is <$stack_level>\n"); + } + } + + # Check if there are any more adapter connector types + # to try + # + if (($list_type eq "ent") && ($j < $i)) { + $adap_conn = $adap_conn_list[$j]; + nc_msg($verbose, "Status: Trying connector type $adap_conn\n"); + $j++; + + # Need to work around a default catch problem in open + # firmware by sending a "0 to my-self" instruction + # following the ping. To make sure this happens in + # this rare case where we have an adapter with multiple connectors, + # we have to force the instruction into the 0th slot in + # the array. This is OK, since we only set the current + # adapter once, upon entering this procedure. + # + $done[0] = 0; + $cmd[0] = "0 to my-self\r"; + $msg[0] = "Status: resetting pointer\n"; + $pattern[0] = "(.*)ok(.*)0 >(.*)"; + $newstate[0] = 1; + + $state = 0; + } + } else { + nc_msg($verbose, "Unexpected ping return code\n"); + return 1; + } + } + } + return $ping_rc; } - return $ping_rc; - }; } @@ -1892,197 +1895,197 @@ sub set_disk_boot { my $rc = 0; if ($secOF == 1) { - nc_msg($verbose, " Status: set_disk_boot: Secured OF\n"); + nc_msg($verbose, " Status: set_disk_boot: Secured OF\n"); - # state 0, get SMS screen - $done[0] = 0; - $cmd[0] = "DISPLAY_BOOTSEQ\r"; - $msg[0] = "Status: sending return to repaint SMS screen\n"; - $pattern[0] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Storage(\r)"; - $newstate[0] = 1; + # state 0, get SMS screen + $done[0] = 0; + $cmd[0] = "DISPLAY_BOOTSEQ\r"; + $msg[0] = "Status: sending return to repaint SMS screen\n"; + $pattern[0] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Storage(\r)"; + $newstate[0] = 1; - # state 1, Set Default Boot Seq - $done[1] = 0; - $cmd[1] = "SET_DEFAULT_BOOTSEQ\r"; - $msg[1] = "Status: Set default boot sequence\n"; - $pattern[1] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Your default boot sequence has been restored(\r)"; - $newstate[1] = 2; + # state 1, Set Default Boot Seq + $done[1] = 0; + $cmd[1] = "SET_DEFAULT_BOOTSEQ\r"; + $msg[1] = "Status: Set default boot sequence\n"; + $pattern[1] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Your default boot sequence has been restored(\r)"; + $newstate[1] = 2; - # state 2, all done - $done[2] = 1; + # state 2, all done + $done[2] = 1; - $timeout = 30; - $state = 0; + $timeout = 30; + $state = 0; - while ($done[$state] eq 0) { - send_command($verbose, $rconsole, $cmd[$state]); - $rconsole->expect( - [ qr/$pattern[$state]/ => - sub { - $rconsole->clear_accum(); - $state = $newstate[$state]; - } - ], - [ qr/THE SELECTED DEVICES WERE NOT DETECTED IN THE SYSTEM/ => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, " Status: THE hard disk WERE NOT DETECTED IN THE SYSTEM!\n"); - $rc = 1; - } - ], - [ timeout => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, "Timeout in settin boot order\n"); - $rc = 1; - } - ], - [ eof => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, "Cannot connect to $node\n"); - $rc = 1; - } - ], - ); - if ($rc == 1) { - return 1; - } else { - return 0; + while ($done[$state] eq 0) { + send_command($verbose, $rconsole, $cmd[$state]); + $rconsole->expect( + [ qr/$pattern[$state]/ => + sub { + $rconsole->clear_accum(); + $state = $newstate[$state]; + } + ], + [ qr/THE SELECTED DEVICES WERE NOT DETECTED IN THE SYSTEM/ => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, " Status: THE hard disk WERE NOT DETECTED IN THE SYSTEM!\n"); + $rc = 1; + } + ], + [ timeout => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Timeout in settin boot order\n"); + $rc = 1; + } + ], + [ eof => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Cannot connect to $node\n"); + $rc = 1; + } + ], + ); + if ($rc == 1) { + return 1; + } else { + return 0; + } } - } - return 0; + return 0; } else { - # state 0, get SMS screen - $done[0] = 0; - if ($expect_out[0] =~ /(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Select Boot Options(\r)/) { - $x0 = $1; - $x1 = $2; - $x2 = $3; - $command = $4; - } - $cmd[0] = "$command\r"; - $msg[0] = "Status: sending return to repaint SMS screen\n"; - $pattern[0] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Configure Boot Device Order(\r)"; - $newstate[0] = 1; - - # state 1, Multiboot - $done[1] = 0; - $msg[1] = "Status: Multiboot\n"; - $pattern[1] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Select 1st Boot Device(\r)"; - $newstate[1] = 2; - - # state 2, Configure Boot Device Order - $done[2] = 0; - $msg[2] = "Status: Configure Boot Device Order"; - $pattern[2] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Hard Drive(.*)"; - $newstate[2] = 3; - - # state 3, Select Device Type - $done[3] = 0; - $msg[3] = "Status: Select Device Type"; - $pattern[3] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)SCSI(.*)"; - $newstate[3] = 4; - - # state 4, Select Media Type - $done[4] = 0; - $msg[4] = "Status: Select Media Type"; - $pattern[4] = "(\n)(\[ ])(\[1])(\[.])(\[ ]+)(\\S+)(.*)"; - $newstate[4] = 5; - - # state 5, Select Media Adapter - $done[5] = 0; - $msg[5] = "Status: Select Media Adapter"; - $pattern[5] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)(\\S)(\[ ]+)SCSI (\[0-9]+) MB Harddisk(.*)loc=(.*)\[)]"; - $newstate[5] = 6; - - # state 6, Select Device - $done[6] = 0; - $msg[6] = "Status: Select Device"; - $pattern[6] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Set Boot Sequence(.*)"; - $newstate[6] = 7; - - # state 7, Select Task - $done[7] = 0; - $msg[7] = "Status: Select Task"; - $pattern[7] = "(.*)Current Boot Sequence(.*)"; - $newstate[7] = 8; - - # state 8, Return to Main Menu - $done[8] = 0; - $cmd[8] = "M"; - $msg[8] = "Status: Restored Default Setting.\n"; - $pattern[8] = "(.*)Navigation key(.*)"; - $newstate[8] = 9; - - # state 9, Getting to SMS Main Menu - $done[9] = 0; - $cmd[9] = "0\r"; - $msg[9] = "Status: Getting to SMS Main Menu.\n"; - $pattern[9] = "(.*)Exit SMS(.*)Prompt?(.*)"; - $newstate[9] = 10; - - # state 10, Exiting SMS - $done[10] = 0; - $cmd[10] = "Y"; - $msg[10] = "Status: Exiting SMS.\n"; - $pattern[10] = "(.*)ok(.*)0 >(.*)"; - $newstate[10] = 11; - - # state 11, all done - $done[11] = 1; - - $timeout = 30; - $state = 0; - - while ($done[$state] eq 0) { - send_command($verbose, $rconsole, $cmd[$state]); - $rconsole->expect( - [ qr/$pattern[$state]/ => - sub { - $rconsole->clear_accum(); - if ($state == 4) { - if ($expect_out[6] eq "None") { - $state = 8; - } - } - $state = $newstate[$state]; - if (($state != 8) && ($state != 9) && ($state != 10)) { - $cmd[$state] = "$expect_out[3]\r"; - } - } - ], - [ qr/THE SELECTED DEVICES WERE NOT DETECTED IN THE SYSTEM/ => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, " Status: THE hard disk WERE NOT DETECTED IN THE SYSTEM!\n"); - $rc = 1; - } - ], - [ timeout => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, "Timeout in settin boot order\n"); - $rc = 1; - } - ], - [ eof => - sub { - $rconsole->clear_accum(); - nc_msg($verbose, "Cannot connect to $node\n"); - $rc = 1; - } - ], - ); - if ($rc == 1) { - return 1; - } else { - return 0; + # state 0, get SMS screen + $done[0] = 0; + if ($expect_out[0] =~ /(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Select Boot Options(\r)/) { + $x0 = $1; + $x1 = $2; + $x2 = $3; + $command = $4; } + $cmd[0] = "$command\r"; + $msg[0] = "Status: sending return to repaint SMS screen\n"; + $pattern[0] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Configure Boot Device Order(\r)"; + $newstate[0] = 1; + + # state 1, Multiboot + $done[1] = 0; + $msg[1] = "Status: Multiboot\n"; + $pattern[1] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Select 1st Boot Device(\r)"; + $newstate[1] = 2; + + # state 2, Configure Boot Device Order + $done[2] = 0; + $msg[2] = "Status: Configure Boot Device Order"; + $pattern[2] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Hard Drive(.*)"; + $newstate[2] = 3; + + # state 3, Select Device Type + $done[3] = 0; + $msg[3] = "Status: Select Device Type"; + $pattern[3] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)SCSI(.*)"; + $newstate[3] = 4; + + # state 4, Select Media Type + $done[4] = 0; + $msg[4] = "Status: Select Media Type"; + $pattern[4] = "(\n)(\[ ])(\[1])(\[.])(\[ ]+)(\\S+)(.*)"; + $newstate[4] = 5; + + # state 5, Select Media Adapter + $done[5] = 0; + $msg[5] = "Status: Select Media Adapter"; + $pattern[5] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)(\\S)(\[ ]+)SCSI (\[0-9]+) MB Harddisk(.*)loc=(.*)\[)]"; + $newstate[5] = 6; + + # state 6, Select Device + $done[6] = 0; + $msg[6] = "Status: Select Device"; + $pattern[6] = "(\n)(\[ ])(\[0-9])(\[.])(\[ ]+)Set Boot Sequence(.*)"; + $newstate[6] = 7; + + # state 7, Select Task + $done[7] = 0; + $msg[7] = "Status: Select Task"; + $pattern[7] = "(.*)Current Boot Sequence(.*)"; + $newstate[7] = 8; + + # state 8, Return to Main Menu + $done[8] = 0; + $cmd[8] = "M"; + $msg[8] = "Status: Restored Default Setting.\n"; + $pattern[8] = "(.*)Navigation key(.*)"; + $newstate[8] = 9; + + # state 9, Getting to SMS Main Menu + $done[9] = 0; + $cmd[9] = "0\r"; + $msg[9] = "Status: Getting to SMS Main Menu.\n"; + $pattern[9] = "(.*)Exit SMS(.*)Prompt?(.*)"; + $newstate[9] = 10; + + # state 10, Exiting SMS + $done[10] = 0; + $cmd[10] = "Y"; + $msg[10] = "Status: Exiting SMS.\n"; + $pattern[10] = "(.*)ok(.*)0 >(.*)"; + $newstate[10] = 11; + + # state 11, all done + $done[11] = 1; + + $timeout = 30; + $state = 0; + + while ($done[$state] eq 0) { + send_command($verbose, $rconsole, $cmd[$state]); + $rconsole->expect( + [ qr/$pattern[$state]/ => + sub { + $rconsole->clear_accum(); + if ($state == 4) { + if ($expect_out[6] eq "None") { + $state = 8; + } + } + $state = $newstate[$state]; + if (($state != 8) && ($state != 9) && ($state != 10)) { + $cmd[$state] = "$expect_out[3]\r"; + } + } + ], + [ qr/THE SELECTED DEVICES WERE NOT DETECTED IN THE SYSTEM/ => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, " Status: THE hard disk WERE NOT DETECTED IN THE SYSTEM!\n"); + $rc = 1; + } + ], + [ timeout => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Timeout in settin boot order\n"); + $rc = 1; + } + ], + [ eof => + sub { + $rconsole->clear_accum(); + nc_msg($verbose, "Cannot connect to $node\n"); + $rc = 1; + } + ], + ); + if ($rc == 1) { + return 1; + } else { + return 0; + } + } + return 0; } - return 0; - }; } @@ -2132,307 +2135,307 @@ sub boot_network { if ($secOF == 1) { - nc_msg($verbose, " Status: boot_network: Secured OF\n"); + nc_msg($verbose, " Status: boot_network: Secured OF\n"); - $done[0] = 0; - if ($dump_target ne "") { + $done[0] = 0; + if ($dump_target ne "") { - $net_device[0] = "$full_path_name:iscsi,ciaddr=$client_ip,subnet-mask=$netmask,itname=dummy,iport=$dump_port,ilun=$dump_lun,iname=$dump_target,siaddr=$server_ip,2"; - $pattern[0] = "iSCSI"; - } else { - - if ($extra_args ne "") { - - if ($server_ip =~ /:/) { #ipv6 - $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node,$extra_args"; - } else { - - $net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip $extra_args"; - } + $net_device[0] = "$full_path_name:iscsi,ciaddr=$client_ip,subnet-mask=$netmask,itname=dummy,iport=$dump_port,ilun=$dump_lun,iname=$dump_target,siaddr=$server_ip,2"; + $pattern[0] = "iSCSI"; } else { - if ($server_ip =~ /:/) { #ipv6 - $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node"; + + if ($extra_args ne "") { + + if ($server_ip =~ /:/) { #ipv6 + $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node,$extra_args"; + } else { + + $net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip $extra_args"; + } } else { - $net_device[0] = "$full_path_name speed=$speed,duplex=$duplex,$server_ip,,$client_ip,$gateway_ip"; + if ($server_ip =~ /:/) { #ipv6 + $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node"; + } else { + $net_device[0] = "$full_path_name speed=$speed,duplex=$duplex,$server_ip,,$client_ip,$gateway_ip"; + } } + $pattern[0] = "BOOTP"; } - $pattern[0] = "BOOTP"; - } - $cmd[0] = "\rPING $full_path_name $server_ip,$client_ip,$gateway_ip,,$netmask \r"; - send_command($verbose, $rconsole, $cmd[0]); + $cmd[0] = "\rPING $full_path_name $server_ip,$client_ip,$gateway_ip,,$netmask \r"; + send_command($verbose, $rconsole, $cmd[0]); - sleep 10; + sleep 10; - $cmd[0] = "\r\rBOOT_FROM_DEVICE #network $net_device[0]\r\r\n"; - $msg[0] = "Status: network boot initiated\n"; - $newstate[0] = 99; + $cmd[0] = "\r\rBOOT_FROM_DEVICE #network $net_device[0]\r\r\n"; + $msg[0] = "Status: network boot initiated\n"; + $newstate[0] = 99; - # state 99, all done - $done[99] = 1; + # state 99, all done + $done[99] = 1; - # state -1, all done - $done[100] = 2; #-1??? + # state -1, all done + $done[100] = 2; #-1??? - if ($speed eq "" || $duplex eq "") { - nc_msg($verbose, "Cannot set speed or duplex for network boot\n"); - return 1; - } - - $timeout = 30; # shouldn't take long - while ($done[$state] eq 0) { - send_command($verbose, $rconsole, $cmd[$state]); - $rconsole->expect( - [ qr/$pattern[$state]/ => - sub { - $rconsole->clear_accum(); - my @expect_out = shift; - if ($state == 2) { - if ($set_boot_order == 1) { - ######################################## - # Set network as boot device - ######################################## - $cmd[3] = "setenv boot-device $net_device[$newstate[3]]\r"; - } elsif ($set_boot_order == 2) { - ######################################## - # Set network as 1st boot device,disk as 2nd boot device - ######################################## - $boot_device_bk = $expect_out[1]; - $cmd[3] = "setenv boot-device $net_device[$newstate[3]] $boot_device_bk\r"; - } elsif ($set_boot_order == 3) { - ######################################## - # Set disk as 1st boot device,network as 2nd boot device - ######################################## - $boot_device_bk = $expect_out[1]; - $cmd[3] = "setenv boot-device $boot_device_bk $net_device[$newstate[3]]\r"; - } elsif ($set_boot_order == 4) { - ######################################## - # set disk as boot device - ######################################## - $boot_device_bk = $expect_out[1]; - $cmd[3] = "setenv boot-device $boot_device_bk\r"; - } - } - nc_msg($verbose, $msg[$state]); - $state = $newstate[$state]; - } - ], - [ qr/----/ => - sub { - nc_msg($verbose, $msg[$state]); - $rconsole->clear_accum(); - $state = $newstate[$state]; - } - ], - [ qr/(.*)DEFAULT(.*)/ => - sub { - nc_msg($verbose, "Default catch error\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - nc_msg($verbose, "Timeout when openning console\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to the $node\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - return 1 if ($rc == 1); - } - return 0; - } - else - { - nc_msg($verbose, "Status: boot_network start\n"); - ################################################################### - # Variables associated with each of the commands sent by this routine - # are defined below. - # - # The done variable is flag that is set to 1 to break out of the loop - # - # The cmd variable is the command to be sent to the chrp interface. - # In one case it set in the special processing code because the - # ihandle is not available then this code is executes. - # - # The msg variable contains the message sent after a successful pattern match - # - # The pattern variable is the pattern passed to expect - # - # The newstate variable indicates what command is to be issued next - ################################################################### - - # If the install adapter is Ethernet or Token Ring, set the speed and - # duplex during boot. - # state 0, stack count 0 - $done[0] = 0; - if ($dump_target ne "") { - $net_device[0] = "$full_path_name:iscsi,ciaddr=$client_ip,subnet-mask=$netmask,itname=dummy,iport=$dump_port,ilun=$dump_lun,iname=$dump_target,siaddr=$server_ip,2"; - $pattern[0] = "iSCSI"; - } else { - if ($extra_args ne "") { - if ($server_ip =~ /:/) { #ipv6 - $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node,$extra_args"; - } else { - $net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip $extra_args"; - } - } else { - if ($server_ip =~ /:/) { #ipv6 - $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node"; - } else { - ####$net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip"; - $net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip"; - } - } - $pattern[0] = "BOOTP"; - } - - $cmd[0] = "boot $net_device[0]\r"; - $msg[0] = "Status: network boot initiated\n"; - $newstate[0] = 99; - - # If the install adapter is FDDI, don't set the speed and duplex - # state 1 - $done[1] = 0; - $net_device[1] = "$full_path_name:bootp,$server_ip,,$client_ip,$gateway_ip"; - $cmd[1] = "boot $net_device[1]\r"; - $msg[1] = "Status: network boot initiated\n"; - $pattern[1] = "BOOTP"; - $newstate[1] = 99; - - # state 99, all done - $done[99] = 1; - - # state -1, all done - $done[100] = 1; #-1??? - - if ($chosen_adap_type eq "fddi") { - $state = 1; - } else { if ($speed eq "" || $duplex eq "") { nc_msg($verbose, "Cannot set speed or duplex for network boot\n"); return 1; } - $state = 0; - } - ################################################################## - # Set the boot device order. - ################################################################## - if ($set_boot_order > 0) { - $done[2] = 0; - $msg[2] = "Status: read original boot-device\n"; - $cmd[2] = "printenv boot-device\r"; - $pattern[2] = ".*boot-device\\s+(\\S+)(.*)ok(.*)"; - $newstate[2] = 3; - $done[3] = 0; - $msg[3] = "Status: set the environment variable boot-device\n"; - $pattern[3] = "(.*)ok(.*)(\[0-9]) >(.*)"; - if ($state eq 0) { - $newstate[3] = 0; - } else { - $newstate[3] = 1; - } - $state = 2; - } - - $timeout = 30; # shouldn't take long - while ($done[$state] eq 0) { - send_command($verbose, $rconsole, $cmd[$state]); - $rconsole->expect( - [ qr/$pattern[$state]/ => - sub { - $rconsole->clear_accum(); - my @expect_out = shift; - if ($state == 2) { - if ($set_boot_order == 1) { - ######################################## - # Set network as boot device - ######################################## - $cmd[3] = "setenv boot-device $net_device[$newstate[3]]\r"; - } elsif ($set_boot_order == 2) { - ######################################## - # Set network as 1st boot device,disk as 2nd boot device - ######################################## - $boot_device_bk = $expect_out[1]; - $cmd[3] = "setenv boot-device $net_device[$newstate[3]] $boot_device_bk\r"; - } elsif ($set_boot_order == 3) { - ######################################## - # Set disk as 1st boot device,network as 2nd boot device - ######################################## - $boot_device_bk = $expect_out[1]; - $cmd[3] = "setenv boot-device $boot_device_bk $net_device[$newstate[3]]\r"; - } elsif ($set_boot_order == 4) { - ######################################## - # set disk as boot device - ######################################## - $boot_device_bk = $expect_out[1]; - $cmd[3] = "setenv boot-device $boot_device_bk\r"; + $timeout = 30; # shouldn't take long + while ($done[$state] eq 0) { + send_command($verbose, $rconsole, $cmd[$state]); + $rconsole->expect( + [ qr/$pattern[$state]/ => + sub { + $rconsole->clear_accum(); + my @expect_out = shift; + if ($state == 2) { + if ($set_boot_order == 1) { + ######################################## + # Set network as boot device + ######################################## + $cmd[3] = "setenv boot-device $net_device[$newstate[3]]\r"; + } elsif ($set_boot_order == 2) { + ######################################## + # Set network as 1st boot device,disk as 2nd boot device + ######################################## + $boot_device_bk = $expect_out[1]; + $cmd[3] = "setenv boot-device $net_device[$newstate[3]] $boot_device_bk\r"; + } elsif ($set_boot_order == 3) { + ######################################## + # Set disk as 1st boot device,network as 2nd boot device + ######################################## + $boot_device_bk = $expect_out[1]; + $cmd[3] = "setenv boot-device $boot_device_bk $net_device[$newstate[3]]\r"; + } elsif ($set_boot_order == 4) { + ######################################## + # set disk as boot device + ######################################## + $boot_device_bk = $expect_out[1]; + $cmd[3] = "setenv boot-device $boot_device_bk\r"; + } } - } - nc_msg($verbose, $msg[$state]); - $state = $newstate[$state]; - } - ], - [ qr/----/ => - sub { - nc_msg($verbose, $msg[$state]); - $rconsole->clear_accum(); - $state = $newstate[$state]; - } - ], - - # For some old firmware, does not output "----" - [ qr/BOOTP/ => - sub { - nc_msg($verbose, $msg[$state]); - $rconsole->clear_accum(); - $state = $newstate[$state]; - } - ], - [ qr/]/ => - sub { - nc_msg($verbose, "Unexpected prompt\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ qr/(.*)DEFAULT(.*)/ => - sub { - nc_msg($verbose, "Default catch error\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - nc_msg($verbose, "Timeout when openning console\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to the $node\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - return 1 if ($rc == 1); + nc_msg($verbose, $msg[$state]); + $state = $newstate[$state]; + } + ], + [ qr/----/ => + sub { + nc_msg($verbose, $msg[$state]); + $rconsole->clear_accum(); + $state = $newstate[$state]; + } + ], + [ qr/(.*)DEFAULT(.*)/ => + sub { + nc_msg($verbose, "Default catch error\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout when openning console\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to the $node\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); + } + return 0; + } + else + { + nc_msg($verbose, "Status: boot_network start\n"); + ################################################################### + # Variables associated with each of the commands sent by this routine + # are defined below. + # + # The done variable is flag that is set to 1 to break out of the loop + # + # The cmd variable is the command to be sent to the chrp interface. + # In one case it set in the special processing code because the + # ihandle is not available then this code is executes. + # + # The msg variable contains the message sent after a successful pattern match + # + # The pattern variable is the pattern passed to expect + # + # The newstate variable indicates what command is to be issued next + ################################################################### + + # If the install adapter is Ethernet or Token Ring, set the speed and + # duplex during boot. + # state 0, stack count 0 + $done[0] = 0; + if ($dump_target ne "") { + $net_device[0] = "$full_path_name:iscsi,ciaddr=$client_ip,subnet-mask=$netmask,itname=dummy,iport=$dump_port,ilun=$dump_lun,iname=$dump_target,siaddr=$server_ip,2"; + $pattern[0] = "iSCSI"; + } else { + if ($extra_args ne "") { + if ($server_ip =~ /:/) { #ipv6 + $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node,$extra_args"; + } else { + $net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip $extra_args"; + } + } else { + if ($server_ip =~ /:/) { #ipv6 + $net_device[0] = "$full_path_name:ipv6,speed=$speed,duplex=$duplex,siaddr=$server_ip,ciaddr=$client_ip,giaddr=$gateway_ip,filename=$node"; + } else { + ####$net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip"; + $net_device[0] = "$full_path_name:speed=$speed,duplex=$duplex,bootp,$server_ip,,$client_ip,$gateway_ip"; + } + } + $pattern[0] = "BOOTP"; + } + + $cmd[0] = "boot $net_device[0]\r"; + $msg[0] = "Status: network boot initiated\n"; + $newstate[0] = 99; + + # If the install adapter is FDDI, don't set the speed and duplex + # state 1 + $done[1] = 0; + $net_device[1] = "$full_path_name:bootp,$server_ip,,$client_ip,$gateway_ip"; + $cmd[1] = "boot $net_device[1]\r"; + $msg[1] = "Status: network boot initiated\n"; + $pattern[1] = "BOOTP"; + $newstate[1] = 99; + + # state 99, all done + $done[99] = 1; + + # state -1, all done + $done[100] = 1; #-1??? + + if ($chosen_adap_type eq "fddi") { + $state = 1; + } else { + if ($speed eq "" || $duplex eq "") { + nc_msg($verbose, "Cannot set speed or duplex for network boot\n"); + return 1; + } + $state = 0; + } + ################################################################## + # Set the boot device order. + ################################################################## + if ($set_boot_order > 0) { + $done[2] = 0; + $msg[2] = "Status: read original boot-device\n"; + $cmd[2] = "printenv boot-device\r"; + $pattern[2] = ".*boot-device\\s+(\\S+)(.*)ok(.*)"; + $newstate[2] = 3; + + $done[3] = 0; + $msg[3] = "Status: set the environment variable boot-device\n"; + $pattern[3] = "(.*)ok(.*)(\[0-9]) >(.*)"; + if ($state eq 0) { + $newstate[3] = 0; + } else { + $newstate[3] = 1; + } + $state = 2; + } + + $timeout = 30; # shouldn't take long + while ($done[$state] eq 0) { + send_command($verbose, $rconsole, $cmd[$state]); + $rconsole->expect( + [ qr/$pattern[$state]/ => + sub { + $rconsole->clear_accum(); + my @expect_out = shift; + if ($state == 2) { + if ($set_boot_order == 1) { + ######################################## + # Set network as boot device + ######################################## + $cmd[3] = "setenv boot-device $net_device[$newstate[3]]\r"; + } elsif ($set_boot_order == 2) { + ######################################## + # Set network as 1st boot device,disk as 2nd boot device + ######################################## + $boot_device_bk = $expect_out[1]; + $cmd[3] = "setenv boot-device $net_device[$newstate[3]] $boot_device_bk\r"; + } elsif ($set_boot_order == 3) { + ######################################## + # Set disk as 1st boot device,network as 2nd boot device + ######################################## + $boot_device_bk = $expect_out[1]; + $cmd[3] = "setenv boot-device $boot_device_bk $net_device[$newstate[3]]\r"; + } elsif ($set_boot_order == 4) { + ######################################## + # set disk as boot device + ######################################## + $boot_device_bk = $expect_out[1]; + $cmd[3] = "setenv boot-device $boot_device_bk\r"; + } + } + nc_msg($verbose, $msg[$state]); + $state = $newstate[$state]; + } + ], + [ qr/----/ => + sub { + nc_msg($verbose, $msg[$state]); + $rconsole->clear_accum(); + $state = $newstate[$state]; + } + ], + + # For some old firmware, does not output "----" + [ qr/BOOTP/ => + sub { + nc_msg($verbose, $msg[$state]); + $rconsole->clear_accum(); + $state = $newstate[$state]; + } + ], + [ qr/]/ => + sub { + nc_msg($verbose, "Unexpected prompt\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ qr/(.*)DEFAULT(.*)/ => + sub { + nc_msg($verbose, "Default catch error\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + nc_msg($verbose, "Timeout when openning console\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to the $node\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return 1 if ($rc == 1); + } + return 0; } - return 0; - }; } # # PROCEDURE @@ -2467,6 +2470,7 @@ sub Boot { $rconsole->clear_accum(); } ], + # Welcome to AIX - some old firmware does not output BOOTP or ---- [ qr/Welcome/ => #-ex sub { @@ -2474,6 +2478,7 @@ sub Boot { $rconsole->clear_accum(); } ], + # tftp file download - some old firmware does not output BOOTP or ---- [ qr/FILE/ => #-ex sub { @@ -2481,6 +2486,7 @@ sub Boot { $rconsole->clear_accum(); } ], + # some old firmware does not output BOOTP or ---- [ qr/Elapsed/ => #-ex sub { @@ -2545,20 +2551,20 @@ sub multiple_open_dev { if ($secOF == 1) { - nc_msg($verbose, " Status: multiple_open_dev: Secured OF\n"); - return $rc; + nc_msg($verbose, " Status: multiple_open_dev: Secured OF\n"); + return $rc; } else { - send_command($verbose, $rconsole, "dev /packages/net \r"); - send_command($verbose, $rconsole, "FALSE value OPEN-DEV_DEBUG \r"); + send_command($verbose, $rconsole, "dev /packages/net \r"); + send_command($verbose, $rconsole, "FALSE value OPEN-DEV_DEBUG \r"); - if (exists $ENV{'OPEN_DEV_DEBUG'}) { - send_command($verbose, $rconsole, "TRUE to OPEN-DEV_DEBUG \r"); - } + if (exists $ENV{'OPEN_DEV_DEBUG'}) { + send_command($verbose, $rconsole, "TRUE to OPEN-DEV_DEBUG \r"); + } - $command = ": new-open-dev ( str len -- true|false ) \ + $command = ": new-open-dev ( str len -- true|false ) \ open-dev_debug if cr .\" NEW-OPEN-DEV: Entering, Device : \" 2dup type cr then \ { _str _len ; _n } \ 0 -> _n \ @@ -2595,80 +2601,80 @@ sub multiple_open_dev { ( start timeout ) \ repeat \ ; \r"; - send_command($verbose, $rconsole, $command); + send_command($verbose, $rconsole, $command); - $timeout = 30; - $rconsole->expect( - $timeout, - [ qr/new-open-dev(.*)ok/ => + $timeout = 30; + $rconsole->expect( + $timeout, + [ qr/new-open-dev(.*)ok/ => - #[qr/>/=> - sub { - nc_msg($verbose, "Status: at End of multiple_open_dev \n"); - $rconsole->clear_accum(); - } - ], - [ qr/]/ => - sub { - nc_msg($verbose, "Unexpected prompt\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - send_user(2, "Timeout\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - send_user(2, "Cannot connect to $node\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); + #[qr/>/=> + sub { + nc_msg($verbose, "Status: at End of multiple_open_dev \n"); + $rconsole->clear_accum(); + } + ], + [ qr/]/ => + sub { + nc_msg($verbose, "Unexpected prompt\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + send_user(2, "Timeout\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + send_user(2, "Cannot connect to $node\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); - $command = "patch new-open-dev open-dev net-ping \r"; - send_command($verbose, $rconsole, $command); + $command = "patch new-open-dev open-dev net-ping \r"; + send_command($verbose, $rconsole, $command); - $rconsole->expect( - $timeout, - [ qr/patch new-open-dev(.*)ok/ => + $rconsole->expect( + $timeout, + [ qr/patch new-open-dev(.*)ok/ => - #[qr/>/=> - sub { - nc_msg($verbose, "Status: at End of multiple_open_dev \n"); - $rconsole->clear_accum(); - return 0; - } - ], - [ qr/]/ => - sub { - nc_msg($verbose, "Unexpected prompt\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ timeout => - sub { - send_user(2, "Timeout\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - [ eof => - sub { - send_user(2, "Cannot connect to $node\n"); - $rconsole->clear_accum(); - $rc = 1; - } - ], - ); - return $rc; - }; + #[qr/>/=> + sub { + nc_msg($verbose, "Status: at End of multiple_open_dev \n"); + $rconsole->clear_accum(); + return 0; + } + ], + [ qr/]/ => + sub { + nc_msg($verbose, "Unexpected prompt\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ timeout => + sub { + send_user(2, "Timeout\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + [ eof => + sub { + send_user(2, "Cannot connect to $node\n"); + $rconsole->clear_accum(); + $rc = 1; + } + ], + ); + return $rc; + } } ################################################################### # @@ -3171,74 +3177,74 @@ sub lparnetbootexp $timeout = 10; if ($secOF == 1) { - nc_msg($verbose, " Status: lparnetboot - console check: Secured OF\n"); + nc_msg($verbose, " Status: lparnetboot - console check: Secured OF\n"); - $rconsole->expect( - $timeout, - [ qr/c?/i => - sub { - $rc = 0; - $rconsole->clear_accum(); - nc_msg($verbose, "Confluent -> Connected.\n"); - } - ], - [ qr/macro_help.*/i => - sub { - $rc = 0; - $rconsole->clear_accum(); - nc_msg($verbose, "Conserver -> Connected.\n"); - } - ], - [ timeout => - sub { - $rc = 1; - $rconsole->clear_accum(); - nc_msg($verbose, "Timeout waiting for console connection.\n"); - } - ], - [ eof => - sub { - $rc = 2; - $rconsole->clear_accum(); - nc_msg(1, "Please make sure rcons $node works.\n"); - } - ], - ); + $rconsole->expect( + $timeout, + [ qr/c?/i => + sub { + $rc = 0; + $rconsole->clear_accum(); + nc_msg($verbose, "Confluent -> Connected.\n"); + } + ], + [ qr/macro_help.*/i => + sub { + $rc = 0; + $rconsole->clear_accum(); + nc_msg($verbose, "Conserver -> Connected.\n"); + } + ], + [ timeout => + sub { + $rc = 1; + $rconsole->clear_accum(); + nc_msg($verbose, "Timeout waiting for console connection.\n"); + } + ], + [ eof => + sub { + $rc = 2; + $rconsole->clear_accum(); + nc_msg(1, "Please make sure rcons $node works.\n"); + } + ], + ); } else { - $rconsole->expect( - $timeout, - [ qr/c?/i => - sub { - $rc = 0; - $rconsole->clear_accum(); - nc_msg($verbose, "Confluent -> Connected.\n"); - } - ], - [ qr/help.*/i => - sub { - $rc = 0; - $rconsole->clear_accum(); - nc_msg($verbose, "Conserver -> Connected.\n"); - } - ], - [ timeout => - sub { - $rc = 1; - $rconsole->clear_accum(); - nc_msg($verbose, "Timeout waiting for console connection.\n"); - } - ], - [ eof => - sub { - $rc = 2; - $rconsole->clear_accum(); - nc_msg(1, "Please make sure rcons $node works.\n"); - } - ], - ); - }; + $rconsole->expect( + $timeout, + [ qr/c?/i => + sub { + $rc = 0; + $rconsole->clear_accum(); + nc_msg($verbose, "Confluent -> Connected.\n"); + } + ], + [ qr/help.*/i => + sub { + $rc = 0; + $rconsole->clear_accum(); + nc_msg($verbose, "Conserver -> Connected.\n"); + } + ], + [ timeout => + sub { + $rc = 1; + $rconsole->clear_accum(); + nc_msg($verbose, "Timeout waiting for console connection.\n"); + } + ], + [ eof => + sub { + $rc = 2; + $rconsole->clear_accum(); + nc_msg(1, "Please make sure rcons $node works.\n"); + } + ], + ); + } unless ($rc eq 0) { return [1]; @@ -3423,147 +3429,147 @@ sub lparnetbootexp nc_msg($verbose, "Check for active console.\n"); $done = 0; $retry_count = 0; - $timeout = 10; + $timeout = 10; if ($secOF == 1) { - nc_msg($verbose, " Status: lparnetboot - check for active console: Secured OF\n"); + nc_msg($verbose, " Status: lparnetboot - check for active console: Secured OF\n"); - while (!$done) { - my @result = $rconsole->expect( - $timeout, - [ qr/0(.*)ok/ => - sub { - nc_msg($verbose, " at ok prompt\n"); - $rconsole->clear_accum(); - $done = 1; - } - ], - [ qr/(.*)elect this consol(.*)/ => - sub { - nc_msg($verbose, " selecting active console\n"); - $rconsole->clear_accum(); - $rconsole->send("0\r"); - } - ], - [ qr/English|French|German|Italian|Spanish|Portuguese|Chinese|Japanese|Korean/ => - sub { - nc_msg($verbose, "Languagae Selection Panel received\n"); - $rconsole->clear_accum(); - $rconsole->send("2\r"); - } - ], - [ qr/admin/ => - sub { - nc_msg($verbose, "No password specified\n"); - $rconsole->soft_close(); - $rc = 1; - } - ], - [ qr/Invalid Password/ => - sub { - nc_msg($verbose, "FSP password is invalid.\n"); - $rconsole->soft_close(); - $rc = 1; - } - ], - [ qr/SMS(.*)Navigation Keys/ => - sub { - nc_msg($verbose, "SMS\n"); - $rconsole->clear_accum(); - $done = 1; - } - ], - [ timeout => - sub { - $rconsole->send("\r"); - $retry_count++; - if ($retry_count == 9) { - nc_msg($verbose, "Timeout waiting for ok prompt; exiting.\n"); + while (!$done) { + my @result = $rconsole->expect( + $timeout, + [ qr/0(.*)ok/ => + sub { + nc_msg($verbose, " at ok prompt\n"); + $rconsole->clear_accum(); + $done = 1; + } + ], + [ qr/(.*)elect this consol(.*)/ => + sub { + nc_msg($verbose, " selecting active console\n"); + $rconsole->clear_accum(); + $rconsole->send("0\r"); + } + ], + [ qr/English|French|German|Italian|Spanish|Portuguese|Chinese|Japanese|Korean/ => + sub { + nc_msg($verbose, "Languagae Selection Panel received\n"); + $rconsole->clear_accum(); + $rconsole->send("2\r"); + } + ], + [ qr/admin/ => + sub { + nc_msg($verbose, "No password specified\n"); $rconsole->soft_close(); $rc = 1; - } - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to $node"); - $rconsole->soft_close(); - $rc = 1; - } - ], - ); - return [1] if ($rc == 1); - } + } + ], + [ qr/Invalid Password/ => + sub { + nc_msg($verbose, "FSP password is invalid.\n"); + $rconsole->soft_close(); + $rc = 1; + } + ], + [ qr/SMS(.*)Navigation Keys/ => + sub { + nc_msg($verbose, "SMS\n"); + $rconsole->clear_accum(); + $done = 1; + } + ], + [ timeout => + sub { + $rconsole->send("\r"); + $retry_count++; + if ($retry_count == 9) { + nc_msg($verbose, "Timeout waiting for ok prompt; exiting.\n"); + $rconsole->soft_close(); + $rc = 1; + } + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->soft_close(); + $rc = 1; + } + ], + ); + return [1] if ($rc == 1); + } } else { - while (!$done) { - my @result = $rconsole->expect( - $timeout, - [ qr/0(.*)ok/ => - sub { - nc_msg($verbose, " at ok prompt\n"); - $rconsole->clear_accum(); - $done = 1; - } - ], - [ qr/(.*)elect this consol(.*)/ => - sub { - nc_msg($verbose, " selecting active console\n"); - $rconsole->clear_accum(); - $rconsole->send("0\r"); - } - ], - [ qr/English|French|German|Italian|Spanish|Portuguese|Chinese|Japanese|Korean/ => - sub { - nc_msg($verbose, "Languagae Selection Panel received\n"); - $rconsole->clear_accum(); - $rconsole->send("2\r"); - } - ], - [ qr/admin/ => - sub { - nc_msg($verbose, "No password specified\n"); - $rconsole->soft_close(); - $rc = 1; - } - ], - [ qr/Invalid Password/ => - sub { - nc_msg($verbose, "FSP password is invalid.\n"); - $rconsole->soft_close(); - $rc = 1; - } - ], - [ qr/SMS(.*)Navigation Keys/ => - sub { - nc_msg($verbose, "SMS\n"); - $rconsole->clear_accum(); - $done = 1; - } - ], - [ timeout => - sub { - $rconsole->send("\r"); - $retry_count++; - if ($retry_count == 9) { - nc_msg($verbose, "Timeout waiting for ok prompt; exiting.\n"); + while (!$done) { + my @result = $rconsole->expect( + $timeout, + [ qr/0(.*)ok/ => + sub { + nc_msg($verbose, " at ok prompt\n"); + $rconsole->clear_accum(); + $done = 1; + } + ], + [ qr/(.*)elect this consol(.*)/ => + sub { + nc_msg($verbose, " selecting active console\n"); + $rconsole->clear_accum(); + $rconsole->send("0\r"); + } + ], + [ qr/English|French|German|Italian|Spanish|Portuguese|Chinese|Japanese|Korean/ => + sub { + nc_msg($verbose, "Languagae Selection Panel received\n"); + $rconsole->clear_accum(); + $rconsole->send("2\r"); + } + ], + [ qr/admin/ => + sub { + nc_msg($verbose, "No password specified\n"); $rconsole->soft_close(); $rc = 1; - } - } - ], - [ eof => - sub { - nc_msg($verbose, "Cannot connect to $node"); - $rconsole->soft_close(); - $rc = 1; - } - ], - ); - return [1] if ($rc == 1); + } + ], + [ qr/Invalid Password/ => + sub { + nc_msg($verbose, "FSP password is invalid.\n"); + $rconsole->soft_close(); + $rc = 1; + } + ], + [ qr/SMS(.*)Navigation Keys/ => + sub { + nc_msg($verbose, "SMS\n"); + $rconsole->clear_accum(); + $done = 1; + } + ], + [ timeout => + sub { + $rconsole->send("\r"); + $retry_count++; + if ($retry_count == 9) { + nc_msg($verbose, "Timeout waiting for ok prompt; exiting.\n"); + $rconsole->soft_close(); + $rc = 1; + } + } + ], + [ eof => + sub { + nc_msg($verbose, "Cannot connect to $node"); + $rconsole->soft_close(); + $rc = 1; + } + ], + ); + return [1] if ($rc == 1); + } } - }; ############################## # Set the node boot order @@ -3918,14 +3924,14 @@ sub lparnetbootexp $rconsole->send("8\r"); $rconsole->clear_accum(); sleep 10; - } + } ], [ qr/timeout/i, sub { nc_msg($verbose, "Timeout; exiting.\n"); $rconsole->clear_accum(); $rc = 1; - } + } ], [ eof => sub { @@ -3947,7 +3953,7 @@ sub lparnetbootexp sleep 10; } } - } + } ], ); return [1] if ($rc == 1);