From 021f0e991a26d7a141ac6f8f97238ec04a93de74 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Thu, 17 Sep 2009 18:27:07 +0000 Subject: [PATCH] -Allow schema to specify a column to treat in the same special way that we treat 'node' git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4162 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Schema.pm | 2 ++ perl-xCAT/xCAT/Table.pm | 23 ++++++++++++++--------- xCAT-server/lib/xcat/plugins/tabutils.pm | 9 +++++++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index 63c226258..f05d6d9d8 100644 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -251,6 +251,7 @@ mp => { mpa => { cols => [qw(mpa username password comments disable)], keys => [qw(mpa)], + nodecol => "mpa", table_desc => 'Contains info about each Management Module and how to access it.', descriptions => { mpa => 'Hostname of the management module.', @@ -369,6 +370,7 @@ noderes => { switches => { cols => [qw(switch snmpversion username password privacy auth comments disable)], keys => [qw(switch)], + nodecol => "switch", table_desc => 'Parameters to use when interrogating switches', descriptions => { switch => 'The hostname/address of the switch to which the settings apply', diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 71dc6e14e..1c033b0c0 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -28,7 +28,6 @@ package xCAT::Table; use xCAT::MsgUtils; use Sys::Syslog; use Storable qw/freeze thaw/; -use Data::Dumper; use IO::Socket; BEGIN { @@ -50,7 +49,6 @@ my $cachethreshold=16; #How many nodes in 'getNodesAttribs' before switching to use DBI; use strict; -#use Data::Dumper; use Scalar::Util qw/weaken/; require xCAT::Schema; require xCAT::NodeRange; @@ -169,7 +167,6 @@ sub handle_dbc_conn { $data .= $lastline; } my $request = thaw($data); - use Data::Dumper; my $response; my @returndata; if ($request->{'wantarray'}) { @@ -1466,15 +1463,19 @@ sub _build_cache { #PRIVATE FUNCTION, PLEASE DON'T CALL DIRECTLY $self->{_use_cache} = 0; #This function must disable cache #to function my $attriblist = shift; - unless (grep /^node$/,@$attriblist) { - push @$attriblist,'node'; + my $nodekey = "node"; + if (defined $xCAT::Schema::tabspec{$self->{tabname}}->{nodecol}) { + $nodekey = $xCAT::Schema::tabspec{$self->{tabname}}->{nodecol} + }; + unless (grep /^$nodekey$/,@$attriblist) { + push @$attriblist,$nodekey; } my @tabcache = $self->getAllAttribs(@$attriblist); $self->{_tablecache} = \@tabcache; $self->{_nodecache} = {}; - if ($tabcache[0]->{node}) { + if ($tabcache[0]->{$nodekey}) { foreach(@tabcache) { - push @{$self->{_nodecache}->{$_->{node}}},$_; + push @{$self->{_nodecache}->{$_->{$nodekey}}},$_; } } @@ -1700,7 +1701,11 @@ sub getNodeAttribs_nosub_returnany my @results; #my $recurse = ((scalar(@_) == 1) ? shift : 1); - @results = $self->getAttribs({node => $node}, @attribs); + my $nodekey = "node"; + if (defined $xCAT::Schema::tabspec{$self->{tabname}}->{nodecol}) { + $nodekey = $xCAT::Schema::tabspec{$self->{tabname}}->{nodecol} + }; + @results = $self->getAttribs({$nodekey => $node}, @attribs); my $data = $results[0]; if (!defined($data)) { @@ -1714,7 +1719,7 @@ sub getNodeAttribs_nosub_returnany my $group; foreach $group (@nodegroups) { - @results = $self->getAttribs({node => $group}, @attribs); + @results = $self->getAttribs({$nodekey => $group}, @attribs); $data = $results[0]; if ($data != undef) { diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index 415375eba..a7447393c 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -1061,8 +1061,13 @@ sub nodels $matchtypes{$_->[0]} = $_->[3]; } } + my $nodekey = "node"; + if (defined $xCAT::Schema::tabspec{$tab}->{nodecol}) { + $nodekey = $xCAT::Schema::tabspec{$tab}->{nodecol} + }; + my $removenodecol=1; - if (grep /^node$/,@cols) { + if (grep /^$nodekey$/,@cols) { $removenodecol=0; } my $rechash=$tabh->getNodesAttribs($nodes,\@cols); @@ -1075,7 +1080,7 @@ sub nodels foreach (keys %$rec) { - if ($_ eq "node" and $removenodecol) { next; } + if ($_ eq $nodekey and $removenodecol) { next; } $satisfiedreqs{$_}=1; my %datseg=(); if (defined $values{$_}) {