2007-11-16 19:42:46 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT_plugin::fsp;
|
|
|
|
use strict;
|
|
|
|
use xCAT::PPC;
|
2011-04-07 07:02:47 +00:00
|
|
|
use xCAT::DBobjUtils;
|
2013-03-12 10:46:21 +00:00
|
|
|
use xCAT::Utils;
|
2011-04-11 02:41:18 +00:00
|
|
|
use xCAT_plugin::hmc;
|
2007-11-16 19:42:46 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Command handler method from tables
|
|
|
|
##########################################################################
|
|
|
|
sub handled_commands {
|
|
|
|
return {
|
|
|
|
rpower => 'nodehm:power,mgt',
|
2012-12-07 06:52:32 +00:00
|
|
|
#reventlog => 'nodehm:mgt',
|
2009-05-20 09:04:19 +00:00
|
|
|
rspconfig => 'nodehm:mgt',
|
2009-12-02 09:38:51 +00:00
|
|
|
mkhwconn => 'nodehm:mgt',
|
|
|
|
rmhwconn => 'nodehm:mgt',
|
|
|
|
lshwconn => 'nodehm:mgt',
|
|
|
|
renergy => 'nodehm:mgt' ,
|
|
|
|
rinv => 'nodehm:mgt',
|
2010-01-07 06:00:53 +00:00
|
|
|
rflash => 'nodehm:mgt',
|
|
|
|
getmacs => 'nodehm:mgt',
|
2010-01-18 06:14:05 +00:00
|
|
|
rnetboot => 'nodehm:mgt',
|
2010-12-13 05:56:39 +00:00
|
|
|
rbootseq => 'nodehm:mgt',
|
2010-05-12 08:21:22 +00:00
|
|
|
rvitals => 'nodehm:mgt',
|
2010-11-25 03:41:36 +00:00
|
|
|
mkvm => 'nodehm:mgt',
|
|
|
|
lsvm => 'nodehm:mgt',
|
2011-03-02 09:35:53 +00:00
|
|
|
chvm => 'nodehm:mgt',
|
2013-09-05 06:27:28 +00:00
|
|
|
rmvm => 'nodehm:mgt',
|
2011-04-07 07:02:47 +00:00
|
|
|
rscan => 'nodehm:mgt',
|
|
|
|
getfspcon => 'nodehm:cons',
|
2011-04-11 02:41:18 +00:00
|
|
|
getmulcon => 'fsp',
|
2014-09-11 09:38:47 +00:00
|
|
|
findme => 'fsp',
|
2007-11-16 19:42:46 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################
|
2008-04-16 16:45:14 +00:00
|
|
|
# Pre-process request from xCat daemon
|
2007-11-16 19:42:46 +00:00
|
|
|
##########################################################################
|
2008-04-16 16:45:14 +00:00
|
|
|
sub preprocess_request {
|
2008-01-15 15:29:42 +00:00
|
|
|
|
|
|
|
#######################################################
|
|
|
|
# IO::Socket::SSL apparently does not work with LWP.pm
|
|
|
|
# When used, POST/GETs return immediately with:
|
|
|
|
# 500 Can't connect to <nodename>:443 (Timeout)
|
|
|
|
#
|
2008-06-02 17:29:52 +00:00
|
|
|
# Net::HTTPS, which is used by LWP::Protocol::https::Socket,
|
2008-01-15 15:29:42 +00:00
|
|
|
# uses either IO::Socket::SSL or Net::SSL. It chooses
|
|
|
|
# by looking to see if $IO::Socket::SSL::VERSION
|
|
|
|
# is defined (i.e. the module's already loaded) and
|
|
|
|
# uses that if so. If not, it first tries Net::SSL,
|
|
|
|
# then IO::Socket::SSL only if that cannot be loaded.
|
2008-06-02 17:29:52 +00:00
|
|
|
# So we should invalidate IO::Socket::SSL here and
|
|
|
|
# load Net::SSL.
|
2008-01-15 15:29:42 +00:00
|
|
|
#######################################################
|
2008-01-17 16:58:07 +00:00
|
|
|
$IO::Socket::SSL::VERSION = undef;
|
2008-01-15 15:29:42 +00:00
|
|
|
eval { require Net::SSL };
|
|
|
|
if ( $@ ) {
|
|
|
|
my $callback = $_[1];
|
2008-06-02 17:29:52 +00:00
|
|
|
$callback->( {errorcode=>1,data=>[$@]} );
|
2008-01-15 15:29:42 +00:00
|
|
|
return(1);
|
|
|
|
}
|
2011-04-07 07:02:47 +00:00
|
|
|
my ($arg1, $arg2, $arg3) = @_;
|
|
|
|
if ($arg1->{command}->[0] eq "getfspcon") { #Can handle it here and now
|
|
|
|
my $node = $arg1->{noderange}->[0];
|
|
|
|
my $callback = $arg2;
|
|
|
|
getfspcon($node,$callback);
|
|
|
|
return [];
|
2011-04-11 02:41:18 +00:00
|
|
|
}
|
|
|
|
if ($arg1->{command}->[0] eq "getmulcon") { #Can handle it here and now
|
|
|
|
my $node = $arg1->{noderange}->[0];
|
|
|
|
my $callback = $arg2;
|
|
|
|
getmulcon($node,$callback);
|
|
|
|
return [];
|
2013-03-12 10:46:21 +00:00
|
|
|
}
|
|
|
|
if ($arg1->{command}->[0] =~ /rspconfig|rvitals|getmacs|renergy/) {
|
2011-12-21 02:51:05 +00:00
|
|
|
# All the nodes with mgt=blade or mgt=fsp will get here
|
|
|
|
# filter out the nodes for fsp.pm
|
2013-03-12 10:46:21 +00:00
|
|
|
my (@fspnodes, @nohandle);
|
|
|
|
xCAT::Utils->filter_nodes($arg1, undef, \@fspnodes, undef, \@nohandle);
|
2011-12-21 02:51:05 +00:00
|
|
|
if (@fspnodes) {
|
2014-12-22 13:25:43 +00:00
|
|
|
$arg1->{node} = \@fspnodes;
|
2011-12-21 02:51:05 +00:00
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 09:30:08 +00:00
|
|
|
|
2008-04-16 16:45:14 +00:00
|
|
|
xCAT::PPC::preprocess_request(__PACKAGE__,@_);
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Process request from xCat daemon
|
|
|
|
##########################################################################
|
|
|
|
sub process_request {
|
2007-11-16 19:42:46 +00:00
|
|
|
xCAT::PPC::process_request(__PACKAGE__,@_);
|
|
|
|
}
|
|
|
|
|
2011-04-07 07:02:47 +00:00
|
|
|
##########################################################################
|
|
|
|
# get hcp and id for rcons with fsp
|
|
|
|
##########################################################################
|
|
|
|
sub getfspcon {
|
|
|
|
|
|
|
|
my $node = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my @attribs = qw(id parent hcp);
|
|
|
|
my %tabs = ();
|
|
|
|
my $rsp;
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Open databases needed
|
|
|
|
##################################
|
|
|
|
foreach ( qw(ppc vpd nodetype) ) {
|
|
|
|
$tabs{$_} = xCAT::Table->new($_);
|
|
|
|
|
|
|
|
if ( !exists( $tabs{$_} )) {
|
|
|
|
#return( sprintf( $errmsg{DB_UNDEF}, $_ ));
|
|
|
|
$rsp->{node}->[0]->{error}=["open table $_ error"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
2011-04-11 02:41:18 +00:00
|
|
|
$callback->($rsp);
|
|
|
|
return $rsp;
|
2011-04-07 07:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Get node type
|
|
|
|
#################################
|
2012-02-10 09:04:50 +00:00
|
|
|
my $type = xCAT::DBobjUtils->getnodetype($node, "ppc");
|
2011-04-07 07:02:47 +00:00
|
|
|
#my ($type) = grep( /^(lpar|osi)$/, @types );
|
|
|
|
|
2012-03-05 06:54:40 +00:00
|
|
|
if ( !defined( $type ) or !($type =~ /lpar|blade/) ) {
|
2011-04-07 07:02:47 +00:00
|
|
|
#return( "Invalid node type: $ent->{nodetype}" );
|
|
|
|
$rsp->{node}->[0]->{error}=["Invalid node type: $type"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
2011-04-11 02:41:18 +00:00
|
|
|
$callback->($rsp);
|
|
|
|
return $rsp;
|
2011-04-07 07:02:47 +00:00
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Get attributes
|
|
|
|
#################################
|
2011-12-07 16:55:32 +00:00
|
|
|
my ($att) = $tabs{ppc}->getNodeAttribs($node, @attribs );
|
2011-04-07 07:02:47 +00:00
|
|
|
|
|
|
|
if ( !defined( $att )) {
|
|
|
|
#return( sprintf( $errmsg{NODE_UNDEF}, "ppc" ));
|
|
|
|
$rsp->{node}->[0]->{error}=["node is not defined in ppc table"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
2011-04-11 02:41:18 +00:00
|
|
|
$callback->($rsp);
|
|
|
|
return $rsp;
|
2011-04-07 07:02:47 +00:00
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Verify required attributes
|
|
|
|
#################################
|
|
|
|
foreach my $at ( @attribs ) {
|
|
|
|
if ( !exists( $att->{$at} )) {
|
|
|
|
#return( sprintf( $errmsg{NO_ATTR}, $at, "ppc" ));
|
|
|
|
$rsp->{node}->[0]->{error}=["Can't find node tarribute $at in ppc table"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
2011-04-11 02:41:18 +00:00
|
|
|
$callback->($rsp);
|
|
|
|
return $rsp;
|
2011-04-07 07:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $fsp_name = $att->{hcp};
|
|
|
|
my $id = $att->{id};
|
2012-04-28 09:25:04 +00:00
|
|
|
|
2012-05-10 02:00:52 +00:00
|
|
|
my %request;
|
|
|
|
xCAT::FSPUtils::getHcpAttribs(\%request, \%tabs);
|
2012-08-09 04:07:40 +00:00
|
|
|
#my $fsp_ip = xCAT::NetworkUtils::getNodeIPaddress( $fsp_name );
|
2012-05-10 02:00:52 +00:00
|
|
|
my $fsp_ip = xCAT::FSPUtils::getIPaddress(\%request, $type, $fsp_name );
|
2011-04-07 07:02:47 +00:00
|
|
|
if(!defined($fsp_ip)) {
|
|
|
|
#return "Failed to get the $fsp_name\'s ip";
|
|
|
|
$rsp->{node}->[0]->{error}=["Can't get node address"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
2011-04-11 02:41:18 +00:00
|
|
|
$callback->($rsp);
|
|
|
|
return $rsp;
|
2011-04-07 07:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$rsp = {node=>[{name=>[$node]}]};
|
|
|
|
$rsp->{node}->[0]->{fsp_ip}->[0]=$fsp_ip;
|
|
|
|
$rsp->{node}->[0]->{id}->[0]=$id;
|
2012-03-05 10:25:08 +00:00
|
|
|
$rsp->{node}->[0]->{type}->[0]=$type;
|
2011-04-07 07:02:47 +00:00
|
|
|
$callback->($rsp);
|
2011-04-11 02:41:18 +00:00
|
|
|
return $rsp
|
2011-04-07 07:02:47 +00:00
|
|
|
}
|
2011-04-11 02:41:18 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# get information for require of multiple sending
|
|
|
|
##########################################################################
|
|
|
|
sub getmulcon {
|
|
|
|
|
|
|
|
my $node = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my @attribs = qw(id parent hcp);
|
|
|
|
my %tabs = ();
|
|
|
|
my %hcphash;
|
|
|
|
my $rsp;
|
|
|
|
my $rsp2;
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Open databases needed
|
|
|
|
##################################
|
|
|
|
foreach ( qw(ppc nodetype) ) {
|
|
|
|
$tabs{$_} = xCAT::Table->new($_);
|
|
|
|
|
|
|
|
if ( !exists( $tabs{$_} )) {
|
|
|
|
$rsp->{node}->[0]->{error}=["open table $_ error"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Get node type
|
|
|
|
#################################
|
2012-02-10 09:04:50 +00:00
|
|
|
my $ntype = xCAT::DBobjUtils->getnodetype($node, "ppc");
|
2011-06-03 07:24:34 +00:00
|
|
|
my @types = split /,/, $ntype;
|
2011-04-11 02:41:18 +00:00
|
|
|
my ($type) = grep( /^(lpar|osi)$/, @types );
|
|
|
|
|
|
|
|
if ( !defined( $type )) {
|
|
|
|
$rsp->{node}->[0]->{error}=["nodetype is invalid"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Get attributes
|
|
|
|
#################################
|
2011-12-07 16:55:32 +00:00
|
|
|
my ($att) = $tabs{ppc}->getNodeAttribs($node, @attribs );
|
2011-04-11 02:41:18 +00:00
|
|
|
|
|
|
|
if ( !defined( $att )) {
|
|
|
|
$rsp->{node}->[0]->{error}=["Node is not defined in ppc table"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Verify required attributes
|
|
|
|
#################################
|
|
|
|
foreach my $at ( @attribs ) {
|
|
|
|
if ( !exists( $att->{$at} )) {
|
|
|
|
$rsp->{node}->[0]->{error}=["Can't find node attribute in ppc table"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my $id = $att->{id};
|
|
|
|
my $parent = $att->{parent};
|
|
|
|
my $hcps = $att->{hcp};
|
|
|
|
my @hcp_list = split(",", $hcps);
|
|
|
|
my $cmd = ();
|
|
|
|
my $res;
|
|
|
|
my $Rc;
|
|
|
|
my $c = @hcp_list;
|
2007-11-16 19:42:46 +00:00
|
|
|
|
2012-02-10 09:04:50 +00:00
|
|
|
my $hashtype = xCAT::DBobjUtils->getnodetype(\@hcp_list, "ppc");
|
2011-04-11 02:41:18 +00:00
|
|
|
foreach my $thishcp ( @hcp_list ) {
|
2012-02-10 09:04:50 +00:00
|
|
|
my $thishcp_type = $$hashtype{$thishcp};
|
2011-04-11 02:41:18 +00:00
|
|
|
if(!defined($thishcp_type)) {
|
|
|
|
$rsp->{node}->[0]->{error}=["Can't get nodetype of $thishcp"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$hcphash{$thishcp}{nodetype} = $thishcp_type;
|
|
|
|
if($thishcp_type =~ /^(fsp)$/) {
|
|
|
|
$rsp = getfspcon($node,$callback);
|
|
|
|
if ( $rsp->{node}->[0]->{errorcode} ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$hcphash{$thishcp}{fsp_ip} = $rsp->{node}->[0]->{fsp_ip}->[0];
|
|
|
|
$hcphash{$thishcp}{id} = $rsp->{node}->[0]->{id}->[0];
|
|
|
|
} elsif ($thishcp_type =~ /^(hmc)$/) {
|
|
|
|
$rsp = xCAT_plugin::hmc::gethmccon($node,$callback,$thishcp);
|
|
|
|
if ( $rsp->{node}->[0]->{errorcode} ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$hcphash{$thishcp}{host} = $thishcp;
|
|
|
|
$hcphash{$thishcp}{lparid} = $rsp->{node}->[0]->{lparid}->[0];
|
|
|
|
$hcphash{$thishcp}{mtms} = $rsp->{node}->[0]->{mtms}->[0];
|
|
|
|
$hcphash{$thishcp}{credencial} = $rsp->{node}->[0]->{cred}->[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$rsp2->{node}->[0]->{hcp}->[0] = \%hcphash;
|
|
|
|
$callback->($rsp2);
|
|
|
|
}
|
2007-11-16 19:42:46 +00:00
|
|
|
|
2011-12-27 03:39:38 +00:00
|
|
|
##########################################################################
|
|
|
|
# generate hardware tree, called from lstree.
|
|
|
|
##########################################################################
|
|
|
|
sub genhwtree
|
|
|
|
{
|
|
|
|
my $nodelist = shift; # array ref
|
|
|
|
my $callback = shift;
|
|
|
|
my %hwtree;
|
|
|
|
|
|
|
|
# read ppc table
|
|
|
|
my $ppctab = xCAT::Table->new('ppc');
|
|
|
|
unless ($ppctab)
|
|
|
|
{
|
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = "Can not open ppc table.\n";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
my @entries = $ppctab->getAllNodeAttribs(['node','parent','hcp']);
|
|
|
|
|
|
|
|
##################################################################
|
|
|
|
####################refine the loop after getnodetype updated!!!!!
|
|
|
|
##################################################################
|
2012-02-10 09:04:50 +00:00
|
|
|
my $typehash = xCAT::DBobjUtils->getnodetype(\@$nodelist, "ppc");
|
2011-12-27 03:39:38 +00:00
|
|
|
# only handle physical hardware objects here.
|
|
|
|
foreach my $node (@$nodelist)
|
|
|
|
{
|
|
|
|
# will build a hash like sfp->frame->cec
|
2012-02-10 09:04:50 +00:00
|
|
|
my $ntype = $$typehash{$node};
|
2011-12-27 03:39:38 +00:00
|
|
|
if ($ntype =~ /^frame$/)
|
|
|
|
{
|
|
|
|
# assume frame always available in DFM.
|
|
|
|
# try to see if sfp available.
|
|
|
|
my $frment = $ppctab->getNodeAttribs($node, ['sfp']);
|
|
|
|
|
|
|
|
foreach my $ent (@entries)
|
|
|
|
{
|
|
|
|
# get all cecs by this frame
|
|
|
|
if ($ent->{parent} =~ /$node/)
|
|
|
|
{
|
|
|
|
if ($frment->{sfp})
|
|
|
|
{
|
|
|
|
unless (grep(/$ent->{node}/, @{$hwtree{$frment->{sfp}}{$node}}))
|
|
|
|
{
|
|
|
|
push @{$hwtree{$frment->{sfp}}{$node}}, $ent->{node};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unless (grep(/$ent->{node}/, @{$hwtree{0}{$node}}))
|
|
|
|
{
|
|
|
|
push @{$hwtree{0}{$node}}, $ent->{node};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($ntype =~ /^cec$/)
|
|
|
|
{
|
|
|
|
# get cec's parent
|
|
|
|
my $cent = $ppctab->getNodeAttribs($node, ['parent']);
|
|
|
|
if ($cent->{parent}) # assume frame always available for DFM
|
|
|
|
{
|
|
|
|
# try to see if sfp available.
|
|
|
|
my $frment = $ppctab->getNodeAttribs($cent->{parent}, ['sfp']);
|
|
|
|
if ($frment->{sfp})
|
|
|
|
{
|
|
|
|
unless (grep(/$node/, @{$hwtree{$frment->{sfp}}{$cent->{parent}}}))
|
|
|
|
{
|
|
|
|
push @{$hwtree{$frment->{sfp}}{$cent->{parent}}}, $node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unless (grep(/$node/, @{$hwtree{0}{$cent->{parent}}}))
|
|
|
|
{
|
|
|
|
push @{$hwtree{0}{$cent->{parent}}}, $node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# may add new support later?
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return \%hwtree;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-11-16 19:42:46 +00:00
|
|
|
1;
|