rmzone support

This commit is contained in:
lissav 2014-03-07 09:56:51 -05:00
parent 35ed43d06b
commit 1ded53ae14
2 changed files with 79 additions and 2 deletions

View File

@ -2013,5 +2013,54 @@ sub updatenodegroups {
@list = keys %saw;
$tabhd->setNodeAttribs($node, {groups=>join(",",@list)});
}
#-----------------------------------------------------------------------------
=head3 rmnodegroups
remove groups from the group attribute for the specified node
Arguments:
node
tabhd: the handler of 'nodelist' table,
groups: the groups that need to be removed.
Can be an array or string.
Globals:
none
Error:
Example:
xCAT::TableUtils->rmnodegroups($node, $tab, $groups);
=cut
#-----------------------------------------------------------------------------
sub rmnodegroups {
my ($class, $node, $tabhd, $groups) = @_;
my ($ent) = $tabhd->getNodeAttribs($node, ['groups']);
my @definedgroups;
my @removegroups;
my @newgroups;
if (defined($ent) and $ent->{groups}) {
push @definedgroups, split(/,/,$ent->{groups});
}
if (ref($groups) eq 'ARRAY') {
push @removegroups, @$groups;
} else {
push @removegroups, split(/,/,$groups);
}
# take out any groups that match the input list of groups to remove
foreach my $dgrp (@definedgroups){
if (grep(/^$dgrp$/, @removegroups)) { # is the group to be removed
next;
} else { # keep this group
push @newgroups,$dgrp;
}
}
my %saw;
@saw{@newgroups} = ();
@newgroups = keys %saw;
$tabhd->setNodeAttribs($node, {groups=>join(",",@newgroups)});
}
1;

View File

@ -328,14 +328,15 @@ sub usingzones
=head3 getzoneinfo
Arguments:
callback
An array of nodes
Returns:
Hash array by zonename point to the nodes in that zonename and sshkeydir
zonename1 -> {nodelist} -> array of nodes in the zone
<zonename1> -> {nodelist} -> array of nodes in the zone
-> {sshkeydir} -> directory containing ssh RSA keys
-> {defaultzone} -> is it the default zone
Example:
my %zonehash =xCAT::Zone->getNodeZones(@nodearray);
my %zonehash =xCAT::Zone->getzoneinfo($callback,@nodearray);
Rules:
If the nodes nodelist.zonename attribute is a zonename, it is assigned to that zone
If the nodes nodelist.zonename attribute is undefined:
@ -421,4 +422,31 @@ sub getzoneinfo
}
return $zonehash;
}
#--------------------------------------------------------------------------------
=head3 getnodesinzone
Arguments:
callback
zonename
Returns:
Array of nodes
Example:
my @nodes =xCAT::Zone->getnodesinzone($callback,$zonename);
=cut
#--------------------------------------------------------------------------------
sub getnodesinzone
{
my ($class, $callback,$zonename) = @_;
my @nodes;
my $nodelisttab = xCAT::Table->new("nodelist");
my @nodelist=$nodelisttab->getAllAttribs('node','zonename');
# build the array of nodes in this zone
foreach my $nodename (@nodelist) {
if ((defined($nodename->{'zonename'})) && ($nodename->{'zonename'} eq $zonename)) {
push @nodes,$nodename->{'node'};
}
}
return @nodes;
}
1;