diff --git a/perl-xCAT/xCAT/TableUtils.pm b/perl-xCAT/xCAT/TableUtils.pm index 9f026379c..519f63a98 100644 --- a/perl-xCAT/xCAT/TableUtils.pm +++ b/perl-xCAT/xCAT/TableUtils.pm @@ -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; diff --git a/perl-xCAT/xCAT/Zone.pm b/perl-xCAT/xCAT/Zone.pm index e790cec36..0b8e7bd67 100644 --- a/perl-xCAT/xCAT/Zone.pm +++ b/perl-xCAT/xCAT/Zone.pm @@ -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 + -> {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;