2007-11-16 19:42:46 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT_plugin::hmc;
|
|
|
|
use strict;
|
|
|
|
use xCAT::PPC;
|
2011-04-08 02:40:47 +00:00
|
|
|
use xCAT::DBobjUtils;
|
2007-11-16 19:42:46 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Command handler method from tables
|
|
|
|
##########################################################################
|
|
|
|
sub handled_commands {
|
|
|
|
return {
|
2008-04-25 14:39:02 +00:00
|
|
|
rpower => 'nodehm:power,mgt',
|
|
|
|
rvitals => 'nodehm:mgt',
|
|
|
|
rinv => 'nodehm:mgt',
|
|
|
|
mkvm => 'nodehm:mgt',
|
|
|
|
rmvm => 'nodehm:mgt',
|
|
|
|
lsvm => 'nodehm:mgt',
|
|
|
|
chvm => 'nodehm:mgt',
|
|
|
|
rscan => 'nodehm:mgt',
|
2009-11-12 03:36:43 +00:00
|
|
|
getmacs => 'nodehm:getmac,mgt',
|
2008-04-25 14:39:02 +00:00
|
|
|
rnetboot => 'nodehm:mgt',
|
2009-01-06 11:08:21 +00:00
|
|
|
rspconfig => 'nodehm:mgt',
|
2009-05-20 09:04:19 +00:00
|
|
|
rflash => 'nodehm:mgt',
|
2009-08-04 20:28:03 +00:00
|
|
|
mkhwconn => 'nodehm:mgt',
|
|
|
|
rmhwconn => 'nodehm:mgt',
|
2009-09-21 06:33:27 +00:00
|
|
|
lshwconn => 'nodehm:mgt',
|
2011-04-08 02:40:47 +00:00
|
|
|
renergy => 'nodehm:mgt',
|
|
|
|
gethmccon => 'nodehm:cons',
|
2007-11-16 19:42:46 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-16 16:45:14 +00:00
|
|
|
##########################################################################
|
|
|
|
# Pre-process request from xCat daemon
|
|
|
|
##########################################################################
|
|
|
|
sub preprocess_request {
|
2011-04-08 02:40:47 +00:00
|
|
|
my ($arg1, $arg2, $arg3) = @_;
|
|
|
|
if ($arg1->{command}->[0] eq "gethmccon") { #Can handle it here and now
|
|
|
|
my $node = $arg1->{noderange}->[0];
|
|
|
|
my $callback = $arg2;
|
|
|
|
gethmccon($node,$callback);
|
|
|
|
return [];
|
|
|
|
}
|
2008-04-16 16:45:14 +00:00
|
|
|
xCAT::PPC::preprocess_request(__PACKAGE__,@_);
|
|
|
|
}
|
|
|
|
|
2007-11-16 19:42:46 +00:00
|
|
|
##########################################################################
|
|
|
|
# Process request from xCat daemon
|
|
|
|
##########################################################################
|
|
|
|
sub process_request {
|
|
|
|
xCAT::PPC::process_request(__PACKAGE__,@_);
|
|
|
|
}
|
|
|
|
|
2011-04-08 02:40:47 +00:00
|
|
|
##########################################################################
|
|
|
|
# get hcp and id for rcons with fsp
|
|
|
|
##########################################################################
|
|
|
|
sub gethmccon {
|
|
|
|
|
|
|
|
my $node = shift;
|
|
|
|
my $callback = shift;
|
2011-04-11 02:03:16 +00:00
|
|
|
my $otherhcp = shift;
|
2011-04-08 02:40:47 +00:00
|
|
|
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];
|
|
|
|
$callback->($rsp);
|
2011-04-11 02:03:16 +00:00
|
|
|
return $rsp;
|
2011-04-08 02:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Get node type
|
|
|
|
#################################
|
|
|
|
my $type = xCAT::DBobjUtils->getnodetype($node);
|
|
|
|
#my ($type) = grep( /^(lpar|osi)$/, @types );
|
|
|
|
|
2011-04-11 02:03:16 +00:00
|
|
|
if ( !defined( $type ) or !($type =~/lpar/) ) {
|
2011-04-08 02:40:47 +00:00
|
|
|
#return( "Invalid node type: $ent->{nodetype}" );
|
|
|
|
$rsp->{node}->[0]->{error}=["Invalid node type: $type"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
|
|
|
$callback->($rsp);
|
2011-04-11 02:03:16 +00:00
|
|
|
return $rsp;
|
2011-04-08 02:40:47 +00:00
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Get attributes
|
|
|
|
#################################
|
2011-12-08 08:12:15 +00:00
|
|
|
my ($att) = $tabs{ppc}->getNodeAttribs( $node, @attribs );
|
2011-04-08 02:40: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];
|
|
|
|
$callback->($rsp);
|
2011-04-11 02:03:16 +00:00
|
|
|
return $rsp;
|
2011-04-08 02:40: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];
|
|
|
|
$callback->($rsp);
|
2011-04-11 02:03:16 +00:00
|
|
|
return $rsp;
|
2011-04-08 02:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Find MTMS in vpd database
|
|
|
|
#################################
|
|
|
|
my @attrs = qw(mtm serial);
|
|
|
|
my ($vpd) = $tabs{vpd}->getNodeAttribs($att->{parent}, \@attrs );
|
|
|
|
|
|
|
|
if ( !defined( $vpd )) {
|
|
|
|
#return( sprintf( $errmsg{NODE_UNDEF}, "vpd" ));
|
|
|
|
$rsp->{node}->[0]->{error}=["Can't find node tarribute in vpd table"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
|
|
|
$callback->($rsp);
|
2011-04-11 02:03:16 +00:00
|
|
|
return $rsp;
|
2011-04-08 02:40:47 +00:00
|
|
|
}
|
|
|
|
################################
|
|
|
|
# Verify both vpd attributes
|
|
|
|
################################
|
|
|
|
foreach ( @attrs ) {
|
|
|
|
if ( !exists( $vpd->{$_} )) {
|
|
|
|
#return( sprintf( $errmsg{NO_ATTR}, $_, "vpd" ));
|
|
|
|
$rsp->{node}->[0]->{error}=["Can't find node tarribute in vpd table"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
|
|
|
$callback->($rsp);
|
2011-04-11 02:03:16 +00:00
|
|
|
return $rsp;
|
2011-04-08 02:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-08 03:29:19 +00:00
|
|
|
################################
|
|
|
|
# Get username and passwd
|
|
|
|
################################
|
|
|
|
my $hwtype = "hmc";
|
2011-04-11 02:03:16 +00:00
|
|
|
my $host;
|
|
|
|
if ($otherhcp) {
|
|
|
|
$host = $otherhcp;
|
|
|
|
} else {
|
|
|
|
$host = $att->{hcp};
|
|
|
|
}
|
2011-04-08 03:29:19 +00:00
|
|
|
my @cred = xCAT::PPCdb::credentials( $host, $hwtype );
|
|
|
|
if ( !defined(@cred) )
|
|
|
|
{
|
|
|
|
$rsp->{node}->[0]->{error}=["Can't username and passwd for the hmc"];
|
|
|
|
$rsp->{node}->[0]->{errorcode}=[1];
|
|
|
|
$callback->($rsp);
|
2011-04-11 02:03:16 +00:00
|
|
|
return $rsp;
|
2011-04-08 03:29:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 02:40:47 +00:00
|
|
|
$rsp = {node=>[{name=>[$node]}]};
|
|
|
|
$rsp->{node}->[0]->{mtms}->[0] = "$vpd->{mtm}*$vpd->{serial}";
|
2011-04-11 02:03:16 +00:00
|
|
|
$rsp->{node}->[0]->{host}->[0] = $host;
|
2011-04-08 02:40:47 +00:00
|
|
|
$rsp->{node}->[0]->{lparid}->[0] = $att->{id};
|
2011-04-08 03:29:19 +00:00
|
|
|
$rsp->{node}->[0]->{cred}->[0] = join ',', @cred;
|
2011-04-08 02:40:47 +00:00
|
|
|
$callback->($rsp);
|
2011-04-11 02:03:16 +00:00
|
|
|
return $rsp;
|
2011-04-08 02:40:47 +00:00
|
|
|
}
|
2007-11-16 19:42:46 +00:00
|
|
|
|
2011-12-27 03:38:22 +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!!!!!
|
|
|
|
##################################################################
|
|
|
|
|
|
|
|
# only handle physical hardware objects here.
|
|
|
|
foreach my $node (@$nodelist)
|
|
|
|
{
|
|
|
|
# will build a hash like hmc->frame->cec
|
|
|
|
# for old xcat defs, ppc.nodetype may be blank, should use getnodetype().
|
|
|
|
my $ntype = xCAT::DBobjUtils->getnodetype($node);
|
|
|
|
if ($ntype =~ /^hmc$/)
|
|
|
|
{
|
|
|
|
# get all objects managed by this hmc.
|
|
|
|
foreach my $ent (@entries)
|
|
|
|
{
|
|
|
|
if ($ent->{hcp} =~ /$node/)
|
|
|
|
{
|
|
|
|
my $type = xCAT::DBobjUtils->getnodetype($ent->{node});
|
|
|
|
# use cec as leaves
|
|
|
|
if ($type =~ /cec/)
|
|
|
|
{
|
|
|
|
if ($ent->{parent})
|
|
|
|
{
|
|
|
|
unless (grep(/$ent->{node}/, @{$hwtree{$node}{$ent->{parent}}}))
|
|
|
|
{
|
|
|
|
push @{$hwtree{$node}{$ent->{parent}}}, $ent->{node};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unless (grep(/$ent->{node}/, @{$hwtree{$node}{0}}))
|
|
|
|
{
|
|
|
|
push @{$hwtree{$node}{0}}, $ent->{node};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($ntype =~ /^frame$/)
|
|
|
|
{
|
|
|
|
# get frame's hcp
|
|
|
|
my $fent = $ppctab->getNodeAttribs($node, ['hcp']);
|
|
|
|
# get all cecs by this frame
|
|
|
|
foreach my $ent (@entries)
|
|
|
|
{
|
|
|
|
if ($ent->{parent} =~ /$node/)
|
|
|
|
{
|
|
|
|
unless (grep(/$ent->{node}/, @{$hwtree{$fent->{hcp}}{$node}}))
|
|
|
|
{
|
|
|
|
push @{$hwtree{$fent->{hcp}}{$node}}, $ent->{node};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($ntype =~ /^cec$/)
|
|
|
|
{
|
|
|
|
# get cec's parent
|
|
|
|
my $cent = $ppctab->getNodeAttribs($node, ['hcp','parent']);
|
|
|
|
if ($cent->{parent})
|
|
|
|
{
|
|
|
|
unless (grep(/$node/, @{$hwtree{$cent->{hcp}}{$cent->{parent}}}))
|
|
|
|
{
|
|
|
|
push @{$hwtree{$cent->{hcp}}{$cent->{parent}}}, $node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unless (grep(/$node/, @{$hwtree{$cent->{hcp}}{0}}))
|
|
|
|
{
|
|
|
|
push @{$hwtree{$cent->{hcp}}{0}}, $node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# may add new support later?
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return \%hwtree;
|
|
|
|
}
|
2007-11-16 19:42:46 +00:00
|
|
|
|
|
|
|
1;
|