dynamic node group support: Noderange.pm->expandatom, DBobjectdefs.pm->defmk and defch, DBobjUtils.pm->getGroupMembers
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3389 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
cacb9652b3
commit
c9f45e190d
@ -1562,12 +1562,27 @@ sub getGroupMembers
|
||||
|
||||
foreach my $testattr (keys %whereHash)
|
||||
{
|
||||
if ($myhash{$objname}{$testattr} ne $::WhereHash{$testattr})
|
||||
if ($whereHash{$testattr} =~ /^\//)
|
||||
{ # wherevals includes regular expression
|
||||
my $tmpwherestring = $whereHash{$testattr};
|
||||
$tmpwherestring =~ /^\/(.*)\/$/g;
|
||||
$tmpwherestring = $1;
|
||||
if (!defined($myhash{$objname}{$testattr}) || ($myhash{$objname}{$testattr} !~ /$tmpwherestring/) )
|
||||
{
|
||||
# don't disply
|
||||
$addlist = 0;
|
||||
next;
|
||||
}
|
||||
}
|
||||
else #no regular expression in wherevals
|
||||
{
|
||||
if ($myhash{$objname}{$testattr} ne $whereHash{$testattr})
|
||||
{
|
||||
|
||||
# don't disply
|
||||
$addlist = 0;
|
||||
next;
|
||||
# don't disply
|
||||
$addlist = 0;
|
||||
next;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($addlist)
|
||||
|
@ -50,12 +50,40 @@ sub expandatom {
|
||||
}
|
||||
|
||||
# Try to match groups?
|
||||
foreach($nodelist->getAllAttribs('node','groups')) {
|
||||
my @groups=split(/,/,$_->{groups}); #The where clause doesn't guarantee the atom is a full group name, only that it could be
|
||||
if (grep { $_ eq "$atom" } @groups ) {
|
||||
push @nodes,$_->{node};
|
||||
}
|
||||
}
|
||||
my $grptab = xCAT::Table->new('nodegroup');
|
||||
my @grplist = @{$grptab->getAllEntries()};
|
||||
my $isdynamicgrp = 0;
|
||||
foreach my $grpdef_ref (@grplist) {
|
||||
my %grpdef = %$grpdef_ref;
|
||||
# Try to match a dynamic node group
|
||||
# do not try to match the static node group from nodegroup table,
|
||||
# the static node groups are stored in nodelist table.
|
||||
if (($grpdef{'groupname'} eq $atom) && ($grpdef{'grouptype'} eq 'dynamic'))
|
||||
{
|
||||
$isdynamicgrp = 1;
|
||||
my $grpname = $atom;
|
||||
my %grphash;
|
||||
$grphash{$grpname}{'objtype'} = 'group';
|
||||
$grphash{$grpname}{'grouptype'} = 'dynamic';
|
||||
$grphash{$grpname}{'wherevals'} = $grpdef{'wherevals'};
|
||||
my $memberlist = xCAT::DBobjUtils->getGroupMembers($grpname, \%grphash);
|
||||
foreach my $grpmember (split ",", $memberlist)
|
||||
{
|
||||
push @nodes, $grpmember;
|
||||
}
|
||||
last; #there should not be more than one group with the same name
|
||||
}
|
||||
}
|
||||
# The atom is not a dynamic node group, is it a static node group???
|
||||
if(!$isdynamicgrp)
|
||||
{
|
||||
foreach($nodelist->getAllAttribs('node','groups')) {
|
||||
my @groups=split(/,/,$_->{groups}); #The where clause doesn't guarantee the atom is a full group name, only that it could be
|
||||
if (grep { $_ eq "$atom" } @groups ) {
|
||||
push @nodes,$_->{node};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($atom =~ m/^[0-9]+\z/) { # if only numbers, then add the prefix
|
||||
my $nodename=$nprefix.$atom.$nsuffix;
|
||||
|
@ -242,15 +242,6 @@ sub processArgs
|
||||
return 2;
|
||||
}
|
||||
|
||||
# opt_d not yet supported
|
||||
if ($::opt_d)
|
||||
{
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] = "The \'-d\' option is not yet implemented.";
|
||||
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
||||
return 2;
|
||||
}
|
||||
|
||||
# can get object names in many ways - easier to keep track
|
||||
$::objectsfrom_args = 0;
|
||||
$::objectsfrom_opto = 0;
|
||||
@ -1163,18 +1154,40 @@ sub defmk
|
||||
|
||||
# get the list of all defined group objects
|
||||
|
||||
my @definedgroups = xCAT::DBobjUtils->getObjectsOfType("group");
|
||||
# getObjectsOfType("group") only returns static groups,
|
||||
# generally speaking, the nodegroup table should includes all the static and dynamic groups,
|
||||
# but it is possible that the static groups are not in nodegroup table,
|
||||
# so we have to get the static and dynamic groups separately.
|
||||
my @definedgroups = xCAT::DBobjUtils->getObjectsOfType("group"); #static groups
|
||||
my $grptab = xCAT::Table->new('nodegroup');
|
||||
my @grplist = @{$grptab->getAllEntries()}; #dynamic groups and static groups in nodegroup table
|
||||
|
||||
my %GroupHash;
|
||||
foreach my $g (@grouplist)
|
||||
{
|
||||
if (!grep(/^$g$/, @definedgroups))
|
||||
my $indynamicgrp = 0;
|
||||
#check the dynamic node groups
|
||||
foreach my $grpdef_ref (@grplist)
|
||||
{
|
||||
|
||||
# define it
|
||||
$GroupHash{$g}{objtype} = "group";
|
||||
$GroupHash{$g}{grouptype} = "static";
|
||||
$GroupHash{$g}{members} = "static";
|
||||
my %grpdef = %$grpdef_ref;
|
||||
if (($grpdef{'groupname'} eq $g) && ($grpdef{'grouptype'} eq 'dynamic'))
|
||||
{
|
||||
$indynamicgrp = 1;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] = "nodegroup $g is a dynamic node group, should not add a node into a dynamic node group statically.\n";
|
||||
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
||||
last;
|
||||
}
|
||||
}
|
||||
if (!$indynamicgrp)
|
||||
{
|
||||
if (!grep(/^$g$/, @definedgroups))
|
||||
{
|
||||
# define it
|
||||
$GroupHash{$g}{objtype} = "group";
|
||||
$GroupHash{$g}{grouptype} = "static";
|
||||
$GroupHash{$g}{members} = "static";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (defined(%GroupHash))
|
||||
@ -1800,7 +1813,13 @@ sub defch
|
||||
|
||||
# get the list of all defined group objects
|
||||
|
||||
my @definedgroups = xCAT::DBobjUtils->getObjectsOfType("group");
|
||||
# getObjectsOfType("group") only returns static groups,
|
||||
# generally speaking, the nodegroup table should includes all the static and dynamic groups,
|
||||
# but it is possible that the static groups are not in nodegroup table,
|
||||
# so we have to get the static and dynamic groups separately.
|
||||
my @definedgroups = xCAT::DBobjUtils->getObjectsOfType("group"); #Static node groups
|
||||
my $grptab = xCAT::Table->new('nodegroup');
|
||||
my @grplist = @{$grptab->getAllEntries()}; #dynamic groups and static groups in nodegroup table
|
||||
|
||||
# if we're creating the node or we're adding to or replacing
|
||||
# the "groups" attr then check if the group
|
||||
@ -1814,13 +1833,30 @@ sub defch
|
||||
my %GroupHash;
|
||||
foreach my $g (@grouplist)
|
||||
{
|
||||
if (!grep(/^$g$/, @definedgroups))
|
||||
my $indynamicgrp = 0;
|
||||
#check the dynamic node groups
|
||||
foreach my $grpdef_ref (@grplist)
|
||||
{
|
||||
my %grpdef = %$grpdef_ref;
|
||||
if (($grpdef{'groupname'} eq $g) && ($grpdef{'grouptype'} eq 'dynamic'))
|
||||
{
|
||||
$indynamicgrp = 1;
|
||||
my $rsp;
|
||||
$rsp->{data}->[0] = "nodegroup $g is a dynamic node group, should not add a node into a dynamic node group statically.\n";
|
||||
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
||||
last;
|
||||
}
|
||||
}
|
||||
if (!$indynamicgrp)
|
||||
{
|
||||
if (!grep(/^$g$/, @definedgroups))
|
||||
{
|
||||
|
||||
# define it
|
||||
$GroupHash{$g}{objtype} = "group";
|
||||
$GroupHash{$g}{grouptype} = "static";
|
||||
$GroupHash{$g}{members} = "static";
|
||||
# define it
|
||||
$GroupHash{$g}{objtype} = "group";
|
||||
$GroupHash{$g}{grouptype} = "static";
|
||||
$GroupHash{$g}{members} = "static";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (defined(%GroupHash))
|
||||
@ -2507,7 +2543,7 @@ sub defls
|
||||
|
||||
if ( ($defhash{$obj}{'objtype'} eq 'group') && ($showattr eq 'members'))
|
||||
{
|
||||
$defhash{$obj}{'grouptype'} = "static";
|
||||
#$defhash{$obj}{'grouptype'} = "static";
|
||||
my $memberlist =
|
||||
xCAT::DBobjUtils->getGroupMembers(
|
||||
$obj,
|
||||
@ -2538,7 +2574,7 @@ sub defls
|
||||
&& ($showattr eq 'members'))
|
||||
|
||||
{
|
||||
$defhash{$obj}{'grouptype'} = "static";
|
||||
#$defhash{$obj}{'grouptype'} = "static";
|
||||
my $memberlist =
|
||||
xCAT::DBobjUtils->getGroupMembers($obj,\%defhash);
|
||||
my $rsp;
|
||||
|
Loading…
Reference in New Issue
Block a user