From 504d6f443e49bfad740978d317e439977fa5805a Mon Sep 17 00:00:00 2001 From: zhaoertao Date: Fri, 30 Dec 2011 07:44:19 +0000 Subject: [PATCH] provide a routine which can retrieve requested attributes that matching the specified options for a node git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@11318 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/PPCdb.pm | 6 ++-- perl-xCAT/xCAT/Table.pm | 66 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/perl-xCAT/xCAT/PPCdb.pm b/perl-xCAT/xCAT/PPCdb.pm index 0bf2a2d7d..0696e2030 100644 --- a/perl-xCAT/xCAT/PPCdb.pm +++ b/perl-xCAT/xCAT/PPCdb.pm @@ -798,7 +798,8 @@ sub credentials { my $ent; if ( $user_specified) { # need regx - ($ent) = $tab->getAttribs( {hcp=>$server,username=>$user},qw(password)); + #($ent) = $tab->getAttribs( {hcp=>$server,username=>$user},qw(password)); + ($ent) = $tab->getNodeSpecAttribs( $server, {username=>$user},qw(password)); } else { @@ -815,7 +816,8 @@ sub credentials { { if ( $user_specified) { # need regx - ($ent) = $tab->getAllAttribs( {hcp=>$defaultgrp{$hwtype},username=>$user},qw(password)); + #($ent) = $tab->getAllAttribs( {hcp=>$defaultgrp{$hwtype},username=>$user},qw(password)); + ($ent) = $tab->getNodeSpecAttribs( $defaultgrp{$hwtype}, {username=>$user},qw(password)); } else { diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 6a4b54c6b..bd55a09e1 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -2319,6 +2319,72 @@ sub getNodeAttribs return wantarray ? @data : $data[0]; } + +#-------------------------------------------------------------------------- + +=head3 getNodeSpecAttribs + Description: Retrieves the requested attributes which matching the specified options for a node + Arguments: + Noderange + The specified options + List of attributes + Return: + Attribute hash + Example: + my $tab = xCAT::Table->new('ppcdirect'); + my $ent = $tab->getNodeSpecAttribs($node, {username=>'HMC'}, qw/password/); + Comments: + The keys of the specified options can be given in the list of attributes or not, + this routine will deal with them. +=cut + +#-------------------------------------------------------------------------- + +sub getNodeSpecAttribs { + my $self = shift; + my $node = shift; + my %options = (); + my @attribs = (); + my @keys = (); + if (ref $_[0]) { + %options = %{shift()}; + @attribs = @_; + foreach my $key (keys %options) { + if (!grep(/^$key$/, @attribs)) { + push @attribs, $key; + } + } + } else { + @attribs = @_; + } + if ((keys (%options)) == 0) { + my $ent = $self->getNodeAttribs($node, \@attribs); + return $ent; + } else { + my $nodekey = "node"; + if (defined $xCAT::Schema::tabspec{$self->{tabname}}->{nodecol}) { + $nodekey = $xCAT::Schema::tabspec{$self->{tabname}}->{nodecol}; + } + $options{$nodekey} = $node; + my $ent = $self->getAttribs(\%options, \@attribs); + if ($ent) { + return $ent; + } + my ($nodeghash) = $self->{nodelist}->getAttribs({node=>$node}, "groups"); + unless(defined($nodeghash) && defined($nodeghash->{groups})) { + return undef; + } + my @nodegroups = split(/,/, $nodeghash->{groups}); + foreach my $group (@nodegroups) { + $options{$nodekey} = $group; + my $g_ret = $self->getAttribs(\%options, \@attribs); + if ($g_ret) { + return $g_ret; + } + } + } + return undef; +} #-------------------------------------------------------------------------- =head3 getNodeAttribs_nosub