2010-02-26 09:42:41 +00:00
|
|
|
# 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;
|
2010-08-09 06:17:58 +00:00
|
|
|
#use Data::Dumper;
|
|
|
|
use xCAT::FSPUtils;
|
2011-04-13 09:38:29 +00:00
|
|
|
use xCAT::PPCconn;
|
2010-02-26 09:42:41 +00:00
|
|
|
|
|
|
|
##############################################
|
|
|
|
# Globals
|
|
|
|
##############################################
|
|
|
|
my %method = (
|
|
|
|
mkhwconn => \&mkhwconn_parse_args,
|
2010-05-05 03:22:39 +00:00
|
|
|
lshwconn => \&lshwconn_parse_args,
|
2010-02-26 09:42:41 +00:00
|
|
|
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" );
|
|
|
|
|
2011-06-21 06:48:18 +00:00
|
|
|
if ( !GetOptions( \%opt, qw(V|verbose h|help t s:s T=s p=s P=s port=s ) )) {
|
2010-02-26 09:42:41 +00:00
|
|
|
return( usage() );
|
|
|
|
}
|
2011-04-13 09:38:29 +00:00
|
|
|
|
|
|
|
if ( exists $opt{s} )
|
|
|
|
{
|
2011-05-22 11:59:04 +00:00
|
|
|
my $opttmp = xCAT::PPCconn::mkhwconn_parse_args($request, $args);
|
|
|
|
return $opttmp;
|
2011-04-13 09:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
return usage() if ( exists $opt{h});
|
|
|
|
|
2011-05-09 03:30:44 +00:00
|
|
|
if ( !exists $opt{t} and !exists $opt{p}) {
|
|
|
|
return ( usage('Flag -t or -p must be used.'));
|
|
|
|
}
|
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
if ( exists $opt{t} and exists $opt{p})
|
|
|
|
{
|
|
|
|
return( usage('Flags -t and -p cannot be used together.'));
|
|
|
|
}
|
|
|
|
|
2011-07-18 08:34:26 +00:00
|
|
|
if ( (exists $opt{P} or grep(/^(-P)$/, @$args)) and !exists $opt{p})
|
2010-02-26 09:42:41 +00:00
|
|
|
{
|
|
|
|
return( usage('Flags -P can only be used when flag -p is specified.'));
|
|
|
|
}
|
2010-12-20 08:41:19 +00:00
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
##########################################
|
|
|
|
# Check if CECs are controlled by a frame
|
|
|
|
##########################################
|
|
|
|
my $nodes = $request->{node};
|
|
|
|
my $ppctab = xCAT::Table->new( 'ppc' );
|
2011-06-03 08:49:05 +00:00
|
|
|
#my $nodetypetab = xCAT::Table->new( 'nodetype');
|
2010-02-26 09:42:41 +00:00
|
|
|
my $vpdtab = xCAT::Table->new( 'vpd');
|
|
|
|
my @bpa_ctrled_nodes = ();
|
|
|
|
my @no_type_nodes = ();
|
|
|
|
my @frame_members = ();
|
2010-03-16 12:35:25 +00:00
|
|
|
|
|
|
|
###########################################
|
|
|
|
# mgt=fsp/bpa for PPCconn.pm
|
|
|
|
##########################################
|
|
|
|
if ( exists $opt{p} )
|
|
|
|
{
|
2011-06-03 08:49:05 +00:00
|
|
|
#my $nodetype_hash = $nodetypetab->getNodeAttribs( $opt{p},[qw(nodetype)]);
|
|
|
|
#my $nodetype = $nodetype_hash->{nodetype};
|
2012-02-10 09:28:41 +00:00
|
|
|
my $nodetype = xCAT::DBobjUtils->getnodetype($opt{p}, "ppc");
|
2010-12-20 08:41:19 +00:00
|
|
|
if( !defined($nodetype) ) {
|
|
|
|
return(usage("Something wrong with the specified HMC (-p Option). The HMC type doesn't exist."));
|
|
|
|
}
|
2010-03-16 12:35:25 +00:00
|
|
|
if ( $nodetype eq 'hmc' )
|
|
|
|
{
|
|
|
|
$request->{ 'hwtype'} = 'hmc';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
if ( $ppctab)
|
|
|
|
{
|
2010-03-16 12:35:25 +00:00
|
|
|
my $hcp_nodetype = undef;
|
2012-02-13 01:59:17 +00:00
|
|
|
my $typehash = xCAT::DBobjUtils->getnodetype($nodes, "ppc");
|
2012-02-10 09:28:41 +00:00
|
|
|
for my $node (@$nodes)
|
2010-02-26 09:42:41 +00:00
|
|
|
{
|
|
|
|
my $node_parent = undef;
|
|
|
|
my $nodetype = undef;
|
2010-03-16 12:35:25 +00:00
|
|
|
my $node_hcp_nodetype = undef;
|
2011-06-03 08:49:05 +00:00
|
|
|
#my $nodetype_hash = $nodetypetab->getNodeAttribs( $node,[qw(nodetype)]);
|
2010-02-26 09:42:41 +00:00
|
|
|
my $node_parent_hash = $ppctab->getNodeAttribs( $node,[qw(parent)]);
|
2010-03-16 12:35:25 +00:00
|
|
|
if ( exists $opt{t} )
|
|
|
|
{
|
|
|
|
my $node_hcp_hash = $ppctab->getNodeAttribs( $node,[qw(hcp)]);
|
|
|
|
if ( $node_hcp_hash->{hcp} )
|
|
|
|
{
|
2011-06-03 08:49:05 +00:00
|
|
|
#my $node_hcp_nodetype_hash = $nodetypetab->getNodeAttribs($node_hcp_hash->{hcp},[qw(nodetype)]);
|
|
|
|
#$node_hcp_nodetype = $node_hcp_nodetype_hash->{nodetype};
|
2012-02-10 09:28:41 +00:00
|
|
|
$node_hcp_nodetype = xCAT::DBobjUtils->getnodetype($node_hcp_hash->{hcp}, "ppc");
|
2010-03-16 12:35:25 +00:00
|
|
|
}
|
|
|
|
if ( defined $hcp_nodetype )
|
|
|
|
{
|
|
|
|
if ( $hcp_nodetype ne $node_hcp_nodetype )
|
|
|
|
{
|
|
|
|
return( usage("Nodetype for all the nodes' hcp must be the same.") );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$hcp_nodetype = $node_hcp_nodetype;
|
|
|
|
if ( $hcp_nodetype eq 'hmc' )
|
|
|
|
{
|
|
|
|
$request->{ 'hwtype'} = 'hmc';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-06-03 08:49:05 +00:00
|
|
|
#$nodetype = $nodetype_hash->{nodetype};
|
2012-02-10 09:28:41 +00:00
|
|
|
$nodetype = $$typehash{$node};
|
2010-02-26 09:42:41 +00:00
|
|
|
$node_parent = $node_parent_hash->{parent};
|
2010-03-16 12:35:25 +00:00
|
|
|
if ( !$nodetype )
|
2010-02-26 09:42:41 +00:00
|
|
|
{
|
|
|
|
push @no_type_nodes, $node;
|
|
|
|
next;
|
2011-03-20 06:07:39 +00:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
unless ( $nodetype =~ /^(fsp|bpa|frame|cec|hmc)$/)
|
|
|
|
{
|
|
|
|
return ( usage("Node type is incorrect. \n"));
|
|
|
|
}
|
2010-02-26 09:42:41 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 07:30:41 +00:00
|
|
|
if (( $nodetype eq 'fsp' or $nodetype eq 'cec') and
|
2010-02-26 09:42:41 +00:00
|
|
|
$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;
|
|
|
|
}
|
2010-12-21 07:30:41 +00:00
|
|
|
if ( $nodetype eq 'frame')
|
|
|
|
{
|
|
|
|
my $my_frame_bpa_cec = xCAT::DBobjUtils::getcecchildren( $node) ;
|
2011-06-21 06:48:18 +00:00
|
|
|
push @frame_members, @$my_frame_bpa_cec if($my_frame_bpa_cec);
|
2010-12-21 07:30:41 +00:00
|
|
|
push @frame_members, $node;
|
|
|
|
}
|
2010-03-16 12:35:25 +00:00
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2010-08-09 06:17:58 +00:00
|
|
|
#if (scalar(@bpa_ctrled_nodes))
|
|
|
|
#{
|
|
|
|
# my $tmp_nodelist = join ',', @bpa_ctrled_nodes;
|
|
|
|
# return ( usage("Node(s) $tmp_nodelist is(are) controlled by BPA."));
|
|
|
|
#}
|
2010-02-26 09:42:41 +00:00
|
|
|
|
|
|
|
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';
|
2010-12-20 08:41:19 +00:00
|
|
|
|
|
|
|
if( ! exists $opt{T} )
|
|
|
|
{
|
2011-02-10 09:06:54 +00:00
|
|
|
$opt{T} = "lpar"; #defaut value is lpar.
|
|
|
|
#return( usage('Missing -T option. The value can be lpar or fnm.'));
|
2010-12-20 08:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( $opt{T} eq "lpar") {
|
|
|
|
$opt{T} = 0;
|
|
|
|
} elsif($opt{T} eq "fnm") {
|
|
|
|
$opt{T} = 1;
|
|
|
|
} else {
|
2011-02-10 09:06:54 +00:00
|
|
|
return( usage('Wrong value of -T option. The value can be lpar or fnm. The defaut value is lpar.'));
|
2010-12-20 08:41:19 +00:00
|
|
|
}
|
|
|
|
|
2010-12-29 02:21:00 +00:00
|
|
|
if( ! exists $opt{port} )
|
|
|
|
{
|
|
|
|
$opt{port} = "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $opt{port} ne "0" and $opt{port} ne "1")
|
|
|
|
{
|
|
|
|
return( usage('Wrong value of --port option. The value can be 0 or 1, and the default value is 0.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$ppctab->close();
|
2011-06-03 08:49:05 +00:00
|
|
|
#$nodetypetab->close();
|
2010-12-29 02:21:00 +00:00
|
|
|
$vpdtab->close();
|
2011-09-22 08:50:06 +00:00
|
|
|
|
|
|
|
if ( scalar( @ARGV)) {
|
|
|
|
return(usage( "No additional flag is support by this command" ));
|
|
|
|
}
|
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
$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" );
|
|
|
|
|
2011-05-22 11:59:04 +00:00
|
|
|
if ( exists $opt{s} )
|
|
|
|
{
|
|
|
|
my $opttmp = xCAT::PPCconn::lshwconn_parse_args($request, $args);
|
|
|
|
return $opttmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !GetOptions( \%opt, qw(V|verbose h|help T=s s) )) {
|
2010-02-26 09:42:41 +00:00
|
|
|
return( usage() );
|
|
|
|
}
|
|
|
|
return usage() if ( exists $opt{h});
|
2010-12-03 05:48:54 +00:00
|
|
|
|
|
|
|
if( ! exists $opt{T} )
|
|
|
|
{
|
2011-02-10 09:06:54 +00:00
|
|
|
$opt{T} = "lpar"; #defaut value is lpar.
|
|
|
|
#return( usage('Missing -T option. The value can be lpar or fnm.'));
|
2010-12-03 05:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( $opt{T} eq "lpar") {
|
|
|
|
$opt{T} = 0;
|
|
|
|
} elsif($opt{T} eq "fnm") {
|
|
|
|
$opt{T} = 1;
|
|
|
|
} else {
|
2011-02-10 09:06:54 +00:00
|
|
|
return( usage('Wrong value of -T option. The value can be lpar or fnm. The defaut value is lpar.'));
|
2010-12-03 05:48:54 +00:00
|
|
|
}
|
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
|
|
|
|
#############################################
|
|
|
|
# Process command-line arguments
|
|
|
|
#############################################
|
|
|
|
if ( scalar( @ARGV)) {
|
|
|
|
return(usage( "No additional flag is support by this command" ));
|
|
|
|
}
|
2011-06-03 08:49:05 +00:00
|
|
|
#my $nodetypetab = xCAT::Table->new('nodetype');
|
|
|
|
#if (! $nodetypetab)
|
|
|
|
#{
|
|
|
|
# return( ["Failed to open table 'nodetype'.\n"]);
|
|
|
|
#}
|
2010-02-26 09:42:41 +00:00
|
|
|
my $nodehmtab = xCAT::Table->new('nodehm');
|
|
|
|
if (! $nodehmtab)
|
|
|
|
{
|
|
|
|
return( ["Failed to open table 'nodehm'.\n"]);
|
|
|
|
}
|
2011-05-24 05:40:17 +00:00
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
my $nodetype;
|
2012-02-10 09:28:41 +00:00
|
|
|
my $typehash = xCAT::DBobjUtils->getnodetype(\@{$request->{node}}, "ppc");
|
2010-02-26 09:42:41 +00:00
|
|
|
for my $node ( @{$request->{node}})
|
|
|
|
{
|
2011-06-03 08:49:05 +00:00
|
|
|
#my $ent = $nodetypetab->getNodeAttribs( $node, [qw(nodetype)]);
|
2010-02-26 09:42:41 +00:00
|
|
|
my $nodehm = $nodehmtab->getNodeAttribs( $node, [qw(mgt)]);
|
2011-06-03 08:49:05 +00:00
|
|
|
#if ( ! $ent)
|
|
|
|
#{
|
|
|
|
# return( ["Failed to get node type for node $node.\n"]);
|
|
|
|
#}
|
2012-02-10 09:28:41 +00:00
|
|
|
my $ttype = $$typehash{$node};
|
2011-06-03 08:49:05 +00:00
|
|
|
if ( ! $ttype)
|
2010-02-26 09:42:41 +00:00
|
|
|
{
|
|
|
|
return( ["Failed to get nodehm.mgt value for node $node.\n"]);
|
|
|
|
}
|
2011-06-03 08:49:05 +00:00
|
|
|
if ( $ttype ne 'fsp' and $ttype ne 'cec'
|
|
|
|
and $ttype ne 'bpa' and $ttype ne 'frame')
|
2010-02-26 09:42:41 +00:00
|
|
|
{
|
2011-06-03 08:49:05 +00:00
|
|
|
return( ["Node type $ttype is not supported for this command in FSPAPI\n"]);
|
2010-02-26 09:42:41 +00:00
|
|
|
}
|
|
|
|
if ( ! $nodetype)
|
|
|
|
{
|
2011-06-03 08:49:05 +00:00
|
|
|
$nodetype = $ttype; #$ent->{nodetype};
|
2010-02-26 09:42:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-03 08:49:05 +00:00
|
|
|
if ( $nodetype ne $ttype) #$ent->{nodetype})
|
2010-02-26 09:42:41 +00:00
|
|
|
{
|
|
|
|
return( ["Cannot support multiple node types in this command line.\n"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-03 08:49:05 +00:00
|
|
|
#$nodetypetab->close();
|
2010-12-29 02:21:00 +00:00
|
|
|
$nodehmtab->close();
|
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
$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" );
|
|
|
|
|
2011-05-22 11:59:04 +00:00
|
|
|
if ( !GetOptions( \%opt, qw(V|verbose h|help T=s s) )) {
|
2010-02-26 09:42:41 +00:00
|
|
|
return( usage() );
|
|
|
|
}
|
|
|
|
return usage() if ( exists $opt{h});
|
2011-05-22 11:59:04 +00:00
|
|
|
|
|
|
|
if ( $opt{s} )
|
|
|
|
{
|
|
|
|
my $opttmp = xCAT::PPCconn::rmhwconn_parse_args($request, $args);
|
|
|
|
return $opttmp;
|
|
|
|
}
|
|
|
|
|
2010-12-03 05:48:54 +00:00
|
|
|
if( ! exists $opt{T} )
|
|
|
|
{
|
2011-02-10 09:06:54 +00:00
|
|
|
$opt{T} = "lpar"; #defaut value is lpar.
|
|
|
|
#return( usage('Missing -T option. The value can be lpar or fnm.'));
|
2010-12-03 05:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( $opt{T} eq "lpar") {
|
|
|
|
$opt{T} = 0;
|
|
|
|
} elsif($opt{T} eq "fnm") {
|
|
|
|
$opt{T} = 1;
|
|
|
|
} else {
|
2011-02-10 09:06:54 +00:00
|
|
|
return( usage('Wrong value of -T option. The value can be lpar or fnm. The default value is lpar.'));
|
2010-12-03 05:48:54 +00:00
|
|
|
}
|
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
|
|
|
|
#############################################
|
|
|
|
# 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);
|
2011-06-03 08:49:05 +00:00
|
|
|
#my $nodetypetab = xCAT::Table->new( 'nodetype');
|
|
|
|
#return( ["Failed to open table 'nodetype'.\n"]) if ( ! $nodetypetab);
|
2010-02-26 09:42:41 +00:00
|
|
|
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 = ();
|
2012-02-13 01:59:17 +00:00
|
|
|
my $nodetype_hash = xCAT::DBobjUtils->getnodetype($nodes, "ppc");
|
2010-02-26 09:42:41 +00:00
|
|
|
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;
|
2012-02-10 09:28:41 +00:00
|
|
|
my $node_parent_hash = $ppctab->getNodeAttribs($node,[qw(parent)]);
|
|
|
|
$nodetype = $$nodetype_hash{$node};
|
2010-02-26 09:42:41 +00:00
|
|
|
$node_parent = $node_parent_hash->{parent};
|
|
|
|
if ( !$nodetype)
|
|
|
|
{
|
|
|
|
push @no_type_nodes, $node;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2010-12-21 08:04:21 +00:00
|
|
|
if ( ($nodetype eq 'fsp' or $nodetype eq 'cec') and
|
2010-02-26 09:42:41 +00:00
|
|
|
$node_parent and
|
|
|
|
$node_parent ne $node)
|
|
|
|
{
|
|
|
|
push @bpa_ctrled_nodes, $node;
|
|
|
|
}
|
|
|
|
|
2010-12-21 07:30:41 +00:00
|
|
|
if ( $nodetype eq 'bpa')
|
|
|
|
{
|
|
|
|
my $my_frame_bpa_cec = getFrameMembers( $node, $vpdtab, $ppctab);
|
|
|
|
push @frame_members, @$my_frame_bpa_cec;
|
|
|
|
}
|
2010-12-20 13:43:11 +00:00
|
|
|
if ( $nodetype eq 'frame')
|
2010-02-26 09:42:41 +00:00
|
|
|
{
|
2010-12-21 07:30:41 +00:00
|
|
|
my $my_frame_bpa_cec = xCAT::DBobjUtils::getcecchildren($node);
|
2010-02-26 09:42:41 +00:00
|
|
|
push @frame_members, @$my_frame_bpa_cec;
|
2010-12-21 07:30:41 +00:00
|
|
|
push @frame_members, $node;
|
2010-02-26 09:42:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2010-12-29 02:21:00 +00:00
|
|
|
$ppctab->close();
|
2011-06-03 08:49:05 +00:00
|
|
|
#$nodetypetab->close();
|
2010-12-29 02:21:00 +00:00
|
|
|
$vpdtab->close();
|
|
|
|
$nodehmtab->close();
|
|
|
|
|
2010-11-22 10:09:49 +00:00
|
|
|
#if (scalar(@bpa_ctrled_nodes))
|
|
|
|
#{
|
|
|
|
# my $tmp_nodelist = join ',', @bpa_ctrled_nodes;
|
|
|
|
# return ( usage("Node(s) $tmp_nodelist is(are) controlled by BPA."));
|
|
|
|
#}
|
2010-02-26 09:42:41 +00:00
|
|
|
|
|
|
|
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;
|
2010-12-03 05:48:54 +00:00
|
|
|
my $tooltype= $opt->{T};
|
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
|
|
|
|
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};
|
|
|
|
|
2011-01-06 08:05:56 +00:00
|
|
|
#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;
|
|
|
|
# }
|
|
|
|
|
|
|
|
#}
|
2010-02-26 09:42:41 +00:00
|
|
|
|
2010-12-29 02:21:00 +00:00
|
|
|
my $res = xCAT::FSPUtils::fsp_api_action( $node_name, $d, "add_connection", $tooltype, $opt->{port} );
|
2010-02-26 09:42:41 +00:00
|
|
|
$Rc = @$res[2];
|
|
|
|
if( @$res[1] ne "") {
|
|
|
|
push @value, [$node_name, @$res[1], $Rc];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return \@value;
|
|
|
|
}
|
|
|
|
##########################################################################
|
2010-05-05 03:22:39 +00:00
|
|
|
# List connection status for CECs/BPAs through FSPAPI
|
2010-02-26 09:42:41 +00:00
|
|
|
##########################################################################
|
|
|
|
sub lshwconn
|
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $hash = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $hwtype = @$exp[2];
|
|
|
|
my $opt = $request->{opt};
|
|
|
|
my @value = ();
|
|
|
|
my $Rc = undef;
|
2010-05-05 03:22:39 +00:00
|
|
|
my $res = undef;
|
2010-12-03 05:48:54 +00:00
|
|
|
my $tooltype = $opt->{T};
|
2010-02-26 09:42:41 +00:00
|
|
|
|
2010-05-05 03:22:39 +00:00
|
|
|
for my $cec_bpa ( keys %$hash)
|
2010-02-26 09:42:41 +00:00
|
|
|
{
|
2010-05-05 03:22:39 +00:00
|
|
|
my $node_hash = $hash->{$cec_bpa};
|
|
|
|
for my $node_name (keys %$node_hash)
|
|
|
|
{
|
|
|
|
my $d = $node_hash->{$node_name};
|
|
|
|
my $action = "query_connection";
|
2010-12-03 05:48:54 +00:00
|
|
|
my $res = xCAT::FSPUtils::fsp_api_action ($node_name, $d, $action, $tooltype);
|
2010-05-05 03:22:39 +00:00
|
|
|
#print "in lshwconn:\n";
|
|
|
|
#print Dumper($res);
|
|
|
|
my $Rc = @$res[2];
|
2011-05-19 03:00:34 +00:00
|
|
|
my $values = @$res[1];
|
2010-05-05 03:22:39 +00:00
|
|
|
|
|
|
|
############################################
|
|
|
|
# If lssysconn failed, put error into all
|
|
|
|
# nodes' return values
|
|
|
|
############################################
|
2011-05-19 03:00:34 +00:00
|
|
|
#if ( $Rc )
|
|
|
|
# {
|
|
|
|
# push @value, [$node_name, $values, $Rc];
|
|
|
|
# next;
|
|
|
|
# }
|
|
|
|
|
|
|
|
my @data_a = split("\n", $values);
|
|
|
|
foreach my $data(@data_a) {
|
|
|
|
if( $data =~ /state/) {
|
2011-11-29 06:20:22 +00:00
|
|
|
$data =~ /state=([\w\s\,]+), type=([\w-]+), MTMS=([\w-\*\#]+), ([\w=]+), slot=([\w]+), ipadd=([\w.]+), alt_ipadd=([\w.]+)/ ;
|
2011-05-19 03:00:34 +00:00
|
|
|
#$data =~ /state=([\w\s]+),\(type=([\w-]+)\),\(serial-number=([\w]+)\),\(machinetype-model=([\w-]+)\),sp=([\w]+),\(ip-address=([\w.]+),([\w.]+)\)/ ;
|
|
|
|
print "parsing: $1,$2,$3,$4,$5,$6,$7\n";
|
|
|
|
my $state = $1;
|
|
|
|
my $type = $2;
|
|
|
|
my $mtms = $3;
|
|
|
|
my $sp = $4;
|
|
|
|
my $slot = $5;
|
|
|
|
my $ipadd = $6;
|
|
|
|
my $alt_ipaddr = $7;
|
|
|
|
$data = "$ipadd: $sp,ipadd=$ipadd,alt_ipadd=$alt_ipaddr,state=$state";
|
|
|
|
}
|
|
|
|
push @value, [$node_name, $data, $Rc];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
return \@value;
|
2010-05-05 03:22:39 +00:00
|
|
|
|
|
|
|
|
2010-02-26 09:42:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# 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;
|
|
|
|
|
2010-08-09 06:17:58 +00:00
|
|
|
my $res = xCAT::FSPUtils::fsp_api_action( $node_name, $d, "rm_connection", $tooltype );
|
2010-02-26 09:42:41 +00:00
|
|
|
$Rc = @$res[2];
|
|
|
|
if( @$res[1] ne "") {
|
|
|
|
push @value, [$node_name, @$res[1], $Rc];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return \@value;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|