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
This commit is contained in:
parent
fb510583ea
commit
504d6f443e
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user