2008-07-09 18:03:41 +00:00
|
|
|
#!/usr/bin/env perl -w
|
2007-11-26 20:05:39 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# Utility subroutines that can be used to manage xCAT data object
|
2010-12-16 02:33:22 +00:00
|
|
|
# definitions.
|
2007-11-26 20:05:39 +00:00
|
|
|
#
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
package xCAT::DBobjUtils;
|
|
|
|
|
|
|
|
use xCAT::NodeRange;
|
|
|
|
use xCAT::Schema;
|
|
|
|
use xCAT::Table;
|
|
|
|
use xCAT::Utils;
|
|
|
|
use xCAT::MsgUtils;
|
2010-05-07 02:44:50 +00:00
|
|
|
use xCAT::NetworkUtils;
|
2008-07-09 18:03:41 +00:00
|
|
|
use strict;
|
2007-11-26 20:05:39 +00:00
|
|
|
|
2008-03-14 17:11:21 +00:00
|
|
|
# IPv6 not yet implemented - need Socket6
|
|
|
|
use Socket;
|
2011-06-27 08:48:59 +00:00
|
|
|
my @tabletype = qw(ppc zvm);
|
2008-03-14 17:11:21 +00:00
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getObjectsOfType
|
|
|
|
|
|
|
|
Get a list of data objects of the given type.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
Returns:
|
|
|
|
undef
|
|
|
|
@objlist - list of objects of this type
|
|
|
|
Globals:
|
|
|
|
Error:
|
|
|
|
Example:
|
|
|
|
Comments:
|
|
|
|
|
2010-12-16 02:33:22 +00:00
|
|
|
@objlist = xCAT::DBobjUtils->getObjectsOfType($type);
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub getObjectsOfType
|
|
|
|
{
|
|
|
|
my ($class, $type) = @_;
|
|
|
|
|
|
|
|
my @objlist;
|
|
|
|
|
|
|
|
# special case for site table
|
|
|
|
if ($type eq 'site')
|
|
|
|
{
|
|
|
|
push(@objlist, 'clustersite');
|
|
|
|
return @objlist;
|
|
|
|
}
|
|
|
|
|
2010-12-15 01:47:06 +00:00
|
|
|
# The database may be changed between getObjectsOfType calls
|
|
|
|
# do not use cache %::saveObjList if --nocache is specified
|
|
|
|
if ($::saveObjList{$type} && !$::opt_c)
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
|
|
|
@objlist = @{$::saveObjList{$type}};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
# get the key for this type object
|
|
|
|
# ex. for "network" type the key is "netname"
|
|
|
|
# get the data type spec from Schema.pm
|
|
|
|
my $datatype = $xCAT::Schema::defspec{$type};
|
|
|
|
|
|
|
|
# get the key for this type object
|
|
|
|
# ex. for "network" type the key is "netname"
|
|
|
|
my $objkey = $datatype->{'objkey'};
|
|
|
|
|
|
|
|
my $table;
|
|
|
|
my $tabkey;
|
2008-07-09 18:03:41 +00:00
|
|
|
foreach my $this_attr (@{$datatype->{'attrs'}})
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
|
|
|
my $attr = $this_attr->{attr_name};
|
|
|
|
if ($attr eq $objkey)
|
|
|
|
{
|
|
|
|
# get the table & key for to lookup
|
|
|
|
# get the actual attr name to use in the table
|
|
|
|
# - may be different then the attr name used for the object.
|
|
|
|
($table, $tabkey) = split('\.', $this_attr->{tabentry});
|
2009-12-30 07:50:28 +00:00
|
|
|
last;
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# get the whole table and add each entry in the objkey column
|
|
|
|
# to the list of objects.
|
|
|
|
my @TableRowArray = xCAT::DBobjUtils->getDBtable($table);
|
|
|
|
|
|
|
|
foreach (@TableRowArray)
|
|
|
|
{
|
|
|
|
push(@objlist, $_->{$tabkey});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
# if this is type "group" we need to check the nodelist table
|
|
|
|
my @nodeGroupList=();
|
|
|
|
if ($type eq 'group')
|
|
|
|
{
|
|
|
|
my $table = "nodelist";
|
|
|
|
my @TableRowArray = xCAT::DBobjUtils->getDBtable($table);
|
|
|
|
foreach (@TableRowArray)
|
|
|
|
{
|
|
|
|
my @tmplist = split(',', $_->{'groups'});
|
|
|
|
push(@nodeGroupList, @tmplist);
|
|
|
|
}
|
|
|
|
foreach my $n (@nodeGroupList)
|
|
|
|
{
|
|
|
|
if (!grep(/^$n$/, @objlist) ) {
|
|
|
|
push(@objlist, $n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-28 18:09:47 +00:00
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
@{$::saveObjList{$type}} = @objlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
return @objlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
2008-12-17 14:48:53 +00:00
|
|
|
=head3 getobjattrs
|
|
|
|
|
|
|
|
Get data from tables
|
|
|
|
|
2009-06-03 08:40:32 +00:00
|
|
|
$type_hash: objectname=>objtype hash
|
|
|
|
$attrs_ref: only get the specific attributes,
|
|
|
|
this can be useful especially for performance considerations
|
2008-12-17 14:48:53 +00:00
|
|
|
Arguments:
|
|
|
|
Returns:
|
|
|
|
undef
|
|
|
|
hash ref - (ex. $tabhash{$table}{$objname}{$attr} = $value)
|
|
|
|
Globals:
|
|
|
|
Error:
|
|
|
|
Example:
|
|
|
|
|
|
|
|
%tabhash = xCAT::DBobjUtils->getobjattrs(\%typehash);
|
|
|
|
|
|
|
|
Comments:
|
|
|
|
For now - only support tables that have 'node' as key !!!
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub getobjattrs
|
|
|
|
{
|
2009-06-03 08:40:32 +00:00
|
|
|
my $class = shift;
|
|
|
|
my $ref_hash = shift;
|
|
|
|
my @attrs;
|
|
|
|
# The $attrs is an optional argument
|
|
|
|
if (ref $_[0]) {
|
|
|
|
@attrs = @{shift()};
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
my %typehash = %$ref_hash;
|
|
|
|
|
|
|
|
my %tableattrs;
|
|
|
|
my %tabhash;
|
|
|
|
|
|
|
|
# get a list of object names for each type
|
|
|
|
my %objtypelist;
|
|
|
|
foreach my $objname (sort (keys %typehash)) {
|
|
|
|
# get list of objects for each type
|
|
|
|
# $objtypelist{$typehash{$objname}}=$objname;
|
|
|
|
push @{$objtypelist{$typehash{$objname}}}, $objname;
|
|
|
|
}
|
|
|
|
|
|
|
|
# go through each object type and look up all the info for each object
|
|
|
|
foreach my $objtype (keys %objtypelist) {
|
|
|
|
|
|
|
|
# only do node type for now
|
|
|
|
if ($objtype eq 'node') {
|
|
|
|
# find the list of tables and corresponding attrs
|
|
|
|
# - for this object type
|
|
|
|
# get the object type decription from Schema.pm
|
|
|
|
my $datatype = $xCAT::Schema::defspec{$objtype};
|
|
|
|
foreach my $this_attr (@{$datatype->{'attrs'}}) {
|
|
|
|
my $attr = $this_attr->{attr_name};
|
2009-06-03 08:40:32 +00:00
|
|
|
if (scalar(@attrs) > 0) { # Only query specific attributes
|
|
|
|
if (!grep(/^$attr$/, @attrs)) {
|
|
|
|
next; # This attribute is not needed
|
|
|
|
}
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
|
|
|
|
# table_attr is the attr that actually appears in the
|
|
|
|
# table which could possibly be different then the attr
|
|
|
|
# used in the node def
|
|
|
|
# ex. 'nodetype.arch'
|
|
|
|
my ($lookup_table, $table_attr) = split('\.', $this_attr->{tabentry});
|
|
|
|
if (!grep(/^$table_attr$/, @{$tableattrs{$lookup_table}})) {
|
|
|
|
push @{$tableattrs{$lookup_table}}, $table_attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# foreach table look up the list of attrs for this
|
|
|
|
# list of object names
|
|
|
|
foreach my $table (keys %tableattrs) {
|
|
|
|
# open the table
|
|
|
|
my $thistable = xCAT::Table->new($table, -create => 1, -autocommit => 0);
|
|
|
|
if (!$thistable) {
|
|
|
|
my $rsp;
|
2010-08-31 02:41:48 +00:00
|
|
|
$rsp->{data}->[0] = "Could not open the \'$table\' table.";
|
2009-12-30 07:50:28 +00:00
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
2010-08-31 02:41:48 +00:00
|
|
|
next;
|
2009-12-30 07:50:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my @objlist = @{$objtypelist{$objtype}};
|
|
|
|
|
|
|
|
my $rec = $thistable->getNodesAttribs(\@objlist, @{$tableattrs{$table}});
|
|
|
|
|
|
|
|
# fill in %tabhash with any values that are set
|
|
|
|
foreach my $n (@objlist) {
|
|
|
|
my $tmp1=$rec->{$n}->[0];
|
|
|
|
foreach $a (@{$tableattrs{$table}}) {
|
|
|
|
if (defined($tmp1->{$a})) {
|
|
|
|
$tabhash{$table}{$n}{$a} = $tmp1->{$a};
|
|
|
|
#print "obj = $n, table = $table, attr =$a, val = $tabhash{$table}{$n}{$a}\n";
|
|
|
|
} else {
|
|
|
|
# Add a has been searched flag to improve the performance
|
|
|
|
$tabhash{$table}{$n}{"$a"."_hassearched"} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#$thistable->commit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return %tabhash;
|
2008-12-17 14:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
=head3 getobjdefs
|
|
|
|
|
|
|
|
Get object definitions from the DB.
|
|
|
|
|
2009-06-03 08:40:32 +00:00
|
|
|
$type_hash: objectname=>objtype hash
|
|
|
|
$verbose: optional
|
|
|
|
$attrs_ref: only get the specific attributes,
|
|
|
|
this can be useful especially for performance considerations
|
2010-09-08 10:38:25 +00:00
|
|
|
$chname_ref: used to get the table entries for changing the object name
|
2007-11-26 20:05:39 +00:00
|
|
|
Arguments:
|
|
|
|
Returns:
|
|
|
|
undef - error
|
|
|
|
hash ref - $objecthash{objectname}{attrname} = value
|
|
|
|
Globals:
|
|
|
|
Error:
|
|
|
|
Example:
|
|
|
|
|
|
|
|
To use create hash for objectname and object type
|
|
|
|
ex. $objhash{$obj} = $type;
|
|
|
|
|
|
|
|
- then call as follows:
|
|
|
|
%myhash = xCAT::DBobjUtils->getobjdefs(\%objhash);
|
|
|
|
|
|
|
|
Comments:
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub getobjdefs
|
|
|
|
{
|
2010-09-08 10:38:25 +00:00
|
|
|
my ($class, $hash_ref, $verbose, $attrs_ref, $chname_ref) = @_;
|
2007-11-26 20:05:39 +00:00
|
|
|
my %objhash;
|
2008-07-09 18:03:41 +00:00
|
|
|
my %typehash = %$hash_ref;
|
2009-06-03 08:40:32 +00:00
|
|
|
my %tabhash;
|
|
|
|
my @attrs;
|
|
|
|
if (ref($attrs_ref))
|
|
|
|
{
|
|
|
|
@attrs = @$attrs_ref;
|
|
|
|
}
|
2008-12-17 14:48:53 +00:00
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
@::foundTableList = ();
|
|
|
|
|
|
|
|
if ($::ATTRLIST eq "none") {
|
2008-04-15 16:52:17 +00:00
|
|
|
# just return the list of obj names
|
|
|
|
foreach my $objname (sort (keys %typehash))
|
|
|
|
{
|
|
|
|
my $type = $typehash{$objname};
|
|
|
|
$objhash{$objname}{'objtype'} = $type;
|
|
|
|
}
|
|
|
|
return %objhash;
|
|
|
|
}
|
2008-03-14 17:11:21 +00:00
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
# see if we need to get any objects of type 'node'
|
|
|
|
my $getnodes=0;
|
|
|
|
foreach my $objname (keys %typehash) {
|
|
|
|
if ($typehash{$objname} eq 'node') {
|
|
|
|
$getnodes=1;
|
|
|
|
}
|
|
|
|
}
|
2008-12-17 14:48:53 +00:00
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
# if so then get node info from tables now
|
2008-12-17 14:48:53 +00:00
|
|
|
# still may need to look up values in some tables using
|
|
|
|
# other keys - also need to figure out what tables to take
|
|
|
|
# values from when using 'only_if' - see below
|
2009-12-30 07:50:28 +00:00
|
|
|
# - but this saves lots of time
|
|
|
|
if ($getnodes) {
|
2009-06-03 08:40:32 +00:00
|
|
|
if (scalar(@attrs) > 0) # Only get specific attributes of the node
|
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
# find the onlyif key for the attributes
|
|
|
|
REDO: my $datatype = $xCAT::Schema::defspec{'node'};
|
|
|
|
foreach my $this_attr (@{$datatype->{'attrs'}}) {
|
|
|
|
my $attr = $this_attr->{attr_name};
|
|
|
|
if (exists($this_attr->{only_if})) {
|
|
|
|
my ($onlyif_key, $onlyif_value) = split('\=', $this_attr->{only_if});
|
|
|
|
if (!grep (/^$onlyif_key$/, @attrs)) {
|
|
|
|
push @attrs, $onlyif_key;
|
|
|
|
goto REDO;
|
2009-06-03 08:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
%tabhash = xCAT::DBobjUtils->getobjattrs(\%typehash, \@attrs);
|
2009-06-03 08:40:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
%tabhash = xCAT::DBobjUtils->getobjattrs(\%typehash);
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
}
|
2008-12-17 14:48:53 +00:00
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
# Classify the nodes with type
|
|
|
|
my %type_obj = ();
|
|
|
|
foreach my $objname (keys %typehash) {
|
|
|
|
push @{$type_obj{$typehash{$objname}}}, $objname;
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
foreach my $objtype (sort (keys %type_obj)) {
|
|
|
|
if ($objtype eq 'site') {
|
2007-11-26 20:05:39 +00:00
|
|
|
my @TableRowArray = xCAT::DBobjUtils->getDBtable('site');
|
2009-12-30 07:50:28 +00:00
|
|
|
foreach my $objname (sort @{$type_obj{$objtype}}) {
|
2010-03-01 10:11:59 +00:00
|
|
|
if (@TableRowArray)
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
my $foundinfo = 0;
|
|
|
|
foreach (@TableRowArray)
|
|
|
|
{
|
|
|
|
if ($_->{key})
|
|
|
|
{
|
|
|
|
if (defined($_->{value}) ) {
|
|
|
|
$foundinfo++;
|
|
|
|
if ($verbose == 1) {
|
|
|
|
$objhash{$objname}{$_->{key}} = "$_->{value}\t(Table:site - Key:$_->{key})";
|
|
|
|
} else {
|
|
|
|
$objhash{$objname}{$_->{key}} = $_->{value};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($foundinfo)
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
$objhash{$objname}{'objtype'} = 'site';
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
else
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] ="Could not read the \'$objname\' object from the \'site\' table.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
} elsif ($objtype eq 'monitoring') {
|
|
|
|
# need a special case for the monitoring table
|
|
|
|
# - need to check the monsetting table for entries that contain
|
|
|
|
# the same name as the monitoring table entry.
|
|
|
|
my @TableRowArray = xCAT::DBobjUtils->getDBtable('monsetting');
|
|
|
|
foreach my $objname (sort @{$type_obj{$objtype}}) {
|
2010-03-01 10:11:59 +00:00
|
|
|
if (@TableRowArray) {
|
2009-12-30 07:50:28 +00:00
|
|
|
my $foundinfo = 0;
|
|
|
|
foreach (@TableRowArray) {
|
|
|
|
if ($_->{name} eq $objname ) {
|
|
|
|
if ($_->{key})
|
|
|
|
{
|
|
|
|
if (defined($_->{value}) ) {
|
|
|
|
$foundinfo++;
|
|
|
|
if ($verbose == 1) {
|
|
|
|
$objhash{$objname}{$_->{key}} = "$_->{value}\t(Table:monsetting)";
|
|
|
|
} else {
|
|
|
|
$objhash{$objname}{$_->{key}} = $_->{value};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 09:07:28 +00:00
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
if ($foundinfo)
|
2009-09-09 09:07:28 +00:00
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
$objhash{$objname}{'objtype'} = 'monitoring';
|
2009-09-09 09:07:28 +00:00
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] ="Could not read the \'$objname\' object from the \'monsetting\' table.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
2009-09-09 09:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
} else {
|
|
|
|
# get the object type decription from Schema.pm
|
|
|
|
my $datatype = $xCAT::Schema::defspec{$objtype};
|
|
|
|
# get the key to look for, for this object type
|
|
|
|
my $objkey = $datatype->{'objkey'};
|
|
|
|
|
|
|
|
# go through the list of valid attrs
|
|
|
|
foreach my $this_attr (@{$datatype->{'attrs'}})
|
|
|
|
{
|
|
|
|
my $ent;
|
|
|
|
my $attr = $this_attr->{attr_name};
|
|
|
|
|
|
|
|
# skip the key attr ???
|
|
|
|
if ($attr eq $objkey)
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
next;
|
|
|
|
}
|
2010-01-13 03:21:50 +00:00
|
|
|
# skip the attributes that does not needed for node type
|
|
|
|
if ($getnodes) {
|
|
|
|
if (scalar(@attrs) > 0 && !grep(/^$attr$/, @attrs)) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
# OK - get the info needed to access the DB table
|
|
|
|
# - i.e. table name, key name, attr names
|
|
|
|
|
|
|
|
# need the actual table attr name corresponding
|
|
|
|
# to the object attr name
|
|
|
|
# ex. noderes.nfsdir
|
|
|
|
my ($tab, $tabattr) = split('\.', $this_attr->{tabentry});
|
|
|
|
|
|
|
|
foreach my $objname (sort @{$type_obj{$objtype}}) {
|
|
|
|
# get table lookup info from Schema.pm
|
|
|
|
# !!!! some tables depend on the value of certain attrs
|
|
|
|
# we need to look up attrs in the correct order or we will
|
|
|
|
# not be able to determine what tables to look
|
|
|
|
# in for some attrs.
|
|
|
|
if (exists($this_attr->{only_if}))
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
my ($check_attr, $check_value) = split('\=', $this_attr->{only_if});
|
|
|
|
# if the object value is not the value we need
|
|
|
|
# to match then try the next only_if value
|
|
|
|
next if ( !($objhash{$objname}{$check_attr} =~ /\b$check_value\b/) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$objhash{$objname}{'objtype'} = $objtype;
|
|
|
|
my %tabentry = ();
|
|
|
|
# def commands need to support multiple keys in one table
|
|
|
|
# the subroutine parse_access_tabentry is used for supporting multiple keys
|
|
|
|
my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname,
|
|
|
|
$this_attr->{access_tabentry}, \%tabentry);
|
|
|
|
if ($rc != 0)
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] =
|
|
|
|
"access_tabentry \'$this_attr->{access_tabentry}\' is not valid.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
#
|
|
|
|
# Only allow one table in the access_tabentry
|
|
|
|
# use multiple tables to look up tabentry does not make any sense
|
|
|
|
my $lookup_table = $tabentry{'lookup_table'};
|
|
|
|
my $intabhash = 0;
|
|
|
|
my $notsearched = 0;
|
|
|
|
foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}})
|
|
|
|
{
|
|
|
|
# Check whether the attribute is already in %tabhash
|
|
|
|
# The %tabhash is for performance considerations
|
|
|
|
if ( ($lookup_attr eq 'node') && ($objtype eq 'node') ){
|
|
|
|
if (defined($tabhash{$lookup_table}{$objname}{$tabattr})) {
|
|
|
|
if ($verbose == 1)
|
|
|
|
{
|
|
|
|
$objhash{$objname}{$attr} = "$tabhash{$lookup_table}{$objname}{$tabattr}\t(Table:$lookup_table - Key:$lookup_attr - Column:$tabattr)";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$objhash{$objname}{$attr} = $tabhash{$lookup_table}{$objname}{$tabattr};
|
|
|
|
}
|
2010-09-08 10:38:25 +00:00
|
|
|
if (defined $chname_ref) {
|
|
|
|
push @{$chname_ref->{$lookup_table}}, ($tabentry{'lookup_attrs'}, $lookup_attr);
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
$intabhash = 1;
|
2009-09-09 09:07:28 +00:00
|
|
|
last;
|
2009-12-30 07:50:28 +00:00
|
|
|
} elsif (! defined($tabhash{$lookup_table}{$objname}{"$tabattr"."_hassearched"})) {
|
|
|
|
$notsearched = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$notsearched = 1;
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
}
|
2008-06-24 14:50:21 +00:00
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
# Not in tabhash,
|
|
|
|
# Need to lookup the table
|
|
|
|
if ($intabhash == 0 && $notsearched == 1)
|
|
|
|
{
|
|
|
|
# look up attr values
|
|
|
|
my @rows = xCAT::DBobjUtils->getDBtable($lookup_table);
|
2010-03-01 10:11:59 +00:00
|
|
|
if (@rows)
|
2009-12-30 07:50:28 +00:00
|
|
|
{
|
|
|
|
foreach my $rowent (@rows)
|
|
|
|
{
|
|
|
|
my $match = 1;
|
|
|
|
my $matchedattr;
|
|
|
|
# Again, multiple keys support needs the "foreach"
|
|
|
|
foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}})
|
|
|
|
{
|
|
|
|
if ($rowent->{$lookup_attr} ne $tabentry{'lookup_attrs'}{$lookup_attr})
|
|
|
|
{
|
|
|
|
$match = 0;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($match == 1)
|
|
|
|
{
|
|
|
|
if ($verbose == 1)
|
|
|
|
{
|
|
|
|
my @lookup_attrs = keys %{$tabentry{'lookup_attrs'}};
|
|
|
|
$objhash{$objname}{$attr} = "$rowent->{$tabattr}\t(Table:$lookup_table - Key: @lookup_attrs - Column:$tabattr)";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$objhash{$objname}{$attr} = $rowent->{$tabattr};
|
|
|
|
}
|
2010-09-08 10:38:25 +00:00
|
|
|
if (defined $chname_ref) {
|
|
|
|
push @{$chname_ref->{$lookup_table}}, ($tabentry{'lookup_attrs'}, (keys %{$tabentry{'lookup_attrs'}}) [0]);
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
} #end if ($match...
|
|
|
|
} #end foreach
|
|
|
|
} # end if (defined...
|
|
|
|
} #end if ($intabhash...
|
2008-06-24 14:50:21 +00:00
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
|
2008-06-24 14:50:21 +00:00
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} #foreach my $objtype
|
2008-06-24 14:50:21 +00:00
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
return %objhash;
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getDBtable
|
|
|
|
|
|
|
|
Get a DB table, cache it , & return list of rows from the table.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
Returns:
|
|
|
|
undef - error
|
|
|
|
@rows - of table
|
|
|
|
Globals:
|
|
|
|
Error:
|
|
|
|
Example:
|
|
|
|
|
|
|
|
call as follows
|
|
|
|
my @TableRowArray= xCAT::DBobjUtils->getDBtable($tablename);
|
|
|
|
|
|
|
|
Comments:
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub getDBtable
|
|
|
|
{
|
|
|
|
my ($class, $table) = @_;
|
|
|
|
my @rows = [];
|
|
|
|
|
2008-03-14 17:11:21 +00:00
|
|
|
# save this table info - in case this subr gets called multiple times
|
2010-12-15 01:47:06 +00:00
|
|
|
# --nocache flag specifies not to use cahe
|
|
|
|
if (grep(/^$table$/, @::foundTableList) && !$::opt_c)
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
|
|
|
|
2008-03-14 17:11:21 +00:00
|
|
|
# already have this
|
|
|
|
@rows = @{$::TableHash{$table}};
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-14 17:11:21 +00:00
|
|
|
|
|
|
|
# need to get info from DB
|
|
|
|
my $thistable = xCAT::Table->new($table, -create => 1, -autocommit => 0);
|
|
|
|
if (!$thistable)
|
|
|
|
{
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
2009-09-23 09:43:36 +00:00
|
|
|
#@rows = $thistable->getTable;
|
|
|
|
@rows = @{$thistable->getAllEntries()};
|
2008-03-14 17:11:21 +00:00
|
|
|
|
|
|
|
# !!!! this routine returns rows even if the table is empty!!!!!!
|
|
|
|
|
|
|
|
# keep track of the fact that we checked this table
|
|
|
|
# - even if it's empty!
|
|
|
|
push(@::foundTableList, $thistable->{tabname});
|
|
|
|
|
|
|
|
@{$::TableHash{$table}} = @rows;
|
|
|
|
|
2009-10-28 20:03:35 +00:00
|
|
|
#$thistable->commit;
|
2008-03-14 17:11:21 +00:00
|
|
|
|
|
|
|
} # end if not cached
|
|
|
|
|
2010-03-01 10:11:59 +00:00
|
|
|
if (@rows)
|
2008-03-14 17:11:21 +00:00
|
|
|
{
|
|
|
|
return @rows;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return undef;
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 setobjdefs
|
|
|
|
|
|
|
|
Set the object definitions in the DB.
|
|
|
|
- Handles the Schema lookup and updating the DB tables.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
Returns:
|
|
|
|
1 - error
|
|
|
|
0 - OK
|
|
|
|
Globals:
|
|
|
|
Error:
|
|
|
|
Example:
|
|
|
|
|
|
|
|
To use:
|
|
|
|
-create hash for objectname and object type
|
|
|
|
ex. $objhash{$object}{$attribute} = value;
|
|
|
|
|
|
|
|
-then call as follows:
|
|
|
|
if (xCAT::DBobjUtils->setobjdefs(\%objhash) != 0)
|
|
|
|
|
|
|
|
Comments:
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub setobjdefs
|
|
|
|
{
|
|
|
|
my ($class, $hash_ref) = @_;
|
|
|
|
my %objhash = %$hash_ref;
|
|
|
|
my %settableref;
|
|
|
|
my $ret = 0;
|
2009-06-01 06:35:43 +00:00
|
|
|
my %allupdates;
|
|
|
|
my $setattrs=0;
|
|
|
|
|
|
|
|
# get the attr=vals for these objects from the DB - if any
|
|
|
|
# - so we can figure out where to put additional attrs
|
|
|
|
# The getobjdefs call was in the foreach loop,
|
|
|
|
# it caused mkdef/chdef performance issue,
|
|
|
|
# so it is moved out of the foreach loop
|
|
|
|
|
|
|
|
my %DBhash;
|
2009-12-30 07:50:28 +00:00
|
|
|
my @attrs;
|
2009-06-01 06:35:43 +00:00
|
|
|
foreach my $objname (keys %objhash)
|
|
|
|
{
|
|
|
|
my $type = $objhash{$objname}{objtype};
|
|
|
|
$DBhash{$objname} = $type;
|
2009-12-30 07:50:28 +00:00
|
|
|
@attrs = keys %{$objhash{$objname}};
|
2009-06-01 06:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my %DBattrvals;
|
2009-12-30 07:50:28 +00:00
|
|
|
%DBattrvals = xCAT::DBobjUtils->getobjdefs(\%DBhash, 0, \@attrs);
|
2009-06-01 06:35:43 +00:00
|
|
|
|
|
|
|
# for each object figure out:
|
|
|
|
# - what tables to update
|
|
|
|
# - which table attrs correspond to which object attrs
|
|
|
|
# - what the keys are for each table
|
|
|
|
# update the tables a row at a time
|
2007-11-26 20:05:39 +00:00
|
|
|
foreach my $objname (keys %objhash)
|
|
|
|
{
|
|
|
|
|
|
|
|
# get attr=val that are set in the DB ??
|
|
|
|
my $type = $objhash{$objname}{objtype};
|
2008-02-28 18:09:47 +00:00
|
|
|
|
2008-07-09 18:03:41 +00:00
|
|
|
# handle the monitoring table as a special case !!!!!
|
2008-06-24 14:50:21 +00:00
|
|
|
if ($type eq 'monitoring')
|
|
|
|
{
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
# Get the names of the attrs stored in monitoring table
|
|
|
|
# get the object type decription from Schema.pm
|
|
|
|
my $datatype = $xCAT::Schema::defspec{$type};
|
|
|
|
|
|
|
|
# get a list of valid attr names
|
|
|
|
# for this type object
|
|
|
|
my @attrlist;
|
|
|
|
foreach my $entry (@{$datatype->{'attrs'}})
|
|
|
|
{
|
|
|
|
push(@attrlist, $entry->{'attr_name'});
|
|
|
|
}
|
2008-06-24 14:50:21 +00:00
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
# open the tables (monitoring and monsetting)
|
2008-06-24 14:50:21 +00:00
|
|
|
my $montable = xCAT::Table->new('monitoring', -create => 1, -autocommit => 0);
|
|
|
|
if (!$montable)
|
|
|
|
{
|
|
|
|
my $rsp;
|
2008-07-09 18:03:41 +00:00
|
|
|
$rsp->{data}->[0] = "Could not set the \'$montable\' table.";
|
2008-06-24 14:50:21 +00:00
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
return 1;
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
# open the table
|
2008-06-24 14:50:21 +00:00
|
|
|
my $monsettable = xCAT::Table->new('monsetting', -create => 1, -autocommit => 0);
|
|
|
|
if (!$monsettable)
|
|
|
|
{
|
|
|
|
my $rsp;
|
2008-07-09 18:03:41 +00:00
|
|
|
$rsp->{data}->[0] = "Could not set the \'$monsettable\' table.";
|
2008-06-24 14:50:21 +00:00
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
my %keyhash;
|
|
|
|
my %updates;
|
|
|
|
|
|
|
|
foreach my $attr (keys %{$objhash{$objname}})
|
2008-06-24 14:50:21 +00:00
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
my $val;
|
2008-06-24 14:50:21 +00:00
|
|
|
if ($attr eq 'objtype')
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
# determine the value if we have plus or minus
|
|
|
|
if ($::plus_option)
|
2008-06-24 14:50:21 +00:00
|
|
|
{
|
|
|
|
# add new to existing - at the end - comma separated
|
|
|
|
if (defined($DBattrvals{$objname}{$attr}))
|
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
$val = "$DBattrvals{$objname}{$attr},$objhash{$objname}{$attr}";
|
2008-06-24 14:50:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$val = "$objhash{$objname}{$attr}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($::minus_option)
|
2009-12-30 07:50:28 +00:00
|
|
|
{
|
2008-06-24 14:50:21 +00:00
|
|
|
# remove the specified list of values from the current
|
|
|
|
# attr values.
|
|
|
|
if ($DBattrvals{$objname}{$attr})
|
|
|
|
{
|
|
|
|
# get the list of attrs to remove
|
2008-07-09 18:03:41 +00:00
|
|
|
my @currentList = split(/,/, $DBattrvals{$objname}{$attr});
|
|
|
|
my @minusList = split(/,/, $objhash{$objname}{$attr});
|
2008-06-24 14:50:21 +00:00
|
|
|
|
|
|
|
# make a new list without the one specified
|
|
|
|
my $first = 1;
|
|
|
|
my $newlist;
|
2010-06-09 09:05:45 +00:00
|
|
|
foreach my $i (@currentList)
|
2008-06-24 14:50:21 +00:00
|
|
|
{
|
|
|
|
chomp $i;
|
|
|
|
if (!grep(/^$i$/, @minusList))
|
|
|
|
{
|
|
|
|
# set new groups list for node
|
|
|
|
if (!$first)
|
|
|
|
{
|
|
|
|
$newlist .= ",";
|
|
|
|
}
|
|
|
|
$newlist .= $i;
|
|
|
|
$first = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$val = $newlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#just set the attr to what was provided! - replace
|
|
|
|
$val = $objhash{$objname}{$attr};
|
|
|
|
}
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
if (grep(/^$attr$/, @attrlist)) {
|
|
|
|
# if the attr belong in the monitoring tabel
|
|
|
|
%keyhash=(name=>$objname);
|
|
|
|
%updates=($attr=>$val);
|
|
|
|
$montable->setAttribs(\%keyhash, \%updates);
|
|
|
|
} else {
|
|
|
|
# else it belongs in the monsetting table
|
|
|
|
$keyhash{name} = $objname;
|
|
|
|
$keyhash{key} = $attr;
|
|
|
|
$updates{value} = $val;
|
|
|
|
$monsettable->setAttribs(\%keyhash, \%updates);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$montable->commit;
|
|
|
|
$monsettable->commit;
|
|
|
|
next;
|
|
|
|
} #if ($type eq 'monitoring')
|
2008-06-24 14:50:21 +00:00
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
# handle the site table as a special case !!!!!
|
|
|
|
if ($type eq 'site')
|
|
|
|
{
|
|
|
|
# open the table
|
2008-07-09 18:03:41 +00:00
|
|
|
my $thistable =
|
2009-12-30 07:50:28 +00:00
|
|
|
xCAT::Table->new('site', -create => 1, -autocommit => 0);
|
2007-11-26 20:05:39 +00:00
|
|
|
if (!$thistable)
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] = "Could not set the \'$thistable\' table.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $attr (keys %{$objhash{$objname}})
|
|
|
|
{
|
|
|
|
if ($attr eq 'objtype')
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
my %keyhash;
|
2007-11-26 20:05:39 +00:00
|
|
|
$keyhash{key} = $attr;
|
|
|
|
|
|
|
|
my $val;
|
|
|
|
if ($::plus_option)
|
|
|
|
{
|
|
|
|
# add new to existing - at the end - comma separated
|
|
|
|
if (defined($DBattrvals{$objname}{$attr}))
|
|
|
|
{
|
|
|
|
$val =
|
|
|
|
"$DBattrvals{$objname}{$attr},$objhash{$objname}{$attr}";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$val = "$objhash{$objname}{$attr}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($::minus_option)
|
|
|
|
{
|
|
|
|
# remove the specified list of values from the current
|
|
|
|
# attr values.
|
|
|
|
if ($DBattrvals{$objname}{$attr})
|
|
|
|
{
|
|
|
|
# get the list of attrs to remove
|
2008-07-09 18:03:41 +00:00
|
|
|
my @currentList = split(/,/, $DBattrvals{$objname}{$attr});
|
|
|
|
my @minusList = split(/,/, $objhash{$objname}{$attr});
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
# make a new list without the one specified
|
|
|
|
my $first = 1;
|
|
|
|
my $newlist;
|
2010-06-09 09:05:45 +00:00
|
|
|
foreach my $i (@currentList)
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
|
|
|
chomp $i;
|
|
|
|
if (!grep(/^$i$/, @minusList))
|
|
|
|
{
|
|
|
|
# set new groups list for node
|
|
|
|
if (!$first)
|
|
|
|
{
|
|
|
|
$newlist .= ",";
|
|
|
|
}
|
|
|
|
$newlist .= $i;
|
|
|
|
$first = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$val = $newlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
#just set the attr to what was provided! - replace
|
|
|
|
$val = $objhash{$objname}{$attr};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
if ( $val eq "") { # delete the line
|
|
|
|
$thistable->delEntries(\%keyhash);
|
|
|
|
} else { # change the attr
|
|
|
|
|
|
|
|
my %updates;
|
|
|
|
$updates{value} = $val;
|
|
|
|
|
|
|
|
my ($rc, $str) = $thistable->setAttribs(\%keyhash, \%updates);
|
|
|
|
if (!defined($rc))
|
|
|
|
{
|
|
|
|
if ($::verbose)
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] =
|
|
|
|
"Could not set the \'$attr\' attribute of the \'$objname\' object in the xCAT database.";
|
|
|
|
$rsp->{data}->[1] =
|
|
|
|
"Error returned is \'$str->errstr\'.";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
|
|
|
}
|
|
|
|
$ret = 1;
|
|
|
|
}
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$thistable->commit;
|
|
|
|
|
|
|
|
next;
|
2009-12-30 07:50:28 +00:00
|
|
|
} #if ($type eq 'site')
|
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# handle the rest of the object types
|
|
|
|
#
|
2009-05-07 13:58:00 +00:00
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
# get the object type decription from Schema.pm
|
|
|
|
my $datatype = $xCAT::Schema::defspec{$type};
|
|
|
|
|
2009-05-07 13:58:00 +00:00
|
|
|
# get the object key to look for, for this object type
|
2008-11-18 18:07:46 +00:00
|
|
|
my $objkey = $datatype->{'objkey'};
|
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
# get a list of valid attr names
|
2009-05-07 13:58:00 +00:00
|
|
|
# for this type object
|
2007-11-26 20:05:39 +00:00
|
|
|
my %attrlist;
|
|
|
|
foreach my $entry (@{$datatype->{'attrs'}})
|
|
|
|
{
|
|
|
|
push(@{$attrlist{$type}}, $entry->{'attr_name'});
|
|
|
|
}
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
my @attrprovided=();
|
2008-02-26 18:07:16 +00:00
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
# check FINALATTRS to see if all the attrs are valid
|
|
|
|
foreach my $attr (keys %{$objhash{$objname}})
|
|
|
|
{
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
if ($attr eq $objkey)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
2008-11-18 18:07:46 +00:00
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
if ($attr eq "objtype")
|
|
|
|
{
|
|
|
|
# objtype not stored in object definition
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(grep /^$attr$/, @{$attrlist{$type}}))
|
|
|
|
{
|
|
|
|
if ($::verbose)
|
|
|
|
{
|
2008-07-09 18:03:41 +00:00
|
|
|
my $rsp;
|
2007-11-26 20:05:39 +00:00
|
|
|
$rsp->{data}->[0] =
|
|
|
|
"\'$attr\' is not a valid attribute for type \'$type\'.";
|
|
|
|
$rsp->{data}->[1] = "Skipping to the next attribute.";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
push(@attrprovided, $attr);
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# we need to figure out what table to
|
2009-05-07 13:58:00 +00:00
|
|
|
# store each attr
|
2007-11-26 20:05:39 +00:00
|
|
|
# And we must do this in the order given in defspec!!
|
2008-02-26 18:07:16 +00:00
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
my @setattrlist=();
|
|
|
|
my @checkedattrs;
|
|
|
|
my $invalidattr;
|
2008-02-26 18:07:16 +00:00
|
|
|
|
2008-07-09 18:03:41 +00:00
|
|
|
foreach my $this_attr (@{$datatype->{'attrs'}})
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
|
|
|
my %keyhash;
|
|
|
|
my %updates;
|
2009-09-09 09:07:28 +00:00
|
|
|
my %tabentry;
|
2009-12-30 07:50:28 +00:00
|
|
|
my ($lookup_table, $lookup_attr, $lookup_data);
|
2007-11-26 20:05:39 +00:00
|
|
|
my $attr_name = $this_attr->{attr_name};
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
if ($attr_name eq $objkey)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
2008-02-26 18:07:16 +00:00
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
# if we have a value for this attribute then process it
|
|
|
|
# - otherwise go to the next attr
|
|
|
|
if (defined($objhash{$objname}{$attr_name}))
|
|
|
|
{
|
|
|
|
# check the defspec to see where this attr goes
|
|
|
|
|
|
|
|
# the table for this attr might depend on the
|
|
|
|
# value of some other attr
|
|
|
|
# need to check the only_if entries to find one where the
|
|
|
|
# other attr value matches what we have
|
|
|
|
# ex. like if I want to set hdwctrlpoint I will have
|
|
|
|
# to match the right value for mgtmethod
|
|
|
|
if (exists($this_attr->{only_if}))
|
|
|
|
{
|
|
|
|
my ($check_attr, $check_value) =
|
|
|
|
split('\=', $this_attr->{only_if});
|
|
|
|
|
|
|
|
# if my attr value for the attr to check doesn't
|
|
|
|
# match this then try the next one
|
|
|
|
# ex. say I want to set hdwctrlpoint, the table
|
|
|
|
# will depend on the mgtmethod attr - so I need
|
|
|
|
# to find the 'only_if' that matches the value
|
|
|
|
# specified for that attr (ex. mgtmethod=hmc)
|
|
|
|
|
|
|
|
# need to check the attrs we are setting for the object
|
|
|
|
# as well as the attrs for this object that may be
|
2008-06-07 16:30:09 +00:00
|
|
|
# already set in DB
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
if ( !($objhash{$objname}{$check_attr}) && !($DBattrvals{$objname}{$check_attr}) ) {
|
2008-06-07 16:30:09 +00:00
|
|
|
# if I didn't already check for this attr
|
|
|
|
my $rsp;
|
|
|
|
if (!grep(/^$attr_name$/, @checkedattrs)) {
|
2009-10-12 07:41:20 +00:00
|
|
|
push @{$rsp->{data}}, "Cannot set the \'$attr_name\' attribute unless a value is provided for \'$check_attr\'.";
|
2008-06-07 16:30:09 +00:00
|
|
|
|
|
|
|
foreach my $tmp_attr (@{$datatype->{'attrs'}}) {
|
|
|
|
my $attr = $tmp_attr->{attr_name};
|
|
|
|
if ($attr eq $check_attr) {
|
|
|
|
my ($tab, $at) = split(/\./, $tmp_attr->{tabentry});
|
|
|
|
my $schema = xCAT::Table->getTableSchema($tab);
|
2008-07-09 18:03:41 +00:00
|
|
|
my $desc = $schema->{descriptions}->{$at};
|
2009-10-12 07:41:20 +00:00
|
|
|
push @{$rsp->{data}}, "$check_attr => $desc";
|
2008-06-07 16:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
|
|
|
push(@checkedattrs, $attr_name);
|
2009-09-25 08:30:11 +00:00
|
|
|
if ( $invalidattr->{$attr_name}->{valid} ne 1 ) {
|
|
|
|
$invalidattr->{$attr_name}->{valid} = 0;
|
|
|
|
$invalidattr->{$attr_name}->{condition} = "\'$check_attr=$check_value\'";
|
|
|
|
}
|
|
|
|
|
2008-06-07 16:30:09 +00:00
|
|
|
next;
|
|
|
|
}
|
2008-02-11 19:44:59 +00:00
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
if ( !($objhash{$objname}{$check_attr} =~ /\b$check_value\b/) && !($DBattrvals{$objname}{$check_attr} =~ /\b$check_value\b/) )
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2009-09-25 08:30:11 +00:00
|
|
|
if ( $invalidattr->{$attr_name}->{valid} ne 1 ) {
|
|
|
|
$invalidattr->{$attr_name}->{valid} = 0;
|
|
|
|
$invalidattr->{$attr_name}->{condition} = "\'$check_attr=$check_value\'";
|
|
|
|
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
|
2009-09-25 08:30:11 +00:00
|
|
|
next;
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-25 08:30:11 +00:00
|
|
|
$invalidattr->{$attr_name}->{valid} = 1;
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
# get the info needed to write to the DB table
|
|
|
|
#
|
|
|
|
# get the actual attr name to use in the table
|
|
|
|
# - may be different then the attr name used for the object.
|
|
|
|
($::tab, $::tabattr) = split('\.', $this_attr->{tabentry});
|
|
|
|
|
2009-09-09 09:07:28 +00:00
|
|
|
my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname,
|
|
|
|
$this_attr->{access_tabentry}, \%tabentry);
|
|
|
|
if ($rc != 0)
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] =
|
|
|
|
"access_tabentry \'$this_attr->{access_tabentry}\' is not valid.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
next;
|
|
|
|
}
|
2010-03-01 10:11:59 +00:00
|
|
|
$lookup_table = $tabentry{'lookup_table'};
|
2009-09-09 09:07:28 +00:00
|
|
|
# Set the lookup criteria for this attribute into %allupdates
|
|
|
|
# the key is 'lookup_attrs'
|
|
|
|
foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}})
|
|
|
|
{
|
|
|
|
$allupdates{$lookup_table}{$objname}{$attr_name}{'lookup_attrs'}{$lookup_attr}
|
|
|
|
=$tabentry{'lookup_attrs'}{$lookup_attr};
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $val;
|
2009-06-30 11:28:26 +00:00
|
|
|
my $delim = ',';
|
|
|
|
if(($type eq 'group') && ($DBattrvals{$objname}{'grouptype'} eq 'dynamic'))
|
|
|
|
{
|
|
|
|
# dynamic node group selection string use "::" as delimiter
|
|
|
|
$delim = '::';
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
if ($::plus_option)
|
|
|
|
{
|
|
|
|
|
|
|
|
# add new to existing - at the end - comma separated
|
|
|
|
if (defined($DBattrvals{$objname}{$attr_name}))
|
|
|
|
{
|
2009-05-13 08:48:27 +00:00
|
|
|
# add the attr into the list if it's not already in the list!
|
|
|
|
# and avoid the duplicate values
|
2009-06-30 11:28:26 +00:00
|
|
|
my @DBattrarray = split(/$delim/, $DBattrvals{$objname}{$attr_name});
|
|
|
|
my @objhasharray = split(/$delim/, $objhash{$objname}{$attr_name});
|
2009-05-13 08:48:27 +00:00
|
|
|
foreach my $objattr (@objhasharray)
|
|
|
|
{
|
|
|
|
if (!grep(/^\Q$objattr\E$/, @DBattrarray))
|
|
|
|
{
|
|
|
|
push @DBattrarray, $objattr;
|
|
|
|
}
|
|
|
|
}
|
2009-06-30 11:28:26 +00:00
|
|
|
$val = join($delim, @DBattrarray);
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$val = "$objhash{$objname}{$attr_name}";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
elsif ($::minus_option)
|
|
|
|
{
|
|
|
|
|
|
|
|
# remove the specified list of values from the current
|
|
|
|
# attr values.
|
|
|
|
if ($DBattrvals{$objname}{$attr_name})
|
|
|
|
{
|
|
|
|
|
|
|
|
# get the list of attrs to remove
|
2008-07-09 18:03:41 +00:00
|
|
|
my @currentList =
|
2009-06-30 11:28:26 +00:00
|
|
|
split(/$delim/, $DBattrvals{$objname}{$attr_name});
|
|
|
|
my @minusList = split(/$delim/, $objhash{$objname}{$attr_name});
|
2007-11-26 20:05:39 +00:00
|
|
|
|
2010-06-13 08:42:05 +00:00
|
|
|
foreach my $em (@minusList)
|
|
|
|
{
|
|
|
|
if (!(grep {$_ eq $em} @currentList))
|
|
|
|
{
|
|
|
|
if (($::opt_t eq 'group') && ($DBattrvals{$objname}{'grouptype'} ne 'dynamic'))
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] = "$objname is not a member of \'$em\'.";
|
|
|
|
xCAT::MsgUtils->message("W", $rsp, $::callback);
|
|
|
|
} else {
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] = "$em is not in the atrribute of \'$attr_name\' for the \'$objname\' definition.";
|
|
|
|
xCAT::MsgUtils->message("W", $rsp, $::callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
# make a new list without the one specified
|
|
|
|
my $first = 1;
|
|
|
|
my $newlist;
|
2010-06-09 09:05:45 +00:00
|
|
|
foreach my $i (@currentList)
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
|
|
|
chomp $i;
|
2010-06-02 09:08:50 +00:00
|
|
|
if (!grep(/^\Q$i\E$/, @minusList))
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
|
|
|
|
2008-02-28 18:09:47 +00:00
|
|
|
# set new list for node
|
2007-11-26 20:05:39 +00:00
|
|
|
if (!$first)
|
|
|
|
{
|
2009-06-30 11:28:26 +00:00
|
|
|
$newlist .= "$delim";
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
|
|
|
$newlist .= $i;
|
|
|
|
$first = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$val = $newlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
#just set the attr to what was provided! - replace
|
|
|
|
$val = $objhash{$objname}{$attr_name};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
# Set the values into %allupdates
|
|
|
|
# the key is 'tabattrs'
|
|
|
|
$allupdates{$lookup_table}{$objname}{$attr_name}{'tabattrs'}{$::tabattr} = $val;
|
|
|
|
$setattrs=1;
|
|
|
|
|
|
|
|
push(@setattrlist, $attr_name);
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
} # end - foreach attribute
|
2008-02-26 18:07:16 +00:00
|
|
|
|
2009-09-25 08:30:11 +00:00
|
|
|
my $rsp;
|
|
|
|
foreach my $att (keys %$invalidattr) {
|
|
|
|
if ( $invalidattr->{$att}->{valid} ne 1) {
|
|
|
|
my $tt = $invalidattr->{$att}->{valid};
|
2009-10-12 07:41:20 +00:00
|
|
|
push @{$rsp->{data}}, "Cannot set the attr=\'$att\' attribute unless $invalidattr->{$att}->{condition}.";
|
2009-09-25 08:30:11 +00:00
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-07 13:58:00 +00:00
|
|
|
|
|
|
|
# TODO - need to get back to this
|
|
|
|
if (0) {
|
2008-02-26 18:07:16 +00:00
|
|
|
#
|
|
|
|
# check to see if all the attrs got set
|
|
|
|
#
|
|
|
|
|
|
|
|
my @errlist;
|
|
|
|
foreach $a (@attrprovided)
|
|
|
|
{
|
|
|
|
# is this attr was not set then add it to the error list
|
|
|
|
if (!grep(/^$a$/, @setattrlist))
|
|
|
|
{
|
|
|
|
push(@errlist, $a);
|
|
|
|
$ret = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($ret == 2) {
|
|
|
|
my $rsp;
|
2009-10-12 07:41:20 +00:00
|
|
|
$rsp->{data}->[0] = "Could not set the following attributes for the \'$objname\' definition in the xCAT database: \'@errlist\'";
|
2008-02-26 18:07:16 +00:00
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
}
|
|
|
|
|
2009-05-07 13:58:00 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
} # end - foreach object
|
2009-09-09 09:07:28 +00:00
|
|
|
#==========================================================#
|
|
|
|
#%allupdates structure:
|
|
|
|
# for command: chdef -t node -o node1 groups=all
|
|
|
|
# usercomment=ddee passwd.HMC=HMC
|
|
|
|
# passwd.admin=cluster passwd.general=abc123
|
|
|
|
# the %allupdates will be:
|
|
|
|
#0 'ppcdirect'
|
|
|
|
#1 HASH(0x12783d30)
|
|
|
|
# 'node1' => HASH(0x12783cc4)
|
|
|
|
# 'passwd.HMC' => HASH(0x12783ed4)
|
|
|
|
# 'lookup_attrs' => HASH(0x12783f70)
|
|
|
|
# 'hcp' => 'node1'
|
|
|
|
# 'username' => 'HMC'
|
|
|
|
# 'tabattrs' => HASH(0x12783e8c)
|
|
|
|
# 'password' => 'HMC'
|
|
|
|
# 'passwd.admin' => HASH(0x12783c64)
|
|
|
|
# 'lookup_attrs' => HASH(0x12784000)
|
|
|
|
# 'hcp' => 'node1'
|
|
|
|
# 'username' => 'admin'
|
|
|
|
# 'tabattrs' => HASH(0x12783f64)
|
|
|
|
# 'password' => 'cluster'
|
|
|
|
# 'passwd.general' => HASH(0x12783a6c)
|
|
|
|
# 'lookup_attrs' => HASH(0x12784198)
|
|
|
|
# 'hcp' => 'node1'
|
|
|
|
# 'username' => 'general'
|
|
|
|
# 'tabattrs' => HASH(0x12783aa8)
|
|
|
|
# 'password' => 'abc123'
|
|
|
|
#2 'nodelist'
|
|
|
|
#3 HASH(0x127842b8)
|
|
|
|
# 'node1' => HASH(0x12784378)
|
|
|
|
# 'groups' => HASH(0x12784090)
|
|
|
|
# 'lookup_attrs' => HASH(0x127844bc)
|
|
|
|
# 'node' => 'node1'
|
|
|
|
# 'tabattrs' => HASH(0x1277fd34)
|
|
|
|
# 'groups' => 'all'
|
|
|
|
# 'usercomment' => HASH(0x12784318)
|
|
|
|
# 'lookup_attrs' => HASH(0x12780550)
|
|
|
|
# 'node' => 'node1'
|
|
|
|
# 'tabattrs' => HASH(0x127842f4)
|
|
|
|
# 'comments' => 'ddee'
|
|
|
|
#=================================================================#
|
2009-05-07 13:58:00 +00:00
|
|
|
# now set the attribute values in the tables
|
|
|
|
# - handles all except site, monitoring & monsetting for now
|
|
|
|
if ($setattrs) {
|
2009-12-30 07:50:28 +00:00
|
|
|
foreach my $table (keys %allupdates) {
|
|
|
|
|
|
|
|
# get the keys for this table
|
|
|
|
my $schema = xCAT::Table->getTableSchema($table);
|
|
|
|
my $keys = $schema->{keys};
|
|
|
|
|
|
|
|
# open the table
|
|
|
|
my $thistable = xCAT::Table->new($table, -create => 1, -autocommit => 0);
|
|
|
|
if (!$thistable) {
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] = "Could not set the \'$thistable\' table.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Special case for the postscripts table
|
|
|
|
# Does not set the postscripts to the postscripts table
|
|
|
|
# if the postscripts already in xcatdefaults
|
|
|
|
# for code logic, it will be clearer to put the special case into defch,
|
|
|
|
# but putting it into defch will introduce additional table access for postscripts table.
|
|
|
|
# accessing table is time consuming.
|
|
|
|
if ($table eq "postscripts") {
|
|
|
|
my $xcatdefaultsps;
|
|
|
|
my $xcatdefaultspbs;
|
|
|
|
my @TableRowArray = xCAT::DBobjUtils->getDBtable('postscripts');
|
2010-03-01 10:11:59 +00:00
|
|
|
if (@TableRowArray)
|
2009-12-30 07:50:28 +00:00
|
|
|
{
|
|
|
|
foreach my $tablerow (@TableRowArray)
|
|
|
|
{
|
|
|
|
if(($tablerow->{node} eq 'xcatdefaults') && !($tablerow->{disable}))
|
|
|
|
{
|
|
|
|
$xcatdefaultsps = $tablerow->{postscripts};
|
|
|
|
$xcatdefaultspbs = $tablerow->{postbootscripts};
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my @xcatdefps = split(/,/, $xcatdefaultsps);
|
|
|
|
my @xcatdefpbs = split(/,/, $xcatdefaultspbs);
|
|
|
|
foreach my $obj(keys %{$allupdates{$table}}) {
|
|
|
|
if ($obj eq 'xcatdefaults') {
|
|
|
|
#xcatdefaults can be treated as a node?
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
my @newps;
|
|
|
|
if (defined($allupdates{$table}{$obj}{'postscripts'})
|
|
|
|
&& defined($allupdates{$table}{$obj}{'postscripts'}{'tabattrs'}{'postscripts'})) {
|
|
|
|
foreach my $tempps (split(/,/, $allupdates{$table}{$obj}{'postscripts'}{'tabattrs'}{'postscripts'})) {
|
|
|
|
if (grep(/^$tempps$/, @xcatdefps)) {
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] = "$obj: postscripts \'$tempps\' is already included in the \'xcatdefaults\'.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
} else {
|
|
|
|
push @newps, $tempps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$allupdates{$table}{$obj}{'postscripts'}{'tabattrs'}{'postscripts'} = join(',', @newps);
|
|
|
|
}
|
|
|
|
my @newpbs;
|
|
|
|
if (defined($allupdates{$table}{$obj}{'postbootscripts'})
|
2009-12-18 08:40:54 +00:00
|
|
|
&& defined($allupdates{$table}{$obj}{'postbootscripts'}{'tabattrs'}{'postbootscripts'})) {
|
2009-12-30 07:50:28 +00:00
|
|
|
foreach my $temppbs (split(/,/, $allupdates{$table}{$obj}{'postbootscripts'}{'tabattrs'}{'postbootscripts'})) {
|
|
|
|
if (grep(/^$temppbs$/, @xcatdefpbs)) {
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] = "$obj: postbootscripts \'$temppbs\' is already included in the \'xcatdefaults\'.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
} else {
|
|
|
|
push @newpbs, $temppbs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$allupdates{$table}{$obj}{'postbootscripts'}{'tabattrs'}{'postbootscripts'} = join(',', @newpbs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $commit_manually = 0;
|
|
|
|
my %node_updates;
|
|
|
|
OBJ: foreach my $obj (keys %{$allupdates{$table}}) {
|
2010-08-30 06:25:34 +00:00
|
|
|
my %keyhash;
|
|
|
|
my %updates;
|
|
|
|
my $firsttime = 1;
|
2009-12-30 07:50:28 +00:00
|
|
|
ROW: foreach my $row (keys %{$allupdates{$table}{$obj}}) {
|
|
|
|
# make sure we have a value for each key
|
|
|
|
foreach my $k (@$keys) {
|
|
|
|
if (!$allupdates{$table}{$obj}{$row}{'lookup_attrs'}) {
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] = "\nMissing required attribute values for the \'$obj\' object. The required attributes are: @$keys";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
$ret = 1;
|
|
|
|
next ROW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-30 06:25:34 +00:00
|
|
|
if ($firsttime) {
|
|
|
|
# lookup keys in %hashkey
|
|
|
|
# ex. $keyhash{'hcp'} = node1
|
|
|
|
foreach my $key (keys %{$allupdates{$table}{$obj}{$row}{'lookup_attrs'}}) {
|
|
|
|
$keyhash{$key} = $allupdates{$table}{$obj}{$row}{'lookup_attrs'}{$key};
|
|
|
|
}
|
|
|
|
$firsttime = 0;
|
|
|
|
} else {
|
|
|
|
# check if the look_attrs is the same as the %keyhash
|
|
|
|
foreach my $key (keys %{$allupdates{$table}{$obj}{$row}{'lookup_attrs'}}) {
|
2010-09-13 05:22:04 +00:00
|
|
|
# The lookup_attrs can be different for tables with more than one keys such as ppcdirect
|
2010-08-30 06:25:34 +00:00
|
|
|
if ((scalar(keys %keyhash) != scalar(keys %{$allupdates{$table}{$obj}{$row}{'lookup_attrs'}}))
|
|
|
|
|| !defined($keyhash{$key})
|
|
|
|
||($keyhash{$key} ne $allupdates{$table}{$obj}{$row}{'lookup_attrs'}{$key})) {
|
2010-09-13 05:22:04 +00:00
|
|
|
# different keys, set the existing attributes into database
|
|
|
|
# update the %keyhash and clean up the %updates hash
|
|
|
|
if (%updates) {
|
|
|
|
$commit_manually = 1;
|
|
|
|
my ($rc, $str) = $thistable->setAttribs(\%keyhash, \%updates);
|
|
|
|
}
|
|
|
|
foreach my $key (keys %{$allupdates{$table}{$obj}{$row}{'lookup_attrs'}}) {
|
|
|
|
$keyhash{$key} = $allupdates{$table}{$obj}{$row}{'lookup_attrs'}{$key};
|
|
|
|
}
|
|
|
|
%updates = ();
|
2010-08-30 06:25:34 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# set values in %updates
|
|
|
|
# ex. $updates{'groups'} = 'all,lpar'
|
|
|
|
foreach my $attr (keys %{$allupdates{$table}{$obj}{$row}{'tabattrs'}}) {
|
|
|
|
if (scalar(keys %keyhash) == 0 && $keyhash{'node'} && $keyhash{'node'} eq "node") {
|
|
|
|
$node_updates{$obj}{$attr} = $allupdates{$table}{$obj}{$row}{'tabattrs'}{$attr};
|
|
|
|
} else {
|
|
|
|
$updates{$attr} = $allupdates{$table}{$obj}{$row}{'tabattrs'}{$attr};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} #end foreach my $row
|
2010-08-30 06:25:34 +00:00
|
|
|
# only uses the setAttribs to set attribute one by one when the obj type is NOT 'node'
|
|
|
|
if (%updates) {
|
|
|
|
$commit_manually = 1;
|
|
|
|
my ($rc, $str) = $thistable->setAttribs(\%keyhash, \%updates);
|
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
} #end foreach my $obj
|
|
|
|
if ($commit_manually) {
|
|
|
|
$thistable->commit;
|
|
|
|
}
|
|
|
|
if (%node_updates) {
|
|
|
|
$thistable->setNodesAttribs(\%node_updates);
|
|
|
|
}
|
|
|
|
} #end forach my $table
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 rmobjdefs
|
|
|
|
|
|
|
|
Remove object definitions from the DB.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
Returns:
|
|
|
|
0 - OK
|
|
|
|
1 - error
|
|
|
|
Globals:
|
|
|
|
Error:
|
|
|
|
Example:
|
|
|
|
|
|
|
|
To use create hash for object name and object type
|
|
|
|
ex. $objhash{$obj} = $type;
|
|
|
|
- then call as follows:
|
|
|
|
xCAT::DBobjUtils->rmobjdefs(\%objhash);
|
|
|
|
|
|
|
|
Comments:
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub rmobjdefs
|
|
|
|
{
|
|
|
|
my ($class, $hash_ref) = @_;
|
|
|
|
|
|
|
|
my %tablehash;
|
|
|
|
|
2008-07-09 18:03:41 +00:00
|
|
|
my %typehash = %$hash_ref;
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
# get the attr=vals for these objects so we know how to
|
|
|
|
# find what tables have to be modified
|
|
|
|
|
2009-12-30 07:50:28 +00:00
|
|
|
foreach my $objname (sort (keys %typehash))
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2008-07-09 18:03:41 +00:00
|
|
|
my $type = $typehash{$objname};
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
# special handling for site table
|
|
|
|
if ($type eq 'site')
|
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
my %DBattrvals = xCAT::DBobjUtils->getobjdefs(\%typehash);
|
2007-11-26 20:05:39 +00:00
|
|
|
my $thistable =
|
|
|
|
xCAT::Table->new('site', -create => 1, -autocommit => 0);
|
|
|
|
my %keyhash;
|
|
|
|
foreach my $attr (keys %{$DBattrvals{$objname}})
|
|
|
|
{
|
|
|
|
|
|
|
|
# ex. key = attr
|
|
|
|
$keyhash{key} = $attr;
|
|
|
|
|
|
|
|
$thistable->delEntries(\%keyhash);
|
|
|
|
|
|
|
|
}
|
|
|
|
$thistable->commit();
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# get the object type decription from Schema.pm
|
|
|
|
my $datatype = $xCAT::Schema::defspec{$type};
|
|
|
|
|
|
|
|
# go through the list of valid attrs
|
|
|
|
# - need to delete the row with a $key value of $objname from $table
|
|
|
|
# - make a hash containing $delhash{$table}{$key}= $objname
|
|
|
|
foreach my $this_attr (@{$datatype->{'attrs'}})
|
|
|
|
{
|
|
|
|
my $attr = $this_attr->{attr_name};
|
|
|
|
|
2008-12-15 16:53:35 +00:00
|
|
|
# get table lookup info from Schema.pm
|
2009-09-09 09:07:28 +00:00
|
|
|
# def commands need to support multiple keys in one table
|
|
|
|
# the subroutine parse_access_tabentry is used for supporting multiple keys
|
|
|
|
my %tabentry = ();
|
|
|
|
my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname, $this_attr->{access_tabentry}, \%tabentry);
|
|
|
|
if ($rc != 0)
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] =
|
|
|
|
"access_tabentry \'$this_attr->{access_tabentry}\' is not valid.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
next;
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
|
2009-09-09 09:07:28 +00:00
|
|
|
# Only allow one table in the access_tabentry
|
|
|
|
# use multiple tables to look up tabentry does not make any sense
|
|
|
|
my $lookup_table = $tabentry{'lookup_table'};
|
|
|
|
# The attr_name is the *def attribute name instead of db column
|
|
|
|
my $attr_name = $this_attr->{'attr_name'};
|
|
|
|
# we'll need table name, object name, attribute name and the lookup entries
|
2008-12-15 16:53:35 +00:00
|
|
|
# put this info in a hash - we'll process it later - below
|
2009-09-09 09:07:28 +00:00
|
|
|
foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}})
|
|
|
|
{
|
|
|
|
$tablehash{$lookup_table}{$objname}{$attr_name}{$lookup_attr}
|
|
|
|
= $tabentry{'lookup_attrs'}{$lookup_attr};
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 09:07:28 +00:00
|
|
|
#=============================================#
|
|
|
|
# The tablehash looks like this
|
|
|
|
# DB<5> x %tablehash
|
|
|
|
# 'bootparams'
|
|
|
|
# HASH(0x1280828c)
|
|
|
|
# 'node1' => HASH(0x127bca50)
|
|
|
|
# 'addkcmdline' => HASH(0x127fb114)
|
|
|
|
# 'node' => 'node1'
|
|
|
|
# 'initrd' => HASH(0x127bcb40)
|
|
|
|
# 'node' => 'node1'
|
|
|
|
# 'kcmdline' => HASH(0x127fb24c)
|
|
|
|
# 'node' => 'node1'
|
|
|
|
# 'kernel' => HASH(0x127b2e80)
|
|
|
|
# 'node' => 'node1'
|
|
|
|
# 'testfsp' => HASH(0x1280e71c)
|
|
|
|
# 'addkcmdline' => HASH(0x1280e7a0)
|
|
|
|
# 'node' => 'testfsp'
|
|
|
|
# 'initrd' => HASH(0x1280e740)
|
|
|
|
# 'node' => 'testfsp'
|
|
|
|
# 'kcmdline' => HASH(0x1280e77c)
|
|
|
|
# 'node' => 'testfsp'
|
|
|
|
# 'kernel' => HASH(0x1280e758)
|
|
|
|
# 'node' => 'testfsp'
|
|
|
|
#...
|
|
|
|
# 'ppcdirect'
|
|
|
|
# HASH(0x1278fe1c)
|
|
|
|
# 'node1' => HASH(0x12808370)
|
|
|
|
# 'passwd.HMC' => HASH(0x128083e8)
|
|
|
|
# 'hcp' => 'node1'
|
|
|
|
# 'username' => 'HMC'
|
|
|
|
# 'passwd.admin' => HASH(0x128081c0)
|
|
|
|
# 'hcp' => 'node1'
|
|
|
|
# 'username' => 'admin'
|
|
|
|
# 'passwd.general' => HASH(0x128075d8)
|
|
|
|
# 'hcp' => 'node1'
|
|
|
|
# 'username' => 'general'
|
|
|
|
# 'testfsp' => HASH(0x12790620)
|
|
|
|
# 'passwd.HMC' => HASH(0x1280ee84)
|
|
|
|
# 'hcp' => 'testfsp'
|
|
|
|
# 'username' => 'HMC'
|
|
|
|
# 'passwd.admin' => HASH(0x128082f8)
|
|
|
|
# 'hcp' => 'testfsp'
|
|
|
|
# 'username' => 'admin'
|
|
|
|
# 'passwd.general' => HASH(0x1280843c)
|
|
|
|
# 'hcp' => 'testfsp'
|
|
|
|
# 'username' => 'general'
|
|
|
|
#...
|
|
|
|
##=========================================================#
|
2007-11-26 20:05:39 +00:00
|
|
|
# now for each table - clear the entry
|
|
|
|
foreach my $table (keys %tablehash)
|
|
|
|
{
|
2009-12-30 07:50:28 +00:00
|
|
|
my @all_keyhash;
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
my $thistable =
|
|
|
|
xCAT::Table->new($table, -create => 1, -autocommit => 0);
|
|
|
|
|
2009-09-09 09:07:28 +00:00
|
|
|
foreach my $obj (keys %{$tablehash{$table}}) {
|
2009-12-30 07:50:28 +00:00
|
|
|
my %keyhash;
|
2009-09-09 09:07:28 +00:00
|
|
|
foreach my $attr (keys %{$tablehash{$table}{$obj}})
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2009-09-09 09:07:28 +00:00
|
|
|
foreach my $key (keys %{$tablehash{$table}{$obj}{$attr}})
|
|
|
|
{
|
2007-11-26 20:05:39 +00:00
|
|
|
|
2010-09-27 13:50:49 +00:00
|
|
|
#multiple keys support
|
|
|
|
if (defined($keyhash{$key}) && ($keyhash{$key} ne $tablehash{$table}{$obj}{$attr}{$key}))
|
|
|
|
{
|
|
|
|
my %tmpkeyhash;
|
|
|
|
# copy hash
|
|
|
|
foreach my $hashkey (keys %keyhash)
|
|
|
|
{
|
|
|
|
$tmpkeyhash{$hashkey} = $keyhash{$hashkey};
|
|
|
|
}
|
|
|
|
push @all_keyhash, \%tmpkeyhash;
|
|
|
|
#$thistable->delEntries(\@all_keyhash);
|
|
|
|
}
|
2009-09-09 09:07:28 +00:00
|
|
|
# ex. $keyhash{node}=c68m3hvp01
|
|
|
|
$keyhash{$key} = $tablehash{$table}{$obj}{$attr}{$key};
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
push @all_keyhash, \%keyhash;
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
2009-12-30 07:50:28 +00:00
|
|
|
# ex. delete the c68m3hvp01 entry of the node column in the
|
|
|
|
# nodelist table
|
|
|
|
$thistable->delEntries(\@all_keyhash);
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
$thistable->commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 readFileInput
|
|
|
|
|
|
|
|
Process the command line input piped in from a file.
|
|
|
|
(Support stanza or xml format.)
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
Returns:
|
|
|
|
0 - OK
|
|
|
|
1 - error
|
|
|
|
Globals:
|
|
|
|
Error:
|
|
|
|
Example:
|
|
|
|
|
|
|
|
Comments:
|
|
|
|
Set @::fileobjtypes, @::fileobjnames, %::FILEATTRS
|
|
|
|
(i.e.- $::FILEATTRS{objname}{attr}=val)
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub readFileInput
|
|
|
|
{
|
|
|
|
my ($class, $filedata) = @_;
|
2008-07-09 18:03:41 +00:00
|
|
|
my ($objectname, $junk1, $junk2);
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
@::fileobjnames = ();
|
|
|
|
|
|
|
|
my @lines = split /\n/, $filedata;
|
|
|
|
|
2010-03-01 10:11:59 +00:00
|
|
|
my $header = $lines[0];
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
# to do
|
|
|
|
#if ($header =~/<xCAT data object stanza file>/) {
|
|
|
|
# do stanza file parsing
|
|
|
|
# } elsis ($header =~/<xCAT data object XML file>/) {
|
|
|
|
# do XML parsing
|
|
|
|
#}
|
|
|
|
|
|
|
|
my $look_for_colon = 1; # start with first line that has a colon
|
2008-07-09 18:03:41 +00:00
|
|
|
my $objtype;
|
2007-11-26 20:05:39 +00:00
|
|
|
|
2008-07-09 18:03:41 +00:00
|
|
|
foreach my $l (@lines)
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
# skip blank and comment lines
|
|
|
|
next if ($l =~ /^\s*$/ || $l =~ /^\s*#/);
|
|
|
|
|
|
|
|
# see if it's a stanza name
|
|
|
|
if (grep(/:\s*$/, $l))
|
|
|
|
{
|
|
|
|
|
|
|
|
$look_for_colon = 0; # ok - we have a colon
|
|
|
|
|
2008-07-09 18:03:41 +00:00
|
|
|
($objectname, $junk2) = split(/:/, $l);
|
2007-11-26 20:05:39 +00:00
|
|
|
|
2008-07-09 18:03:41 +00:00
|
|
|
# if $junk2 is defined or there's an =
|
2008-08-22 14:13:28 +00:00
|
|
|
if ($junk2 || grep(/=/, $objectname))
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
# error - invalid header $line in node definition file
|
|
|
|
# skipping to next node stanza
|
|
|
|
# Skipping to the next valid header.
|
|
|
|
$look_for_colon++;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$objectname =~ s/^\s*//; # Remove any leading whitespace
|
|
|
|
$objectname =~ s/\s*$//; # Remove any trailing whitespace
|
|
|
|
|
|
|
|
# could have different default stanzas for different object types
|
|
|
|
|
|
|
|
if ($objectname =~ /default/)
|
|
|
|
{
|
|
|
|
|
2008-07-09 18:03:41 +00:00
|
|
|
($junk1, $objtype) = split(/-/, $objectname);
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
if ($objtype)
|
|
|
|
{
|
|
|
|
$objectname = 'default';
|
|
|
|
}
|
|
|
|
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
push(@::fileobjnames, $objectname);
|
|
|
|
|
|
|
|
}
|
2010-08-20 05:33:50 +00:00
|
|
|
elsif (($l =~ /^\s*(.*?)\s*=\s*(.*)\s*/) && (!$look_for_colon))
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2008-07-09 18:03:41 +00:00
|
|
|
my $attr = $1;
|
|
|
|
my $val = $2;
|
2007-11-26 20:05:39 +00:00
|
|
|
$attr =~ s/^\s*//; # Remove any leading whitespace
|
|
|
|
$attr =~ s/\s*$//; # Remove any trailing whitespace
|
|
|
|
$val =~ s/^\s*//;
|
|
|
|
$val =~ s/\s*$//;
|
|
|
|
|
|
|
|
# remove spaces and quotes so createnode won't get upset
|
|
|
|
$val =~ s/^\s*"\s*//;
|
|
|
|
$val =~ s/\s*"\s*$//;
|
|
|
|
|
|
|
|
if ($objectname eq "default")
|
|
|
|
{
|
|
|
|
|
|
|
|
# set the default for this attribute
|
|
|
|
$::defAttrs{$objtype}{$attr} = $val;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
# set the value in the hash for this object
|
|
|
|
$::FILEATTRS{$objectname}{$attr} = $val;
|
|
|
|
|
|
|
|
# if the attr being set is "objtype" then check
|
|
|
|
# to see if we have any defaults set for this type
|
|
|
|
# the objtype should be the first etntry in each stanza
|
|
|
|
# so after we set the defaults they will be overwritten
|
|
|
|
# by any values that appear in the rest of the stanza
|
|
|
|
if ($attr eq 'objtype')
|
|
|
|
{
|
|
|
|
push(@::fileobjtypes, $val);
|
|
|
|
|
|
|
|
# $val will be the object type ex. site, node etc.
|
|
|
|
foreach my $a (keys %{$::defAttrs{$val}})
|
|
|
|
{
|
|
|
|
|
|
|
|
# set the default values for this object hash
|
|
|
|
$::FILEATTRS{$objectname}{$a} = $::defAttrs{$val}{$a};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
# error - invalid line in node definition file
|
|
|
|
$look_for_colon++;
|
|
|
|
}
|
|
|
|
|
|
|
|
} # end while - go to next line
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getGroupMembers
|
|
|
|
|
|
|
|
Get the list of members for the specified group.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
Returns:
|
|
|
|
undef - error
|
|
|
|
$members - comma-separated list of group members
|
|
|
|
Globals:
|
|
|
|
Error:
|
|
|
|
Example:
|
|
|
|
To use:
|
|
|
|
- create hash for objectname and and attr values (need group
|
|
|
|
name (object), and grouptype & members attr values at a
|
|
|
|
minimum.)
|
|
|
|
|
|
|
|
ex. $objhash{$obj}{$attr} = value;
|
|
|
|
|
|
|
|
- then call as follows:
|
|
|
|
xCAT::DBobjUtils->getGroupMembers($objectname, \%objhash);
|
|
|
|
|
|
|
|
Comments:
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub getGroupMembers
|
|
|
|
{
|
|
|
|
my ($class, $objectname, $hash_ref) = @_;
|
|
|
|
|
|
|
|
my $members;
|
|
|
|
|
|
|
|
my %objhash = %$hash_ref;
|
|
|
|
|
2010-02-03 09:52:03 +00:00
|
|
|
# set 'static' as the dafault of nodetype
|
|
|
|
if (!defined($objhash{$objectname}{'grouptype'}) ||
|
|
|
|
$objhash{$objectname}{'grouptype'} eq "") {
|
|
|
|
$objhash{$objectname}{'grouptype'} = 'static';
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:05:39 +00:00
|
|
|
if ($objhash{$objectname}{'grouptype'} eq 'static')
|
|
|
|
{
|
|
|
|
|
|
|
|
my $table = "nodelist";
|
|
|
|
|
|
|
|
my @TableRowArray = xCAT::DBobjUtils->getDBtable($table);
|
|
|
|
|
|
|
|
my $first = 1;
|
|
|
|
foreach (@TableRowArray)
|
|
|
|
{
|
|
|
|
|
|
|
|
# if find the group name in the "groups" attr value then add the
|
|
|
|
# node name to the member list
|
|
|
|
#if ($_->{'groups'} =~ /$objectname/)
|
|
|
|
|
2008-07-09 18:03:41 +00:00
|
|
|
my @nodeGroupList = split(',', $_->{'groups'});
|
2007-11-26 20:05:39 +00:00
|
|
|
if (grep(/^$objectname$/, @nodeGroupList))
|
|
|
|
|
|
|
|
{
|
|
|
|
chomp($_->{'node'});
|
|
|
|
if (!$first)
|
|
|
|
{
|
|
|
|
$members .= ",";
|
|
|
|
}
|
|
|
|
$members .= $_->{'node'};
|
|
|
|
$first = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
elsif ($objhash{$objectname}{'grouptype'} eq 'dynamic')
|
|
|
|
{
|
|
|
|
|
|
|
|
# find all nodes that satisfy the criteria specified in "wherevals"
|
|
|
|
# value
|
|
|
|
my %whereHash;
|
2009-06-03 08:40:32 +00:00
|
|
|
my %tabhash;
|
2007-11-26 20:05:39 +00:00
|
|
|
|
|
|
|
# remove spaces and quotes so createnode won't get upset
|
|
|
|
#$val =~ s/^\s*"\s*//;
|
|
|
|
#$val =~ s/\s*"\s*$//;
|
|
|
|
|
2009-06-30 09:47:48 +00:00
|
|
|
my @tmpWhereList = split('::', $objhash{$objectname}{'wherevals'});
|
|
|
|
my $rc = xCAT::Utils->parse_selection_string(\@tmpWhereList, \%whereHash);
|
|
|
|
if ($rc != 0)
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2009-06-30 09:47:48 +00:00
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] =
|
2009-07-06 09:45:22 +00:00
|
|
|
"The \'-w\' option has an incorrect attr*val pair.";
|
2009-06-30 09:47:48 +00:00
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
2007-11-26 20:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# see what nodes have these attr=values
|
|
|
|
# get a list of all nodes
|
|
|
|
my @tmplist = xCAT::DBobjUtils->getObjectsOfType('node');
|
|
|
|
|
|
|
|
# create a hash of obj names and types
|
2008-07-09 18:03:41 +00:00
|
|
|
my %tmphash;
|
2007-11-26 20:05:39 +00:00
|
|
|
foreach my $n (@tmplist)
|
|
|
|
{
|
|
|
|
$tmphash{$n} = 'node';
|
|
|
|
}
|
|
|
|
|
2009-06-03 08:40:32 +00:00
|
|
|
# Only get the specific attributes of the node
|
2009-06-30 09:47:48 +00:00
|
|
|
my @whereattrs = keys %whereHash;
|
2009-06-03 08:40:32 +00:00
|
|
|
my %nodeattrhash = xCAT::DBobjUtils->getobjdefs(\%tmphash, 0, \@whereattrs);
|
2007-11-26 20:05:39 +00:00
|
|
|
|
2010-06-10 05:18:12 +00:00
|
|
|
# The attribute 'node' can be used as a key of selection string,
|
|
|
|
# however, the 'node' attribute is not included in the getobjdefs hash
|
|
|
|
foreach my $objname (keys %nodeattrhash)
|
|
|
|
{
|
|
|
|
$nodeattrhash{$objname}{'node'} = $objname;
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
my $first = 1;
|
2009-06-03 08:40:32 +00:00
|
|
|
foreach my $objname (keys %nodeattrhash)
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
2009-06-30 09:47:48 +00:00
|
|
|
if (xCAT::Utils->selection_string_match(\%nodeattrhash, $objname, \%whereHash))
|
2007-11-26 20:05:39 +00:00
|
|
|
{
|
|
|
|
chomp($objname);
|
|
|
|
if (!$first)
|
|
|
|
{
|
|
|
|
$members .= ",";
|
|
|
|
}
|
|
|
|
$members .= $objname;
|
|
|
|
$first = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return $members;
|
|
|
|
}
|
|
|
|
|
2008-03-14 17:11:21 +00:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getNetwkInfo
|
|
|
|
|
|
|
|
Get the network info from the database for a list of nodes.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
Returns:
|
|
|
|
undef
|
|
|
|
hash ref - ex. $nethash{nodename}{networks attr name} = value
|
|
|
|
Globals:
|
|
|
|
Error:
|
|
|
|
Example:
|
|
|
|
|
|
|
|
%nethash = xCAT::DBobjUtils->getNetwkInfo(\@targetnodes);
|
|
|
|
|
|
|
|
Comments:
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub getNetwkInfo
|
|
|
|
{
|
|
|
|
my ($class, $ref_nodes) = @_;
|
|
|
|
my @nodelist = @$ref_nodes;
|
|
|
|
|
|
|
|
my %nethash;
|
2008-07-09 18:03:41 +00:00
|
|
|
my @attrnames;
|
2008-03-14 17:11:21 +00:00
|
|
|
|
|
|
|
# get the current list of network attrs (networks table columns)
|
|
|
|
my $datatype = $xCAT::Schema::defspec{'network'};
|
|
|
|
foreach my $a (@{$datatype->{'attrs'}}) {
|
|
|
|
my $attr = $a->{attr_name};
|
|
|
|
push(@attrnames, $attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
# read the networks table
|
|
|
|
my @TableRowArray = xCAT::DBobjUtils->getDBtable('networks');
|
2010-03-01 10:11:59 +00:00
|
|
|
if (! @TableRowArray)
|
2008-03-14 17:11:21 +00:00
|
|
|
{
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
# for each node - get the network info
|
|
|
|
foreach my $node (@nodelist)
|
|
|
|
{
|
|
|
|
|
|
|
|
# get, check, split the node IP
|
2010-05-07 02:44:50 +00:00
|
|
|
my $IP = xCAT::NetworkUtils->getipaddr($node);
|
2008-03-14 17:11:21 +00:00
|
|
|
chomp $IP;
|
2010-05-06 09:32:49 +00:00
|
|
|
unless (($IP =~ /\d+\.\d+\.\d+\.\d+/) || ($IP =~ /:/))
|
2008-03-14 17:11:21 +00:00
|
|
|
{
|
2010-05-06 09:32:49 +00:00
|
|
|
next;
|
2008-03-14 17:11:21 +00:00
|
|
|
}
|
|
|
|
my ($ia, $ib, $ic, $id) = split('\.', $IP);
|
|
|
|
|
|
|
|
# check the entries of the networks table
|
|
|
|
# - if the bitwise AND of the IP and the netmask gives you
|
|
|
|
# the "net" name then that is the entry you want.
|
|
|
|
foreach (@TableRowArray) {
|
|
|
|
my $NM = $_->{'mask'};
|
|
|
|
my $net=$_->{'net'};
|
|
|
|
chomp $NM;
|
|
|
|
chomp $net;
|
|
|
|
|
2010-05-07 09:56:01 +00:00
|
|
|
if(xCAT::NetworkUtils->ishostinsubnet($IP, $NM, $net))
|
2010-05-06 09:32:49 +00:00
|
|
|
{
|
2008-03-14 17:11:21 +00:00
|
|
|
# fill in the hash -
|
|
|
|
foreach my $attr (@attrnames) {
|
|
|
|
if ( defined($_->{$attr}) ) {
|
|
|
|
$nethash{$node}{$attr} = $_->{$attr};
|
|
|
|
}
|
2010-05-06 09:32:49 +00:00
|
|
|
}
|
2011-03-22 02:22:58 +00:00
|
|
|
if($nethash{$node}{'gateway'} eq '<xcatmaster>')
|
2011-02-24 03:15:01 +00:00
|
|
|
{
|
|
|
|
if(xCAT::NetworkUtils->ip_forwarding_enabled())
|
|
|
|
{
|
|
|
|
$nethash{$node}{'gateway'} = xCAT::NetworkUtils->my_ip_in_subnet($net, $NM);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$nethash{$node}{'gateway'} = '';
|
|
|
|
}
|
|
|
|
$nethash{$node}{'myselfgw'} = 1;
|
2011-03-30 06:06:38 +00:00
|
|
|
# For hwctrl commands, it is possible that this subroutine is called
|
|
|
|
# on MN instead of SN, if the hcp SN is not set
|
|
|
|
if (xCAT::Utils->isMN() && !$nethash{$node}{'gateway'})
|
|
|
|
{
|
|
|
|
# does not have ip address in this subnet,
|
|
|
|
# use the node attribute 'xcatmaster'
|
|
|
|
my $noderestab = xCAT::Table->new('noderes');
|
|
|
|
my $et = $noderestab->getNodeAttribs($node, ['xcatmaster']);
|
|
|
|
if ($et and defined($et->{'xcatmaster'}))
|
|
|
|
{
|
|
|
|
my $value = $et->{'xcatmaster'};
|
|
|
|
$nethash{$node}{'gateway'} = xCAT::NetworkUtils->getipaddr($value);
|
|
|
|
}
|
|
|
|
$noderestab->close();
|
|
|
|
}
|
|
|
|
|
2011-02-24 03:15:01 +00:00
|
|
|
}
|
2010-05-06 09:32:49 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2008-03-14 17:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} #end - for each node
|
|
|
|
|
|
|
|
return %nethash;
|
|
|
|
}
|
2009-09-09 09:07:28 +00:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 parse_access_tabentry
|
|
|
|
|
|
|
|
Parse the access_tabentry field in Schema.pm.
|
|
|
|
We needs to support multiple keys in the table
|
|
|
|
Arguments:
|
|
|
|
$objname: objectname=>objtype hash
|
|
|
|
$access_tabentry: the access_tabentry defined in Schema.pm
|
|
|
|
$tabentry_ref: return the parsed result through this hash ref
|
|
|
|
The structure of the hash is:
|
|
|
|
{
|
|
|
|
'lookup_tables' => <table_name>
|
2010-12-30 02:07:02 +00:00
|
|
|
'lookup_attrs' =>
|
2009-09-09 09:07:28 +00:00
|
|
|
{
|
|
|
|
'attr1' => 'val1'
|
|
|
|
'attr2' => 'val2'
|
|
|
|
...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Returns:
|
|
|
|
0 - success
|
|
|
|
1 - failed
|
|
|
|
Globals:
|
|
|
|
Error:
|
|
|
|
Example:
|
2008-03-14 17:11:21 +00:00
|
|
|
|
2009-09-09 09:07:28 +00:00
|
|
|
To parse the access_tabentry field
|
|
|
|
|
|
|
|
my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname, $this_attr->{access_tabentry}, \%tabentry);
|
|
|
|
|
|
|
|
Comments:
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub parse_access_tabentry()
|
|
|
|
{
|
|
|
|
my ($class, $objname, $access_tabentry, $tabentry_ref) = @_;
|
|
|
|
|
|
|
|
# ex. 'nodelist.node', 'attr:node'
|
|
|
|
foreach my $ent (split('::', $access_tabentry))
|
|
|
|
{
|
|
|
|
# ex. 'nodelist.node', 'attr:node'
|
|
|
|
my ($lookup_key, $lookup_value) = split('\=', $ent);
|
|
|
|
|
|
|
|
# ex. 'nodelist', 'node'
|
|
|
|
my ($lookup_table, $lookup_attr) = split('\.', $lookup_key);
|
|
|
|
|
|
|
|
# ex. 'attr', 'node'
|
|
|
|
my ($lookup_type, $lookup_data) = split('\:', $lookup_value);
|
|
|
|
|
|
|
|
if (!defined($tabentry_ref->{'lookup_table'}))
|
|
|
|
{
|
|
|
|
$tabentry_ref->{'lookup_table'} = $lookup_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Only support one lookup table in the access_tabentry
|
|
|
|
# Do we need to support multiple tables in one access_tabentry ????
|
|
|
|
# has not seen any requirement...
|
|
|
|
if ($lookup_table ne $tabentry_ref->{'lookup_table'})
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] =
|
|
|
|
"The access_tabentry \"$access_tabentry\" is not valid, can not specify more than one tables to look up.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($lookup_type eq 'attr')
|
|
|
|
{
|
|
|
|
# TODO: may need to update in the future
|
|
|
|
# for now, the "val" in attr:val in
|
|
|
|
# Schema.pm can only be the object name
|
|
|
|
# In the future, even if we need to change here,
|
|
|
|
# be caution about the performance
|
|
|
|
# looking up table is time consuming
|
|
|
|
$tabentry_ref->{'lookup_attrs'}->{$lookup_attr} = $objname;
|
|
|
|
}
|
|
|
|
elsif ($lookup_type eq 'str')
|
|
|
|
{
|
|
|
|
$tabentry_ref->{'lookup_attrs'}->{$lookup_attr} = $lookup_data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] =
|
|
|
|
"The access_tabentry \"$access_tabentry\" is not valid, the lookup type can only be 'attr' or 'str'.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2010-12-16 02:33:22 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getchildren
|
|
|
|
returns fsp(or bpa) of the specified cec(or frame),
|
2011-02-16 10:04:51 +00:00
|
|
|
if specified port, it will just return nodes within the port.
|
2010-12-16 02:33:22 +00:00
|
|
|
Arguments:
|
|
|
|
none
|
|
|
|
Returns:
|
|
|
|
refrence of fsp/bpa hostnames (IPs)
|
|
|
|
Globals:
|
|
|
|
%PARENT_CHILDREN
|
|
|
|
Error:
|
|
|
|
none
|
|
|
|
Example:
|
|
|
|
$c1 = getchildren($nodetocheck);
|
|
|
|
Comments:
|
|
|
|
none
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
sub getchildren
|
|
|
|
{
|
|
|
|
my $parent = shift;
|
|
|
|
if (($parent) && ($parent =~ /xCAT::/))
|
|
|
|
{
|
|
|
|
$parent = shift;
|
|
|
|
}
|
2011-02-17 08:13:16 +00:00
|
|
|
my $port = shift;
|
2010-12-16 02:33:22 +00:00
|
|
|
my @children = ();
|
2011-02-16 10:04:51 +00:00
|
|
|
my @children_prot = ();
|
2010-12-16 02:33:22 +00:00
|
|
|
if (!%::PARENT_CHILDREN) {
|
|
|
|
my $ppctab = xCAT::Table->new( 'ppc' );
|
|
|
|
my @ps = $ppctab->getAllNodeAttribs(['node','parent']);
|
|
|
|
for my $entry ( @ps ) {
|
|
|
|
my $p = $entry->{parent};
|
|
|
|
my $c = $entry->{node};
|
|
|
|
if ( $p and $c) {
|
2011-06-03 03:31:17 +00:00
|
|
|
#my $type = $ppctab->getNodeAttribs($c, ["nodetype"]);
|
|
|
|
my $type = getnodetype($c);
|
|
|
|
#if ( $type and ($type->{nodetype} eq 'fsp') or ($type->{nodetype} eq 'bpa'))
|
|
|
|
if ( $type eq 'fsp' or $type eq 'bpa')
|
2010-12-16 02:33:22 +00:00
|
|
|
{
|
|
|
|
push @{$::PARENT_CHILDREN{$p}}, $c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (@{$::PARENT_CHILDREN{$parent}}) {
|
|
|
|
push @children, $_;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (exists($::PARENT_CHILDREN{$parent})) {
|
|
|
|
foreach (@{$::PARENT_CHILDREN{$parent}}) {
|
|
|
|
push @children, $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-19 09:55:34 +00:00
|
|
|
if ( !defined($port ))
|
2011-02-16 10:04:51 +00:00
|
|
|
{
|
|
|
|
return \@children;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
my $vpdtab = xCAT::Table->new( 'vpd' );
|
|
|
|
my $sides = $vpdtab->getNodesAttribs(\@children, ['side']);
|
2011-02-19 09:55:34 +00:00
|
|
|
if(!$sides)
|
|
|
|
{
|
|
|
|
return undef;
|
|
|
|
}
|
2011-02-16 10:04:51 +00:00
|
|
|
for my $n (@children)
|
|
|
|
{
|
2011-02-19 09:55:34 +00:00
|
|
|
my $nside = $sides->{$n}->[0];
|
|
|
|
if ($nside->{side} =~ /$port/)
|
2011-02-16 10:04:51 +00:00
|
|
|
{
|
|
|
|
push @children_prot, $n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return \@children_prot;
|
|
|
|
}
|
2010-12-16 02:33:22 +00:00
|
|
|
}
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getnodetype
|
|
|
|
returns nodetype,
|
|
|
|
first requery ppc table, if not exist, requery nodetypetable
|
|
|
|
if the input is a array it will return a refrence,
|
|
|
|
if the input is a simple node,it will return its type value
|
|
|
|
if the value in the talbe is null, it will be undef but not ''
|
|
|
|
Arguments:
|
|
|
|
none
|
|
|
|
Returns:
|
|
|
|
type of node
|
|
|
|
Globals:
|
|
|
|
%::GLOBLE_NODE_TYPE
|
|
|
|
Error:
|
|
|
|
none
|
|
|
|
Example:
|
|
|
|
$type = getnodetype($node);
|
|
|
|
$typerefer = getnodetype(\@nodes);
|
|
|
|
Comments:
|
|
|
|
none
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
sub getnodetype
|
|
|
|
{
|
|
|
|
my $nodes = shift;
|
|
|
|
if (($nodes) && ($nodes =~ /xCAT::/))
|
|
|
|
{
|
|
|
|
$nodes = shift;
|
|
|
|
}
|
2011-06-27 08:48:59 +00:00
|
|
|
my $rsp;
|
2011-07-02 01:35:50 +00:00
|
|
|
|
2010-12-16 02:33:22 +00:00
|
|
|
my $nodetypetab = xCAT::Table->new( 'nodetype' );
|
|
|
|
if ( !$nodetypetab )
|
|
|
|
{
|
|
|
|
$rsp->{data}->[0] = "Could not open the nodetype table.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
2011-07-02 01:35:50 +00:00
|
|
|
|
2010-12-16 02:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my @types = ();
|
|
|
|
my $typep;
|
|
|
|
my $type;
|
2011-06-27 08:48:59 +00:00
|
|
|
my %typehash;
|
2010-12-16 02:33:22 +00:00
|
|
|
if ( $nodes =~ /^ARRAY/) {
|
2011-06-27 08:48:59 +00:00
|
|
|
my @nodetypes = $nodetypetab->getAllAttribs('node','nodetype');
|
|
|
|
for my $tn( @nodetypes ) {
|
|
|
|
$typehash{ $tn->{'node'} } = $tn->{'nodetype'};
|
|
|
|
}
|
|
|
|
for my $nn (@$nodes) {
|
|
|
|
$type = $typehash{$nn};
|
|
|
|
if ($type) {
|
2011-07-02 01:35:50 +00:00
|
|
|
my $flag = 0;
|
|
|
|
my @tablename;
|
|
|
|
for my $tt ( split /,/, $type ) {
|
|
|
|
if ( grep(/$tt/, @tabletype)) {
|
|
|
|
@tablename = grep(/$tt/, @tabletype);
|
|
|
|
$flag = 1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unless ($flag) { # find type in nodetype table
|
2010-12-16 02:33:22 +00:00
|
|
|
push (@types, $type);
|
2011-06-27 08:48:59 +00:00
|
|
|
} else {
|
2011-07-02 01:35:50 +00:00
|
|
|
my $tablehandler = xCAT::Table->new( $tablename[0] );
|
|
|
|
if ( !$tablehandler ) {
|
|
|
|
$rsp->{data}->[0] = "Could not open the $tablename[0] table.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
push (@types, undef);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$typep = $tablehandler->getNodeAttribs($nn, ["nodetype"]); # find type in ppc table
|
2011-06-27 08:48:59 +00:00
|
|
|
if ($typep and $typep->{nodetype}) {
|
|
|
|
$type = $typep->{nodetype};
|
|
|
|
push (@types, $type);
|
|
|
|
} else {
|
|
|
|
push (@types, undef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
push (@types, undef);
|
|
|
|
}
|
2010-12-16 02:33:22 +00:00
|
|
|
}
|
|
|
|
return \@types;
|
|
|
|
} else {
|
2011-06-27 08:48:59 +00:00
|
|
|
$typep = $nodetypetab->getNodeAttribs($nodes, ["nodetype"]);
|
|
|
|
if ( $typep and $typep->{nodetype} ) {
|
|
|
|
$type = $typep->{nodetype};
|
2011-07-02 01:35:50 +00:00
|
|
|
my $flag = 0;
|
|
|
|
my @tablename;
|
|
|
|
for my $tt ( split /,/, $type ) {
|
|
|
|
if ( grep(/$tt/, @tabletype)) {
|
|
|
|
@tablename = grep(/$tt/, @tabletype);
|
|
|
|
$flag = 1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unless ($flag) { # find type in nodetype table
|
2010-12-16 02:33:22 +00:00
|
|
|
return $type;
|
2011-06-27 08:48:59 +00:00
|
|
|
} else { # find type in ppc table
|
2011-07-02 01:35:50 +00:00
|
|
|
my $tablehandler = xCAT::Table->new( $tablename[0] );
|
|
|
|
if ( !$tablehandler ) {
|
|
|
|
$rsp->{data}->[0] = "Could not open the $tablename[0] table.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
$typep = $tablehandler->getNodeAttribs($nodes, ["nodetype"]);
|
2011-06-27 08:48:59 +00:00
|
|
|
if ( $typep and $typep->{nodetype} ) {
|
|
|
|
$type = $typep->{nodetype};
|
|
|
|
return $type;
|
|
|
|
} else {
|
|
|
|
return undef;
|
|
|
|
}
|
2010-12-16 02:33:22 +00:00
|
|
|
}
|
2011-06-27 08:48:59 +00:00
|
|
|
} else {
|
|
|
|
return undef;
|
|
|
|
}
|
2010-12-16 02:33:22 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-21 07:34:25 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getcecchildren
|
|
|
|
returns cec of the specified frame,
|
|
|
|
Arguments:
|
2011-01-06 08:11:27 +00:00
|
|
|
frame name
|
2010-12-21 07:34:25 +00:00
|
|
|
Returns:
|
|
|
|
refrence of cec hostnames
|
|
|
|
Globals:
|
|
|
|
$::PARENT_CHILDREN_CEC
|
|
|
|
Error:
|
|
|
|
none
|
|
|
|
Example:
|
|
|
|
$c1 = getcecchildren($nodetocheck);
|
|
|
|
Comments:
|
|
|
|
none
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
sub getcecchildren
|
|
|
|
{
|
|
|
|
my $parent = shift;
|
|
|
|
if (($parent) && ($parent =~ /xCAT::/))
|
|
|
|
{
|
|
|
|
$parent = shift;
|
|
|
|
}
|
|
|
|
my @children = ();
|
|
|
|
if (!%::PARENT_CHILDREN_CEC) {
|
|
|
|
my $ppctab = xCAT::Table->new( 'ppc' );
|
2011-01-06 08:11:27 +00:00
|
|
|
if ($ppctab)
|
|
|
|
{
|
|
|
|
my @ps = $ppctab->getAllNodeAttribs(['node','parent']);
|
|
|
|
for my $entry ( @ps ) {
|
|
|
|
my $p = $entry->{parent};
|
|
|
|
my $c = $entry->{node};
|
|
|
|
if ( $p and $c) {
|
2011-06-03 03:31:17 +00:00
|
|
|
#my $type = $ppctab->getNodeAttribs($c, ["nodetype"]);
|
|
|
|
my $type = getnodetype($c);
|
|
|
|
if ( $type eq 'cec') {
|
2011-01-06 08:11:27 +00:00
|
|
|
push @{$::PARENT_CHILDREN_CEC{$p}}, $c;
|
|
|
|
}
|
2010-12-21 07:34:25 +00:00
|
|
|
}
|
2011-01-06 08:11:27 +00:00
|
|
|
}
|
|
|
|
foreach (@{$::PARENT_CHILDREN_CEC{$parent}}) {
|
|
|
|
push @children, $_;
|
2010-12-21 07:34:25 +00:00
|
|
|
}
|
2011-01-06 08:11:27 +00:00
|
|
|
return \@children;
|
|
|
|
}
|
2010-12-21 07:34:25 +00:00
|
|
|
} else {
|
|
|
|
if (exists($::PARENT_CHILDREN_CEC{$parent})) {
|
|
|
|
foreach (@{$::PARENT_CHILDREN_CEC{$parent}}) {
|
|
|
|
push @children, $_;
|
|
|
|
}
|
2011-01-06 08:11:27 +00:00
|
|
|
return \@children;
|
2010-12-21 07:34:25 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-06 08:11:27 +00:00
|
|
|
return undef;
|
2010-12-21 07:34:25 +00:00
|
|
|
}
|
2011-02-17 08:13:16 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 judge_node
|
|
|
|
judge the node is a real FSP/BPA,
|
|
|
|
use to distinguish if the data is defined in xCAT 2.5 or later
|
|
|
|
Arguments:
|
|
|
|
node name
|
|
|
|
Returns:
|
|
|
|
0 is a fake FSP/BPA,defined in xCAT 2.5
|
|
|
|
1 is a real FSP/BPA,defined in xCAT 2.6 or later
|
|
|
|
Error:
|
|
|
|
none
|
|
|
|
Example:
|
|
|
|
$result = judge_node($nodetocheck);
|
|
|
|
Comments:
|
|
|
|
none
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
sub judge_node
|
|
|
|
{
|
|
|
|
my $node = shift;
|
|
|
|
if (($node) && ($node =~ /xCAT::/))
|
|
|
|
{
|
|
|
|
$node = shift;
|
|
|
|
}
|
|
|
|
my $type = shift;
|
|
|
|
my $flag = 0;
|
|
|
|
my $parenttype;
|
|
|
|
my $nodeparent;
|
|
|
|
my $ppctab = xCAT::Table->new( 'ppc' );
|
|
|
|
if ( $ppctab ) {
|
|
|
|
$nodeparent = $ppctab->getNodeAttribs($node, ["parent"]);
|
|
|
|
if ($nodeparent and $nodeparent->{parent}) {
|
|
|
|
$parenttype = getnodetype($nodeparent->{parent});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type =~ /^fsp$/) {
|
2011-02-19 09:55:34 +00:00
|
|
|
if ($parenttype =~ /^cec$/)
|
2011-02-17 08:13:16 +00:00
|
|
|
{
|
|
|
|
$flag = 1;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
$flag = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-02-19 09:55:34 +00:00
|
|
|
|
2011-02-17 08:13:16 +00:00
|
|
|
if ($type =~ /^bpa$/) {
|
2011-02-19 09:55:34 +00:00
|
|
|
if ($parenttype =~ /^frame$/)
|
2011-02-17 08:13:16 +00:00
|
|
|
{
|
|
|
|
$flag = 1;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
$flag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $flag;
|
|
|
|
}
|
2007-11-26 20:05:39 +00:00
|
|
|
1;
|