Commit f61bab43 authored by Leigh B Stoller's avatar Leigh B Stoller

Allow the gid in a group_policy to be '*', for example:

+---------+---------+---------+---------+--------+---------------+--------+
| pid     | gid     | pid_idx | gid_idx | policy | auxdata       | count  |
+---------+---------+---------+---------+--------+---------------+--------+
| testbed | *       |   10345 |       0 | type   | d430          |     10 |

which says to apply the policy to all subgroups, using the current
count for the project.
parent 7e56ab1c
......@@ -206,6 +206,7 @@ use vars qw(@ISA @EXPORT);
# Must come after package declaration!
use English;
use Data::Dumper;
use libdb;
use libtestbed;
use libtblog_simple;
......@@ -817,7 +818,8 @@ sub TestPolicies($$$$)
$query_result =
DBQueryWarn("select distinct * from group_policies ".
"where (pid='$pid' and (pid=gid or gid='$gid')) or ".
"where (pid='$pid' and ".
" (pid=gid or gid='$gid' or gid='*')) or ".
" pid='' or pid='-' ".
"order by pid,gid desc");
return -1
......@@ -882,6 +884,10 @@ sub TestPolicies($$$$)
my $global = ($ppid eq $pid ? 0 : 1);
my $result;
# If the group is a wildcard, then we want the project limit.
if ($pgid eq "*") {
$gid = $pid;
}
$result = TestGroupPolicy($pid, $gid,
$policy, $count, $auxdata, $global);
......@@ -1000,6 +1006,7 @@ sub UpdateNodeTypeXpidPermissions()
if (!$query_result);
while (my $rowref = $query_result->fetchrow_hashref()) {
my $pid_idx = $rowref->{'pid_idx'};
my $gid_idx = $rowref->{'gid_idx'};
my $ppid = $rowref->{'pid'};
my $pgid = $rowref->{'gid'};
......@@ -1011,7 +1018,13 @@ sub UpdateNodeTypeXpidPermissions()
if (! ($policy eq TBADMINCTRL_POLICY_TYPE()));
if ($debug) {
print "Type Perm: $ppid, $pgid, $count, $auxdata\n";
print "Type Perm: $ppid ($pid_idx), $pgid ($gid_idx), ".
"$count, $auxdata\n";
}
if ($pgid eq "*") {
$pgid = $ppid;
$gid_idx = $pid_idx;
}
my $group = Group->Lookup($gid_idx);
......@@ -1032,6 +1045,10 @@ sub UpdateNodeTypeXpidPermissions()
}
$permissions{"$gid_idx"}->{$auxdata} = 1;
}
if ($debug) {
print Dumper(\%permissions);
return -1;
}
#
# Generate the nodetypeXpid_permissions table (pid, type). We want to
......@@ -1297,8 +1314,7 @@ sub LoadCurrent($$$$)
"left join node_types as nt on nt.type=n.type ".
"left join experiments as e on ".
" e.pid=r.pid and e.eid=r.eid ".
"where (e.expt_swap_uid='$uid' or ".
" r.pid='$pid' and e.gid='$gid') and ".
"where (e.expt_swap_uid='$uid' or r.pid='$pid') and ".
" r.pid!='" . TBOPSPID() . "' and ".
" n.role='testnode'");
return undef
......
......@@ -2169,7 +2169,7 @@ CREATE TABLE `group_policies` (
`policy` varchar(32) NOT NULL default '',
`auxdata` varchar(64) NOT NULL default '',
`count` int(10) NOT NULL default '0',
PRIMARY KEY (`gid_idx`,`policy`,`auxdata`),
PRIMARY KEY (`pid_idx`,`gid_idx`,`policy`,`auxdata`),
UNIQUE KEY `pid` (`pid`,`gid`,`policy`,`auxdata`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
......
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
DBQueryFatal("alter table group_policies drop primary key");
DBQueryFatal("alter table group_policies add primary key " .
"(`pid_idx`,`gid_idx`,`policy`,`auxdata`)");
return 0;
}
# Local Variables:
# mode:perl
# End:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment