request_swapexp.php3 4.29 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
24 25 26
include("defs.php3");

#
27
# Only known and logged in users.
28
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32 33

#
34
# Only admins can do this!
35
#
36
if (!$isadmin) {
37
    USERERROR("Only TB admins can do this!", 1);
38 39 40
}

#
41
# Verify page arguments.
42
#
43 44 45 46 47
$reqargs = RequiredPageArguments("experiment", PAGEARG_EXPERIMENT);
$optargs = OptionalPageArguments("canceled",   PAGEARG_STRING,
				 "confirmed",  PAGEARG_STRING,
				 "force",      PAGEARG_BOOLEAN);

48 49 50 51 52
#
# Standard Testbed Header
#
PAGEHEADER("Request a Swap/Terminate");

53 54 55 56 57 58 59 60 61
#
# Need these below
#
$pid = $experiment->pid();
$eid = $experiment->eid();
$pcs = $experiment->PCCount();

echo $experiment->PageHeader();
echo "<br>";
62 63 64 65 66 67 68

#
# We run this twice. The first time we are checking for a confirmation
# by putting up a form. The next time through the confirmation will be
# set. Or, the user can hit the cancel button, in which case we should
# probably redirect the browser back up a level.
#
69 70 71
if (isset($canceled) && $canceled) {
    echo "<center><h3>Swap request canceled!</h3>
          </center>\n";
72 73 74 75
    PAGEFOOTER();
    return;
}

76
# We only send to the proj leader after we have sent $tell_proj_head requests
77
$tell_proj_head = TBGetSiteVar("idle/cc_grp_ldrs");
78
$q = DBQueryWarn("select swappable, swap_requests,
79 80 81 82
                  date_format(last_swap_req,\"%T\") as lastreq
                  from experiments
                  where eid='$eid' and pid='$pid'");
$r = mysql_fetch_array($q);
83

84 85 86
$swappable     = $experiment->swappable();
$swap_requests = $experiment->swap_requests();
$last_swap_req = $experiment->last_swap_req();
87

88
if (!isset($confirmed)) {
89
    echo "<center><h3>
90 91
           Expt. '$eid' in project '$pid' has $pcs Emulab node(s) ".
     "reserved,<br>\nand has been sent $swap_requests swap request".
92
      ($swap_requests!=1?"s":"")." since it went idle.<br>\n";
93
    if ($swap_requests > 0) {
94
      echo "The most recent one was sent at $last_swap_req.<br>\n";
95 96
    }
    if ($swap_requests >= $tell_proj_head) {
97
      echo "This notification will also be sent to the project leader.\n";
98 99
    }
    echo "<p>
100 101
          Are you sure you want to send an email message requesting that
          experiment '$eid' be swapped or terminated?</p>
102
          </h3>\n";
103 104 105

    #
    # Dump experiment record.
106 107 108 109 110 111
    #
    $experiment->Show();

    $url = CreateURL("request_swapexp", $experiment);

    echo "<form action='$url' method=post>";
112 113 114 115
    echo "<p><input type=checkbox name=force value=1>Force: ".
	"Send message even if not idle</p>\n";
    echo "<input type=submit name=confirmed value=Confirm>\n";
    echo "<input type=submit name=canceled value=Cancel>\n";
116 117 118 119 120 121 122
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

123
# Confirmed and ready to go...
124
if (isset($force) && $force) {
125
    $force="-f";
126 127
}
else {
128
    $force="";
129
}
130

131
STARTBUSY("Sending request");
132 133
SUEXEC($uid, $TBADMINGROUP,
       "webidlemail $force $pid $eid", SUEXEC_ACTION_IGNORE);
134
CLEARBUSY();
135

136 137
if ($suexec_retval == 0) {
    echo "<p><center>
138
         Message successfully sent!
139 140
         </center></p>\n";
} elseif ($suexec_retval == 2) {
141 142
    $url = CreateURL("request_swapexp", $experiment);

143 144
    echo "<p><center>
         No message was sent, because it wasn't time for a message.<br>
145
	 Use the <a href=\"$url\">Force</a> option to send a message anyway.
146 147 148 149 150 151 152 153
         </center></p>\n";
} else {
    echo "<p><center>
	 There was an unknown problem sending the message.<br>
	 Output was:<pre>$suexec_output</pre>
         </center></p>\n";
}

154 155 156 157 158
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>