Misc code cleanup.
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1859 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
8a6f1c90d5
commit
4fd9a21a84
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env perl
|
||||
#!/usr/bin/env perl -w
|
||||
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
#####################################################
|
||||
@ -15,6 +15,7 @@ use xCAT::Schema;
|
||||
use xCAT::Table;
|
||||
use xCAT::Utils;
|
||||
use xCAT::MsgUtils;
|
||||
use strict;
|
||||
|
||||
# IPv6 not yet implemented - need Socket6
|
||||
use Socket;
|
||||
@ -70,7 +71,7 @@ sub getObjectsOfType
|
||||
|
||||
my $table;
|
||||
my $tabkey;
|
||||
foreach $this_attr (@{$datatype->{'attrs'}})
|
||||
foreach my $this_attr (@{$datatype->{'attrs'}})
|
||||
{
|
||||
my $attr = $this_attr->{attr_name};
|
||||
if ($attr eq $objkey)
|
||||
@ -151,7 +152,7 @@ sub getobjdefs
|
||||
my ($class, $hash_ref) = @_;
|
||||
my %objhash;
|
||||
|
||||
%typehash = %$hash_ref;
|
||||
my %typehash = %$hash_ref;
|
||||
|
||||
@::foundTableList = ();
|
||||
|
||||
@ -211,7 +212,7 @@ sub getobjdefs
|
||||
{
|
||||
|
||||
# get data from DB
|
||||
$type = $typehash{$objname};
|
||||
my $type = $typehash{$objname};
|
||||
|
||||
# add the type to the hash for each object
|
||||
$objhash{$objname}{'objtype'} = $type;
|
||||
@ -224,13 +225,14 @@ sub getobjdefs
|
||||
|
||||
# get a list of valid attr names
|
||||
# for this type object
|
||||
my %attrlist;
|
||||
foreach my $entry (@{$datatype->{'attrs'}})
|
||||
{
|
||||
push(@{$attrlist{$type}}, $entry->{'attr_name'});
|
||||
}
|
||||
|
||||
# go through the list of valid attrs
|
||||
foreach $this_attr (@{$datatype->{'attrs'}})
|
||||
foreach my $this_attr (@{$datatype->{'attrs'}})
|
||||
{
|
||||
my $ent;
|
||||
|
||||
@ -266,13 +268,13 @@ sub getobjdefs
|
||||
my ($tab, $tabattr) = split('\.', $this_attr->{tabentry});
|
||||
|
||||
# ex. 'nodelist.node', 'attr:node'
|
||||
($lookup_key, $lookup_value) = split('\=', $this_attr->{access_tabentry});
|
||||
my ($lookup_key, $lookup_value) = split('\=', $this_attr->{access_tabentry});
|
||||
|
||||
# ex. 'nodelist', 'node'
|
||||
($lookup_table, $lookup_attr) = split('\.', $lookup_key);
|
||||
my ($lookup_table, $lookup_attr) = split('\.', $lookup_key);
|
||||
|
||||
# ex. 'attr', 'node'
|
||||
($lookup_type, $lookup_data) = split('\:', $lookup_value);
|
||||
my ($lookup_type, $lookup_data) = split('\:', $lookup_value);
|
||||
|
||||
#
|
||||
# Get the attr values from the DB tables
|
||||
@ -299,7 +301,7 @@ sub getobjdefs
|
||||
);
|
||||
if (!$thistable)
|
||||
{
|
||||
my %rsp;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] =
|
||||
"Could not get the \'$thistable\' table.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
||||
@ -336,7 +338,7 @@ sub getobjdefs
|
||||
}
|
||||
else
|
||||
{
|
||||
my %rsp;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] =
|
||||
"Could not read the \'$lookup_table\' table from the xCAT database.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
||||
@ -433,7 +435,7 @@ sub getDBtable
|
||||
my $thistable = xCAT::Table->new($table, -create => 1, -autocommit => 0);
|
||||
if (!$thistable)
|
||||
{
|
||||
my %rsp;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] = "Could not get the \'$table\' table.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
||||
return undef;
|
||||
@ -503,7 +505,7 @@ sub setobjdefs
|
||||
# get attr=val that are set in the DB ??
|
||||
my $type = $objhash{$objname}{objtype};
|
||||
|
||||
# handle the site table as a special case !!!!!
|
||||
# handle the monitoring table as a special case !!!!!
|
||||
if ($type eq 'monitoring')
|
||||
{
|
||||
|
||||
@ -532,7 +534,7 @@ sub setobjdefs
|
||||
if (!$montable)
|
||||
{
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] = "Could not set the \'$thistable\' table.";
|
||||
$rsp->{data}->[0] = "Could not set the \'$montable\' table.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
||||
return 1;
|
||||
}
|
||||
@ -541,7 +543,7 @@ sub setobjdefs
|
||||
if (!$monsettable)
|
||||
{
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] = "Could not set the \'$thistable\' table.";
|
||||
$rsp->{data}->[0] = "Could not set the \'$monsettable\' table.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
||||
return 1;
|
||||
}
|
||||
@ -551,6 +553,7 @@ sub setobjdefs
|
||||
|
||||
foreach my $attr (keys %{$objhash{$objname}})
|
||||
{
|
||||
my $val;
|
||||
if ($attr eq 'objtype')
|
||||
{
|
||||
next;
|
||||
@ -577,8 +580,8 @@ sub setobjdefs
|
||||
if ($DBattrvals{$objname}{$attr})
|
||||
{
|
||||
# get the list of attrs to remove
|
||||
@currentList = split(/,/, $DBattrvals{$objname}{$attr});
|
||||
@minusList = split(/,/, $objhash{$objname}{$attr});
|
||||
my @currentList = split(/,/, $DBattrvals{$objname}{$attr});
|
||||
my @minusList = split(/,/, $objhash{$objname}{$attr});
|
||||
|
||||
# make a new list without the one specified
|
||||
my $first = 1;
|
||||
@ -638,7 +641,7 @@ sub setobjdefs
|
||||
%DBattrvals = xCAT::DBobjUtils->getobjdefs(\%DBhash);
|
||||
|
||||
# open the table
|
||||
$thistable =
|
||||
my $thistable =
|
||||
xCAT::Table->new('site', -create => 1, -autocommit => 0);
|
||||
if (!$thistable)
|
||||
{
|
||||
@ -655,6 +658,7 @@ sub setobjdefs
|
||||
next;
|
||||
}
|
||||
|
||||
my %keyhash;
|
||||
$keyhash{key} = $attr;
|
||||
|
||||
my $val;
|
||||
@ -682,8 +686,8 @@ sub setobjdefs
|
||||
{
|
||||
|
||||
# get the list of attrs to remove
|
||||
@currentList = split(/,/, $DBattrvals{$objname}{$attr});
|
||||
@minusList = split(/,/, $objhash{$objname}{$attr});
|
||||
my @currentList = split(/,/, $DBattrvals{$objname}{$attr});
|
||||
my @minusList = split(/,/, $objhash{$objname}{$attr});
|
||||
|
||||
# make a new list without the one specified
|
||||
my $first = 1;
|
||||
@ -721,6 +725,7 @@ sub setobjdefs
|
||||
|
||||
} else { # change the attr
|
||||
|
||||
my %updates;
|
||||
$updates{value} = $val;
|
||||
|
||||
my ($rc, $str) = $thistable->setAttribs(\%keyhash, \%updates);
|
||||
@ -728,7 +733,7 @@ sub setobjdefs
|
||||
{
|
||||
if ($::verbose)
|
||||
{
|
||||
my %rsp;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] =
|
||||
"Could not set the \'$attr\' attribute of the \'$objname\' object in the xCAT database.\n";
|
||||
$rsp->{data}->[1] =
|
||||
@ -783,7 +788,7 @@ sub setobjdefs
|
||||
{
|
||||
if ($::verbose)
|
||||
{
|
||||
my %rsp;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] =
|
||||
"\'$attr\' is not a valid attribute for type \'$type\'.";
|
||||
$rsp->{data}->[1] = "Skipping to the next attribute.";
|
||||
@ -801,12 +806,14 @@ sub setobjdefs
|
||||
|
||||
|
||||
my @setattrlist=();
|
||||
my @checkedattrs;
|
||||
|
||||
foreach $this_attr (@{$datatype->{'attrs'}})
|
||||
foreach my $this_attr (@{$datatype->{'attrs'}})
|
||||
{
|
||||
|
||||
my %keyhash;
|
||||
my %updates;
|
||||
my ($lookup_table, $lookup_attr);
|
||||
my $attr_name = $this_attr->{attr_name};
|
||||
|
||||
|
||||
@ -851,7 +858,7 @@ sub setobjdefs
|
||||
if ($attr eq $check_attr) {
|
||||
my ($tab, $at) = split(/\./, $tmp_attr->{tabentry});
|
||||
my $schema = xCAT::Table->getTableSchema($tab);
|
||||
$desc = $schema->{descriptions}->{$at};
|
||||
my $desc = $schema->{descriptions}->{$at};
|
||||
push @{$rsp->{data}}, "$check_attr => $desc\n";
|
||||
}
|
||||
}
|
||||
@ -877,14 +884,14 @@ sub setobjdefs
|
||||
|
||||
# get the lookup info from defspec in Schema.pm
|
||||
# ex. 'nodelist.node', 'attr:node'
|
||||
($lookup_key, $lookup_value) =
|
||||
my ($lookup_key, $lookup_value) =
|
||||
split('\=', $this_attr->{access_tabentry});
|
||||
|
||||
# ex. 'nodelist', 'node'
|
||||
($lookup_table, $lookup_attr) = split('\.', $lookup_key);
|
||||
|
||||
# ex. 'attr', 'node'
|
||||
($lookup_type, $lookup_data) = split('\:', $lookup_value);
|
||||
my ($lookup_type, $lookup_data) = split('\:', $lookup_value);
|
||||
|
||||
}
|
||||
else
|
||||
@ -932,9 +939,9 @@ sub setobjdefs
|
||||
{
|
||||
|
||||
# get the list of attrs to remove
|
||||
@currentList =
|
||||
my @currentList =
|
||||
split(/,/, $DBattrvals{$objname}{$attr_name});
|
||||
@minusList = split(/,/, $objhash{$objname}{$attr_name});
|
||||
my @minusList = split(/,/, $objhash{$objname}{$attr_name});
|
||||
|
||||
# make a new list without the one specified
|
||||
my $first = 1;
|
||||
@ -988,7 +995,7 @@ sub setobjdefs
|
||||
|
||||
if (!$thistable)
|
||||
{
|
||||
my %rsp;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] =
|
||||
"Could not set the \'$thistable\' table.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
||||
@ -1001,7 +1008,7 @@ sub setobjdefs
|
||||
{
|
||||
if ($::verbose)
|
||||
{
|
||||
my %rsp;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] =
|
||||
"Could not set the \'$attr_name\' attribute of the \'$objname\' object in the xCAT database.\n";
|
||||
$rsp->{data}->[1] = "Error returned is \'$str->errst
|
||||
@ -1080,16 +1087,15 @@ sub rmobjdefs
|
||||
|
||||
my %tablehash;
|
||||
|
||||
%objhash = %$hash_ref;
|
||||
my %typehash = %$hash_ref;
|
||||
|
||||
# get the attr=vals for these objects so we know how to
|
||||
# find what tables have to be modified
|
||||
%DBattrvals = xCAT::DBobjUtils->getobjdefs(\%objhash);
|
||||
my %DBattrvals = xCAT::DBobjUtils->getobjdefs(\%typehash);
|
||||
|
||||
foreach my $objname (keys %objhash)
|
||||
foreach my $objname (sort (keys %typehash))
|
||||
{
|
||||
|
||||
$type = $typehash{$objname};
|
||||
my $type = $typehash{$objname};
|
||||
|
||||
# special handling for site table
|
||||
if ($type eq 'site')
|
||||
@ -1219,7 +1225,7 @@ sub rmobjdefs
|
||||
sub readFileInput
|
||||
{
|
||||
my ($class, $filedata) = @_;
|
||||
my $objectname;
|
||||
my ($objectname, $junk1, $junk2);
|
||||
|
||||
@::fileobjnames = ();
|
||||
|
||||
@ -1235,8 +1241,9 @@ sub readFileInput
|
||||
#}
|
||||
|
||||
my $look_for_colon = 1; # start with first line that has a colon
|
||||
my $objtype;
|
||||
|
||||
foreach $l (@lines)
|
||||
foreach my $l (@lines)
|
||||
{
|
||||
|
||||
# skip blank and comment lines
|
||||
@ -1248,11 +1255,10 @@ sub readFileInput
|
||||
|
||||
$look_for_colon = 0; # ok - we have a colon
|
||||
|
||||
($objectname, $junk1, $junk2) = split(/:/, $l);
|
||||
($objectname, $junk2) = split(/:/, $l);
|
||||
|
||||
# check for second : or = sign
|
||||
# if $junk2 is defined then there was a second :
|
||||
if (defined($junk2) || grep(/=/, $junk))
|
||||
# if $junk2 is defined or there's an =
|
||||
if (defined($junk2) || grep(/=/, $objectname))
|
||||
{
|
||||
|
||||
# error - invalid header $line in node definition file
|
||||
@ -1270,7 +1276,7 @@ sub readFileInput
|
||||
if ($objectname =~ /default/)
|
||||
{
|
||||
|
||||
($junk, $objtype) = split(/-/, $objectname);
|
||||
($junk1, $objtype) = split(/-/, $objectname);
|
||||
|
||||
if ($objtype)
|
||||
{
|
||||
@ -1285,8 +1291,8 @@ sub readFileInput
|
||||
}
|
||||
elsif (($l =~ /^\s*(\w+)\s*=\s*(.*)\s*/) && (!$look_for_colon))
|
||||
{
|
||||
$attr = $1;
|
||||
$val = $2;
|
||||
my $attr = $1;
|
||||
my $val = $2;
|
||||
$attr =~ s/^\s*//; # Remove any leading whitespace
|
||||
$attr =~ s/\s*$//; # Remove any trailing whitespace
|
||||
$val =~ s/^\s*//;
|
||||
@ -1393,7 +1399,7 @@ sub getGroupMembers
|
||||
# node name to the member list
|
||||
#if ($_->{'groups'} =~ /$objectname/)
|
||||
|
||||
@nodeGroupList = split(',', $_->{'groups'});
|
||||
my @nodeGroupList = split(',', $_->{'groups'});
|
||||
if (grep(/^$objectname$/, @nodeGroupList))
|
||||
|
||||
{
|
||||
@ -1425,7 +1431,7 @@ sub getGroupMembers
|
||||
my ($a, $v) = $w =~ /^\s*(\S+?)\s*=\s*(\S*.*)$/;
|
||||
if (!defined($a) || !defined($v))
|
||||
{
|
||||
my %rsp;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] =
|
||||
"The \'-w\' option has an incorrect attr=val pair - \'$w\'.";
|
||||
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
||||
@ -1441,6 +1447,7 @@ sub getGroupMembers
|
||||
my @tmplist = xCAT::DBobjUtils->getObjectsOfType('node');
|
||||
|
||||
# create a hash of obj names and types
|
||||
my %tmphash;
|
||||
foreach my $n (@tmplist)
|
||||
{
|
||||
$tmphash{$n} = 'node';
|
||||
@ -1463,7 +1470,7 @@ sub getGroupMembers
|
||||
|
||||
# don't disply
|
||||
$addlist = 0;
|
||||
break;
|
||||
next;
|
||||
}
|
||||
}
|
||||
if ($addlist)
|
||||
@ -1510,6 +1517,7 @@ sub getNetwkInfo
|
||||
my @nodelist = @$ref_nodes;
|
||||
|
||||
my %nethash;
|
||||
my @attrnames;
|
||||
|
||||
# get the current list of network attrs (networks table columns)
|
||||
my $datatype = $xCAT::Schema::defspec{'network'};
|
||||
|
Loading…
x
Reference in New Issue
Block a user