Commit 4b3af027 authored by Leigh Stoller's avatar Leigh Stoller

Update the free node counts to respect the policy tables and the user or

project.
parent bd129835
<?php
#
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
# Copyright (c) 2000-2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -111,7 +111,9 @@ function SHOWSTATS($mini = 0)
#
function ShowStatus()
{
$freepcs = TBFreePCs();
global $this_user;
$freepcs = TBFreePCs($this_user);
$reload = TBReloadingPCs();
$users = TBLoggedIn();
$active = TBActiveExperiments();
......@@ -138,13 +140,38 @@ function ShowStatus()
#
function SHOWFREENODES()
{
global $this_user;
$freecounts = array();
$findinset = "";
$pids = array();
$clause = "0";
if ($this_user) {
$uid_idx = $this_user->uid_idx();
$query_result =
DBQueryFatal("select distinct pid from group_membership ".
"where uid_idx='$uid_idx'");
if (mysql_num_rows($query_result)) {
$clauses = array();
while ($row = mysql_fetch_row($query_result)) {
$pid = $row[0];
$pids[] = $pid;
$clauses[] = "p.pid='$pid'";
}
}
$clause = "p.pid is null or " . join(" or ", $clauses);
$findinset = "or FIND_IN_SET(n.reserved_pid, '" . join(",", $pids)."')";
}
# Get typelist and set freecounts to zero.
$query_result =
DBQueryFatal("select n.type from nodes as n ".
"left join node_types as nt on n.type=nt.type ".
"where (role='testnode') and class='pc' ");
"left join node_type_attributes as attr on ".
" attr.type=n.type and ".
" attr.attrkey='noshowfreenodes' ".
"where (role='testnode') and class='pc' and ".
" attr.attrvalue is null");
while ($row = mysql_fetch_array($query_result)) {
$type = $row[0];
$freecounts[$type] = 0;
......@@ -159,8 +186,13 @@ function SHOWFREENODES()
DBQueryFatal("select n.eventstate,n.type,count(*) from nodes as n ".
"left join node_types as nt on n.type=nt.type ".
"left join reserved as r on r.node_id=n.node_id ".
"where (role='testnode') and class='pc' ".
" and r.pid is null and n.reserved_pid is null ".
"left join node_type_attributes as attr on ".
" attr.type=n.type and ".
" attr.attrkey='noshowfreenodes' ".
"where (role='testnode') and class='pc' and ".
" r.pid is null and ".
" attr.attrvalue is null and ".
" (n.reserved_pid is null $findinset) ".
"group BY n.eventstate,n.type");
while ($row = mysql_fetch_array($query_result)) {
......@@ -171,12 +203,24 @@ function SHOWFREENODES()
($row[0] == TBDB_NODESTATE_PXEWAIT) ||
($row[0] == TBDB_NODESTATE_ALWAYSUP) ||
($row[0] == TBDB_NODESTATE_POWEROFF)) {
$policy_result =
DBQueryFatal("select max(count) from group_policies as p ".
"where p.policy='type' and p.auxdata='$type' and ".
" (p.pid='-' or $clause)");
if (mysql_num_rows($policy_result)) {
$row = mysql_fetch_row($policy_result);
if ($count > $row[0]) {
$count = $row[0];
}
}
$freecounts[$type] += $count;
}
}
$output = "";
$freepcs = TBFreePCs();
$freepcs = TBFreePCs($this_user);
$reloading = TBReloadingPCs();
$output .= "<table valign=top align=center width=100% height=100% border=1
......
<?php
#
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
# Copyright (c) 2000-2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -381,27 +381,75 @@ function TBExpUidLastLogins($pid, $eid)
# usage of the eventstate. A node is not really considered free for use
# unless it is also in the ISUP/PXEWAIT state.
#
function TBFreePCs()
function TBFreePCs($target = null)
{
$clause = "0";
$findinset = "";
$pids = array();
if ($target) {
if (get_class($target) == "Group") {
$pid = $target->pid();
$pids[] = $pid;
$clauses[] = "p.pid='$pid'";
}
else {
$uid_idx = $target->uid_idx();
$query_result =
DBQueryFatal("select distinct pid from group_membership ".
"where uid_idx='$uid_idx'");
if (mysql_num_rows($query_result)) {
$clauses = array();
while ($row = mysql_fetch_row($query_result)) {
$pid = $row[0];
$pids[] = $pid;
$clauses[] = "p.pid='$pid'";
}
}
}
$clause = "p.pid is null or " . join(" or ", $clauses);
$findinset = "or FIND_IN_SET(a.reserved_pid, '" . join(",", $pids)."')";
}
$total = 0;
$query_result =
DBQueryFatal("select count(a.node_id) from nodes as a ".
DBQueryFatal("select a.type,count(a.node_id) from nodes as a ".
"left join reserved as b on a.node_id=b.node_id ".
"left join node_types as nt on a.type=nt.type ".
"left join nodetypeXpid_permissions as p ".
" on a.type=p.type ".
"where b.node_id is null and a.role='testnode' ".
" and a.reserved_pid is null ".
" and nt.class = 'pc' and p.pid is null and ".
"left join node_type_attributes as attr on ".
" attr.type=a.type and ".
" attr.attrkey='noshowfreenodes' ".
"where b.node_id is null and a.role='testnode' and ".
" attr.attrvalue is null and ".
" nt.class = 'pc' and ".
" (a.reserved_pid is null $findinset) and ".
" (a.eventstate='" . TBDB_NODESTATE_ISUP . "' or ".
" a.eventstate='" . TBDB_NODESTATE_POWEROFF . "' or ".
" a.eventstate='" . TBDB_NODESTATE_PXEWAIT . "') and".
" (p.pid is null)");
" a.eventstate='" . TBDB_NODESTATE_ALWAYSUP . "' or ".
" a.eventstate='" . TBDB_NODESTATE_PXEWAIT . "') ".
"group by a.type");
if (mysql_num_rows($query_result) == 0) {
return 0;
}
$row = mysql_fetch_row($query_result);
return $row[0];
while ($row = mysql_fetch_row($query_result)) {
$type = $row[0];
$count = $row[1];
$policy_result =
DBQueryFatal("select max(count) from group_policies as p ".
"where p.policy='type' and p.auxdata='$type' and ".
" (p.pid='-' or $clause)");
if (mysql_num_rows($policy_result)) {
$row = mysql_fetch_row($policy_result);
if ($count > $row[0]) {
$count = $row[0];
}
}
$total += $count;
}
return $total;
}
#
......
<?php
#
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
# Copyright (c) 2000-2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -887,7 +887,7 @@ function WRITESIDEBAR() {
if (0 && $login_user) {
NavMenuSection("Status", "Status");
$freepcs = TBFreePCs();
$freepcs = TBFreePCs($login_user);
$reload = TBReloadingPCs();
$users = TBLoggedIn();
$active = TBActiveExperiments();
......
<?php
#
# Copyright (c) 2006-2014 University of Utah and the Flux Group.
# Copyright (c) 2006-2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -1744,57 +1744,32 @@ function ShowFreeNodes($user, $group)
$query_result =
DBQueryFatal("select n.type from nodes as n ".
"left join node_types as nt on n.type=nt.type ".
"where (role='testnode') and class='pc' ");
"left join node_type_attributes as attr on ".
" attr.type=n.type and ".
" attr.attrkey='noshowfreenodes' ".
"where (role='testnode') and class='pc' and ".
" attr.attrvalue is null");
while ($row = mysql_fetch_array($query_result)) {
$type = $row[0];
$freecounts[$type] = 0;
$perms[$type] = 1;
$perms[$type] = 1;
}
if (!count($freecounts)) {
return "";
}
#
# Anything listed in the perm tables is restricted.
#
$query_result =
DBQueryFatal("select distinct type from nodetypeXpid_permissions");
while ($row = mysql_fetch_array($query_result)) {
$perms[$row[0]] = 0;
}
#
# Want to restrict the actual free counts to what the current user
# is allowed to use, within the project the experiment belongs too.
# The wrinkle is if the person looking at the experiment is not a
# member of the project, in which case its probably an admin person.
# In that case just use the nodes the project has access to.
#
if ($group->IsMember($user, $ignored)) {
$query_result =
DBQueryFatal("select distinct type from group_membership as g ".
"left join nodetypeXpid_permissions as p ".
" on g.pid=p.pid ".
"where uid_idx='$uid_idx' and g.pid_idx='$pid_idx'");
}
else {
$query_result =
DBQueryFatal("select distinct type from nodetypeXpid_permissions ".
"where pid_idx='$pid_idx'");
}
while ($row = mysql_fetch_array($query_result)) {
$perms[$row[0]] = 1;
}
# Get free totals by type.
$query_result =
DBQueryFatal("select n.eventstate,n.type,count(*) from nodes as n ".
"left join node_types as nt on n.type=nt.type ".
"left join reserved as r on r.node_id=n.node_id ".
"where (role='testnode') and class='pc' ".
" and r.pid is null and ".
"left join node_type_attributes as attr on ".
" attr.type=n.type and ".
" attr.attrkey='noshowfreenodes' ".
"where (role='testnode') and class='pc' and ".
" r.pid is null and ".
" attr.attrvalue is null and ".
" (n.reserved_pid is null or ".
" n.reserved_pid='$pid') ".
"group BY n.eventstate,n.type");
......@@ -1807,6 +1782,18 @@ function ShowFreeNodes($user, $group)
($row[0] == TBDB_NODESTATE_PXEWAIT) ||
($row[0] == TBDB_NODESTATE_ALWAYSUP) ||
($row[0] == TBDB_NODESTATE_POWEROFF)) {
$policy_result =
DBQueryFatal("select max(count) from group_policies as p ".
"where p.policy='type' and p.auxdata='$type' and ".
" (p.pid='-' or p.pid='$pid')");
if (mysql_num_rows($policy_result)) {
$row = mysql_fetch_row($policy_result);
if ($count > $row[0]) {
$count = $row[0];
}
}
$freecounts[$type] = $count;
}
}
......@@ -1823,7 +1810,7 @@ function ShowFreeNodes($user, $group)
}
}
$freepcs = TBFreePCs();
$freepcs = TBFreePCs($group);
$reloading = TBReloadingPCs();
$output .= "<table valign=top align=center width=100% height=100% border=1
......
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