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;
|
|
|
|
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Factory defaults
|
|
|
|
###########################################
|
|
|
|
my %logon = (
|
|
|
|
hmc => ["hscroot","abc123"],
|
|
|
|
ivm => ["padmin", "padmin"],
|
|
|
|
fsp => ["admin", "admin"],
|
|
|
|
bpa => ["admin", "admin"]
|
|
|
|
);
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Tables based on HW Type
|
|
|
|
###########################################
|
|
|
|
my %hcptab = (
|
|
|
|
hmc => "ppchcp",
|
|
|
|
ivm => "ppchcp",
|
|
|
|
fsp => "ppcdirect",
|
|
|
|
bpa => "ppcdirect"
|
|
|
|
);
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# The default groups of hcp
|
|
|
|
###########################################
|
|
|
|
my %defaultgrp = (
|
|
|
|
hmc => "hmc",
|
|
|
|
ivm => "ivm",
|
|
|
|
fsp => "fsp",
|
|
|
|
bpa => "bpa"
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# 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 = ();
|
|
|
|
my %nodetype = (
|
|
|
|
fsp => $::NODETYPE_FSP,
|
|
|
|
bpa => $::NODETYPE_BPA,
|
|
|
|
lpar =>"$::NODETYPE_LPAR,$::NODETYPE_OSI",
|
|
|
|
hmc => $::NODETYPE_HMC,
|
|
|
|
ivm => $::NODETYPE_IVM,
|
|
|
|
);
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# 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
|
|
|
|
###############################
|
|
|
|
if ( $type =~ /^(fsp|bpa|lpar|hmc|ivm)$/ ) {
|
|
|
|
$db{nodetype}->setNodeAttribs( $name,{nodetype=>$nodetype{$type}} );
|
|
|
|
$db{nodetype}{commit} = 1;
|
|
|
|
}
|
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;
|
|
|
|
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
|
|
|
|
###############################
|
|
|
|
if ( $type =~ /^(fsp|bpa|lpar)$/ ) {
|
|
|
|
$db{ppc}->setNodeAttribs( $name,
|
|
|
|
{ hcp=>$server,
|
|
|
|
id=>$id,
|
|
|
|
pprofile=>$pprofile,
|
|
|
|
parent=>$parent
|
|
|
|
});
|
|
|
|
$db{ppc}{commit} = 1;
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Update nodelist table
|
|
|
|
###########################
|
|
|
|
updategroups( $name, $db{nodelist}, $type );
|
|
|
|
$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
|
|
|
|
###############################
|
|
|
|
if ( $type =~ /^(fsp|bpa)$/ ) {
|
|
|
|
$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
|
|
|
});
|
|
|
|
$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;
|
2009-12-28 08:10:42 +00:00
|
|
|
my @tabs = qw(ppc vpd nodehm nodelist nodetype ppcdirect hosts);
|
2009-11-19 09:48:37 +00:00
|
|
|
my %db = ();
|
|
|
|
my %nodetype = (
|
|
|
|
fsp => $::NODETYPE_FSP,
|
|
|
|
bpa => $::NODETYPE_BPA,
|
|
|
|
lpar =>"$::NODETYPE_LPAR,$::NODETYPE_OSI",
|
|
|
|
hmc => $::NODETYPE_HMC,
|
|
|
|
ivm => $::NODETYPE_IVM,
|
|
|
|
);
|
|
|
|
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']);
|
|
|
|
###################################
|
|
|
|
# Update FSP in tables
|
|
|
|
###################################
|
|
|
|
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;
|
|
|
|
|
|
|
|
next if ( $type ne 'fsp' );
|
|
|
|
|
|
|
|
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};
|
2010-03-23 07:29:09 +00:00
|
|
|
print "TEST:prefdefined_node=$predefined_node\n";
|
2010-03-23 04:42:47 +00:00
|
|
|
if ( $predefined_node =~ /-B$/ ) {
|
|
|
|
$name = $name . "-B";
|
|
|
|
}
|
2009-11-19 09:48:37 +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, \@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
|
|
|
###################################
|
|
|
|
# Update BPA in tables
|
|
|
|
###################################
|
|
|
|
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
|
|
|
|
|
|
|
next if ( $type ne 'bpa');
|
|
|
|
|
|
|
|
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};
|
2010-03-23 07:29:09 +00:00
|
|
|
if ( $predefined_node =~ /-B$/ ) {
|
2010-03-23 04:42:47 +00:00
|
|
|
$name = $name . "-B";
|
|
|
|
}
|
|
|
|
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
|
|
|
|
$namediff)
|
|
|
|
{
|
|
|
|
$db->{ppc}->delEntries( $key_col) if ( $namediff);
|
|
|
|
$db->{ppc}->setNodeAttribs( $name,
|
|
|
|
{ hcp=>$server,
|
|
|
|
id=>$id,
|
|
|
|
pprofile=>$pprofile,
|
|
|
|
parent=>$parent
|
|
|
|
});
|
|
|
|
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);
|
|
|
|
$db->{nodetype}->setNodeAttribs( $name,{nodetype=>$type} );
|
|
|
|
$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-02-25 10:22:25 +00:00
|
|
|
my $hostslisthash = $db->{hosts}->getNodeAttribs( $predefined_node, [qw(ip)]);
|
2009-12-28 08:10:42 +00:00
|
|
|
if ( $namediff )
|
|
|
|
{
|
|
|
|
$db->{hosts}->delEntries( $key_col);
|
|
|
|
$db->{hosts}->setNodeAttribs( $name,{ip=>$ips} );
|
|
|
|
$db->{hosts}->{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;
|
|
|
|
my @tabs = qw(ppchcp nodehm nodelist nodetype mac);
|
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
|
|
|
|
###################################
|
2009-07-27 16:59:24 +00:00
|
|
|
$db{nodetype}->setNodeAttribs( $name, {nodetype=>lc($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
|
|
|
|
|
|
|
###########################################
|
|
|
|
# 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;
|
|
|
|
|