2009-05-20 09:04:19 +00:00
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::PPCconn ;
use strict ;
use Getopt::Long ;
use xCAT::PPCcli qw( SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR ) ;
use xCAT::Usage ;
2011-05-10 08:00:32 +00:00
use xCAT::DBobjUtils ;
2012-05-03 05:00:28 +00:00
use xCAT::FSPUtils ;
2009-05-20 09:04:19 +00:00
##############################################
# Globals
##############################################
my % method = (
2009-08-04 20:28:03 +00:00
mkhwconn = > \ & mkhwconn_parse_args ,
lshwconn = > \ & lshwconn_parse_args ,
2009-08-21 06:36:28 +00:00
rmhwconn = > \ & rmhwconn_parse_args ,
inithwpw = > \ & inithwpw_parse_args
2009-05-20 09:04:19 +00:00
) ;
##########################################################################
# 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 ) ;
}
##########################################################################
2009-08-04 20:28:03 +00:00
# Parse arguments for mkhwconn
2009-05-20 09:04:19 +00:00
##########################################################################
2009-08-04 20:28:03 +00:00
sub mkhwconn_parse_args
2009-05-20 09:04:19 +00:00
{
my $ request = shift ;
my $ args = shift ;
my % opt = ( ) ;
local * usage = sub {
2009-08-04 20:28:03 +00:00
my $ usage_string = xCAT::Usage - > getUsage ( "mkhwconn" ) ;
2009-05-20 09:04:19 +00:00
return ( [ $ _ [ 0 ] , $ usage_string ] ) ;
} ;
#############################################
# Process command-line arguments
#############################################
if ( ! defined ( $ args ) ) {
return ( usage ( "No command specified" ) ) ;
}
2009-08-04 18:33:52 +00:00
local @ ARGV = ref ( $ args ) eq 'ARRAY' ? @$ args: ( ) ;
2009-05-20 09:04:19 +00:00
$ Getopt:: Long:: ignorecase = 0 ;
Getopt::Long:: Configure ( "bundling" ) ;
2011-06-21 06:42:00 +00:00
if ( ! GetOptions ( \ % opt , qw( V|verbose h|help t p=s P=s port=s s:s ) ) ) {
2009-05-20 09:04:19 +00:00
return ( usage ( ) ) ;
}
2009-08-06 11:22:29 +00:00
return usage ( ) if ( exists $ opt { h } ) ;
2009-05-20 09:04:19 +00:00
2011-05-09 03:30:44 +00:00
if ( ! exists $ opt { t } and ! exists $ opt { p } and ! exists $ opt { s } ) {
return ( usage ( 'Flag -t or -p or -s must be used.' ) ) ;
}
2011-06-21 06:42:00 +00:00
if ( ( exists $ opt { t } and exists $ opt { p } ) or ( exists $ opt { s } and exists $ opt { p } ) or ( exists $ opt { t } and exists $ opt { p } ) )
2009-05-20 09:04:19 +00:00
{
return ( usage ( 'Flags -t and -p cannot be used together.' ) ) ;
}
2011-06-21 06:42:00 +00:00
if ( exists $ opt { P } and ( ! exists $ opt { p } and ! exists $ opt { s } ) )
2009-05-20 09:04:19 +00:00
{
return ( usage ( 'Flags -P can only be used when flag -p is specified.' ) ) ;
}
2011-07-13 04:28:27 +00:00
##########################################
# Find the sfp for the mkhwconn -s
##########################################
$ request - > { sfp } = $ opt { s } ;
2009-05-20 09:04:19 +00:00
##########################################
# Check if CECs are controlled by a frame
##########################################
my $ nodes = $ request - > { node } ;
my $ ppctab = xCAT::Table - > new ( 'ppc' ) ;
2011-06-07 06:23:16 +00:00
#my $nodetypetab = xCAT::Table->new( 'nodetype');
2009-07-31 19:45:28 +00:00
my $ vpdtab = xCAT::Table - > new ( 'vpd' ) ;
2009-05-20 09:04:19 +00:00
my @ bpa_ctrled_nodes = ( ) ;
my @ no_type_nodes = ( ) ;
2009-07-31 19:45:28 +00:00
my @ frame_members = ( ) ;
2009-05-20 09:04:19 +00:00
if ( $ ppctab )
{
for my $ node ( @$ nodes )
{
my $ node_parent = undef ;
my $ nodetype = undef ;
2012-04-06 02:21:26 +00:00
#my $nodetype_hash = $nodetypetab->getNodeAttribs( $node,[qw(nodetype)]);
2009-05-20 09:04:19 +00:00
my $ node_parent_hash = $ ppctab - > getNodeAttribs ( $ node , [ qw( parent ) ] ) ;
2012-04-06 02:21:26 +00:00
#$nodetype = $nodetype_hash->{nodetype};
$ nodetype = xCAT::DBobjUtils - > getnodetype ( $ node ) ;
2009-05-20 09:04:19 +00:00
$ node_parent = $ node_parent_hash - > { parent } ;
2011-02-19 09:49:11 +00:00
if ( ! $ nodetype )
2009-05-20 09:04:19 +00:00
{
push @ no_type_nodes , $ node ;
next ;
2011-03-20 06:06:59 +00:00
} else
{
unless ( $ nodetype =~ /^(fsp|bpa|frame|cec|hmc)$/ )
{
return ( usage ( "Node type is incorrect. \n" ) ) ;
}
2009-05-20 09:04:19 +00:00
}
2011-02-19 09:49:11 +00:00
if ( $ nodetype eq 'fsp' )
2009-05-20 09:04:19 +00:00
{
2011-02-19 09:49:11 +00:00
my $ jr = xCAT::DBobjUtils:: judge_node ( $ node , $ nodetype ) ;
unless ( $ jr )
{
if ( $ node_parent and $ node_parent ne $ node )
{
push @ bpa_ctrled_nodes , $ node ;
}
}
2009-05-20 09:04:19 +00:00
}
2011-02-19 09:49:11 +00:00
##########################################
# Nothing to do with cec
##########################################
#if (($nodetype eq 'cec') and
# $node_parent and
# $node_parent ne $node)
#{
# push @bpa_ctrled_nodes, $node;
#}
##########################################
# Now we suppport the operation on sigal bpa
##########################################
2011-02-14 09:37:04 +00:00
if ( $ nodetype eq 'bpa' )
2009-07-31 19:45:28 +00:00
{
2011-02-19 09:49:11 +00:00
my $ jr = xCAT::DBobjUtils:: judge_node ( $ node , $ nodetype ) ;
unless ( $ jr )
{
my $ my_frame_bpa_cec = getFrameMembers ( $ node , $ vpdtab , $ ppctab ) ;
push @ frame_members , @$ my_frame_bpa_cec ;
}
2009-07-31 19:45:28 +00:00
}
2011-02-19 09:49:11 +00:00
##########################################
# For the Frame, we will have its CEC to do
# mkhwconn at the same time
##########################################
2011-02-14 09:37:04 +00:00
if ( $ nodetype eq 'frame' )
{
my $ my_frame_bpa_cec = xCAT::DBobjUtils:: getcecchildren ( $ node ) ;
2011-06-21 06:42:00 +00:00
push @ frame_members , @$ my_frame_bpa_cec if ( $ my_frame_bpa_cec ) ;
2011-02-14 09:37:04 +00:00
push @ frame_members , $ node ;
}
2009-05-20 09:04:19 +00:00
}
}
2009-07-31 19:45:28 +00:00
2009-05-20 09:04:19 +00:00
if ( scalar ( @ no_type_nodes ) )
{
my $ tmp_nodelist = join ',' , @ no_type_nodes ;
2012-04-06 02:21:26 +00:00
return ( usage ( "Attribute nodetype.nodetype cannot be found for node(s) $tmp_nodelist. Please define first and try again." ) ) ;
2009-05-20 09:04:19 +00:00
}
2009-07-31 19:45:28 +00:00
2009-05-20 09:04:19 +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." ) ) ;
}
2011-06-21 06:42:00 +00:00
2009-07-31 19:45:28 +00:00
if ( scalar ( @ frame_members ) )
{
2009-07-31 21:11:48 +00:00
my @ all_nodes = xCAT::Utils:: get_unique_members ( @$ nodes , @ frame_members ) ;
$ request - > { node } = \ @ all_nodes ;
2009-07-31 19:45:28 +00:00
}
2011-02-19 09:49:11 +00:00
# Set HW type to 'hmc' anyway, so that this command will not going to
2009-07-31 19:45:28 +00:00
# PPCfsp.pm
$ request - > { 'hwtype' } = 'hmc' ;
2010-03-16 12:35:25 +00:00
$ request - > { hcp } = 'hmc' ;
2011-02-19 09:49:11 +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.' ) ) ;
}
2009-08-04 20:28:03 +00:00
$ request - > { method } = 'mkhwconn' ;
2011-09-22 08:50:06 +00:00
if ( scalar ( @ ARGV ) ) {
return ( usage ( "No additional flag is support by this command" ) ) ;
}
2009-05-20 09:04:19 +00:00
return ( \ % opt ) ;
}
2009-07-31 19:45:28 +00:00
####################################################
# 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 ;
2009-08-04 22:44:58 +00:00
my @ frame_members = ( ) ;
my @ bpa_nodes = ( ) ;
2009-07-31 19:45:28 +00:00
my $ vpdhash = $ vpdtab - > getNodeAttribs ( $ node , [ qw( mtm serial ) ] ) ;
my $ mtm = $ vpdhash - > { mtm } ;
my $ serial = $ vpdhash - > { serial } ;
2009-08-04 22:44:58 +00:00
if ( scalar ( @ all_vpd_nodes ) == 0 )
2009-07-31 19:45:28 +00:00
{
2009-08-04 22:44:58 +00:00
@ all_vpd_nodes = $ vpdtab - > getAllNodeAttribs ( [ 'node' , 'mtm' , 'serial' ] ) ;
2009-07-31 19:45:28 +00:00
}
2009-08-04 22:44:58 +00:00
for my $ vpd_node ( @ all_vpd_nodes )
2009-07-31 19:45:28 +00:00
{
2009-08-04 22:44:58 +00:00
if ( $ vpd_node - > { 'mtm' } eq $ mtm and $ vpd_node - > { 'serial' } eq $ serial )
2009-07-31 19:45:28 +00:00
{
2009-08-04 22:44:58 +00:00
push @ frame_members , $ vpd_node - > { 'node' } ;
push @ bpa_nodes , $ vpd_node - > { 'node' } ;
2009-07-31 19:45:28 +00:00
}
}
2009-08-04 22:44:58 +00:00
if ( scalar ( @ all_ppc_nodes ) == 0 )
2009-07-31 19:45:28 +00:00
{
2009-08-04 22:44:58 +00:00
@ all_ppc_nodes = $ ppctab - > getAllNodeAttribs ( [ 'node' , 'parent' ] ) ;
2009-07-31 19:45:28 +00:00
}
2009-08-04 22:44:58 +00:00
for my $ bpa_node ( @ bpa_nodes )
2009-07-31 19:45:28 +00:00
{
2009-08-04 22:44:58 +00:00
for my $ ppc_node ( @ all_ppc_nodes )
2009-07-31 19:45:28 +00:00
{
2009-08-04 22:44:58 +00:00
if ( $ ppc_node - > { parent } eq $ bpa_node )
{
push @ frame_members , $ ppc_node - > { 'node' } ;
}
2009-07-31 19:45:28 +00:00
}
}
return \ @ frame_members ;
}
2009-05-26 06:02:03 +00:00
##########################################################################
2009-08-04 20:28:03 +00:00
# Parse arguments for lshwconn
2009-05-26 06:02:03 +00:00
##########################################################################
2009-08-04 20:28:03 +00:00
sub lshwconn_parse_args
2009-05-20 09:04:19 +00:00
{
2009-05-26 06:02:03 +00:00
my $ request = shift ;
my $ args = shift ;
my % opt = ( ) ;
2009-05-20 09:04:19 +00:00
2009-05-26 06:02:03 +00:00
local * usage = sub {
2009-08-04 20:28:03 +00:00
my $ usage_string = xCAT::Usage - > getUsage ( "lshwconn" ) ;
2009-05-26 06:02:03 +00:00
return ( [ $ _ [ 0 ] , $ usage_string ] ) ;
} ;
#############################################
# Get options in command line
#############################################
2009-07-31 19:45:28 +00:00
local @ ARGV = ref ( $ args ) eq 'ARRAY' ? @$ args: ( ) ;
2009-05-26 06:02:03 +00:00
$ Getopt:: Long:: ignorecase = 0 ;
Getopt::Long:: Configure ( "bundling" ) ;
2011-05-20 09:19:02 +00:00
if ( ! GetOptions ( \ % opt , qw( V|verbose h|help s ) ) ) {
2009-05-26 06:02:03 +00:00
return ( usage ( ) ) ;
}
2009-08-04 20:28:03 +00:00
return usage ( ) if ( exists $ opt { h } ) ;
2009-05-26 06:02:03 +00:00
#############################################
# Process command-line arguments
#############################################
2009-08-04 20:28:03 +00:00
if ( scalar ( @ ARGV ) ) {
2011-05-20 09:19:02 +00:00
unless ( $ opt { s } ) {
2009-05-26 06:02:03 +00:00
return ( usage ( "No additional flag is support by this command" ) ) ;
2011-05-20 09:19:02 +00:00
}
2009-05-26 06:02:03 +00:00
}
2011-06-07 06:23:16 +00:00
#my $nodetypetab = xCAT::Table->new('nodetype');
#if (! $nodetypetab)
#{
# return( ["Failed to open table 'nodetype'.\n"]);
#}
2009-08-04 22:44:58 +00:00
my $ nodehmtab = xCAT::Table - > new ( 'nodehm' ) ;
if ( ! $ nodehmtab )
2009-07-20 18:46:13 +00:00
{
2009-08-04 22:44:58 +00:00
return ( [ "Failed to open table 'nodehm'.\n" ] ) ;
2009-07-20 18:46:13 +00:00
}
my $ nodetype ;
2012-04-06 02:21:26 +00:00
my @ no_type_nodes = ( ) ;
my @ no_mgt_nodes = ( ) ;
my @ error_type_nodes = ( ) ;
2009-07-20 18:46:13 +00:00
for my $ node ( @ { $ request - > { node } } )
{
2011-06-07 06:23:16 +00:00
#my $ent = $nodetypetab->getNodeAttribs( $node, [qw(nodetype)]);
my $ ttype = xCAT::DBobjUtils - > getnodetype ( $ node ) ;
2009-08-04 22:44:58 +00:00
my $ nodehm = $ nodehmtab - > getNodeAttribs ( $ node , [ qw( mgt ) ] ) ;
2011-06-07 06:23:16 +00:00
if ( ! $ ttype )
2009-07-20 18:46:13 +00:00
{
2012-04-06 02:21:26 +00:00
push @ no_type_nodes , $ node ;
next ;
2009-07-20 18:46:13 +00:00
}
2009-08-04 22:44:58 +00:00
if ( ! $ nodehm )
{
2012-04-06 02:21:26 +00:00
push @ no_mgt_nodes , $ node ;
next ;
2009-08-04 22:44:58 +00:00
}
elsif ( $ nodehm - > { mgt } ne 'hmc' )
{
return ( [ "lshwconn can only support HMC nodes, or nodes managed by HMC, i.e. nodehm.mgt should be 'hmc'. Please make sure node $node has correect nodehm.mgt and ppc.hcp value.\n" ] ) ;
}
2011-06-07 06:23:16 +00:00
if ( $ ttype ne 'hmc'
and $ ttype ne 'fsp' and $ ttype ne 'cec'
and $ ttype ne 'bpa' and $ ttype ne 'frame' )
2009-07-20 18:46:13 +00:00
{
2012-04-06 02:21:26 +00:00
push @ error_type_nodes , $ node ;
next ;
2009-07-20 18:46:13 +00:00
}
if ( ! $ nodetype )
{
2011-06-07 06:23:16 +00:00
$ nodetype = $ ttype ;
2009-07-20 18:46:13 +00:00
}
else
{
2011-06-07 06:23:16 +00:00
if ( $ nodetype ne $ ttype )
2009-07-20 18:46:13 +00:00
{
return ( [ "Cannot support multiple node types in this command line.\n" ] ) ;
}
}
}
2012-04-06 02:21:26 +00:00
if ( scalar ( @ no_type_nodes ) ) {
my $ tmp_nodelist = join ',' , @ no_type_nodes ;
return ( [ "Failed to get node type for node(s) $tmp_nodelist. Please define first and try again\n" ] ) ;
}
if ( scalar ( @ no_mgt_nodes ) ) {
my $ tmp_nodelist = join ',' , @ no_mgt_nodes ;
return ( [ "Failed to get nodehm.mgt value for node(s) $tmp_nodelist. Please define first and try again.\n" ] ) ;
}
if ( scalar ( @ error_type_nodes ) ) {
my $ tmp_nodelist = join ',' , @ error_type_nodes ;
my $ link = ( scalar ( @ error_type_nodes ) == '1' ) ? 'is' : 'are' ;
return ( [ "Node type of node(s) $tmp_nodelist $link not supported for this command.\n" ] ) ;
}
2009-07-20 18:46:13 +00:00
$ request - > { nodetype } = $ nodetype ;
2009-08-04 20:28:03 +00:00
$ request - > { method } = 'lshwconn' ;
2009-05-26 06:02:03 +00:00
return ( \ % opt ) ;
2009-05-20 09:04:19 +00:00
}
2009-05-26 06:02:03 +00:00
##########################################################################
2009-08-04 20:28:03 +00:00
# Parse arguments for rmhwconn
2009-05-26 06:02:03 +00:00
##########################################################################
2009-08-04 20:28:03 +00:00
sub rmhwconn_parse_args
2009-05-20 09:04:19 +00:00
{
2009-05-26 06:02:03 +00:00
my $ request = shift ;
my $ args = shift ;
my % opt = ( ) ;
local * usage = sub {
2009-08-04 20:28:03 +00:00
my $ usage_string = xCAT::Usage - > getUsage ( "rmhwconn" ) ;
2009-05-26 06:02:03 +00:00
return ( [ $ _ [ 0 ] , $ usage_string ] ) ;
} ;
2009-12-28 08:10:42 +00:00
#############################################
# Get options in command line
#############################################
2009-08-04 18:33:52 +00:00
local @ ARGV = ref ( $ args ) eq 'ARRAY' ? @$ args: ( ) ;
2009-05-26 06:02:03 +00:00
$ Getopt:: Long:: ignorecase = 0 ;
Getopt::Long:: Configure ( "bundling" ) ;
2011-05-20 09:19:02 +00:00
if ( ! GetOptions ( \ % opt , qw( V|verbose h|help s ) ) ) {
2009-05-26 06:02:03 +00:00
return ( usage ( ) ) ;
}
2009-08-06 11:22:29 +00:00
return usage ( ) if ( exists $ opt { h } ) ;
2009-05-26 06:02:03 +00:00
#############################################
# Process command-line arguments
#############################################
2009-08-04 20:28:03 +00:00
if ( scalar ( @ ARGV ) ) {
2011-05-20 09:19:02 +00:00
unless ( $ opt { s } ) {
2009-05-26 06:02:03 +00:00
return ( usage ( "No additional flag is support by this command" ) ) ;
2011-05-20 09:19:02 +00:00
}
2009-05-26 06:02:03 +00:00
}
2009-07-31 21:11:48 +00:00
##########################################
# Check if CECs are controlled by a frame
##########################################
my $ nodes = $ request - > { node } ;
my $ ppctab = xCAT::Table - > new ( 'ppc' ) ;
2009-08-04 22:44:58 +00:00
return ( [ "Failed to open table 'ppc'.\n" ] ) if ( ! $ ppctab ) ;
2009-07-31 21:11:48 +00:00
my $ vpdtab = xCAT::Table - > new ( 'vpd' ) ;
2009-08-04 22:44:58 +00:00
return ( [ "Failed to open table 'vpd'.\n" ] ) if ( ! $ vpdtab ) ;
2009-07-31 21:11:48 +00:00
my @ bpa_ctrled_nodes = ( ) ;
my @ no_type_nodes = ( ) ;
my @ frame_members = ( ) ;
2009-08-04 22:44:58 +00:00
for my $ node ( @$ nodes )
2009-07-31 21:11:48 +00:00
{
2009-08-04 22:44:58 +00:00
my $ node_parent = undef ;
my $ node_parent_hash = $ ppctab - > getNodeAttribs ( $ node , [ qw( parent ) ] ) ;
$ node_parent = $ node_parent_hash - > { parent } ;
2011-02-19 09:49:11 +00:00
my $ newtype = xCAT::DBobjUtils:: getnodetype ( $ node ) ;
unless ( $ newtype ) {
2009-08-04 22:44:58 +00:00
push @ no_type_nodes , $ node ;
2012-04-06 02:21:26 +00:00
next ;
2009-08-04 22:44:58 +00:00
}
2011-02-19 09:49:11 +00:00
if ( $ newtype =~ /^(fsp|bpa)$/ )
2009-08-04 22:44:58 +00:00
{
2011-02-19 09:49:11 +00:00
##########################################
# We should judge if the node is defined in xCAT 2.5
# If it is, it should really be a cec or frame
# If not, we will do nothing to it,
# which means we support remove a sigal connection
##########################################
my $ jr = xCAT::DBobjUtils:: judge_node ( $ node , $ newtype ) ;
#$jr is defined by the xCAT2.5
unless ( $ jr )
{
if ( ( $ newtype eq 'fsp' ) and $ node_parent and $ node_parent ne $ node )
{
push @ bpa_ctrled_nodes , $ node ;
}
2009-08-04 22:44:58 +00:00
2011-02-19 09:49:11 +00:00
if ( $ newtype eq 'bpa' )
{
my $ my_frame_bpa_cec = getFrameMembers ( $ node , $ vpdtab , $ ppctab ) ;
push @ frame_members , @$ my_frame_bpa_cec ;
}
}
}
if ( ( $ newtype eq 'cec' ) and $ node_parent and $ node_parent ne $ node )
2009-08-04 22:44:58 +00:00
{
2011-02-19 09:49:11 +00:00
#push @bpa_ctrled_nodes, $node;
2009-07-31 21:11:48 +00:00
}
2011-02-19 09:49:11 +00:00
if ( $ newtype eq 'frame' )
2011-02-14 09:37:04 +00:00
{
my $ my_frame_bpa_cec = xCAT::DBobjUtils:: getcecchildren ( $ node ) ;
push @ frame_members , @$ my_frame_bpa_cec ;
push @ frame_members , $ node ;
}
2009-07-31 21:11:48 +00:00
}
if ( scalar ( @ no_type_nodes ) )
{
my $ tmp_nodelist = join ',' , @ no_type_nodes ;
2012-04-06 02:21:26 +00:00
return ( usage ( "Attribute nodetype.nodetype cannot be found for node(s) $tmp_nodelist. Please define first and try again.\n" ) ) ;
2009-07-31 21:11:48 +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." ) ) ;
}
2011-06-21 06:42:00 +00:00
2009-07-31 21:11:48 +00:00
if ( scalar ( @ frame_members ) )
{
my @ all_nodes = xCAT::Utils:: get_unique_members ( @$ nodes , @ frame_members ) ;
$ request - > { node } = \ @ all_nodes ;
}
2009-08-04 20:28:03 +00:00
$ request - > { method } = 'rmhwconn' ;
2009-05-26 06:02:03 +00:00
return ( \ % opt ) ;
2009-05-20 09:04:19 +00:00
}
##########################################################################
# Create connection for CECs/BPAs
##########################################################################
2009-08-04 20:28:03 +00:00
sub mkhwconn
2009-05-20 09:04:19 +00:00
{
my $ request = shift ;
my $ hash = shift ;
my $ exp = shift ;
my $ hwtype = @$ exp [ 2 ] ;
my $ opt = $ request - > { opt } ;
my @ value = ( ) ;
my $ Rc = undef ;
for my $ cec_bpa ( keys %$ hash )
{
my $ node_hash = $ hash - > { $ cec_bpa } ;
2009-07-31 21:11:48 +00:00
for my $ node_name ( keys %$ node_hash )
2009-05-20 09:04:19 +00:00
{
2009-07-31 21:11:48 +00:00
my $ d = $ node_hash - > { $ node_name } ;
############################
# Get IP address
############################
2011-02-19 09:49:11 +00:00
my $ cnode ;
my $ ntype = xCAT::DBobjUtils:: getnodetype ( $ node_name ) ;
if ( $ ntype =~ /^(cec|frame)$/ )
2009-07-31 21:11:48 +00:00
{
2011-02-19 09:49:11 +00:00
$ cnode = xCAT::DBobjUtils:: getchildren ( $ node_name , $ opt - > { port } ) ;
} else {
$ cnode = $ node_name ;
2009-05-20 09:04:19 +00:00
}
2011-02-19 09:49:11 +00:00
my @ newnodes = ( ) ;
if ( $ cnode =~ /ARRAY/ )
2009-07-31 21:11:48 +00:00
{
2011-02-19 09:49:11 +00:00
foreach ( @$ cnode ) {
push @ newnodes , $ _ ;
}
} else {
push @ newnodes , $ cnode ;
2009-07-31 21:11:48 +00:00
}
2011-02-19 09:49:11 +00:00
for my $ nn ( @ newnodes )
2009-07-31 21:11:48 +00:00
{
2011-02-19 09:49:11 +00:00
my $ node_ip ;
unless ( xCAT::Utils - > isIpaddr ( $ nn ) ) {
$ node_ip = xCAT::Utils:: getNodeIPaddress ( $ nn ) ;
} else {
$ node_ip = $ nn ;
}
unless ( $ node_ip )
2009-09-11 10:54:39 +00:00
{
2011-02-19 09:49:11 +00:00
push @ value , [ $ node_name , "Cannot get IP address. Please check table 'hosts' or name resolution" , 1 ] ;
2009-09-11 10:54:39 +00:00
next ;
}
2011-02-19 09:49:11 +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 ;
}
2009-05-20 09:04:19 +00:00
2011-02-19 09:49:11 +00:00
}
my $ res = xCAT::PPCcli:: mksysconn ( $ exp , $ node_ip , $ type , $ passwd ) ;
$ Rc = shift @$ res ;
push @ value , [ $ node_name , @$ res [ 0 ] , $ Rc ] ;
2011-07-15 15:19:39 +00:00
if ( ! $ Rc and ! ( exists $ opt - > { s } ) )
2011-02-19 09:49:11 +00:00
{
sethmcmgt ( $ node_name , $ exp - > [ 3 ] ) ;
}
2009-07-31 21:11:48 +00:00
}
2009-12-28 08:10:42 +00:00
# if ( exists $opt->{N} )
# {
# my $newpwd = $opt->{N};
# my $Res = xCAT::PPCcli::chsyspwd( $exp, "access", $type, $mtms, $passwd, $newpwd );
# $Rc = shift @$Res;
# push @value, [$node_name, @$Res[0], $Rc];
# }
2009-07-31 19:45:28 +00:00
}
2009-05-20 09:04:19 +00:00
}
return \ @ value ;
}
2009-05-26 06:02:03 +00:00
##########################################################################
# List connection status for CECs/BPAs
##########################################################################
2009-08-04 20:28:03 +00:00
sub lshwconn
2009-05-20 09:04:19 +00:00
{
2009-05-26 06:02:03 +00:00
my $ request = shift ;
my $ hash = shift ;
my $ exp = shift ;
my $ hwtype = @$ exp [ 2 ] ;
my $ opt = $ request - > { opt } ;
my @ value = ( ) ;
my $ Rc = undef ;
2009-12-28 08:10:42 +00:00
2009-07-31 21:11:48 +00:00
my $ hosttab = xCAT::Table - > new ( 'hosts' ) ;
2009-12-28 08:10:42 +00:00
my $ res = xCAT::PPCcli:: lssysconn ( $ exp , "all" ) ;
2009-05-26 06:02:03 +00:00
$ Rc = shift @$ res ;
2009-07-20 18:46:13 +00:00
if ( $ request - > { nodetype } eq 'hmc' )
2009-05-20 09:04:19 +00:00
{
2009-07-20 18:46:13 +00:00
if ( $ Rc )
2009-05-20 09:04:19 +00:00
{
2009-07-20 18:46:13 +00:00
push @ value , [ $ exp - > [ 3 ] , $ res - > [ 0 ] , $ Rc ] ;
return \ @ value ;
2009-05-20 09:04:19 +00:00
}
2009-07-20 18:46:13 +00:00
my $ vpdtab = xCAT::Table - > new ( 'vpd' ) ;
my @ vpdentries = $ vpdtab - > getAllAttribs ( qw( node serial mtm ) ) ;
my % node_vpd_hash ;
for my $ vpdent ( @ vpdentries )
2009-05-20 09:04:19 +00:00
{
2009-07-20 18:46:13 +00:00
if ( $ vpdent - > { node } and $ vpdent - > { serial } and $ vpdent - > { mtm } )
{
$ node_vpd_hash { "$vpdent->{mtm}*$vpdent->{serial}" } = $ vpdent - > { node } ;
}
2009-05-26 06:02:03 +00:00
}
2009-10-15 07:49:19 +00:00
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 } ;
}
2009-07-20 18:46:13 +00:00
for my $ r ( @$ res )
2009-05-26 06:02:03 +00:00
{
2009-07-20 18:46:13 +00:00
$ 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 } ;
2009-10-15 07:49:19 +00:00
$ r = "hcp=$exp->[3],parent=$node_ppc_hash{$node_name}," . $ r ;
2009-07-20 18:46:13 +00:00
}
else
2009-05-20 09:04:19 +00:00
{
2009-07-20 18:46:13 +00:00
$ node_name = $ mtms ;
2009-10-15 07:49:19 +00:00
$ r = "hcp=$exp->[3],parent=," . $ r ;
2009-05-20 09:04:19 +00:00
}
2009-07-20 18:46:13 +00:00
push @ value , [ $ node_name , $ r , $ Rc ] ;
2009-05-20 09:04:19 +00:00
}
2009-07-20 18:46:13 +00:00
}
else
{
for my $ cec_bpa ( keys %$ hash )
2009-05-26 06:02:03 +00:00
{
2009-07-20 18:46:13 +00:00
my $ node_hash = $ hash - > { $ cec_bpa } ;
2009-07-31 21:11:48 +00:00
for my $ node_name ( keys %$ node_hash )
2009-07-20 18:46:13 +00:00
{
2009-07-31 21:11:48 +00:00
############################################
# If lssysconn failed, put error into all
# nodes' return values
############################################
if ( $ Rc )
{
push @ value , [ $ node_name , @$ res [ 0 ] , $ Rc ] ;
next ;
}
2009-07-20 18:46:13 +00:00
2009-07-31 21:11:48 +00:00
############################
# Get IP address
############################
my $ node_ip = undef ;
if ( $ hosttab )
2009-07-20 18:46:13 +00:00
{
2011-02-19 09:49:11 +00:00
#my $node_ip_hash = $hosttab->getNodeAttribs( $node_name,[qw(ip)]);
#$node_ip = $node_ip_hash->{ip};
2011-12-15 07:28:02 +00:00
#$node_ip = xCAT::Utils::getNodeIPaddress( $node_name );
2012-05-02 06:42:48 +00:00
my $ d = $ node_hash - > { $ node_name } ;
2012-05-02 06:30:46 +00:00
$ node_ip = xCAT::FSPUtils:: getIPaddress ( $ request , $$ d [ 4 ] , $ node_name ) ;
2009-07-31 21:11:48 +00:00
}
2011-12-15 07:28:02 +00:00
if ( ! $ node_ip || ( $ node_ip == - 3 ) )
2009-07-31 21:11:48 +00:00
{
2011-12-15 07:28:02 +00:00
push @ value , [ $ node_name , "Failed to get IP address." , $ Rc ] ;
2009-12-28 08:10:42 +00:00
next ;
2009-07-31 21:11:48 +00:00
}
2011-02-19 09:49:11 +00:00
my @ nodes_ip = split ( /,/ , $ node_ip ) ;
for my $ ip ( @ nodes_ip )
2009-07-31 21:11:48 +00:00
{
2011-02-19 09:49:11 +00:00
if ( my @ res_matched = grep /\Qipaddr=$ip,\E/ , @$ res )
2009-07-31 21:11:48 +00:00
{
2011-02-19 09:49:11 +00:00
for my $ r ( @ res_matched )
{
$ r =~ s/\Qtype_model_serial_num=$cec_bpa,\E// ;
#$r =~ s/\Qresource_type=$type,\E//;
$ r =~ s/sp=.*?,// ;
2009-07-31 21:11:48 +00:00
$ r =~ s/sp_phys_loc=.*?,// ;
2011-02-19 09:49:11 +00:00
my $ new_name = $ node_name . "(" . $ ip . ")" ;
push @ value , [ $ new_name , $ r , $ Rc ] ;
}
}
else
{
my $ new_name = $ node_name . "(" . $ ip . ")" ;
push @ value , [ $ new_name , 'Connection not found' , 1 ] ;
2009-07-31 21:11:48 +00:00
}
2009-07-20 18:46:13 +00:00
}
}
2009-05-26 06:02:03 +00:00
}
2009-05-20 09:04:19 +00:00
}
2009-05-26 06:02:03 +00:00
return \ @ value ;
}
##########################################################################
# Remove connection for CECs/BPAs to HMCs
##########################################################################
2009-08-04 20:28:03 +00:00
sub rmhwconn
2009-05-26 06:02:03 +00:00
{
my $ request = shift ;
my $ hash = shift ;
my $ exp = shift ;
my $ hwtype = @$ exp [ 2 ] ;
my $ opt = $ request - > { opt } ;
my @ value = ( ) ;
my $ Rc = undef ;
2011-08-10 10:54:38 +00:00
my $ nodes_found = xCAT::PPCcli:: lssysconn ( $ exp , "all" ) ;
if ( @$ nodes_found [ 0 ] eq SUCCESS ) {
$ Rc = shift ( @$ nodes_found ) ;
} else {
return undef ;
}
2009-05-26 06:02:03 +00:00
for my $ cec_bpa ( keys %$ hash )
{
my $ node_hash = $ hash - > { $ cec_bpa } ;
2009-07-31 21:11:48 +00:00
for my $ node_name ( keys %$ node_hash )
{
my $ d = $ node_hash - > { $ node_name } ;
2009-05-26 06:02:03 +00:00
2009-07-31 21:11:48 +00:00
my ( undef , undef , undef , undef , $ type ) = @$ d ;
2009-05-26 06:02:03 +00:00
2009-07-31 21:11:48 +00:00
############################
# Get IP address
############################
2011-08-10 10:54:38 +00:00
#get node ip from hmc
#my $node_ip = xCAT::PPCcli::getHMCcontrolIP($node_name, $exp);
my $ tab = xCAT::Table - > new ( "vpd" ) ;
my $ ent ;
if ( $ tab ) {
$ ent = $ tab - > getNodeAttribs ( $ node_name , [ 'serial' , 'mtm' ] ) ;
}
my $ serial = $ ent - > { 'serial' } ;
my $ mtm = $ ent - > { 'mtm' } ;
my $ node_ip ;
my @ ips ;
foreach my $ entry ( @$ nodes_found ) {
if ( $ entry =~ /$mtm\*$serial/ ) {
$ entry =~ /ipaddr=(\d+\.\d+\.\d+\.\d+),/ ;
push @ ips , $ 1 ;
}
}
if ( ! @ ips )
2009-07-31 21:11:48 +00:00
{
2009-12-28 08:10:42 +00:00
push @ value , [ $ node_name , $ node_ip , $ Rc ] ;
next ;
2009-07-31 21:11:48 +00:00
}
2011-08-10 10:54:38 +00:00
for my $ nn ( @ ips )
2009-07-31 21:11:48 +00:00
{
2011-02-19 09:49:11 +00:00
my $ res = xCAT::PPCcli:: rmsysconn ( $ exp , $ type , $ nn ) ;
$ Rc = shift @$ res ;
push @ value , [ $ node_name , @$ res [ 0 ] , $ Rc ] ;
2011-05-20 09:19:02 +00:00
if ( ! $ Rc and ! $ opt - > { s } )
2011-02-19 09:49:11 +00:00
{
rmhmcmgt ( $ node_name , $ type ) ;
}
2009-07-31 21:11:48 +00:00
}
2009-07-31 19:45:28 +00:00
}
2009-05-26 06:02:03 +00:00
}
return \ @ value ;
2009-05-20 09:04:19 +00:00
}
2009-07-31 19:45:28 +00:00
#################################################################
# set node mgt to hmc, and hcp to the hmc node name
#################################################################
sub sethmcmgt
{
my $ node = shift ;
my $ hcp = shift ;
my $ nodehm_tab = xCAT::Table - > new ( 'nodehm' , - create = > 1 ) ;
2011-05-10 08:00:32 +00:00
my $ ppc_tab = xCAT::Table - > new ( 'ppc' , - create = > 1 ) ;
my @ nodes ;
push @ nodes , $ node ;
my $ ntype = xCAT::DBobjUtils - > getnodetype ( $ node ) ;
if ( $ ntype =~ /^(cec|frame)$/ ) {
my $ cnodep = xCAT::DBobjUtils - > getchildren ( $ node ) ;
if ( $ cnodep ) {
push @ nodes , @$ cnodep ;
}
}
for my $ n ( @ nodes ) {
my $ ent = $ nodehm_tab - > getNodeAttribs ( $ n , [ 'mgt' ] ) ;
if ( ! $ ent or $ ent - > { mgt } ne 'hmc' ) {
$ nodehm_tab - > setNodeAttribs ( $ n , { mgt = > 'hmc' } ) ;
}
my $ ent = $ ppc_tab - > getNodeAttribs ( $ n , [ 'hcp' ] ) ;
if ( ! $ ent or $ ent - > { hcp } ne $ hcp ) {
$ ppc_tab - > setNodeAttribs ( $ n , { hcp = > $ hcp } ) ;
}
2009-07-31 19:45:28 +00:00
}
}
#################################################################
# set node as the standalone fsp/bpa node
#################################################################
sub rmhmcmgt
{
my $ node = shift ;
my $ hwtype = shift ;
my $ nodehm_tab = xCAT::Table - > new ( 'nodehm' , - create = > 1 ) ;
my $ ppc_tab = xCAT::Table - > new ( 'ppc' , - create = > 1 ) ;
2011-05-10 08:00:32 +00:00
my @ nodes ;
push @ nodes , $ node ;
my $ ntype = xCAT::DBobjUtils - > getnodetype ( $ node ) ;
if ( $ ntype =~ /^(cec|frame)$/ ) {
my $ cnodep = xCAT::DBobjUtils - > getchildren ( $ node ) ;
if ( $ cnodep ) {
push @ nodes , @$ cnodep ;
}
2009-07-31 19:45:28 +00:00
}
2011-05-10 08:00:32 +00:00
for my $ n ( @ nodes ) {
my $ ent = $ nodehm_tab - > getNodeAttribs ( $ n , [ 'mgt' ] ) ;
if ( ! $ ent or $ ent - > { mgt } ne $ hwtype ) {
if ( $ hwtype eq "cec" || $ hwtype eq "frame" ) {
$ nodehm_tab - > setNodeAttribs ( $ n , { mgt = > "fsp" } ) ;
} else {
$ nodehm_tab - > setNodeAttribs ( $ n , { mgt = > $ hwtype } ) ;
}
}
my $ ent = $ ppc_tab - > getNodeAttribs ( $ n , [ 'hcp' ] ) ;
if ( ! $ ent or $ ent - > { hcp } ne $ n ) {
$ ppc_tab - > setNodeAttribs ( $ n , { hcp = > $ n } ) ;
}
}
2009-07-31 19:45:28 +00:00
}
2009-05-20 09:04:19 +00:00
1 ;