diff --git a/xCAT-server/lib/perl/xCAT/PPC.pm b/xCAT-server/lib/perl/xCAT/PPC.pm index 8362ca58c..2a8c9b27b 100644 --- a/xCAT-server/lib/perl/xCAT/PPC.pm +++ b/xCAT-server/lib/perl/xCAT/PPC.pm @@ -22,29 +22,29 @@ use Thread qw(yield); # Globals ########################################## my %modules = ( - rinv => "xCAT::PPCinv", - rpower => "xCAT::PPCpower", - rvitals => "xCAT::PPCvitals", - rscan => "xCAT::PPCscan", - mkvm => "xCAT::PPCvm", - rmvm => "xCAT::PPCvm", - lsvm => "xCAT::PPCvm", - chvm => "xCAT::PPCvm", - rnetboot => "xCAT::PPCboot", - getmacs => "xCAT::PPCmac", - reventlog => "xCAT::PPClog", - rspconfig => "xCAT::PPCcfg", - rflash => "xCAT::PPCrflash" -); + rinv => "xCAT::PPCinv", + rpower => "xCAT::PPCpower", + rvitals => "xCAT::PPCvitals", + rscan => "xCAT::PPCscan", + mkvm => "xCAT::PPCvm", + rmvm => "xCAT::PPCvm", + lsvm => "xCAT::PPCvm", + chvm => "xCAT::PPCvm", + rnetboot => "xCAT::PPCboot", + getmacs => "xCAT::PPCmac", + reventlog => "xCAT::PPClog", + rspconfig => "xCAT::PPCcfg", + rflash => "xCAT::PPCrflash" + ); ########################################## # Database errors ########################################## my %errmsg = ( - NODE_UNDEF =>"Node not defined in '%s' database", - NO_ATTR =>"'%s' not defined in '%s' database", - DB_UNDEF =>"'%s' database not defined" -); + NODE_UNDEF =>"Node not defined in '%s' database", + NO_ATTR =>"'%s' not defined in '%s' database", + DB_UNDEF =>"'%s' database not defined" + ); ########################################################################## @@ -56,9 +56,9 @@ sub send_msg { my $ecode = shift; my %output; - ################################################# - # Called from child process - send to parent - ################################################# +################################################# +# Called from child process - send to parent +################################################# if ( exists( $request->{pipe} )) { my $out = $request->{pipe}; @@ -67,9 +67,9 @@ sub send_msg { print $out freeze( [\%output] ); print $out "\nENDOFFREEZE6sK4ci\n"; } - ################################################# - # Called from parent - invoke callback directly - ################################################# +################################################# +# Called from parent - invoke callback directly +################################################# elsif ( exists( $request->{callback} )) { my $callback = $request->{callback}; @@ -92,18 +92,18 @@ sub process_command { my @site = qw(ppcmaxp ppctimeout maxssh ppcretry fsptimeout); my $start; - ####################################### - # Default site table attributes - ####################################### +####################################### +# Default site table attributes +####################################### $request->{ppcmaxp} = 64; $request->{ppctimeout} = 0; $request->{fsptimeout} = 0; $request->{ppcretry} = 3; $request->{maxssh} = 10; - ####################################### - # Get site table attributes - ####################################### +####################################### +# Get site table attributes +####################################### if ( defined( $sitetab )) { foreach ( @site ) { my ($ent) = $sitetab->getAttribs({ key=>$_},'value'); @@ -115,117 +115,117 @@ sub process_command { if ( exists( $request->{verbose} )) { $start = Time::HiRes::gettimeofday(); } - ####################################### - # Group nodes based on command - ####################################### +####################################### +# Group nodes based on command +####################################### my $nodes = preprocess_nodes( $request ); if ( !defined( $nodes )) { return(1); } - #get new node status - my %oldnodestatus=(); #saves the old node status - my @allerrornodes=(); - my $check=0; - my $global_check=1; - if ($sitetab) { - (my $ref) = $sitetab->getAttribs({key => 'nodestatus'}, 'value'); - if ($ref) { - if ($ref->{value} =~ /0|n|N/) { $global_check=0; } - } - } - - my $command=$request->{command}; - if (($command eq 'rpower') || ($command eq 'rnetboot')) { - my $subcommand="temp"; - if ($command eq 'rpower') { $subcommand=$request->{op}; } - if (($global_check) && ($subcommand ne 'stat') && ($subcommand ne 'status') && ($subcommand ne 'state')) { - $check=1; - my $noderange = $request->{node}; - my @allnodes=@$noderange; - - #save the old status - my $nodelisttab = xCAT::Table->new('nodelist'); - if ($nodelisttab) { - my $tabdata = $nodelisttab->getNodesAttribs(\@allnodes, ['node', 'status']); - foreach my $node (@allnodes) - { - my $tmp1 = $tabdata->{$node}->[0]; - if ($tmp1) { - if ($tmp1->{status}) { $oldnodestatus{$node}=$tmp1->{status}; } - else { $oldnodestatus{$node}=""; } - } - } - } - #print "oldstatus:" . Dumper(\%oldnodestatus); - - #set the new status to the nodelist.status - my %newnodestatus=(); - my $newstat; - if (($subcommand eq 'off') || ($subcommand eq 'softoff')) { - my $newstat=$::STATUS_POWERING_OFF; - $newnodestatus{$newstat}=\@allnodes; - } else { - #get the current nodeset stat - if (@allnodes>0) { - my $nsh={}; - my ($ret, $msg)=xCAT::SvrUtils->getNodesetStates(\@allnodes, $nsh); - if (!$ret) { - foreach (keys %$nsh) { - my $newstat=xCAT_monitoring::monitorctrl->getNodeStatusFromNodesetState($_, $command); - $newnodestatus{$newstat}=$nsh->{$_}; - } - } else { - trace( $request, $msg ); - } +#get new node status + my %oldnodestatus=(); #saves the old node status + my @allerrornodes=(); + my $check=0; + my $global_check=1; + if ($sitetab) { + (my $ref) = $sitetab->getAttribs({key => 'nodestatus'}, 'value'); + if ($ref) { + if ($ref->{value} =~ /0|n|N/) { $global_check=0; } + } + } + + my $command=$request->{command}; + if (($command eq 'rpower') || ($command eq 'rnetboot')) { + my $subcommand="temp"; + if ($command eq 'rpower') { $subcommand=$request->{op}; } + if (($global_check) && ($subcommand ne 'stat') && ($subcommand ne 'status') && ($subcommand ne 'state')) { + $check=1; + my $noderange = $request->{node}; + my @allnodes=@$noderange; + +#save the old status + my $nodelisttab = xCAT::Table->new('nodelist'); + if ($nodelisttab) { + my $tabdata = $nodelisttab->getNodesAttribs(\@allnodes, ['node', 'status']); + foreach my $node (@allnodes) + { + my $tmp1 = $tabdata->{$node}->[0]; + if ($tmp1) { + if ($tmp1->{status}) { $oldnodestatus{$node}=$tmp1->{status}; } + else { $oldnodestatus{$node}=""; } + } + } + } +#print "oldstatus:" . Dumper(\%oldnodestatus); + +#set the new status to the nodelist.status + my %newnodestatus=(); + my $newstat; + if (($subcommand eq 'off') || ($subcommand eq 'softoff')) { + my $newstat=$::STATUS_POWERING_OFF; + $newnodestatus{$newstat}=\@allnodes; + } else { +#get the current nodeset stat + if (@allnodes>0) { + my $nsh={}; + my ($ret, $msg)=xCAT::SvrUtils->getNodesetStates(\@allnodes, $nsh); + if (!$ret) { + foreach (keys %$nsh) { + my $newstat=xCAT_monitoring::monitorctrl->getNodeStatusFromNodesetState($_, $command); + $newnodestatus{$newstat}=$nsh->{$_}; + } + } else { + trace( $request, $msg ); + } + } + } +#print "newstatus" . Dumper(\%newnodestatus); + xCAT_monitoring::monitorctrl::setNodeStatusAttributes(\%newnodestatus, 1); } - } - #print "newstatus" . Dumper(\%newnodestatus); - xCAT_monitoring::monitorctrl::setNodeStatusAttributes(\%newnodestatus, 1); } - } - ####################################### - # Fork process - ####################################### +####################################### +# Fork process +####################################### my $children = 0; my $fds = new IO::Select; - # For the commands getmacs and rnetboot, each time - # to fork process, pick out the HMC that has the - # least process number created to connect to the HMC. - # After the process by preprocess_nodes, the $nodes - # variable has following structure: - # $nodes - # |hcp - # |[[hcp,node1_attr], [hcp,node2_attr] ...] - # |count //node number managed by the hcp - # |runprocess //the process number connect to the hcp - # |index //the index of node will be forked of the hcp +# For the commands getmacs and rnetboot, each time +# to fork process, pick out the HMC that has the +# least process number created to connect to the HMC. +# After the process by preprocess_nodes, the $nodes +# variable has following structure: +# $nodes +# |hcp +# |[[hcp,node1_attr], [hcp,node2_attr] ...] +# |count //node number managed by the hcp +# |runprocess //the process number connect to the hcp +# |index //the index of node will be forked of the hcp if ( $request->{command} =~ /^(getmacs|rnetboot)$/ ) { my %pid_owner = (); - # Use the CHID signal to control the - #connection number of certain hcp +# Use the CHID signal to control the +#connection number of certain hcp $SIG{CHLD} = sub { my $pid = 0; while (($pid = waitpid(-1, WNOHANG)) > 0) - { $nodes->{$pid_owner{$pid}}{'runprocess'}--; $children--; } }; - + { $nodes->{$pid_owner{$pid}}{'runprocess'}--; $children--; } }; + my $hasnode = 1; while ($hasnode) { while ( $children >= $request->{ppcmaxp} ) { my $handlednodes={}; child_response( $callback, $fds, $handlednodes); - - #update the node status to the nodelist.status table + +#update the node status to the nodelist.status table if ($check) { updateNodeStatus($handlednodes, \@allerrornodes); } - + Time::HiRes::sleep(0.1); } - # Pick out the hcp which has least processes +# Pick out the hcp which has least processes my $least_processes = $request->{maxssh}; my $least_hcp; my $got_one = 0; @@ -240,35 +240,35 @@ sub process_command { } } } - + if (!$hasnode) { - # There are no node in the $nodes +# There are no node in the $nodes goto ENDOFFORK; } - + if ($least_processes < $request->{maxssh}) { $got_one = 1; } else { my $handlednodes={}; child_response( $callback, $fds, $handlednodes); - - #update the node status to the nodelist.status table + +#update the node status to the nodelist.status table if ($check) { updateNodeStatus($handlednodes, \@allerrornodes); } Time::HiRes::sleep(0.1); } } - + my ($pipe, $pid) = fork_cmd( $nodes->{$least_hcp}{'nodegroup'}->[$nodes->{$least_hcp}{'index'}]->[0], - $nodes->{$least_hcp}{'nodegroup'}->[$nodes->{$least_hcp}{'index'}]->[1], $request ); - + $nodes->{$least_hcp}{'nodegroup'}->[$nodes->{$least_hcp}{'index'}]->[1], $request ); + if ($pid) { $pid_owner{$pid} = $least_hcp; $nodes->{$least_hcp}{'index'}++; $nodes->{$least_hcp}{'runprocess'}++; } - + if ( $pipe ) { $fds->add( $pipe ); $children++; @@ -278,23 +278,23 @@ sub process_command { $SIG{CHLD} = sub { while (waitpid(-1, WNOHANG) > 0) { $children--; } }; my $hw; my $sessions; - + foreach ( @$nodes ) { while ( $children >= $request->{ppcmaxp} ) { my $handlednodes={}; child_response( $callback, $fds, $handlednodes); - - #update the node status to the nodelist.status table + +#update the node status to the nodelist.status table if ($check) { updateNodeStatus($handlednodes, \@allerrornodes); } - + Time::HiRes::sleep(0.1); } - ################################### - # sleep between connects to same - # HMC/IVM so as not to overwelm it - ################################### +################################### +# sleep between connects to same +# HMC/IVM so as not to overwelm it +################################### if ( $hw ne @$_[0] ) { $sessions = 1; } elsif ( $sessions++ >= $request->{maxssh} ) { @@ -302,7 +302,7 @@ sub process_command { $sessions = 1; } $hw = @$_[0]; - + my ($pipe) = fork_cmd( @$_[0], @$_[1], $request ); if ( $pipe ) { $fds->add( $pipe ); @@ -310,32 +310,32 @@ sub process_command { } } } - + ENDOFFORK: - ####################################### - # Process responses from children - ####################################### +####################################### +# Process responses from children +####################################### while ( $fds->count > 0 or $children > 0 ) { my $handlednodes={}; child_response( $callback, $fds, $handlednodes); - #update the node status to the nodelist.status table +#update the node status to the nodelist.status table if ($check) { - updateNodeStatus($handlednodes, \@allerrornodes); + updateNodeStatus($handlednodes, \@allerrornodes); } Time::HiRes::sleep(0.1); } - - #drain one more time + +#drain one more time my $rc=1; while ( $rc>0 ) { - my $handlednodes={}; - $rc=child_response( $callback, $fds, $handlednodes); - #update the node status to the nodelist.status table - if ($check) { - updateNodeStatus($handlednodes, \@allerrornodes); - } + my $handlednodes={}; + $rc=child_response( $callback, $fds, $handlednodes); +#update the node status to the nodelist.status table + if ($check) { + updateNodeStatus($handlednodes, \@allerrornodes); + } } if ( exists( $request->{verbose} )) { @@ -345,18 +345,18 @@ ENDOFFORK: } if ($check) { - #print "allerrornodes=@allerrornodes\n"; - #revert the status back for there is no-op for the nodes +#print "allerrornodes=@allerrornodes\n"; +#revert the status back for there is no-op for the nodes my %old=(); foreach my $node (@allerrornodes) { - my $stat=$oldnodestatus{$node}; - if (exists($old{$stat})) { - my $pa=$old{$stat}; - push(@$pa, $node); - } - else { - $old{$stat}=[$node]; - } + my $stat=$oldnodestatus{$node}; + if (exists($old{$stat})) { + my $pa=$old{$stat}; + push(@$pa, $node); + } + else { + $old{$stat}=[$node]; + } } xCAT_monitoring::monitorctrl::setNodeStatusAttributes(\%old, 1); } @@ -369,11 +369,11 @@ ENDOFFORK: # updateNodeStatus ########################################################################## sub updateNodeStatus { - my $handlednodes=shift; - my $allerrornodes=shift; - foreach my $node (keys(%$handlednodes)) { - if ($handlednodes->{$node} == -1) { push(@$allerrornodes, $node); } - } + my $handlednodes=shift; + my $allerrornodes=shift; + foreach my $node (keys(%$handlednodes)) { + if ($handlednodes->{$node} == -1) { push(@$allerrornodes, $node); } + } } ########################################################################## @@ -406,33 +406,33 @@ sub child_response { foreach my $rfh (@ready_fds) { my $data = <$rfh>; - ################################# - # Read from child process - ################################# +################################# +# Read from child process +################################# if ( defined( $data )) { while ($data !~ /ENDOFFREEZE6sK4ci/) { $data .= <$rfh>; } my $responses = thaw($data); foreach ( @$responses ) { - #save the nodes that has errors for node status monitoring +#save the nodes that has errors for node status monitoring if ((exists($_->{errorcode})) && ($_->{errorcode} != 0)) { - if ($errornodes) { $errornodes->{$_->{node}->[0]->{name}->[0]}=-1; } - } else { - if ($errornodes) { $errornodes->{$_->{node}->[0]->{name}->[0]}=1; } - } + if ($errornodes) { $errornodes->{$_->{node}->[0]->{name}->[0]}=-1; } + } else { + if ($errornodes) { $errornodes->{$_->{node}->[0]->{name}->[0]}=1; } + } $callback->( $_ ); } next; } - ################################# - # Done - close handle - ################################# +################################# +# Done - close handle +################################# $fds->remove($rfh); close($rfh); } yield; #Try to avoid useless iterations as much as possible - return $rc; + return $rc; } @@ -447,16 +447,16 @@ sub resolve_hcp { my $tab = ($request->{hwtype} eq "fsp" or $request->{hwtype} eq "bpa") ? "ppcdirect" : "ppchcp"; my $db = xCAT::Table->new( $tab ); - #################################### - # Database not defined - #################################### +#################################### +# Database not defined +#################################### if ( !defined( $db )) { send_msg( $request, 1, sprintf( $errmsg{DB_UNDEF}, $tab )); return undef; } - #################################### - # Process each node - #################################### +#################################### +# Process each node +#################################### foreach my $hcp ( @$noderange ) { my ($ent) = $db->getAttribs( {hcp=>$hcp},"hcp" ); @@ -465,15 +465,15 @@ sub resolve_hcp { send_msg( $request, 1, $msg ); next; } - ################################ - # Get userid and password - ################################ +################################ +# Get userid and password +################################ my @cred = xCAT::PPCdb::credentials( $hcp, $request->{hwtype} ); $request->{$hcp}{cred} = \@cred; - ################################ - # Save values - ################################ +################################ +# Save values +################################ push @nodegroup,[$hcp]; } return( \@nodegroup ); @@ -495,28 +495,28 @@ sub preprocess_nodes { my %tabs = (); my $netwk; - ######################################## - # Special cases - # rscan - Nodes are hardware control pts - # Direct-attached FSP - ######################################## +######################################## +# Special cases +# rscan - Nodes are hardware control pts +# Direct-attached FSP +######################################## if (( $request->{command} =~ /^(rscan|rspconfig)$/ ) or - ( $request->{hwtype} eq "fsp" or $request->{hwtype} eq "bpa")) { + ( $request->{hwtype} eq "fsp" or $request->{hwtype} eq "bpa")) { my $result = resolve_hcp( $request, $noderange ); return( $result ); } - ########################################## - # Special processing - rnetboot - ########################################## +########################################## +# Special processing - rnetboot +########################################## if ( $request->{command} eq "rnetboot" ) { $netwk = resolve_netwk( $request, $noderange ); if ( !defined( %$netwk )) { return undef; } } - ########################################## - # Open databases needed - ########################################## +########################################## +# Open databases needed +########################################## foreach ( qw(ppc vpd nodetype) ) { $tabs{$_} = xCAT::Table->new($_); @@ -525,72 +525,72 @@ sub preprocess_nodes { return undef; } } - - #################### - # $f1 and $f2 are the flags for rflash, to check if there are BPAs and CECs at the same time. - ################# + +#################### +# $f1 and $f2 are the flags for rflash, to check if there are BPAs and CECs at the same time. +################# my $f1 = 0; my $f2 = 0; - ########################################## - # Group nodes - ########################################## +########################################## +# Group nodes +########################################## foreach my $node ( @$noderange ) { my $d = resolve( $request, $node, \%tabs ); - ###################################### - # Error locating node attributes - ###################################### +###################################### +# Error locating node attributes +###################################### if ( ref($d) ne 'ARRAY' ) { send_msg( $request, 1, "$node: $d"); next; } - ###################################### - # Get data values - ###################################### +###################################### +# Get data values +###################################### my $hcp = @$d[3]; my $mtms = @$d[2]; - if ( $request->{command} eq "rflash" ) { - if(@$d[4] =~/^(fsp|lpar)$/) { - $f1 = 1; - } else { - $f2 = 1; - my $exargs=$request->{arg}; - my $t= xCAT::PPCrflash::print_var($exargs, "exargs"); - if ( grep(/commit/,@$exargs) != 0 || grep(/recover/,@$exargs) != 0) { - send_msg( $request, 1, "When run \"rflash\" with the \"commit\" or \"recover\" operation, the noderange cannot be BPA and can only be CEC or LPAR."); - send_msg( $request, 1, "And then, it will do the operation for both managed systems and power subsystems."); - return undef; - } - - } - } - + if ( $request->{command} eq "rflash" ) { + if(@$d[4] =~/^(fsp|lpar)$/) { + $f1 = 1; + } else { + $f2 = 1; + my $exargs=$request->{arg}; + my $t= xCAT::PPCrflash::print_var($exargs, "exargs"); + if ( grep(/commit/,@$exargs) != 0 || grep(/recover/,@$exargs) != 0) { + send_msg( $request, 1, "When run \"rflash\" with the \"commit\" or \"recover\" operation, the noderange cannot be BPA and can only be CEC or LPAR."); + send_msg( $request, 1, "And then, it will do the operation for both managed systems and power subsystems."); + return undef; + } + + } + } + $nodehash{$hcp}{$mtms}{$node} = $d; } - - if($f1 * $f2) { - send_msg( $request, 1, "The argument noderange of rflash can't be BPA and CEC(or LPAR) at the same time"); - return undef; - } - ########################################## - # Get userid and password - ########################################## + if($f1 * $f2) { + send_msg( $request, 1, "The argument noderange of rflash can't be BPA and CEC(or LPAR) at the same time"); + return undef; + } + +########################################## +# Get userid and password +########################################## while (my ($hcp,$hash) = each(%nodehash) ) { my @cred = xCAT::PPCdb::credentials( $hcp, $request->{hwtype} ); $request->{$hcp}{cred} = \@cred; } - ########################################## - # Group the nodes - we will fork one - # process per nodegroup array element. - ########################################## +########################################## +# Group the nodes - we will fork one +# process per nodegroup array element. +########################################## - ########################################## - # These commands are grouped on an - # LPAR-by-LPAR basis - fork one process - # per LPAR. - ########################################## +########################################## +# These commands are grouped on an +# LPAR-by-LPAR basis - fork one process +# per LPAR. +########################################## if ( $method =~ /^(getmacs|rnetboot)$/ ) { while (my ($hcp,$hash) = each(%nodehash) ) { @nodegroup = (); @@ -598,9 +598,9 @@ sub preprocess_nodes { while (my ($lpar,$d) = each(%$h)) { push @$d, $lpar; - ########################## - # Save network info - ########################## +########################## +# Save network info +########################## if ( $method =~ /^rnetboot$/ ) { push @$d, $netwk->{$lpar}; } @@ -615,14 +615,14 @@ sub preprocess_nodes { return( \%hcpgroup ); } - ########################################## - # Power control commands are grouped - # by CEC which is the smallest entity - # that commands can be sent to in parallel. - # If commands are sent in parallel to a - # single CEC, the CEC itself will serialize - # them - fork one process per CEC. - ########################################## +########################################## +# Power control commands are grouped +# by CEC which is the smallest entity +# that commands can be sent to in parallel. +# If commands are sent in parallel to a +# single CEC, the CEC itself will serialize +# them - fork one process per CEC. +########################################## elsif ( $method =~ /^powercmd/ ) { while (my ($hcp,$hash) = each(%nodehash) ) { while (my ($mtms,$h) = each(%$hash) ) { @@ -631,11 +631,11 @@ sub preprocess_nodes { } return( \@nodegroup ); } - ########################################## - # All other commands are grouped by - # hardware control point - fork one - # process per hardware control point. - ########################################## +########################################## +# All other commands are grouped by +# hardware control point - fork one +# process per hardware control point. +########################################## while (my ($hcp,$hash) = each(%nodehash) ) { push @nodegroup,[$hcp,$hash]; } @@ -655,25 +655,25 @@ sub resolve_netwk { my %result = (); my $ip; - ##################################### - # Network attributes undefined - ##################################### +##################################### +# Network attributes undefined +##################################### if ( !%nethash ) { send_msg( $request,1,sprintf( $errmsg{NODE_UNDEF}, "networks" )); return undef; } - ##################################### - # mac database undefined - ##################################### +##################################### +# mac database undefined +##################################### if ( !defined( $tab )) { send_msg( $request, 1, sprintf( $errmsg{DB_UNDEF}, "mac" )); return undef; } foreach ( @$noderange ) { - ################################# - # Get gateway (-G) - ################################# +################################# +# Get gateway (-G) +################################# if ( !exists( $nethash{$_} )) { my $msg = sprintf( "$_: $errmsg{NODE_UNDEF}", "networks"); send_msg( $request, 1, $msg ); @@ -692,9 +692,9 @@ sub resolve_netwk { } my $gateway_ip = @$ip[1]; - ################################# - # Get server (-S) - ################################# +################################# +# Get server (-S) +################################# my $server = xCAT::Utils->GetMasterNodeName( $_ ); if ( $server == 1 ) { send_msg( $request, 1, "$_: Unable to identify master" ); @@ -707,28 +707,28 @@ sub resolve_netwk { } my $server_ip = @$ip[1]; - ################################# - # Get client (-C) - ################################# +################################# +# Get client (-C) +################################# $ip = xCAT::Utils::toIP( $_ ); if ( @$ip[0] != 0 ) { send_msg( $request, 1, "$_: Cannot resolve '$_'" ); next; } my $client_ip = @$ip[1]; - - ################################# - # Get mac-address (-m) - ################################# + +################################# +# Get mac-address (-m) +################################# my ($ent) = $tab->getNodeAttribs( $_, ['mac'] ); if ( !defined($ent) ) { my $msg = sprintf( "$_: $errmsg{NO_ATTR}","mac","mac"); send_msg( $request, 1, $msg ); next; } - ################################# - # Save results - ################################# +################################# +# Save results +################################# $result{$_}{gateway} = $gateway_ip; $result{$_}{server} = $server_ip; $result{$_}{client} = $client_ip; @@ -749,40 +749,40 @@ sub resolve { my @attribs = qw(id pprofile parent hcp); my @values = (); - ################################# - # Get node type - ################################# +################################# +# Get node type +################################# my $ent = $tabs->{nodetype}->getNodeAttribs($node,[qw(nodetype node)]); if ( !defined( $ent )) { return( sprintf( $errmsg{NODE_UNDEF}, "nodetype" )); } - ################################# - # Check for type - ################################# +################################# +# Check for type +################################# if ( !exists( $ent->{nodetype} )) { return( sprintf( $errmsg{NO_ATTR}, "nodetype","nodetype" )); } - ################################# - # Check for valid "type" - ################################# +################################# +# Check for valid "type" +################################# my ($type) = grep( - /^$::NODETYPE_LPAR|$::NODETYPE_OSI|$::NODETYPE_BPA|$::NODETYPE_FSP$/, - split /,/, $ent->{nodetype} ); + /^$::NODETYPE_LPAR|$::NODETYPE_OSI|$::NODETYPE_BPA|$::NODETYPE_FSP$/, + split /,/, $ent->{nodetype} ); if ( !defined( $type )) { return( "Invalid node type: $ent->{nodetype}" ); } - ################################# - # Get attributes - ################################# +################################# +# Get attributes +################################# my ($att) = $tabs->{ppc}->getNodeAttribs( $node, \@attribs ); - + if ( !defined( $att )) { return( sprintf( $errmsg{NODE_UNDEF}, "ppc" )); } - ################################# - # Special lpar processing - ################################# +################################# +# Special lpar processing +################################# if ( $type =~ /^$::NODETYPE_OSI|$::NODETYPE_LPAR$/ ) { $att->{bpa} = 0; $att->{type} = "lpar"; @@ -791,26 +791,26 @@ sub resolve { if ( !exists( $att->{parent} )) { return( sprintf( $errmsg{NO_ATTR}, "parent", "ppc" )); } - ############################# - # Get BPA (if any) - ############################# +############################# +# Get BPA (if any) +############################# if (( $request->{command} eq "rvitals" ) && - ( $request->{method} =~ /^all|temp$/ )) { - my ($ent) = $tabs->{ppc}->getNodeAttribs( $att->{parent},['parent']); - - ############################# - # Find MTMS in vpd database - ############################# - if (( defined( $ent )) && exists( $ent->{parent} )) { - my @attrs = qw(mtm serial); - my ($vpd) = $tabs->{vpd}->getNodeAttribs($ent->{parent},\@attrs); + ( $request->{method} =~ /^all|temp$/ )) { + my ($ent) = $tabs->{ppc}->getNodeAttribs( $att->{parent},['parent']); - if ( !defined( $vpd )) { - return( sprintf( $errmsg{NO_UNDEF}, "vpd" )); +############################# +# Find MTMS in vpd database +############################# + if (( defined( $ent )) && exists( $ent->{parent} )) { + my @attrs = qw(mtm serial); + my ($vpd) = $tabs->{vpd}->getNodeAttribs($ent->{parent},\@attrs); + + if ( !defined( $vpd )) { + return( sprintf( $errmsg{NO_UNDEF}, "vpd" )); } - ######################## - # Verify attributes - ######################## +######################## +# Verify attributes +######################## foreach ( @attrs ) { if ( !exists( $vpd->{$_} )) { return( sprintf( $errmsg{NO_ATTR}, $_, "vpd" )); @@ -820,9 +820,9 @@ sub resolve { } } } - ################################# - # Optional and N/A fields - ################################# +################################# +# Optional and N/A fields +################################# elsif ( $type =~ /^$::NODETYPE_FSP$/ ) { $att->{pprofile} = 0; $att->{id} = 0; @@ -841,18 +841,18 @@ sub resolve { $att->{node} = $node; $att->{type} = $type; } - ################################# - # Find MTMS in vpd database - ################################# +################################# +# Find MTMS in vpd database +################################# my @attrs = qw(mtm serial); my ($vpd) = $tabs->{vpd}->getNodeAttribs($att->{node}, \@attrs ); if ( !defined( $vpd )) { return( sprintf( $errmsg{NODE_UNDEF}, "vpd: ($att->{node})" )); } - ################################ - # Verify both vpd attributes - ################################ +################################ +# Verify both vpd attributes +################################ foreach ( @attrs ) { if ( !exists( $vpd->{$_} )) { return( sprintf( $errmsg{NO_ATTR}, $_, "vpd: ($att->{node})" )); @@ -860,17 +860,17 @@ sub resolve { } $att->{fsp} = "$vpd->{mtm}*$vpd->{serial}"; - ################################# - # Verify required attributes - ################################# +################################# +# Verify required attributes +################################# foreach my $at ( @attribs ) { if ( !exists( $att->{$at} )) { return( sprintf( $errmsg{NO_ATTR}, $at, "ppc" )); } } - ################################# - # Build array of data - ################################# +################################# +# Build array of data +################################# foreach ( qw(id pprofile fsp hcp type bpa) ) { push @values, $att->{$_}; } @@ -888,25 +888,25 @@ sub fork_cmd { my $nodes = shift; my $request = shift; - ####################################### - # Pipe childs output back to parent - ####################################### +####################################### +# Pipe childs output back to parent +####################################### my $parent; my $child; pipe $parent, $child; my $pid = xCAT::Utils->xfork; if ( !defined($pid) ) { - ################################### - # Fork error - ################################### +################################### +# Fork error +################################### send_msg( $request, 1, "Fork error: $!" ); return undef; } elsif ( $pid == 0 ) { - ################################### - # Child process - ################################### +################################### +# Child process +################################### close( $parent ); $request->{pipe} = $child; @@ -914,9 +914,9 @@ sub fork_cmd { exit(0); } else { - ################################### - # Parent process - ################################### +################################### +# Parent process +################################### close( $child ); return( $parent, $pid ); } @@ -938,14 +938,14 @@ sub invoke_cmd { my $verbose_log; my @outhash; - ######################################## - # Direct-attached FSP handler - ######################################## +######################################## +# Direct-attached FSP handler +######################################## if ( $hwtype eq "fsp" or $hwtype eq "bpa") { - - #################################### - # Dynamically load FSP module - #################################### + +#################################### +# Dynamically load FSP module +#################################### eval { require xCAT::PPCfsp }; if ( $@ ) { send_msg( $request, 1, $@ ); @@ -953,18 +953,18 @@ sub invoke_cmd { } my @exp = xCAT::PPCfsp::connect( $request, $host ); - #################################### - # Error connecting - #################################### +#################################### +# Error connecting +#################################### if ( ref($exp[0]) ne "LWP::UserAgent" ) { send_msg( $request, 1, $exp[0] ); return; } my $result = xCAT::PPCfsp::handler( $host, $request, \@exp ); - #################################### - # Output verbose Perl::LWP - #################################### +#################################### +# Output verbose Perl::LWP +#################################### if ( $verbose ) { $verbose_log = $exp[3]; @@ -978,61 +978,61 @@ sub invoke_cmd { return; } - ######################################## - # HMC and IVM-managed handler - # Connect to list of remote servers - ######################################## +######################################## +# HMC and IVM-managed handler +# Connect to list of remote servers +######################################## foreach ( split /,/, $host ) { @exp = xCAT::PPCcli::connect( $request, $hwtype, $_ ); - #################################### - # Successfully connected - #################################### +#################################### +# Successfully connected +#################################### if ( ref($exp[0]) eq "Expect" ) { last; } } - ######################################## - # Error connecting - ######################################## +######################################## +# Error connecting +######################################## if ( ref($exp[0]) ne "Expect" ) { send_msg( $request, 1, $exp[0] ); return; } - ######################################## - # Process specific command - ######################################## +######################################## +# Process specific command +######################################## my $result = runcmd( $request, $nodes, \@exp ); - ######################################## - # Close connection to remote server - ######################################## +######################################## +# Close connection to remote server +######################################## xCAT::PPCcli::disconnect( \@exp ); - ######################################## - # Get verbose Expect output - ######################################## +######################################## +# Get verbose Expect output +######################################## if ( $verbose ) { $verbose_log = $exp[6]; } - ######################################## - # Return error - ######################################## +######################################## +# Return error +######################################## if ( ref($result) ne 'ARRAY' ) { send_msg( $request, 1, $$verbose_log.$result ); return; } - ######################################## - # Prepend verbose output - ######################################## +######################################## +# Prepend verbose output +######################################## if ( defined( $verbose_log )) { my %output; $output{data} = [$$verbose_log]; push @outhash, \%output; } - ######################################## - # Send result back to parent process - ######################################## +######################################## +# Send result back to parent process +######################################## if ( @$result[0] eq "FORMATDATA6sK4ci" ) { my $out = $request->{pipe}; @@ -1041,9 +1041,9 @@ sub invoke_cmd { print $out "\nENDOFFREEZE6sK4ci\n"; return; } - ######################################## - # Format and send back to parent - ######################################## +######################################## +# Format and send back to parent +######################################## foreach ( @$result ) { my %output; $output{node}->[0]->{name}->[0] = @$_[0]; @@ -1068,22 +1068,22 @@ sub runcmd { my $hwtype = $request->{hwtype}; my $modname = $modules{$cmd}; - ###################################### - # Command not supported - ###################################### +###################################### +# Command not supported +###################################### if ( !defined( $modname )) { return( ["$cmd not a supported command by $hwtype method"] ); } - ###################################### - # Load specific module - ###################################### +###################################### +# Load specific module +###################################### eval "require $modname"; if ( $@ ) { return( [$@] ); } - ###################################### - # Invoke method - ###################################### +###################################### +# Invoke method +###################################### no strict 'refs'; my $result = ${$modname."::"}{$method}->($request,@_); use strict; @@ -1098,130 +1098,130 @@ sub runcmd { ########################################################################## sub preprocess_request { - my $package = shift; - my $req = shift; - #if ($req->{_xcatdest}) { return [$req]; } #exit if preprocessed - if ($req->{_xcatpreprocessed}->[0] == 1 ) { return [$req]; } - my $callback = shift; - my @requests; + my $package = shift; + my $req = shift; +#if ($req->{_xcatdest}) { return [$req]; } #exit if preprocessed + if ($req->{_xcatpreprocessed}->[0] == 1 ) { return [$req]; } + my $callback = shift; + my @requests; ##################################### # Parse arguments ##################################### - my $opt = parse_args($package, $req, $callback); - if ( ref($opt) eq 'ARRAY' ) - { - send_msg( $req, 1, @$opt ); - return(1); - } - - $req->{opt} = $opt; - - #################################### - # Get hwtype - #################################### - $package =~ s/xCAT_plugin:://; - - #################################### - # Prompt for usage if needed and on MN - #################################### - my $noderange = $req->{node}; #Should be arrayref - my $command = $req->{command}->[0]; - my $extrargs = $req->{arg}; - my @exargs=($req->{arg}); - if (ref($extrargs)) { - @exargs=@$extrargs; - } - if ($ENV{'XCATBYPASS'}){ - my $usage_string=xCAT::Usage->parseCommand($command, @exargs); - if ($usage_string) { - $callback->({data=>[$usage_string]}); - $req = {}; - return ; - } - if (!$noderange) { - $usage_string="Missing noderange"; - $callback->({data=>[$usage_string]}); - $req = {}; - return ; - } - } - - - ################################################################## - # get the HCPs for the LPARs in order to figure out which service - # nodes to send the requests to - ################################################################### - my $hcptab_name = ($package eq "fsp" or $package eq "bpa") ? "ppcdirect" : "ppchcp"; - my $hcptab = xCAT::Table->new( $hcptab_name ); - unless ($hcptab ) { - $callback->({data=>["Cannot open $hcptab_name table"]}); - $req = {}; - return; - } - # Check if each node is hcp - my %hcp_hash=(); - my @missednodes=(); - foreach ( @$noderange ) { - my ($ent) = $hcptab->getAttribs( {hcp=>$_},"hcp" ); - if ( !defined( $ent )) { - push @missednodes, $_; - next; + my $opt = parse_args($package, $req, $callback); + if ( ref($opt) eq 'ARRAY' ) + { + send_msg( $req, 1, @$opt ); + return(1); } - push @{$hcp_hash{$_}{nodes}}, $_; - } - - #check if the left-over nodes are lpars - if (@missednodes > 0) { - my $ppctab = xCAT::Table->new("ppc"); - unless ($ppctab) { - $callback->({data=>["Cannot open ppc table"]}); - $req = {}; - return; + + $req->{opt} = $opt; + +#################################### +# Get hwtype +#################################### + $package =~ s/xCAT_plugin:://; + +#################################### +# Prompt for usage if needed and on MN +#################################### + my $noderange = $req->{node}; #Should be arrayref + my $command = $req->{command}->[0]; + my $extrargs = $req->{arg}; + my @exargs=($req->{arg}); + if (ref($extrargs)) { + @exargs=@$extrargs; } - foreach my $node (@missednodes) { - my $ent=$ppctab->getNodeAttribs($node,['hcp']); - if (defined($ent->{hcp})) { push @{$hcp_hash{$ent->{hcp}}{nodes}}, $node;} - else { - $callback->({data=>["The node $node is neither a hcp nor an lpar"]}); + if ($ENV{'XCATBYPASS'}){ + my $usage_string=xCAT::Usage->parseCommand($command, @exargs); + if ($usage_string) { + $callback->({data=>[$usage_string]}); + $req = {}; + return ; + } + if (!$noderange) { + $usage_string="Missing noderange"; + $callback->({data=>[$usage_string]}); + $req = {}; + return ; + } + } + + +################################################################## +# get the HCPs for the LPARs in order to figure out which service +# nodes to send the requests to +################################################################### + my $hcptab_name = ($package eq "fsp" or $package eq "bpa") ? "ppcdirect" : "ppchcp"; + my $hcptab = xCAT::Table->new( $hcptab_name ); + unless ($hcptab ) { + $callback->({data=>["Cannot open $hcptab_name table"]}); $req = {}; return; - } } - } - - #################### - #suport for "rflash", copy the rpm and xml packages from user-spcefied-directory to /install/packages_fw - ##################### - if ( ( $command eq "rflash" ) && (grep(/commit/,@exargs) == 0 && grep(/recover/,@exargs) == 0)) { - # if ( $command eq "rflash" ) { - preprocess_for_rflash($req,$callback, \@exargs); - } - - - # find service nodes for the HCPs - # build an individual request for each service node - my $service = "xcat"; - my @hcps=keys(%hcp_hash); - my $sn = xCAT::Utils->get_ServiceNode(\@hcps, $service, "MN"); +# Check if each node is hcp + my %hcp_hash=(); + my @missednodes=(); + foreach ( @$noderange ) { + my ($ent) = $hcptab->getAttribs( {hcp=>$_},"hcp" ); + if ( !defined( $ent )) { + push @missednodes, $_; + next; + } + push @{$hcp_hash{$_}{nodes}}, $_; + } - # build each request for each service node - foreach my $snkey (keys %$sn) - { - #$callback->({data=>["The service node $snkey "]}); +#check if the left-over nodes are lpars + if (@missednodes > 0) { + my $ppctab = xCAT::Table->new("ppc"); + unless ($ppctab) { + $callback->({data=>["Cannot open ppc table"]}); + $req = {}; + return; + } + foreach my $node (@missednodes) { + my $ent=$ppctab->getNodeAttribs($node,['hcp']); + if (defined($ent->{hcp})) { push @{$hcp_hash{$ent->{hcp}}{nodes}}, $node;} + else { + $callback->({data=>["The node $node is neither a hcp nor an lpar"]}); + $req = {}; + return; + } + } + } + +#################### +#suport for "rflash", copy the rpm and xml packages from user-spcefied-directory to /install/packages_fw +##################### + if ( ( $command eq "rflash" ) && (grep(/commit/,@exargs) == 0 && grep(/recover/,@exargs) == 0)) { +# if ( $command eq "rflash" ) { + preprocess_for_rflash($req,$callback, \@exargs); +} + + +# find service nodes for the HCPs +# build an individual request for each service node +my $service = "xcat"; +my @hcps=keys(%hcp_hash); +my $sn = xCAT::Utils->get_ServiceNode(\@hcps, $service, "MN"); + +# build each request for each service node +foreach my $snkey (keys %$sn) +{ +#$callback->({data=>["The service node $snkey "]}); my $reqcopy = {%$req}; $reqcopy->{'_xcatdest'} = $snkey; $reqcopy->{_xcatpreprocessed}->[0] = 1; my $hcps1=$sn->{$snkey}; my @nodes=(); foreach (@$hcps1) { - push @nodes, @{$hcp_hash{$_}{nodes}}; + push @nodes, @{$hcp_hash{$_}{nodes}}; } $reqcopy->{node} = \@nodes; - #print "nodes=@nodes\n"; +#print "nodes=@nodes\n"; push @requests, $reqcopy; - } - return \@requests; +} +return \@requests; } #################################### # Parse arguments @@ -1247,99 +1247,99 @@ sub parse_args $req->{hwtype} = $package; $req->{callback} = $callback; $req->{method} = "parse_args"; - + my $opt = runcmd( $req); - + $req->{command} = [ $command]; $req->{stdin} = [ $stdin]; return $opt; } sub preprocess_for_rflash { - my $req = shift; - my $callback = shift; - my $exargs = shift; + my $req = shift; + my $callback = shift; + my $exargs = shift; - my $packages_fw = "/install/packages_fw"; - my $c = 0; - my $packages_d; - foreach (@$exargs) { - $c++; - if($_ eq "-p") { - $packages_d = $$exargs[$c]; - last; - } - } - if($packages_d ne $packages_fw ) { - $$exargs[$c] = $packages_fw; - if(! -d $packages_d) { - $callback->({data=>["The directory $packages_d doesn't exist!"]}); - $req = (); - return; - } - - #print "opening directory and reading names\n"; - opendir DIRHANDLE, $packages_d; - my @dirlist= readdir DIRHANDLE; - closedir DIRHANDLE; + my $packages_fw = "/install/packages_fw"; + my $c = 0; + my $packages_d; + foreach (@$exargs) { + $c++; + if($_ eq "-p") { + $packages_d = $$exargs[$c]; + last; + } + } + if($packages_d ne $packages_fw ) { + $$exargs[$c] = $packages_fw; + if(! -d $packages_d) { + $callback->({data=>["The directory $packages_d doesn't exist!"]}); + $req = (); + return; + } - @dirlist = File::Spec->no_upwards( @dirlist ); +#print "opening directory and reading names\n"; + opendir DIRHANDLE, $packages_d; + my @dirlist= readdir DIRHANDLE; + closedir DIRHANDLE; - # Make sure we have some files to process - # - if( !scalar( @dirlist ) ) { - $callback->({data=>["The directory $packages_d is empty !"]}); - $req = (); - return; - } - - #Find the rpm lic file - my @rpmlist = grep /\.rpm$/, @dirlist; - my @xmllist = grep /\.xml$/, @dirlist; - if( @rpmlist == 0 | @xmllist == 0) { - $callback->({data=>["There isn't any rpm and xml files in the directory $packages_d!"]}); - $req = (); - return; - } - - my $rpm_list = join(" ", @rpmlist); - my $xml_list = join(" ", @xmllist); - - my $cmd; - if( -d $packages_fw) { - $cmd = "rm -rf $packages_fw"; - xCAT::Utils->runcmd($cmd, 0); - if ($::RUNCMD_RC != 0) - { - $callback->({data=>["Failed to remove the old packages in $packages_fw."]}); - $req = (); - return; + @dirlist = File::Spec->no_upwards( @dirlist ); - } - } - - $cmd = "mkdir $packages_fw"; - xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) - { - $callback->({data=>["$cmd failed."]}); - $req = (); - return; +# Make sure we have some files to process +# + if( !scalar( @dirlist ) ) { + $callback->({data=>["The directory $packages_d is empty !"]}); + $req = (); + return; + } - } - - $cmd = "cp $packages_d/*.rpm $packages_d/*.xml $packages_fw"; - xCAT::Utils->runcmd($cmd, 0); - if ($::RUNCMD_RC != 0) - { - $callback->({data=>["$cmd failed."]}); - $req = (); - return; +#Find the rpm lic file + my @rpmlist = grep /\.rpm$/, @dirlist; + my @xmllist = grep /\.xml$/, @dirlist; + if( @rpmlist == 0 | @xmllist == 0) { + $callback->({data=>["There isn't any rpm and xml files in the directory $packages_d!"]}); + $req = (); + return; + } - } + my $rpm_list = join(" ", @rpmlist); + my $xml_list = join(" ", @xmllist); - $req->{arg} = $exargs; - } + my $cmd; + if( -d $packages_fw) { + $cmd = "rm -rf $packages_fw"; + xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) + { + $callback->({data=>["Failed to remove the old packages in $packages_fw."]}); + $req = (); + return; + + } + } + + $cmd = "mkdir $packages_fw"; + xCAT::Utils->runcmd("$cmd", 0); + if ($::RUNCMD_RC != 0) + { + $callback->({data=>["$cmd failed."]}); + $req = (); + return; + + } + + $cmd = "cp $packages_d/*.rpm $packages_d/*.xml $packages_fw"; + xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) + { + $callback->({data=>["$cmd failed."]}); + $req = (); + return; + + } + + $req->{arg} = $exargs; + } } ########################################################################## @@ -1351,28 +1351,28 @@ sub process_request { my $req = shift; my $callback = shift; - #################################### - # Get hwtype - #################################### +#################################### +# Get hwtype +#################################### $package =~ s/xCAT_plugin:://; - #################################### - # Build hash to pass around - #################################### +#################################### +# Build hash to pass around +#################################### my $request = {%$req}; $request->{command} = $req->{command}->[0]; $request->{stdin} = $req->{stdin}->[0]; $request->{hwtype} = $package; $request->{callback}= $callback; - #################################### - # Option -V for verbose output - #################################### +#################################### +# Option -V for verbose output +#################################### if ( exists( $request->{opt}->{V} )) { $request->{verbose} = 1; } - #################################### - # Process remote command - #################################### +#################################### +# Process remote command +#################################### process_command( $request ); } @@ -1385,7 +1385,7 @@ sub sshcmds_on_hmc my $user = shift; my $password = shift; my @cmds = @_; - + my %handled; my @data; my @exp; @@ -1410,11 +1410,11 @@ sub sshcmds_on_hmc my $valid_ip; foreach my $individual_ip ( split /,/, $ip ) { - ################################ - # Get userid and password - ################################ - my @cred = xCAT::PPCdb::credentials( $individual_ip, "hmc" ); - $request{$individual_ip}{cred} = \@cred; +################################ +# Get userid and password +################################ + my @cred = xCAT::PPCdb::credentials( $individual_ip, "hmc" ); + $request{$individual_ip}{cred} = \@cred; @exp = xCAT::PPCcli::connect( \%request, 'hmc', $individual_ip); #################################### @@ -1494,10 +1494,10 @@ sub updconf_in_asm my $valid_ip; my @exp; foreach my $individual_ip ( split /,/, $ip ) { - ################################ - # Get userid and password - ################################ - my @cred = xCAT::PPCdb::credentials( $individual_ip, lc($target_dev->{'type'})); +################################ +# Get userid and password +################################ + my @cred = xCAT::PPCdb::credentials( $individual_ip, lc($target_dev->{'type'})); $request{$individual_ip}{cred} = \@cred; $request{node} = [$individual_ip];