From 8096b2141c84d31186bd8004bc53f5e65470432d Mon Sep 17 00:00:00 2001 From: jjhua Date: Fri, 26 Feb 2010 09:42:41 +0000 Subject: [PATCH] 1.FSPAPI supports for mkhwconn and rmhwconn 2. move the invoking fsp-api function in every FSPxxx.pm to Utils.pm git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5308 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/FSPconn.pm | 564 +++++++++++++++++++++++++++++++ perl-xCAT/xCAT/FSPflash.pm | 133 ++------ perl-xCAT/xCAT/FSPinv.pm | 96 +----- perl-xCAT/xCAT/FSPpower.pm | 251 +++++--------- perl-xCAT/xCAT/FSPvitals.pm | 90 +---- perl-xCAT/xCAT/PPCrflash.pm | 4 +- xCAT-server/lib/perl/xCAT/PPC.pm | 12 +- 7 files changed, 712 insertions(+), 438 deletions(-) create mode 100644 perl-xCAT/xCAT/FSPconn.pm diff --git a/perl-xCAT/xCAT/FSPconn.pm b/perl-xCAT/xCAT/FSPconn.pm new file mode 100644 index 000000000..9b0cc8eae --- /dev/null +++ b/perl-xCAT/xCAT/FSPconn.pm @@ -0,0 +1,564 @@ +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html + +package xCAT::FSPconn; +use strict; +use Getopt::Long; +use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR); +use xCAT::Usage; +use Data::Dumper; +use xCAT::Utils; + +############################################## +# Globals +############################################## +my %method = ( + mkhwconn => \&mkhwconn_parse_args, +# lshwconn => \&lshwconn_parse_args, + rmhwconn => \&rmhwconn_parse_args, +); +########################################################################## +# Parse the command line for options and operands +########################################################################## +sub parse_args { + + my $request = shift; + my $cmd = $request->{command}; + ############################### + # Invoke correct parse_args + ############################### + + my $result = $method{$cmd}( $request, $request->{arg}); + return( $result ); +} + +########################################################################## +# Parse arguments for mkhwconn +########################################################################## +sub mkhwconn_parse_args +{ + my $request = shift; + my $args = shift; + my %opt = (); + + local *usage = sub { + my $usage_string = xCAT::Usage->getUsage("mkhwconn"); + return( [ $_[0], $usage_string] ); + }; + ############################################# + # Process command-line arguments + ############################################# + if ( !defined( $args )) { + return(usage( "No command specified" )); + } + + local @ARGV = ref($args) eq 'ARRAY'? @$args:(); + $Getopt::Long::ignorecase = 0; + Getopt::Long::Configure( "bundling" ); + + if ( !GetOptions( \%opt, qw(V|verbose h|help t T=i p=s P=s) )) { + return( usage() ); + } + return usage() if ( exists $opt{h}); + + if ( exists $opt{t} and exists $opt{p}) + { + return( usage('Flags -t and -p cannot be used together.')); + } + + if ( exists $opt{P} and ! exists $opt{p}) + { + return( usage('Flags -P can only be used when flag -p is specified.')); + } + + ########################################## + # Check if CECs are controlled by a frame + ########################################## + my $nodes = $request->{node}; + my $ppctab = xCAT::Table->new( 'ppc' ); + my $nodetypetab = xCAT::Table->new( 'nodetype'); + my $vpdtab = xCAT::Table->new( 'vpd'); + my @bpa_ctrled_nodes = (); + my @no_type_nodes = (); + my @frame_members = (); + if ( $ppctab) + { + for my $node ( @$nodes) + { + my $node_parent = undef; + my $nodetype = undef; + my $nodetype_hash = $nodetypetab->getNodeAttribs( $node,[qw(nodetype)]); + my $node_parent_hash = $ppctab->getNodeAttribs( $node,[qw(parent)]); + $nodetype = $nodetype_hash->{nodetype}; + $node_parent = $node_parent_hash->{parent}; + if ( !$nodetype) + { + push @no_type_nodes, $node; + next; + } + + if ( $nodetype eq 'fsp' and + $node_parent and + $node_parent ne $node) + { + push @bpa_ctrled_nodes, $node; + } + + if ( $nodetype eq 'bpa') + { + my $my_frame_bpa_cec = getFrameMembers( $node, $vpdtab, $ppctab); + push @frame_members, @$my_frame_bpa_cec; + } + } + } + + if (scalar(@no_type_nodes)) + { + my $tmp_nodelist = join ',', @no_type_nodes; + return ( usage("Attribute nodetype.nodetype cannot be found for node(s) $tmp_nodelist")); + } + + if (scalar(@bpa_ctrled_nodes)) + { + my $tmp_nodelist = join ',', @bpa_ctrled_nodes; + return ( usage("Node(s) $tmp_nodelist is(are) controlled by BPA.")); + } + + if ( scalar( @frame_members)) + { + my @all_nodes = xCAT::Utils::get_unique_members( @$nodes, @frame_members); + $request->{node} = \@all_nodes; + } + # Set HW type to 'hmc' anyway, so that this command will not going to + # PPCfsp.pm + # $request->{ 'hwtype'} = 'hmc'; + $request->{method} = 'mkhwconn'; + return( \%opt); +} + +#################################################### +# Get frame members +#################################################### +#ppc/vpd nodes cache +my @all_ppc_nodes; +my @all_vpd_nodes; +sub getFrameMembers +{ + my $node = shift; #this a BPA node + my $vpdtab = shift; + my $ppctab = shift; + my @frame_members = (); + my @bpa_nodes = (); + my $vpdhash = $vpdtab->getNodeAttribs( $node, [qw(mtm serial)]); + my $mtm = $vpdhash->{mtm}; + my $serial = $vpdhash->{serial}; + if ( scalar( @all_vpd_nodes) == 0) + { + @all_vpd_nodes = $vpdtab->getAllNodeAttribs( ['node', 'mtm', 'serial']); + } + for my $vpd_node (@all_vpd_nodes) + { + if ( $vpd_node->{'mtm'} eq $mtm and $vpd_node->{'serial'} eq $serial) + { + push @frame_members, $vpd_node->{'node'}; + push @bpa_nodes, $vpd_node->{'node'}; + } + } + + if ( scalar( @all_ppc_nodes) == 0) + { + @all_ppc_nodes = $ppctab->getAllNodeAttribs( ['node', 'parent']); + } + for my $bpa_node (@bpa_nodes) + { + for my $ppc_node (@all_ppc_nodes) + { + if ( $ppc_node->{parent} eq $bpa_node) + { + push @frame_members, $ppc_node->{'node'}; + } + } + } + return \@frame_members; +} + +########################################################################## +# Parse arguments for lshwconn --- This function isn't implemented and used. +########################################################################## +sub lshwconn_parse_args +{ + my $request = shift; + my $args = shift; + my %opt = (); + + local *usage = sub { + my $usage_string = xCAT::Usage->getUsage("lshwconn"); + return( [ $_[0], $usage_string] ); + }; +############################################# +# Get options in command line +############################################# + local @ARGV = ref($args) eq 'ARRAY'? @$args:(); + $Getopt::Long::ignorecase = 0; + Getopt::Long::Configure( "bundling" ); + + if ( !GetOptions( \%opt, qw(V|verbose h|help) )) { + return( usage() ); + } + return usage() if ( exists $opt{h}); + + ############################################# + # Process command-line arguments + ############################################# + if ( scalar( @ARGV)) { + return(usage( "No additional flag is support by this command" )); + } + my $nodetypetab = xCAT::Table->new('nodetype'); + if (! $nodetypetab) + { + return( ["Failed to open table 'nodetype'.\n"]); + } + my $nodehmtab = xCAT::Table->new('nodehm'); + if (! $nodehmtab) + { + return( ["Failed to open table 'nodehm'.\n"]); + } + + my $nodetype; + for my $node ( @{$request->{node}}) + { + my $ent = $nodetypetab->getNodeAttribs( $node, [qw(nodetype)]); + my $nodehm = $nodehmtab->getNodeAttribs( $node, [qw(mgt)]); + if ( ! $ent) + { + return( ["Failed to get node type for node $node.\n"]); + } + if ( ! $nodehm) + { + return( ["Failed to get nodehm.mgt value for node $node.\n"]); + } + if ( $ent->{nodetype} ne 'hmc' + and $ent->{nodetype} ne 'fsp' + and $ent->{nodetype} ne 'bpa') + { + return( ["Node type $ent->{nodetype} is not supported for this command.\n"]); + } + if ( ! $nodetype) + { + $nodetype = $ent->{nodetype}; + } + else + { + if ( $nodetype ne $ent->{nodetype}) + { + return( ["Cannot support multiple node types in this command line.\n"]); + } + } + } + + $request->{nodetype} = $nodetype; + + $request->{method} = 'lshwconn'; + return( \%opt); +} + +########################################################################## +# Parse arguments for rmhwconn +########################################################################## +sub rmhwconn_parse_args +{ + my $request = shift; + my $args = shift; + my %opt = (); + + local *usage = sub { + my $usage_string = xCAT::Usage->getUsage("rmhwconn"); + return( [ $_[0], $usage_string] ); + }; + ############################################# + # Get options in command line + ############################################# + local @ARGV = ref($args) eq 'ARRAY'? @$args:(); + $Getopt::Long::ignorecase = 0; + Getopt::Long::Configure( "bundling" ); + + if ( !GetOptions( \%opt, qw(V|verbose h|help T=i) )) { + return( usage() ); + } + return usage() if ( exists $opt{h}); + + ############################################# + # Process command-line arguments + ############################################# + if ( scalar (@ARGV)) { + return(usage( "No additional flag is support by this command" )); + } + ########################################## + # Check if CECs are controlled by a frame + ########################################## + my $nodes = $request->{node}; + my $ppctab = xCAT::Table->new( 'ppc' ); + return( ["Failed to open table 'ppc'.\n"]) if ( ! $ppctab); + my $nodetypetab = xCAT::Table->new( 'nodetype'); + return( ["Failed to open table 'nodetype'.\n"]) if ( ! $nodetypetab); + my $vpdtab = xCAT::Table->new( 'vpd'); + return( ["Failed to open table 'vpd'.\n"]) if ( ! $vpdtab); + my $nodehmtab = xCAT::Table->new('nodehm'); + return( ["Failed to open table 'nodehm'.\n"]) if (! $nodehmtab); + my @bpa_ctrled_nodes = (); + my @no_type_nodes = (); + my @frame_members = (); + for my $node ( @$nodes) + { + my $nodehm = $nodehmtab->getNodeAttribs( $node, [qw(mgt)]); + if ( ! $nodehm) + { + return( ["Failed to get nodehm.mgt value for node $node.\n"]); + } + + my $node_parent = undef; + my $nodetype = undef; + my $nodetype_hash = $nodetypetab->getNodeAttribs( $node,[qw(nodetype)]); + my $node_parent_hash = $ppctab->getNodeAttribs( $node,[qw(parent)]); + $nodetype = $nodetype_hash->{nodetype}; + $node_parent = $node_parent_hash->{parent}; + if ( !$nodetype) + { + push @no_type_nodes, $node; + next; + } + + if ( $nodetype eq 'fsp' and + $node_parent and + $node_parent ne $node) + { + push @bpa_ctrled_nodes, $node; + } + + if ( $nodetype eq 'bpa') + { + my $my_frame_bpa_cec = getFrameMembers( $node, $vpdtab, $ppctab); + push @frame_members, @$my_frame_bpa_cec; + } + } + + if (scalar(@no_type_nodes)) + { + my $tmp_nodelist = join ',', @no_type_nodes; + return ( usage("Attribute nodetype.nodetype cannot be found for node(s) $tmp_nodelist")); + } + + if (scalar(@bpa_ctrled_nodes)) + { + my $tmp_nodelist = join ',', @bpa_ctrled_nodes; + return ( usage("Node(s) $tmp_nodelist is(are) controlled by BPA.")); + } + + if ( scalar( @frame_members)) + { + my @all_nodes = xCAT::Utils::get_unique_members( @$nodes, @frame_members); + $request->{node} = \@all_nodes; + } + $request->{method} = 'rmhwconn'; + return( \%opt); +} + + +########################################################################## +# Create connection for CECs/BPAs +########################################################################## +sub mkhwconn +{ + my $request = shift; + my $hash = shift; + #my $exp = shift; + #my $hwtype = @$exp[2]; + my $opt = $request->{opt}; + my @value = (); + my $Rc = undef; + my $tooltype = $opt->{T}; + + for my $cec_bpa ( keys %$hash) + { + my $node_hash = $hash->{$cec_bpa}; + for my $node_name ( keys %$node_hash) + { + my $d = $node_hash->{$node_name}; + + my ( undef,undef,$mtms,undef,$type) = @$d; + my ($user, $passwd); + if ( exists $opt->{P}) + { + ($user, $passwd) = ('HMC', $opt->{P}); + } + else + { + ($user, $passwd) = xCAT::PPCdb::credentials( $node_name, $type,'HMC'); + if ( !$passwd) + { + push @value, [$node_name, "Cannot get password of userid 'HMC'. Please check table 'passwd' or 'ppcdirect'.",1]; + next; + } + + } + + my $res = xCAT::Utils::fsp_api_action( $node_name, $d, "add_connection", $tooltype ); + $Rc = @$res[2]; + if( @$res[1] ne "") { + push @value, [$node_name, @$res[1], $Rc]; + } + + } + } + return \@value; +} +########################################################################## +# List connection status for CECs/BPAs -- This function isn't impletmented and used. +########################################################################## +sub lshwconn +{ + my $request = shift; + my $hash = shift; + my $exp = shift; + my $hwtype = @$exp[2]; + my $opt = $request->{opt}; + my @value = (); + my $Rc = undef; + + + my $hosttab = xCAT::Table->new( 'hosts' ); + my $res = xCAT::PPCcli::lssysconn( $exp, "all" ); + $Rc = shift @$res; + if ( $request->{nodetype} eq 'hmc') + { + if ( $Rc) + { + push @value, [$exp->[3], $res->[0], $Rc]; + return \@value; + } + my $vpdtab = xCAT::Table->new('vpd'); + my @vpdentries = $vpdtab->getAllAttribs(qw(node serial mtm)); + my %node_vpd_hash; + for my $vpdent ( @vpdentries) + { + if ( $vpdent->{node} and $vpdent->{serial} and $vpdent->{mtm}) + { + $node_vpd_hash{"$vpdent->{mtm}*$vpdent->{serial}"} = $vpdent->{node}; + } + } + my %node_ppc_hash; + my $ppctab = xCAT::Table->new('ppc'); + for my $node ( values %node_vpd_hash) + { + my $node_parent_hash = $ppctab->getNodeAttribs( $node, [qw(parent)]); + $node_ppc_hash{$node} = $node_parent_hash->{parent}; + } + + for my $r ( @$res) + { + $r =~ s/type_model_serial_num=([^,]*),//; + my $mtms = $1; + $r =~ s/resource_type=([^,]*),//; + $r =~ s/sp=.*?,//; + $r =~ s/sp_phys_loc=.*?,//; + my $node_name; + if ( exists $node_vpd_hash{$mtms}) + { + $node_name = $node_vpd_hash{$mtms}; + $r = "hcp=$exp->[3],parent=$node_ppc_hash{$node_name}," . $r; + } + else + { + $node_name = $mtms; + $r = "hcp=$exp->[3],parent=," . $r; + } + push @value, [ $node_name, $r, $Rc]; + } + } + else + { + for my $cec_bpa ( keys %$hash) + { + my $node_hash = $hash->{$cec_bpa}; + for my $node_name (keys %$node_hash) + { + ############################################ + # If lssysconn failed, put error into all + # nodes' return values + ############################################ + if ( $Rc ) + { + push @value, [$node_name, @$res[0], $Rc]; + next; + } + + ############################ + # Get IP address + ############################ + my $node_ip = undef; + if ( $hosttab) + { + my $node_ip_hash = $hosttab->getNodeAttribs( $node_name,[qw(ip)]); + $node_ip = $node_ip_hash->{ip}; + } + if (!$node_ip) + { + push @value, [$node_name, $node_ip, $Rc]; + next; + } + + if ( my @res_matched = grep /\Qipaddr=$node_ip,\E/, @$res) + { + for my $r ( @res_matched) + { + $r =~ s/\Qtype_model_serial_num=$cec_bpa,\E//; +# $r =~ s/\Qresource_type=$type,\E//; + $r =~ s/sp=.*?,//; + $r =~ s/sp_phys_loc=.*?,//; + push @value, [$node_name, $r, $Rc]; + } + } + else + { + push @value, [$node_name, 'Connection not found', 1]; + } + } + } + } + return \@value; +} + +########################################################################## +# Remove connection for CECs/BPAs to Hardware servers +########################################################################## +sub rmhwconn +{ + my $request = shift; + my $hash = shift; + #my $exp = shift; + #my $hwtype = @$exp[2]; + my $opt = $request->{opt}; + my @value = (); + my $Rc = undef; + my $tooltype = $opt->{T}; + + for my $cec_bpa ( keys %$hash) + { + my $node_hash = $hash->{$cec_bpa}; + for my $node_name (keys %$node_hash) + { + my $d = $node_hash->{$node_name}; + + my ( undef,undef,undef,undef,$type) = @$d; + + my $res = xCAT::Utils::fsp_api_action( $node_name, $d, "rm_connection", $tooltype ); + $Rc = @$res[2]; + if( @$res[1] ne "") { + push @value, [$node_name, @$res[1], $Rc]; + } + + } + } + return \@value; +} + +1; diff --git a/perl-xCAT/xCAT/FSPflash.pm b/perl-xCAT/xCAT/FSPflash.pm index 10d4a602d..3cd303eb1 100644 --- a/perl-xCAT/xCAT/FSPflash.pm +++ b/perl-xCAT/xCAT/FSPflash.pm @@ -320,7 +320,7 @@ sub fork_cmd { close( $parent ); $pipe = $child; - $res = action( $node_name, $attrs, $action ); + $res = xCAT::Utils::fsp_api_action( $node_name, $attrs, $action ); print "res\n"; print Dumper($res); my %output; @@ -347,93 +347,6 @@ sub fork_cmd { } - - -sub action { - my $node_name = shift; - my $attrs = shift; - my $action = shift; -# my $user = "HMC"; -# my $password = "abc123"; -# my $fsp_api ="/opt/xcat/sbin/fsp-api"; - my $fsp_api = ($::XCATROOT) ? "$::XCATROOT/sbin/fsp-api" : "/opt/xcat/sbin/fsp-api"; - my $id = 1; - my $fsp_name = (); - my $fsp_ip = (); - my $target_list=(); - my $type = (); # fsp|lpar -- 0. BPA -- 1 - my @result; - my $Rc = 0 ; - my %outhash = (); - my $res; - - $id = $$attrs[0]; - $fsp_name = $$attrs[3]; - - my %objhash = (); - $objhash{$fsp_name} = "node"; - my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash); - my $password = $myhash{$fsp_name}{"passwd.hscroot"}; - print "fspname:$fsp_name password:$password\n"; - print Dumper(%myhash); - if(!$password ) { - $res = "The password.hscroot of $fsp_name in ppcdirect table is empty"; - return ([$node_name, $res, -1]); - } - # my $user = "HMC"; - my $user = "hscroot"; -# my $cred = $request->{$fsp_name}{cred}; -# my $user = @$cred[0]; -# my $password = @$cred[1]; - - if($action =~ /^commit$/) { $action = "code_commit"} - if($action =~ /^recover$/) { $action = "code_reject"} - if($action =~ /^disruptive$/) { $action = "code_update"} - if($action =~ /^concurrent$/) { - $res = "\'$action\' option not supported in FSPflash.Please use disruptive mode"; - return ([$node_name, $res, -1]); - } - - - if($$attrs[4] =~ /^fsp$/ || $$attrs[4] =~ /^lpar$/ ) { - $type = 0; - $id = 0; - } else { - $type = 1; - } - - ############################ - # Get IP address - ############################ - $fsp_ip = xCAT::Utils::get_hdwr_ip($fsp_name); - if($fsp_ip == -1) { - $res = "Failed to get the $fsp_name\'s ip"; - return ([$node_name, $res, -1]); - } - - print "fsp name: $fsp_name\n"; - print "fsp ip: $fsp_ip\n"; - - my $cmd = "$fsp_api -a $action -u $user -p $password -t $type:$fsp_ip:$id:$node_name: -d /install/packages_fw/"; - - print "cmd: $cmd\n"; - $SIG{CHLD} = (); - my $res = xCAT::Utils->runcmd($cmd, -1); - #my $res = "good"; - $Rc = $::RUNCMD_RC; - #$Rc = -1; - ################## - # output the prompt - ################# - #$outhash{ $node_name } = $res; - - return( [$node_name,$res, $Rc] ); - -} - - - - ########################## #Performs Licensed Internal Code (LIC) update support for HMC-attached POWER5 and POWER6 Systems ########################### @@ -449,11 +362,12 @@ sub rflash { my $housekeeping = $request->{housekeeping}; $packages_dir = $request->{opt}->{p}; $activate = $request->{opt}->{activate}; - + print "housekeeping:$housekeeping\n"; my $mtms; my $h; my $user; - + my $action; + my $tmp_file; #the file handle of the stanza my $rpm_file; my $xml_file; @@ -495,13 +409,13 @@ sub rflash { #For one mtms, it just needs to do the operation one time. # $flag += 1; - if($flag > 1) { - last; - } + if($flag > 1) { + last; + } - $mtms =~ /(\w+)-(\w+)\*(\w+)/; - my $mtm = "$1-$2"; - my $serial = $3; + $mtms =~ /(\w+)-(\w+)\*(\w+)/; + my $mtm = "$1-$2"; + my $serial = $3; while (my ($name,$d) = each(%$h) ) { @@ -509,10 +423,10 @@ sub rflash { if($flag2 > 1) { last; } - my $values = xCAT::FSPinv::action( $name, $d, "list_firmware_level"); + my $values = xCAT::Utils::fsp_api_action( $name, $d, "list_firmware_level"); # my $level = xCAT::PPCcli::lslic( $exp, $d, $timeout ); - my $Rc = shift(@$values); - my $level = $$values[0]->{$name}; + my $Rc = @$values[2]; + my $level = @$values[1]; ##################################### # Return error ##################################### @@ -536,6 +450,15 @@ sub rflash { $active_level = $1; &dpush( \@value, [$name,"$mtms :activated level:$1"]); } + + if($housekeeping =~ /^commit$/) { $action = "code_commit"} + if($housekeeping =~ /^recover$/) { $action = "code_reject"} + if($activate =~ /^disruptive$/) { $action = "code_update"} + if($activate =~ /^concurrent$/) { + my $res = "\'concurrent\' option not supported in FSPflash.Please use disruptive mode"; + push @value, [$name, $res, -1]; + next; + } my $msg; if(!defined($housekeeping)) { @@ -589,12 +512,8 @@ sub rflash { my($hcp, $id) = get_hcp_id($name2); my @dt = ($id, @$d[1], $mtms, $hcp, @$d[4], 0); - if( defined( $housekeeping ) ) { - ($pipe) = fork_cmd( $name2, \@dt, $housekeeping ); + ($pipe) = fork_cmd( $name2, \@dt, $action ); - } else { - ($pipe) = fork_cmd( $name2, \@dt, $activate); - } if ( $pipe ) { $fds->add( $pipe ); $children++; @@ -602,12 +521,8 @@ sub rflash { sleep(5); } $pipe = undef; - if( defined( $housekeeping ) ) { - ($pipe) = fork_cmd( $name, $d, $housekeeping ); + ($pipe) = fork_cmd( $name, $d, $action ); - } else { - ($pipe) = fork_cmd( $name, $d, $activate ); - } if ( $pipe ) { $fds->add( $pipe ); $children++; diff --git a/perl-xCAT/xCAT/FSPinv.pm b/perl-xCAT/xCAT/FSPinv.pm index 836647b6d..34af133e7 100644 --- a/perl-xCAT/xCAT/FSPinv.pm +++ b/perl-xCAT/xCAT/FSPinv.pm @@ -84,17 +84,18 @@ sub firmware { ########## if(@$d[4] eq "lpar") { @$d[4] = "fsp"; + @$d[0] = 0; } - my $values = action( $name, $d, "list_firmware_level"); - my $Rc = shift(@$values); - my $data = @$values[0]; + my $values = xCAT::Utils::fsp_api_action( $name, $d, "list_firmware_level"); + my $Rc = @$values[2]; + my $data = @$values[1]; #print "values"; #print Dumper($values); - ##################################### - # Return error - ##################################### - if ( $Rc != SUCCESS ) { - push @result, [$name,$data->{$name},$Rc]; + ##################################### + # Return error + ##################################### + if ( $Rc != SUCCESS ) { + push @result, [$name,$data,$Rc]; next; } @@ -103,7 +104,7 @@ sub firmware { ##################################### my $val; foreach $val ( @licmap ) { - if ( $data->{$name} =~ /@$val[0]=(\w+)/ ) { + if ( $data =~ /@$val[0]=(\w+)/ ) { push @result, [$name,"@$val[1]: $1",$Rc]; } } @@ -112,83 +113,6 @@ sub firmware { return( \@result ); } -########################################################################## -# invoke the fsp-api command -########################################################################## -sub action { - my $node_name = shift; - my $attrs = shift; - my $action = shift; -# my $fsp_api ="/opt/xcat/sbin/fsp-api"; - my $fsp_api = ($::XCATROOT) ? "$::XCATROOT/sbin/fsp-api" : "/opt/xcat/sbin/fsp-api"; - my $id = 1; - my $fsp_name = (); - my $fsp_ip = (); - my $target_list=(); - my $type = (); # fsp|lpar -- 0. BPA -- 1 - my @result; - my $Rc = 0 ; - my %outhash = (); - - $id = $$attrs[0]; - $fsp_name = $$attrs[3]; - - my %objhash = (); - $objhash{$fsp_name} = "node"; - my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash); - my $password = $myhash{$fsp_name}{"passwd.hscroot"}; - #print "fspname:$fsp_name password:$password\n"; - #print Dumper(%myhash); - if(!$password ) { - $outhash{$node_name} = "The password.hscroot of $fsp_name in ppcdirect table is empty"; - return ([-1, \%outhash]); - } - # my $user = "HMC"; - my $user = "hscroot"; -# my $cred = $request->{$fsp_name}{cred}; -# my $user = @$cred[0]; -# my $password = @$cred[1]; - - if($$attrs[4] =~ /^lpar$/) { - $type = 0; - $id = 1; - } elsif($$attrs[4] =~ /^fsp$/) { - $type = 0; - } else { - $type = 1; - } - - ############################ - # Get IP address - ############################ - $fsp_ip = xCAT::Utils::get_hdwr_ip($fsp_name); - if($fsp_ip == -1) { - $outhash{$node_name} = "Failed to get the $fsp_name\'s ip"; - return ([-1, \%outhash]); - } - - - print "fsp name: $fsp_name\n"; - print "fsp ip: $fsp_ip\n"; - - my $cmd = "$fsp_api -a $action -u $user -p $password -t $type:$fsp_ip:$id:$node_name:"; - - print "cmd: $cmd\n"; - $SIG{CHLD} = (); - my $res = xCAT::Utils->runcmd($cmd, -1); - if($::RUNCMD_RC != 0){ - $Rc = -1; - } else { - $Rc = SUCCESS; - } - - $outhash{ $node_name } = $res; - - return( [$Rc,\%outhash] ); - -} - - ########################################################################## # Returns firmware version diff --git a/perl-xCAT/xCAT/FSPpower.pm b/perl-xCAT/xCAT/FSPpower.pm index fa1f7eae1..9daa698f2 100644 --- a/perl-xCAT/xCAT/FSPpower.pm +++ b/perl-xCAT/xCAT/FSPpower.pm @@ -50,39 +50,44 @@ sub powercmd_boot { { my $d = $hash->{$node_name}; - my $stat = action ($node_name, $d, "state"); + if (!($$d[4] =~ /^lpar$/)) { + push @output, [$node_name, "\'boot\' command not supported for CEC or BPA", -1 ]; + #return (\@output); + next; + } + + my $res = xCAT::Utils::fsp_api_action ($node_name, $d, "state"); print "In boot, state\n"; - print Dumper($stat); - my $Rc = shift(@$stat); - my $data = @$stat[0]; - my $type = @$d[4]; - my $id = ($type=~/^(fsp|bpa)$/) ? $type : @$d[0]; + print Dumper($res); + my $Rc = @$res[2]; + my $data = @$res[1]; + #my $type = @$d[4]; + #my $id = ($type=~/^(fsp|bpa)$/) ? $type : @$d[0]; - ################################## + ################################## # Output error ################################## if ( $Rc != SUCCESS ) { push @output, [$node_name,$data,$Rc]; next; } - my $t = $data->{$node_name}; - print "boot: $t \n"; + ################################## # Convert state to on/off ################################## - my $state = power_status($data->{$node_name}); + my $state = power_status($data); print "boot:state:$state\n"; - my $op = ($state =~ /^off$/) ? "on" : "reset"; - $stat = action ($node_name, $d, $op); + my $op = ($state =~ /^off$/) ? "on" : "reset"; + $res = xCAT::Utils::fsp_api_action ($node_name, $d, $op); # @output ... - $Rc = shift(@$stat); - $data = @$stat[0]; - if ( $Rc != SUCCESS ) { - push @output, [$node_name,$data->{$node_name},$Rc]; - next; + $Rc = @$res[2]; + $data = @$res[1]; + if ( $Rc != SUCCESS ) { + push @output, [$node_name,$data,$Rc]; + next; } - push @output,[$node_name, "SUCCESS", 0]; + push @output,[$node_name, "Success", 0]; } return( \@output ); @@ -99,7 +104,8 @@ sub powercmd { my $hash = shift; my @result = (); my @output; - + my $action = $request->{'op'}; + print "++++in powercmd++++\n"; print Dumper($hash); @@ -123,24 +129,45 @@ sub powercmd { foreach my $node_name ( keys %$hash) { my $d = $hash->{$node_name}; - my $res = action ($node_name, $d, $request->{'op'}); - print "In boot, state\n"; - print Dumper($res); - my $Rc = shift(@$res); - my $data = @$res[0]; - my $t = $data->{$node_name}; - my $type = @$d[4]; - my $id = ($type=~/^(fsp|bpa)$/) ? $type : @$d[0]; + if ($$d[4] =~ /^lpar$/) { + if( !($action =~ /^(on|off|of|reset|sms)$/)) { + push @output, [$node_name, "\'$action\' command not supported for LPAR", -1 ]; + return (\@output); + } + } elsif ($$d[4] =~ /^fsp$/) { + if($action =~ /^on$/) { $action = "cec_on_autostart"; } + if($action =~ /^off$/) { $action = "cec_off"; } + if($action =~ /^of$/ ) { + push @output, [$node_name, "\'$action\' command not supported for CEC", -1 ]; + #return (\@output); + next; + } + } else { + if($action =~ /^state$/) { + $action = "cec_state"; + } else { + push @output, [$node_name, "$node_name\'s type isn't fsp or lpar. Not allow doing this operation", -1 ]; + #return (\@output); + next; + } + } + my $res = xCAT::Utils::fsp_api_action($node_name, $d, $action ); + # print "In boot, state\n"; + # print Dumper($res); + my $Rc = @$res[2]; + my $data = @$res[1]; + #my $type = @$d[4]; + #my $id = ($type=~/^(fsp|bpa)$/) ? $type : @$d[0]; - ################################## + ################################## # Output error ################################## if ( $Rc != SUCCESS ) { - push @output, [$node_name,$t,$Rc]; - next; - } - - push @output, [$node_name,$t,$Rc]; + push @output, [$node_name,$data,$Rc]; + # next; + } else { + push @output, [$node_name,"Success",$Rc]; + } } return( \@output ); @@ -159,7 +186,7 @@ sub power_status { "Open Firmware|open-firmware" ); foreach ( @states ) { - if ( /^$_[0]$/ ) { + if ( /$_[0]/ ) { return("on"); } } @@ -177,7 +204,7 @@ sub state { my $prefix = shift; my $convert = shift; my @output = (); - + my $action = "state"; #print "------in state--------\n"; @@ -194,11 +221,11 @@ sub state { # 'Server-9110-51A-SN1075ECF' => [ # 0, # 0, - # '9110-51A*1075ECF', - # 'fsp1_name', - # 'fsp', - # 0 - # ] + # '9110-51A*1075ECF', + # 'fsp1_name', + # 'fsp', + # 0 + # ] # } # }; @@ -210,21 +237,39 @@ sub state { for my $node_name ( keys %$node_hash) { my $d = $node_hash->{$node_name}; - my $stat = action ($node_name, $d, "state", $prefix, $convert); - my $Rc = shift(@$stat); - my $data = @$stat[0]; - my $t = $data->{$node_name}; + if($$d[4] =~ /^fsp$/ || $$d[4] =~ /^bpa$/) { + $action = "cec_state"; + } + my $stat = xCAT::Utils::fsp_api_action ($node_name, $d, $action); + my $Rc = @$stat[2]; + my $data = @$stat[1]; my $type = @$d[4]; - my $id = ($type=~/^(fsp|bpa)$/) ? $type : @$d[0]; + #my $id = ($type=~/^(fsp|bpa)$/) ? $type : @$d[0]; ################################## # Output error ################################## if ( $Rc != SUCCESS ) { - push @output, [$node_name,$t,$Rc]; + push @output, [$node_name,$data,$Rc]; next; } - push @output,[$node_name, $t, $Rc]; + ############################## + # Convert state to on/off + ############################## + if ( defined( $convert )) { + $data = power_status( $data ); + } + + #print Dumper($prefix); + ################## + # state cec_state + ################# + if ( defined($prefix) ) { + $data = "$prefix $data"; + } + + + push @output,[$node_name, $data, $Rc]; } } @@ -233,117 +278,5 @@ sub state { } -########################################################################## -# invoke the fsp-api command. -########################################################################## -sub action { - my $node_name = shift; - my $attrs = shift; - my $action = shift; - my $prefix = shift; - my $convert = shift; -# my $fsp_api ="/opt/xcat/sbin/fsp-api"; - my $fsp_api = ($::XCATROOT) ? "$::XCATROOT/sbin/fsp-api" : "/opt/xcat/sbin/fsp-api"; - my $id = 1; - my $fsp_name = (); - my $fsp_ip = (); - my $target_list=(); - my $type = (); # fsp|lpar -- 0. BPA -- 1 - my @result; - my $Rc = 0 ; - my %outhash = (); - - $id = $$attrs[0]; - $fsp_name = $$attrs[3]; - - my %objhash = (); - $objhash{$fsp_name} = "node"; - my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash); - my $password = $myhash{$fsp_name}{"passwd.hscroot"}; - #print "fspname:$fsp_name password:$password\n"; -# print Dumper(%myhash); - if(!$password ) { - $outhash{$node_name} = "The password.hscroot of $fsp_name in ppcdirect table is empty"; - return ([-1, \%outhash]); - } -# my $user = "HMC"; - my $user = "hscroot"; -# my $cred = $request->{$fsp_name}{cred}; -# my $user = @$cred[0]; -# my $password = @$cred[1]; - - if($$attrs[4] =~ /^lpar$/) { - $type = 0; - } elsif($$attrs[4] =~ /^fsp$/) { - $type = 0; - if($action =~ /^state$/) {$action = "cec_state"; } - if($action =~ /^on$/) { $action = "cec_on_autostart"; } - if($action =~ /^off$/) { $action = "cec_off"; } - if($action =~ /^of$/ ) { - $outhash{$node_name} = "\'$action\' command not supported"; - return ([-1, \%outhash]); - } - - } else { - $type = 1; - if($action =~ /^state$/) { - $action = "cec_state"; - } else { - $outhash{$node_name} = "$node_name\'s type isn't fsp or lpar. Not allow doing this operation"; - return ([-1, \%outhash]); - } - } - - ############################ - # Get IP address - ############################ - $fsp_ip = xCAT::Utils::get_hdwr_ip($fsp_name); - if($fsp_ip == -1) { - $outhash{$node_name} = "Failed to get the $fsp_name\'s ip"; - return ([-1, \%outhash]); - } - - print "fsp name: $fsp_name\n"; - print "fsp ip: $fsp_ip\n"; - - my $cmd = "$fsp_api -a $action -u $user -p $password -t $type:$fsp_ip:$id:$node_name:"; - - print "cmd: $cmd\n"; - $SIG{CHLD} = (); - my $res = xCAT::Utils->runcmd($cmd, -1); - if($::RUNCMD_RC != 0){ - $Rc = -1; - } else { - $Rc = SUCCESS; - #################### - # on,off, of, reset, cec_onstandby,cec_off, if $? == 0, it will return sucess - ################### - if(index($action,"state") == -1 ) { - $outhash{$node_name} = "Sucess"; - return ([$Rc, \%outhash]); - } - } - ############################## - # Convert state to on/off - ############################## - if ( defined( $convert )) { - $res = power_status( $res ); - } - - #print Dumper($prefix); - ################## - # state cec_state - ################# - if (!defined($prefix)) { - $outhash{ $node_name } = $res; - } else { - $outhash{ $node_name } = "$prefix $res"; - } - - return( [$Rc,\%outhash] ); - -} - - 1; diff --git a/perl-xCAT/xCAT/FSPvitals.pm b/perl-xCAT/xCAT/FSPvitals.pm index bc26072ad..ee4896e0f 100644 --- a/perl-xCAT/xCAT/FSPvitals.pm +++ b/perl-xCAT/xCAT/FSPvitals.pm @@ -15,79 +15,6 @@ sub parse_args { xCAT::PPCvitals::parse_args(@_); } -########################################################################## -# invoke the fsp-api command. -########################################################################## -sub action { - my $node_name = shift; - my $attrs = shift; - my $action = shift; -# my $fsp_api ="/opt/xcat/sbin/fsp-api"; - my $fsp_api = ($::XCATROOT) ? "$::XCATROOT/sbin/fsp-api" : "/opt/xcat/sbin/fsp-api"; - my $id = 1; - my $fsp_name = (); - my $fsp_ip = (); - my $target_list=(); - my $type = (); # fsp|lpar -- 0. BPA -- 1 - my @result; - my $Rc = 0 ; - my %outhash = (); - - $id = $$attrs[0]; - $fsp_name = $$attrs[3]; - - my %objhash = (); - $objhash{$fsp_name} = "node"; - my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash); - my $password = $myhash{$fsp_name}{"passwd.hscroot"}; - #print "fspname:$fsp_name password:$password\n"; -# print Dumper(%myhash); - if(!$password ) { - $outhash{$node_name} = "The password.hscroot of $fsp_name in ppcdirect table is empty"; - return ([-1, \%outhash]); - } -# my $user = "HMC"; - my $user = "hscroot"; -# my $cred = $request->{$fsp_name}{cred}; -# my $user = @$cred[0]; -# my $password = @$cred[1]; - - if($$attrs[4] =~ /^lpar$/) { - $type = 0; - if($action =~ /^lcds$/) {$action = "query_lcds"; } - - } elsif($$attrs[4] =~ /^fsp$/) { - $type = 0; - if($action =~ /^lcds$/) {$action = "cec_query_lcds";} - } else { - $type = 1; - if($action =~ /^lcds$/) {$action = "cec_query_lcds"; } - } - - ############################ - # Get IP address - ############################ - $fsp_ip = xCAT::Utils::get_hdwr_ip($fsp_name); - if($fsp_ip == -1) { - $outhash{$node_name} = "Failed to get the $fsp_name\'s ip"; - return ([-1, \%outhash]); - } - - print "fsp name: $fsp_name\n"; - print "fsp ip: $fsp_ip\n"; - - my $cmd = "$fsp_api -a $action -u $user -p $password -t $type:$fsp_ip:$id:$node_name:"; - - print "cmd: $cmd\n"; - $SIG{CHLD} = (); - my $res = xCAT::Utils->runcmd($cmd, -1); - $Rc = $::RUNCMD_RC; - ################## - - return( [$Rc, $res] ); - -} - ########################################################################## # Returns Frame voltages/currents ########################################################################## @@ -138,10 +65,19 @@ sub enumerate_lcds { my $nodetype = @$d[4]; my $lpar_id = @$d[0]; my @refcode = (); - - my $values = action ($name, $d, "lcds" ); - $Rc = shift(@$values); - my $data = @$values[0]; + my $action; + if($$d[4] =~ /^lpar$/) { + $action = "query_lcds"; + + #} elsif($$d[4] =~ /^fsp$/) { + # $action = "cec_query_lcds"; + } else { + $action = "cec_query_lcds"; + } + + my $values = xCAT::Utils::fsp_api_action ($name, $d, $action); + $Rc = @$values[2]; + my $data = @$values[1]; $data =~ /\|(\w*)/ ; my $code = $1; if ( ! $code) { diff --git a/perl-xCAT/xCAT/PPCrflash.pm b/perl-xCAT/xCAT/PPCrflash.pm index 25e868f82..870a5b9dd 100644 --- a/perl-xCAT/xCAT/PPCrflash.pm +++ b/perl-xCAT/xCAT/PPCrflash.pm @@ -174,7 +174,7 @@ sub parse_args { return(usage()); } - $request->{callback}->({data =>[ "It may take considerable time to complete, depending on the number of systems being updated and the workload on the target HMC. In particular, power subsystem updates may take an hour or more if there are many attached managed systems. Please waiting."]}); + $request->{callback}->({data =>[ "It may take considerable time to complete, depending on the number of systems being updated. In particular, power subsystem updates may take an hour or more if there are many attached managed systems. Please waiting."]}); #################################### # No operands - add command name @@ -243,7 +243,7 @@ sub noderange_validate { } } #print "type:$type\n"; - if( $type =~/^(fsp|lpar)$/) { + if( $type =~/(fsp|lpar)/) { $f1 = 1; } else { $f2 = 1; diff --git a/xCAT-server/lib/perl/xCAT/PPC.pm b/xCAT-server/lib/perl/xCAT/PPC.pm index 8c276ac41..bbbb888c3 100644 --- a/xCAT-server/lib/perl/xCAT/PPC.pm +++ b/xCAT-server/lib/perl/xCAT/PPC.pm @@ -62,12 +62,12 @@ my %modules = ( bpa => "xCAT::FSPflash", }, mkhwconn => { hmc => "xCAT::PPCconn", - fsp => "xCAT::PPCconn", - bpa => "xCAT::PPCconn", + fsp => "xCAT::FSPconn", + bpa => "xCAT::FSPconn", }, rmhwconn => { hmc => "xCAT::PPCconn", - fsp => "xCAT::PPCconn", - bpa => "xCAT::PPCconn", + fsp => "xCAT::FSPconn", + bpa => "xCAT::FSPconn", }, lshwconn => { hmc => "xCAT::PPCconn", fsp => "xCAT::PPCconn", @@ -167,7 +167,9 @@ sub process_command { my $fsp_api = check_fsp_api($request); if($fsp_api == 0 && ($request->{command} =~ /^(rpower)$/ || $request->{command} =~ /^rinv$/ || $request->{command} =~ /^rflash$/ - || $request->{command} =~ /^getmacs$/ || $request->{command} =~ /^rnetboot$/ || $request->{command} =~ /^rvitals$/ ) + || $request->{command} =~ /^getmacs$/ || $request->{command} =~ /^rnetboot$/ || $request->{command} =~ /^rvitals$/ + || $request->{command} =~ /^mkhwconn$/ || $request->{command} =~ /^rmhwconn$/ + ) ) { #support FSPpower, FSPinv and FSPrflash $request->{fsp_api} = 1;