2009-04-06 19:27:36 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT::PPCdb;
|
|
|
|
use strict;
|
|
|
|
use xCAT::Table;
|
|
|
|
use xCAT::GlobalDef;
|
2011-01-28 16:17:24 +00:00
|
|
|
use xCAT_plugin::lsslp;
|
2009-04-06 19:27:36 +00:00
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Factory defaults
|
|
|
|
###########################################
|
|
|
|
my %logon = (
|
2010-12-07 06:11:05 +00:00
|
|
|
hmc => ["hscroot","abc123"],
|
|
|
|
ivm => ["padmin", "padmin"],
|
|
|
|
fsp => ["admin", "admin"],
|
|
|
|
bpa => ["admin", "admin"],
|
|
|
|
frame => ["admin", "admin"],
|
|
|
|
cec => ["admin", "admin"],
|
2009-04-06 19:27:36 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Tables based on HW Type
|
|
|
|
###########################################
|
|
|
|
my %hcptab = (
|
2010-12-07 06:11:05 +00:00
|
|
|
hmc => "ppchcp",
|
|
|
|
ivm => "ppchcp",
|
|
|
|
fsp => "ppcdirect",
|
|
|
|
bpa => "ppcdirect",
|
|
|
|
frame => "ppcdirect",
|
|
|
|
cec => "ppcdirect",
|
|
|
|
|
2009-04-06 19:27:36 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# The default groups of hcp
|
|
|
|
###########################################
|
|
|
|
my %defaultgrp = (
|
2010-12-07 06:11:05 +00:00
|
|
|
hmc => "hmc",
|
|
|
|
ivm => "ivm",
|
|
|
|
fsp => "fsp",
|
|
|
|
bpa => "bpa",
|
|
|
|
frame => "frame",
|
|
|
|
cec => "cec",
|
|
|
|
|
2009-04-06 19:27:36 +00:00
|
|
|
);
|
2011-06-28 13:43:00 +00:00
|
|
|
my %globlehwtype = (
|
|
|
|
fsp => $::NODETYPE_FSP,
|
|
|
|
bpa => $::NODETYPE_BPA,
|
|
|
|
lpar => $::NODETYPE_LPAR,
|
|
|
|
hmc => $::NODETYPE_HMC,
|
|
|
|
ivm => $::NODETYPE_IVM,
|
|
|
|
frame => $::NODETYPE_FRAME,
|
|
|
|
cec => $::NODETYPE_CEC,
|
|
|
|
);
|
2009-04-06 19:27:36 +00:00
|
|
|
|
2011-07-02 01:49:18 +00:00
|
|
|
my %globalnodetype = (
|
|
|
|
fsp => $::NODETYPE_PPC,
|
|
|
|
bpa => $::NODETYPE_PPC,
|
|
|
|
cec => $::NODETYPE_PPC,
|
|
|
|
frame=> $::NODETYPE_PPC,
|
|
|
|
hmc => $::NODETYPE_PPC,
|
|
|
|
ivm => $::NODETYPE_PPC,
|
|
|
|
lpar =>"$::NODETYPE_PPC,$::NODETYPE_OSI"
|
|
|
|
);
|
2009-04-06 19:27:36 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Adds a node to the xCAT databases
|
|
|
|
##########################################################################
|
|
|
|
sub add_ppc {
|
|
|
|
|
|
|
|
my $hwtype = shift;
|
|
|
|
my $values = shift;
|
2009-10-26 13:46:52 +00:00
|
|
|
my $not_overwrite = shift;
|
2010-02-04 08:29:06 +00:00
|
|
|
my $otherinterfaces = shift;
|
|
|
|
my @tabs = qw(ppc vpd nodehm nodelist nodetype hosts mac);
|
2009-04-06 19:27:36 +00:00
|
|
|
my %db = ();
|
|
|
|
###################################
|
|
|
|
# Open database needed
|
|
|
|
###################################
|
|
|
|
foreach ( @tabs ) {
|
|
|
|
$db{$_} = xCAT::Table->new( $_, -create=>1, -autocommit=>0 );
|
|
|
|
if ( !$db{$_} ) {
|
|
|
|
return( "Error opening '$_'" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
###################################
|
|
|
|
# Update tables
|
|
|
|
###################################
|
|
|
|
foreach ( @$values ) {
|
|
|
|
my ($type,
|
|
|
|
$name,
|
|
|
|
$id,
|
|
|
|
$model,
|
|
|
|
$serial,
|
2009-12-28 08:10:42 +00:00
|
|
|
$side,
|
2009-04-06 19:27:36 +00:00
|
|
|
$server,
|
|
|
|
$pprofile,
|
|
|
|
$parent,
|
2010-02-04 08:29:06 +00:00
|
|
|
$ips,
|
|
|
|
$mac ) = split /,/;
|
2009-04-06 19:27:36 +00:00
|
|
|
|
|
|
|
###############################
|
|
|
|
# Update nodetype table
|
|
|
|
###############################
|
2011-06-27 15:02:26 +00:00
|
|
|
if ( $type =~ /^(fsp|bpa|hmc|ivm|frame|cec)$/ ) {
|
2011-06-27 13:09:59 +00:00
|
|
|
$db{nodetype}->setNodeAttribs( $name,{nodetype=>'ppc'} );
|
2009-04-06 19:27:36 +00:00
|
|
|
$db{nodetype}{commit} = 1;
|
2011-06-28 13:43:00 +00:00
|
|
|
} elsif ($type =~ /^lpar$/) {
|
|
|
|
$db{nodetype}->setNodeAttribs( $name,{nodetype=>'ppc,osi'} );
|
|
|
|
$db{nodetype}{commit} = 1;
|
2009-04-06 19:27:36 +00:00
|
|
|
}
|
2009-10-26 13:46:52 +00:00
|
|
|
###############################
|
|
|
|
# If cannot be overwroten, get
|
|
|
|
# old data firstly
|
|
|
|
###############################
|
2009-11-13 03:02:07 +00:00
|
|
|
my $mgt = $hwtype;
|
2010-12-15 09:25:04 +00:00
|
|
|
|
|
|
|
# Specify CEC and Frame's mgt as fsp and bpa
|
|
|
|
if ( $type =~ /^cec$/) {
|
|
|
|
$mgt = "fsp";
|
|
|
|
}
|
|
|
|
if ( $type =~ /^frame$/) {
|
|
|
|
$mgt = "bpa";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-13 03:02:07 +00:00
|
|
|
my $cons= $hwtype;
|
2009-10-26 13:46:52 +00:00
|
|
|
if ( $not_overwrite)
|
|
|
|
{
|
|
|
|
my $enthash = $db{ppc}->getNodeAttribs( $name, [qw(hcp id pprofile parent)]);
|
|
|
|
if ( $enthash )
|
|
|
|
{
|
|
|
|
$server = $enthash->{hcp} if ($enthash->{hcp});
|
|
|
|
$id = $enthash->{id} if ( $enthash->{id});
|
|
|
|
$pprofile = $enthash->{pprofile} if ( $enthash->{pprofile});
|
|
|
|
$parent = $enthash->{parent} if ( $enthash->{parent});
|
|
|
|
}
|
|
|
|
$enthash = $db{nodehm}->getNodeAttribs( $name, [qw(mgt)]);
|
|
|
|
if ( $enthash )
|
|
|
|
{
|
|
|
|
$mgt= $enthash->{mgt} if ( $enthash->{mgt});
|
|
|
|
$cons= $enthash->{cons} if ( $enthash->{cons});
|
|
|
|
}
|
|
|
|
$enthash = $db{vpd}->getNodeAttribs( $name, [qw(mtm serial)]);
|
|
|
|
if ( $enthash )
|
|
|
|
{
|
|
|
|
$model = $enthash->{mtm} if ( $enthash->{mtm});
|
|
|
|
$serial= $enthash->{serial} if ( $enthash->{serial});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-06 19:27:36 +00:00
|
|
|
###############################
|
|
|
|
# Update ppc table
|
|
|
|
###############################
|
2010-12-07 06:11:05 +00:00
|
|
|
if ( $type =~ /^(fsp|bpa|lpar|frame|cec)$/ ) {
|
2009-04-06 19:27:36 +00:00
|
|
|
$db{ppc}->setNodeAttribs( $name,
|
|
|
|
{ hcp=>$server,
|
|
|
|
id=>$id,
|
|
|
|
pprofile=>$pprofile,
|
2010-12-15 07:14:43 +00:00
|
|
|
parent=>$parent,
|
2011-06-28 13:43:00 +00:00
|
|
|
nodetype=>$globlehwtype{$type},
|
2009-04-06 19:27:36 +00:00
|
|
|
});
|
|
|
|
$db{ppc}{commit} = 1;
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Update nodelist table
|
|
|
|
###########################
|
|
|
|
updategroups( $name, $db{nodelist}, $type );
|
2011-01-10 08:27:32 +00:00
|
|
|
if ( $type =~ /^(fsp|bpa)$/ ) {
|
2011-01-12 03:00:00 +00:00
|
|
|
$db{nodelist}->setNodeAttribs( $name, {hidden => '1'});
|
2011-01-13 03:20:07 +00:00
|
|
|
} else {
|
|
|
|
$db{nodelist}->setNodeAttribs( $name, {hidden => '0'});
|
2011-01-10 08:27:32 +00:00
|
|
|
}
|
|
|
|
|
2009-04-06 19:27:36 +00:00
|
|
|
$db{nodelist}{commit} = 1;
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Update nodehm table
|
|
|
|
###########################
|
|
|
|
if($type =~ /^lpar$/){
|
2009-10-26 13:46:52 +00:00
|
|
|
$db{nodehm}->setNodeAttribs( $name, {mgt=>$mgt,cons=>$cons} );
|
2009-04-06 19:27:36 +00:00
|
|
|
} else {
|
2009-10-26 13:46:52 +00:00
|
|
|
$db{nodehm}->setNodeAttribs( $name, {mgt=>$mgt} );
|
2009-04-06 19:27:36 +00:00
|
|
|
}
|
|
|
|
$db{nodehm}{commit} = 1;
|
|
|
|
}
|
|
|
|
###############################
|
|
|
|
# Update vpd table
|
|
|
|
###############################
|
2011-07-02 01:49:18 +00:00
|
|
|
if ( $type =~ /^(fsp|bpa)$/ ) {
|
2009-04-06 19:27:36 +00:00
|
|
|
$db{vpd}->setNodeAttribs( $name,
|
|
|
|
{ mtm=>$model,
|
2009-12-28 08:10:42 +00:00
|
|
|
serial=>$serial,
|
|
|
|
side=>$side
|
2009-04-06 19:27:36 +00:00
|
|
|
});
|
2011-07-02 01:49:18 +00:00
|
|
|
}
|
|
|
|
if ( $type =~ /^(frame|cec)$/ ) {
|
|
|
|
$db{vpd}->setNodeAttribs( $name,
|
|
|
|
{ mtm=>$model,
|
|
|
|
serial=>$serial,
|
|
|
|
});
|
2009-04-06 19:27:36 +00:00
|
|
|
}
|
2011-07-02 01:49:18 +00:00
|
|
|
$db{vpd}{commit} = 1;
|
2010-02-04 08:29:06 +00:00
|
|
|
|
|
|
|
###############################
|
|
|
|
# Update hosts table
|
|
|
|
###############################
|
|
|
|
if ( $otherinterfaces ) {
|
|
|
|
$db{hosts}->setNodeAttribs( $name,
|
|
|
|
{ otherinterfaces=>$ips });
|
|
|
|
} else {
|
|
|
|
$db{hosts}->setNodeAttribs( $name,
|
|
|
|
{ ip=>$ips });
|
|
|
|
}
|
|
|
|
$db{hosts}{commit} = 1;
|
2009-12-28 08:10:42 +00:00
|
|
|
|
2010-02-04 08:29:06 +00:00
|
|
|
###############################
|
|
|
|
# Update mac table
|
|
|
|
###############################
|
|
|
|
if ( $mac ) {
|
|
|
|
$db{mac}->setNodeAttribs( $name,
|
|
|
|
{ mac=>$mac });
|
|
|
|
}
|
|
|
|
$db{mac}{commit} = 1;
|
2009-04-06 19:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Commit changes
|
|
|
|
###################################
|
|
|
|
foreach ( @tabs ) {
|
|
|
|
if ( exists( $db{$_}{commit} )) {
|
|
|
|
$db{$_}->commit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
2009-11-19 09:48:37 +00:00
|
|
|
##########################################################################
|
|
|
|
# Update nodes in the xCAT databases
|
|
|
|
##########################################################################
|
|
|
|
sub update_ppc {
|
|
|
|
|
|
|
|
my $hwtype = shift;
|
|
|
|
my $values = shift;
|
|
|
|
my $not_overwrite = shift;
|
2010-04-28 10:33:57 +00:00
|
|
|
my @tabs = qw(ppc vpd nodehm nodelist nodetype ppcdirect hosts mac);
|
2009-11-19 09:48:37 +00:00
|
|
|
my %db = ();
|
|
|
|
my @update_list = ();
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Open database needed
|
|
|
|
###################################
|
|
|
|
foreach ( @tabs ) {
|
|
|
|
$db{$_} = xCAT::Table->new( $_, -create=>1, -autocommit=>0 );
|
|
|
|
if ( !$db{$_} ) {
|
|
|
|
return( "Error opening '$_'" );
|
|
|
|
}
|
|
|
|
}
|
2009-12-28 08:10:42 +00:00
|
|
|
my @vpdlist = $db{vpd}->getAllNodeAttribs(['node','serial','mtm','side']);
|
|
|
|
my @hostslist = $db{hosts}->getAllNodeAttribs(['node','ip']);
|
2009-11-19 09:48:37 +00:00
|
|
|
my @ppclist = $db{ppc}->getAllNodeAttribs(['node','hcp','id',
|
|
|
|
'pprofile','parent','supernode',
|
|
|
|
'comments', 'disable']);
|
2010-04-28 10:33:57 +00:00
|
|
|
my @maclist = $db{mac}->getAllNodeAttribs(['node','mac']);
|
2011-01-28 14:30:02 +00:00
|
|
|
###################################
|
|
|
|
# Need to do database migration first
|
|
|
|
###################################
|
|
|
|
foreach my $value ( @$values ) {
|
|
|
|
my ($ttype,
|
|
|
|
$tname,
|
|
|
|
$tid,
|
|
|
|
$tmtm,
|
|
|
|
$tsn,
|
|
|
|
$tside,
|
|
|
|
$server,
|
|
|
|
$pprofile,
|
|
|
|
$parent,
|
|
|
|
$ips ) = split /,/, $value;
|
|
|
|
|
|
|
|
if ( $ttype eq 'cec' )
|
|
|
|
{
|
|
|
|
my $hostname = xCAT_plugin::lsslp::gethost_from_url_or_old($tname, "FSP", $tmtm, $tsn, "", "", $tid, "","");
|
|
|
|
if ($hostname ne $tname)
|
|
|
|
{
|
|
|
|
$hostname =~ /\-(\w)$/;
|
|
|
|
if ($1 =~ /^(A|B)$/)
|
|
|
|
{
|
|
|
|
$tside = $1;
|
|
|
|
}
|
|
|
|
if ( update_node_attribs($hwtype, $ttype, $hostname, $tid, $tmtm, $tsn, $tside,
|
|
|
|
$server, $pprofile, $parent, $ips, \%db, $tname, \@ppclist))
|
|
|
|
{
|
|
|
|
push @update_list, $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elsif ( $ttype eq 'frame' )
|
|
|
|
{
|
|
|
|
my $hostname = xCAT_plugin::lsslp::gethost_from_url_or_old($tname, "BPA", $tmtm, $tsn, "", "", $tid, "","");
|
|
|
|
if ($hostname ne $tname)
|
|
|
|
{
|
|
|
|
$hostname =~ /\-(\w)$/;
|
|
|
|
if ($1 =~ /^(A|B)$/)
|
|
|
|
{
|
|
|
|
$tside = $1;
|
|
|
|
}
|
2010-04-28 10:33:57 +00:00
|
|
|
|
2011-01-28 14:30:02 +00:00
|
|
|
if ( update_node_attribs($hwtype, $ttype, $hostname, $tid, $tmtm, $tsn, $tside,
|
|
|
|
$server, $pprofile, $parent, $ips, \%db, $tname, \@ppclist))
|
|
|
|
{
|
|
|
|
push @update_list, $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-19 09:48:37 +00:00
|
|
|
###################################
|
2011-01-28 14:30:02 +00:00
|
|
|
# Update CEC in tables
|
2009-11-19 09:48:37 +00:00
|
|
|
###################################
|
|
|
|
foreach my $value ( @$values ) {
|
|
|
|
my ($type,
|
|
|
|
$name,
|
|
|
|
$id,
|
|
|
|
$model,
|
|
|
|
$serial,
|
2009-12-28 08:10:42 +00:00
|
|
|
$side,
|
2009-11-19 09:48:37 +00:00
|
|
|
$server,
|
|
|
|
$pprofile,
|
|
|
|
$parent,
|
|
|
|
$ips ) = split /,/, $value;
|
|
|
|
|
2011-01-28 14:30:02 +00:00
|
|
|
next if ( $type ne 'cec' );
|
2009-11-19 09:48:37 +00:00
|
|
|
|
|
|
|
my $predefined_node = undef;
|
|
|
|
foreach my $vpdent (@vpdlist)
|
|
|
|
{
|
2011-01-28 14:30:02 +00:00
|
|
|
if ( $vpdent->{mtm} eq $model && $vpdent->{serial} eq $serial )
|
2009-11-19 09:48:37 +00:00
|
|
|
{
|
|
|
|
$predefined_node = $vpdent->{node};
|
2010-03-23 04:42:47 +00:00
|
|
|
if ( update_node_attribs($hwtype, $type, $name, $id, $model, $serial, $side,
|
|
|
|
$server, $pprofile, $parent, $ips,
|
|
|
|
\%db, $predefined_node, \@ppclist))
|
|
|
|
{
|
|
|
|
push @update_list, $value;
|
|
|
|
}
|
|
|
|
}
|
2009-12-28 08:10:42 +00:00
|
|
|
}
|
|
|
|
|
2009-11-19 09:48:37 +00:00
|
|
|
}
|
|
|
|
|
2010-02-25 10:22:25 +00:00
|
|
|
my @newppclist = $db{ppc}->getAllNodeAttribs(['node','hcp','id',
|
|
|
|
'pprofile','parent','supernode',
|
|
|
|
'comments', 'disable']);
|
2009-11-19 09:48:37 +00:00
|
|
|
###################################
|
2011-01-28 14:30:02 +00:00
|
|
|
# Update FRAME in tables
|
2009-11-19 09:48:37 +00:00
|
|
|
###################################
|
|
|
|
foreach my $value ( @$values ) {
|
|
|
|
my ($type,
|
|
|
|
$name,
|
|
|
|
$id,
|
|
|
|
$model,
|
|
|
|
$serial,
|
2009-12-28 08:10:42 +00:00
|
|
|
$side,
|
2009-11-19 09:48:37 +00:00
|
|
|
$server,
|
|
|
|
$pprofile,
|
|
|
|
$parent,
|
2010-02-25 10:22:25 +00:00
|
|
|
$ips ) = split /,/, $value;
|
2009-11-19 09:48:37 +00:00
|
|
|
|
2011-01-28 14:30:02 +00:00
|
|
|
next if ( $type ne 'frame');
|
2009-11-19 09:48:37 +00:00
|
|
|
|
|
|
|
my $predefined_node = undef;
|
|
|
|
foreach my $vpdent (@vpdlist)
|
|
|
|
{
|
2009-12-28 08:10:42 +00:00
|
|
|
if ( $vpdent->{mtm} eq $model && $vpdent->{serial} eq $serial && $vpdent->{side} eq $side )
|
2009-11-19 09:48:37 +00:00
|
|
|
{
|
|
|
|
$predefined_node = $vpdent->{node};
|
2011-01-28 14:30:02 +00:00
|
|
|
|
2010-03-23 04:42:47 +00:00
|
|
|
if (update_node_attribs($hwtype, $type, $name, $id, $model, $serial, $side,
|
|
|
|
$server, $pprofile, $parent, $ips,
|
|
|
|
\%db, $predefined_node, \@newppclist))
|
|
|
|
{
|
|
|
|
push @update_list, $value;
|
|
|
|
}
|
2009-11-19 09:48:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Commit changes
|
|
|
|
###################################
|
|
|
|
foreach ( @tabs ) {
|
|
|
|
if ( exists( $db{$_}{commit} )) {
|
|
|
|
$db{$_}->commit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return \@update_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Update one node in the xCAT databases
|
|
|
|
##########################################################################
|
|
|
|
sub update_node_attribs
|
|
|
|
{
|
|
|
|
my $mgt = shift;
|
|
|
|
my $type = shift;
|
|
|
|
my $name = shift;
|
|
|
|
my $id = shift;
|
|
|
|
my $model = shift;
|
|
|
|
my $serial = shift;
|
2009-12-28 08:10:42 +00:00
|
|
|
my $side = shift;
|
2009-11-19 09:48:37 +00:00
|
|
|
my $server = shift;
|
|
|
|
my $pprofile = shift;
|
|
|
|
my $parent = shift;
|
|
|
|
my $ips = shift;
|
|
|
|
my $db = shift;
|
|
|
|
my $predefined_node = shift;
|
|
|
|
my $ppclist = shift;
|
|
|
|
|
|
|
|
my $updated = undef;
|
|
|
|
my $namediff = $name ne $predefined_node;
|
|
|
|
my $key_col = { node=>$predefined_node};
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# update vpd table
|
|
|
|
#############################
|
2010-02-25 10:22:25 +00:00
|
|
|
my $vpdhash = $db->{vpd}->getNodeAttribs( $predefined_node, [qw(mtm serial)]);
|
2009-11-19 09:48:37 +00:00
|
|
|
if ( $model ne $vpdhash->{mtm} or $serial ne $vpdhash->{serial} or $namediff)
|
|
|
|
{
|
|
|
|
$db->{vpd}->delEntries( $key_col) if ( $namediff);
|
2009-12-28 08:10:42 +00:00
|
|
|
$db->{vpd}->setNodeAttribs( $name, { mtm=>$model, serial=>$serial, side=>$side});
|
2009-11-19 09:48:37 +00:00
|
|
|
$db->{vpd}->{commit} = 1;
|
|
|
|
$updated = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Update ppcdirect table
|
|
|
|
###########################
|
2010-03-05 09:53:24 +00:00
|
|
|
my @users = qw(HMC admin general);
|
|
|
|
foreach my $user ( @users ) {
|
|
|
|
my $pwhash = $db->{ppcdirect}->getAttribs( {hcp=>$predefined_node,username=>$user}, qw(password comments disable));
|
|
|
|
if ( $pwhash )
|
2009-11-19 09:48:37 +00:00
|
|
|
{
|
2010-03-05 09:53:24 +00:00
|
|
|
if ( $namediff )
|
|
|
|
{
|
|
|
|
$db->{ppcdirect}->delEntries( {hcp=>$predefined_node,username=>$user}) if ( $namediff);;
|
|
|
|
$db->{ppcdirect}->setAttribs({hcp=>$name,username=>$user},
|
|
|
|
{password=>$pwhash->{password},
|
|
|
|
comments=>$pwhash->{comments},
|
|
|
|
disable=>$pwhash->{disable}});
|
|
|
|
$db->{ppcdirect}->{commit} = 1;
|
|
|
|
$updated = 1;
|
|
|
|
}
|
2009-11-19 09:48:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# update ppc table
|
|
|
|
#############################
|
2010-02-25 10:22:25 +00:00
|
|
|
my $ppchash = $db->{ppc}->getNodeAttribs( $predefined_node, [qw(hcp id pprofile parent)]);
|
|
|
|
if ( $ppchash->{parent} ne $predefined_node )
|
|
|
|
{
|
|
|
|
$parent = $ppchash->{parent};
|
|
|
|
}
|
|
|
|
|
2009-11-19 09:48:37 +00:00
|
|
|
if ( $server ne $ppchash->{hcp} or
|
|
|
|
$id ne $ppchash->{id} or
|
|
|
|
$pprofile ne $ppchash->{pprofile} or
|
|
|
|
$parent ne $ppchash->{parent} or
|
2011-06-27 13:09:59 +00:00
|
|
|
$type ne $ppchash->{nodetype} or
|
2009-11-19 09:48:37 +00:00
|
|
|
$namediff)
|
|
|
|
{
|
|
|
|
$db->{ppc}->delEntries( $key_col) if ( $namediff);
|
|
|
|
$db->{ppc}->setNodeAttribs( $name,
|
|
|
|
{ hcp=>$server,
|
|
|
|
id=>$id,
|
|
|
|
pprofile=>$pprofile,
|
2011-06-27 13:09:59 +00:00
|
|
|
parent=>$parent,
|
2011-07-02 01:49:18 +00:00
|
|
|
nodetype=>$globlehwtype{$type},
|
2009-11-19 09:48:37 +00:00
|
|
|
});
|
|
|
|
if ( $namediff)
|
|
|
|
{
|
|
|
|
for my $ppcent (@$ppclist)
|
|
|
|
{
|
|
|
|
next if ($ppcent->{node} eq $predefined_node);
|
|
|
|
if ($ppcent->{parent} eq $predefined_node)
|
|
|
|
{
|
|
|
|
$db->{ppc}->setNodeAttribs( $ppcent->{node}, {parent=>$name});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$db->{ppc}->{commit} = 1;
|
|
|
|
$updated = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Update nodehm table
|
|
|
|
###########################
|
2010-02-25 10:22:25 +00:00
|
|
|
my $nodehmhash = $db->{nodehm}->getNodeAttribs( $predefined_node, [qw(mgt)]);
|
2009-11-19 09:48:37 +00:00
|
|
|
if ( $mgt ne $nodehmhash->{mgt} or $namediff)
|
|
|
|
{
|
|
|
|
$db->{nodehm}->delEntries( $key_col) if ( $namediff);
|
|
|
|
$db->{nodehm}->setNodeAttribs( $name, {mgt=>$mgt} );
|
|
|
|
$db->{nodehm}->{commit} = 1;
|
|
|
|
$updated = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Update nodetype table
|
|
|
|
###########################
|
2010-02-25 10:22:25 +00:00
|
|
|
my $nodetypehash = $db->{nodetype}->getNodeAttribs( $predefined_node, [qw(nodetype)]);
|
2009-11-19 09:48:37 +00:00
|
|
|
if ( $type ne $nodetypehash->{nodetype} or $namediff)
|
|
|
|
{
|
|
|
|
$db->{nodetype}->delEntries( $key_col) if ( $namediff);
|
2011-07-02 01:49:18 +00:00
|
|
|
$db->{nodetype}->setNodeAttribs( $name,{nodetype=>$globalnodetype{$type}} );
|
2009-11-19 09:48:37 +00:00
|
|
|
$db->{nodetype}->{commit} = 1;
|
|
|
|
$updated = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Update nodelist table
|
|
|
|
###########################
|
2010-02-25 10:22:25 +00:00
|
|
|
my $nodelisthash = $db->{nodelist}->getNodeAttribs( $predefined_node, [qw(groups status appstatus primarysn comments disable)]);
|
2009-11-19 09:48:37 +00:00
|
|
|
if ( $namediff)
|
|
|
|
{
|
|
|
|
updategroups( $name, $db->{nodelist}, $type );
|
|
|
|
$db->{nodelist}->setNodeAttribs( $name, {status=>$nodelisthash->{status},
|
|
|
|
appstatus=>$nodelisthash->{appstatus},
|
|
|
|
primarysn=>$nodelisthash->{primarysn},
|
|
|
|
comments=>$nodelisthash->{comments},
|
|
|
|
disable=>$nodelisthash->{disable}
|
|
|
|
});
|
|
|
|
$db->{nodelist}->delEntries( $key_col);
|
|
|
|
$db->{nodelist}->{commit} = 1;
|
|
|
|
$updated = 1;
|
|
|
|
}
|
2009-12-28 08:10:42 +00:00
|
|
|
|
|
|
|
###########################
|
|
|
|
# Update hosts table
|
|
|
|
###########################
|
2010-04-28 10:33:57 +00:00
|
|
|
my $hostslisthash = $db->{hosts}->getNodeAttribs( $predefined_node, [qw(ip otherinterfaces)]);
|
2009-12-28 08:10:42 +00:00
|
|
|
if ( $namediff )
|
|
|
|
{
|
|
|
|
$db->{hosts}->delEntries( $key_col);
|
2010-04-28 10:33:57 +00:00
|
|
|
$db->{hosts}->setNodeAttribs( $name,{ip=>$ips,
|
|
|
|
otherinterfaces=>$hostslisthash->{otherinterfaces}
|
|
|
|
} );
|
2009-12-28 08:10:42 +00:00
|
|
|
$db->{hosts}->{commit} = 1;
|
|
|
|
$updated = 1;
|
|
|
|
}
|
2010-04-28 10:33:57 +00:00
|
|
|
|
|
|
|
###########################
|
|
|
|
# Update mac table
|
|
|
|
###########################
|
|
|
|
my $maclisthash = $db->{mac}->getNodeAttribs( $predefined_node, [qw(mac)]);
|
|
|
|
if ( $namediff )
|
|
|
|
{
|
|
|
|
$db->{mac}->delEntries( $key_col);
|
|
|
|
$db->{mac}->setNodeAttribs( $name,{mac=>$maclisthash->{mac}} );
|
|
|
|
$db->{mac}->{commit} = 1;
|
|
|
|
$updated = 1;
|
|
|
|
}
|
|
|
|
|
2009-11-19 09:48:37 +00:00
|
|
|
return $updated;
|
|
|
|
}
|
2009-04-06 19:27:36 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Updates the nodelist.groups attribute
|
|
|
|
##########################################################################
|
|
|
|
sub updategroups {
|
|
|
|
|
|
|
|
my $name = shift;
|
|
|
|
my $tab = shift;
|
|
|
|
my $hwtype = shift;
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Get current value
|
|
|
|
###############################
|
|
|
|
my ($ent) = $tab->getNodeAttribs( $name, ['groups'] );
|
|
|
|
my @list = ( lc($hwtype), "all" );
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Keep any existing groups
|
|
|
|
###############################
|
|
|
|
if ( defined($ent) and $ent->{groups} ) {
|
|
|
|
push @list, split( /,/, $ent->{groups} );
|
|
|
|
}
|
|
|
|
###############################
|
|
|
|
# Remove duplicates
|
|
|
|
###############################
|
|
|
|
my %saw;
|
|
|
|
@saw{@list} = ();
|
|
|
|
@list = keys %saw;
|
|
|
|
|
|
|
|
$tab->setNodeAttribs( $name, {groups=>join(",",@list)} );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Adds an HMC/IVM to the xCAT database
|
|
|
|
##########################################################################
|
|
|
|
sub add_ppchcp {
|
|
|
|
|
|
|
|
my $hwtype = shift;
|
2010-02-04 08:29:06 +00:00
|
|
|
my $values = shift;
|
2011-07-02 01:49:18 +00:00
|
|
|
my @tabs = qw(ppchcp nodehm nodelist nodetype mac ppc);
|
2009-04-06 19:27:36 +00:00
|
|
|
my %db = ();
|
|
|
|
|
2010-02-04 08:29:06 +00:00
|
|
|
my ($name, $mac) = split ',', $values;
|
|
|
|
|
2009-04-06 19:27:36 +00:00
|
|
|
###################################
|
|
|
|
# Open database needed
|
|
|
|
###################################
|
|
|
|
foreach ( @tabs ) {
|
|
|
|
$db{$_} = xCAT::Table->new( $_, -create=>1, -autocommit=>1 );
|
|
|
|
if ( !$db{$_} ) {
|
|
|
|
return( "Error opening '$_'" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
###################################
|
|
|
|
# Update ppchcp table
|
|
|
|
###################################
|
|
|
|
my ($ent) = $db{ppchcp}->getAttribs({ hcp=>$name},'hcp');
|
|
|
|
if ( !defined($ent) ) {
|
|
|
|
$db{ppchcp}->setAttribs( {hcp=>$name},
|
|
|
|
{ username=>"",
|
|
|
|
password=>""
|
|
|
|
});
|
|
|
|
}
|
|
|
|
###################################
|
|
|
|
# Update nodehm table
|
|
|
|
###################################
|
|
|
|
$db{nodehm}->setNodeAttribs( $name, {mgt=>lc($hwtype)} );
|
2009-07-27 15:28:11 +00:00
|
|
|
|
|
|
|
###################################
|
|
|
|
# Update nodetype table
|
|
|
|
###################################
|
2011-07-02 01:49:18 +00:00
|
|
|
$db{nodetype}->setNodeAttribs( $name, {nodetype=>$globalnodetype{$hwtype}});
|
|
|
|
$db{ppc}->setNodeAttribs( $name, {nodetype=>$globlehwtype{$hwtype}});
|
2009-04-06 19:27:36 +00:00
|
|
|
|
2010-02-04 08:29:06 +00:00
|
|
|
###################################
|
|
|
|
# Update mac table
|
|
|
|
###################################
|
|
|
|
$db{mac}->setNodeAttribs( $name, {mac=>$mac});
|
|
|
|
|
2009-04-06 19:27:36 +00:00
|
|
|
###################################
|
|
|
|
# Update nodelist table
|
|
|
|
###################################
|
|
|
|
updategroups( $name, $db{nodelist}, $hwtype );
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Removes a node from the xCAT databases
|
|
|
|
##########################################################################
|
|
|
|
sub rm_ppc {
|
|
|
|
|
|
|
|
my $node = shift;
|
|
|
|
my @tabs = qw(ppc nodehm nodelist);
|
|
|
|
|
|
|
|
foreach ( @tabs ) {
|
|
|
|
###################################
|
|
|
|
# Open table
|
|
|
|
###################################
|
|
|
|
my $tab = xCAT::Table->new($_);
|
|
|
|
if ( !$tab ) {
|
|
|
|
return( "Error opening '$_'" );
|
|
|
|
}
|
|
|
|
###############################
|
|
|
|
# Remove entry
|
|
|
|
###############################
|
|
|
|
$tab->delEntries( {'node'=>$node} );
|
|
|
|
}
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Adds a Management-Module or RSA to the appropriate tables
|
|
|
|
##########################################################################
|
|
|
|
sub add_systemX {
|
|
|
|
|
|
|
|
my $hwtype = shift;
|
2010-02-09 08:58:10 +00:00
|
|
|
my $name = shift;
|
2009-04-06 19:27:36 +00:00
|
|
|
my $data = shift;
|
|
|
|
my @tabs = qw(mpa mp nodehm nodelist);
|
|
|
|
my %db = ();
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Open database needed
|
|
|
|
###################################
|
|
|
|
foreach ( @tabs ) {
|
|
|
|
$db{$_} = xCAT::Table->new( $_, -create=>1, -autocommit=>1 );
|
|
|
|
if ( !$db{$_} ) {
|
|
|
|
return( "Error opening '$_'" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
###################################
|
|
|
|
# Update mpa table
|
|
|
|
###################################
|
|
|
|
my ($ent) = $db{mpa}->getAttribs({ mpa=>$name},'mpa');
|
|
|
|
if ( !defined($ent) ) {
|
|
|
|
$db{mpa}->setAttribs( {mpa=>$name},
|
|
|
|
{ username=>"",
|
|
|
|
password=>""
|
|
|
|
});
|
|
|
|
}
|
|
|
|
###################################
|
|
|
|
# Update mp table
|
|
|
|
###################################
|
|
|
|
$db{mp}->setNodeAttribs( $name,
|
|
|
|
{ mpa=>$name,
|
|
|
|
id=>"0"
|
|
|
|
});
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Update nodehm table
|
|
|
|
###################################
|
|
|
|
$db{nodehm}->setNodeAttribs( $name, {mgt=>"blade"} );
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Update nodelist table
|
|
|
|
###################################
|
|
|
|
updategroups( $name, $db{nodelist}, $hwtype );
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Get userids and passwords from tables
|
|
|
|
##########################################################################
|
|
|
|
sub credentials {
|
|
|
|
|
|
|
|
my $server = shift;
|
|
|
|
my $hwtype = shift;
|
2009-09-11 10:54:39 +00:00
|
|
|
my $user = shift;
|
|
|
|
my $pass = undef;
|
|
|
|
my $user_specified = $user;
|
|
|
|
if ( !$user_specified or $user eq @{$logon{$hwtype}}[0])
|
|
|
|
{
|
|
|
|
$user = @{$logon{$hwtype}}[0];
|
2009-12-28 08:10:42 +00:00
|
|
|
$pass = @{$logon{$hwtype}}[1];
|
2009-09-11 10:54:39 +00:00
|
|
|
}
|
2009-04-06 19:27:36 +00:00
|
|
|
|
2011-03-18 05:38:58 +00:00
|
|
|
###########################################
|
|
|
|
# find parent for fsp/bpa, use parent's attributes first
|
|
|
|
###########################################
|
|
|
|
my $ntype = xCAT::DBobjUtils->getnodetype($server);
|
|
|
|
if ($ntype =~ /^(fsp|bpa)$/) {
|
|
|
|
my $ptab = xCAT::Table->new('ppc');
|
|
|
|
if ($ptab) {
|
|
|
|
my $parent = $ptab->getNodeAttribs($server, ["parent"]);
|
|
|
|
if ($parent and $parent->{parent}) {
|
|
|
|
my $ptype = xCAT::DBobjUtils->getnodetype($parent->{parent});
|
|
|
|
if (($ptype =~ /^cec$/ and $ntype =~ /^fsp$/) or ($ptype =~ /^frame$/ and $ntype =~ /^bpa$/))
|
|
|
|
{
|
|
|
|
$server = $parent->{parent};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-06 19:27:36 +00:00
|
|
|
###########################################
|
|
|
|
# Check passwd tab
|
|
|
|
###########################################
|
|
|
|
my $tab = xCAT::Table->new( 'passwd' );
|
|
|
|
if ( $tab ) {
|
2009-09-11 10:54:39 +00:00
|
|
|
my $ent;
|
|
|
|
if ( $user_specified)
|
|
|
|
{
|
|
|
|
($ent) = $tab->getAttribs( {key=>$hwtype,username=>$user},qw(password));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
($ent) = $tab->getAttribs( {key=>$hwtype}, qw(username password));
|
|
|
|
}
|
2009-04-06 19:27:36 +00:00
|
|
|
if ( $ent ) {
|
|
|
|
if (defined($ent->{password})) { $pass = $ent->{password}; }
|
|
|
|
if (defined($ent->{username})) { $user = $ent->{username}; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##########################################
|
|
|
|
# Check table based on specific node
|
|
|
|
##########################################
|
|
|
|
$tab = xCAT::Table->new( $hcptab{$hwtype} );
|
|
|
|
if ( $tab ) {
|
2009-09-11 10:54:39 +00:00
|
|
|
my $ent;
|
|
|
|
if ( $user_specified)
|
|
|
|
{
|
|
|
|
($ent) = $tab->getAttribs( {hcp=>$server,username=>$user},qw(password));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
($ent) = $tab->getAttribs( {hcp=>$server}, qw(username password));
|
|
|
|
}
|
2009-04-06 19:27:36 +00:00
|
|
|
if ( $ent){
|
|
|
|
if (defined($ent->{password})) { $pass = $ent->{password}; }
|
|
|
|
if (defined($ent->{username})) { $user = $ent->{username}; }
|
|
|
|
}
|
|
|
|
##############################################################
|
|
|
|
# If no user/passwd found, check if there is a default group
|
|
|
|
##############################################################
|
|
|
|
elsif( ($ent) = $tab->getAttribs( {hcp=>$defaultgrp{$hwtype}}, qw(username password)))
|
|
|
|
{
|
2009-09-11 10:54:39 +00:00
|
|
|
if ( $user_specified)
|
|
|
|
{
|
|
|
|
($ent) = $tab->getAttribs( {hcp=>$defaultgrp{$hwtype},username=>$user},qw(password));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
($ent) = $tab->getAttribs( {hcp=>$defaultgrp{$hwtype}}, qw(username password));
|
|
|
|
}
|
|
|
|
if ( $ent){
|
|
|
|
if (defined($ent->{password})) { $pass = $ent->{password}; }
|
|
|
|
if (defined($ent->{username})) { $user = $ent->{username}; }
|
|
|
|
}
|
2009-04-06 19:27:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return( $user,$pass );
|
|
|
|
}
|
|
|
|
|
2009-12-29 11:42:49 +00:00
|
|
|
##########################################################################
|
|
|
|
# Set userids and passwords to tables
|
|
|
|
##########################################################################
|
|
|
|
sub update_credentials
|
|
|
|
{
|
|
|
|
|
|
|
|
my $server = shift;
|
|
|
|
my $hwtype = shift;
|
|
|
|
my $user = shift;
|
|
|
|
my $pass = shift;
|
|
|
|
|
|
|
|
##########################################
|
|
|
|
# Set password to specific table
|
|
|
|
##########################################
|
|
|
|
my $tab = xCAT::Table->new( $hcptab{$hwtype} );
|
|
|
|
if ( $tab ) {
|
|
|
|
my $ent;
|
|
|
|
$tab->setAttribs( {hcp=>$server, username=>$user},{password=>$pass} );
|
|
|
|
}
|
|
|
|
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-06 19:27:36 +00:00
|
|
|
1;
|
|
|
|
|