Commit e49e2f9a authored by Leigh Stoller's avatar Leigh Stoller

Add support for pre-reserving nodes. New link off the ShowNode page

allows takes you to new (admin only) page to select a project that
node will be reserved for.

* The node is not actually *reserved*, it is *pre* reserved! The node
  stays in the free pool, and is available only for use in the project
  to which it is reserved.

* The node can already be reserved to some other project when you
  pre-reserve it. It is not until the current owner releases the node
  that the pre-reservation takes effect.

* The node free counts (on the web pages) count a free a node with a
  pre-reservation, as allocated. This way people do not see a free
  count that includes a node they will never be able to get.
parent 576ec174
......@@ -326,6 +326,10 @@ if (defined($exempt_eid)) {
$free_condition = "($free_condition or ".
"(b.pid='$pid' and b.eid='$exempt_eid'))";
}
elsif (defined($pid)) {
$free_condition = "($free_condition and ".
"(np.reserved_pid is null or np.reserved_pid='$pid'))";
}
# If the user wants all nodes, we consider everything to be free (this
# overrides the other possible free conditions
......
......@@ -104,7 +104,7 @@ function SHOWFREENODES()
"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 r.pid is null and n.reserved_pid is null ".
"group BY n.eventstate,n.type");
while ($row = mysql_fetch_array($query_result)) {
......
......@@ -1475,6 +1475,7 @@ function TBFreePCs()
"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 ".
" (a.eventstate='" . TBDB_NODESTATE_ISUP . "' or ".
" a.eventstate='" . TBDB_NODESTATE_PXEWAIT . "') and".
......
......@@ -215,7 +215,7 @@ if (! strcmp($showtype, "summary")) {
"where (role='testnode') and ".
" (nt.class!='shark' and nt.class!='pcRemote' ".
" and nt.class!='pcplabphys') ".
" and r.pid is null ".
" and r.pid is null and n.reserved_pid is null ".
"group BY n.eventstate,n.type");
while ($row = mysql_fetch_array($query_result)) {
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
#
# Only admin people!
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);
if (! $isadmin) {
USERERROR("You do not have permission to pre-reserve nodes!", 1);
}
#
# Verify page arguments.
#
if (!isset($node_id) ||
strcmp($node_id, "") == 0) {
USERERROR("You must provide a node ID.", 1);
}
if (!TBvalid_node_id($node_id)) {
PAGEARGERROR("Illegal characters in node_id");
}
#
# Check to make sure that this is a valid nodeid
#
if (! TBValidNodeName($node_id)) {
USERERROR("$node_id is not a valid node name!", 1);
}
#
# Clear and zap back.
#
if (isset($clear)) {
DBQueryFatal("update nodes set reserved_pid=NULL ".
"where node_id='$node_id'");
header("Location: $TBBASE/shownode.php3?node_id=$node_id");
return;
}
#
# Spit the form out using the array of data.
#
function SPITFORM($node_id, $reserved_pid, $error)
{
#
# Standard Testbed Header
#
PAGEHEADER("Pre Reserve a node to a project");
#
# Get list of projects.
#
$query_result =
DBQueryFatal("select pid from projects where approved!=0");
if (mysql_num_rows($query_result) == 0) {
USERERROR("There are no projects!", 1);
}
if ($error) {
echo "<center>
<font size=+1 color=red>$error</font>
</center>\n";
}
echo "<br>
<table align=center border=1>
<form action='prereserve_node.php3?node_id=$node_id' method=post>\n";
#
# Select Project
#
echo "<tr>
<td>Select Project:</td>
<td><select name=\"reserved_pid\">
<option value=''>Please Select &nbsp</option>\n";
while ($row = mysql_fetch_array($query_result)) {
$pid = $row['pid'];
$selected = "";
if ($reserved_pid == $pid)
$selected = "selected";
echo " <option $selected value='$pid'>$pid </option>\n";
}
echo " </select>";
echo " </td>
</tr>\n";
echo "<tr>
<td align=center colspan=2>
<b><input type=submit name=submit value=Submit></b>
</td>
</tr>\n";
echo "</form>
</table>\n";
}
#
# On first load, display a virgin form and exit.
#
if (! $submit) {
SPITFORM($node_id, $TBOPSPID, False);
PAGEFOOTER();
return;
}
#
# Otherwise, must validate and redisplay if errors.
#
$error = False;
#
# Project:
#
if (!isset($reserved_pid) || $reserved_pid == "") {
$error = "Must supply a project name";
}
elseif (!TBvalid_pid($reserved_pid)) {
$error = "Illegal characters in project name";
}
elseif (!TBValidProject($reserved_pid)) {
$error = "Invalid project name";
}
if ($error) {
SPITFORM($node_id, $TBOPSPID, $error);
PAGEFOOTER();
return;
}
#
# Set the pid and zap back to shownode page.
#
DBQueryFatal("update nodes set reserved_pid='$reserved_pid' ".
"where node_id='$node_id'");
header("Location: $TBBASE/shownode.php3?node_id=$node_id");
......@@ -74,7 +74,7 @@ if (! $isadmin &&
}
$query_result =
DBQueryFatal("select r.vname,r.pid,r.eid from nodes as n ".
DBQueryFatal("select r.vname,r.pid,r.eid,n.reserved_pid from nodes as n ".
"left join reserved as r on n.node_id=r.node_id ".
"where n.node_id='$node_id'");
......@@ -86,6 +86,7 @@ $row = mysql_fetch_array($query_result);
$vname = $row[vname];
$pid = $row[pid];
$eid = $row[eid];
$reserved_pid = $row[reserved_pid];
if (isset($pid) && $vname != "") {
echo " (<b>".
......@@ -176,6 +177,17 @@ if ($isadmin || STUDLY() || OPSGUY()) {
"modnodeattributes_form.php3?node_id=$node_id");
}
if ($isadmin) {
if (!isset($reserved_pid)) {
WRITESUBMENUBUTTON("Pre-Reserve Node",
"prereserve_node?node_id=$node_id");
}
else {
WRITESUBMENUBUTTON("Clear Pre-Reserve",
"prereserve_node?node_id=$node_id&clear=1");
}
}
SUBMENUEND();
#
......
......@@ -2031,6 +2031,7 @@ function SHOWNODE($node_id, $flags = 0) {
$battery_percentage = $row[battery_percentage];
$battery_timestamp = $row[battery_timestamp];
$boot_errno = $row[boot_errno];
$reserved_pid = $row[reserved_pid];
if (!$def_boot_cmd_line)
$def_boot_cmd_line = "&nbsp";
......@@ -2352,6 +2353,15 @@ function SHOWNODE($node_id, $flags = 0) {
</tr>\n";
}
if ($reserved_pid) {
echo "<tr>
<td>Reserved Pid:</td>
<td class=left>
<a href='showproject.php3?pid=$reserved_pid'>
$reserved_pid</a></td>
</tr>\n";
}
#
# Show battery stuff
#
......
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