quickvm_status.php 12.5 KB
Newer Older
Leigh B Stoller's avatar
Leigh B Stoller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
#
# Copyright (c) 2000-2013 University of Utah and the Flux Group.
# 
# {{{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/>.
# 
# }}}
#
chdir("..");
include("defs.php3");
include_once("osinfo_defs.php");
include_once("geni_defs.php");
28
chdir("apt");
Leigh B Stoller's avatar
Leigh B Stoller committed
29
30
31
32
33
34
35
36
37
include("quickvm_sup.php");

$ajax_request = 0;

#
# Verify page arguments.
#
$reqargs = OptionalPageArguments("uuid",          PAGEARG_STRING,
				 "ajax_request",  PAGEARG_BOOLEAN,
Leigh B Stoller's avatar
Leigh B Stoller committed
38
39
				 "ajax_method",   PAGEARG_STRING,
				 "ajax_argument", PAGEARG_STRING);
Leigh B Stoller's avatar
Leigh B Stoller committed
40
41
if (!isset($uuid)) {
    if ($ajax_request) {
Leigh B Stoller's avatar
Leigh B Stoller committed
42
	SPITAJAX_ERROR(1, "must provide uuid");
Leigh B Stoller's avatar
Leigh B Stoller committed
43
44
45
	exit();
    }
    SPITHEADER(1);
46
47
48
49
50
    echo "<div class='align-center'>
            <p class='lead text-center'>
              What experiment would you like to look at?
            </p>
          </div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
51
52
53
54
55
56
57
58
59
60
    SPITFOOTER();
    return;
}

#
# See if the quickvm exists. If not, redirect back to the create page
#
$quickvm = QuickVM::Lookup($uuid);
if (!$quickvm) {
    if ($ajax_request) {
Leigh B Stoller's avatar
Leigh B Stoller committed
61
	SPITAJAX_ERROR(1, "no such quickvm uuid");
Leigh B Stoller's avatar
Leigh B Stoller committed
62
63
64
	exit();
    }
    SPITHEADER(1);
65
66
67
68
69
    echo "<div class='align-center'>
            <p class='lead text-center'>
              Experiment does not exist. Redirecting to the front page.
            </p>
          </div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
70
71
72
73
74
75
76
77
78
    SPITFOOTER();
    flush();
    sleep(3);
    PAGEREPLACE("quickvm.php");
    return;
}
$creator = GeniUser::Lookup("sa", $quickvm->creator_uuid());
if (!$creator) {
    if ($ajax_request) {
Leigh B Stoller's avatar
Leigh B Stoller committed
79
	SPITAJAX_ERROR(1, "no such quickvm uuid");
Leigh B Stoller's avatar
Leigh B Stoller committed
80
81
82
	exit();
    }
    SPITHEADER(1);
83
84
    echo "<div class='align-center'>
            <p class='lead text-center'>
Leigh B Stoller's avatar
Leigh B Stoller committed
85
               Hmm, there seems to be a problem.
86
87
            </p>
          </div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
88
89
90
91
92
93
94
    SPITFOOTER();
    TBERROR("No creator for quickvm $uuid", 0);
    return;
}
$slice = GeniSlice::Lookup("sa", $quickvm->slice_uuid());
if (!$slice) {
    if ($ajax_request) {
Leigh B Stoller's avatar
Leigh B Stoller committed
95
	SPITAJAX_ERROR(1, "no slice for quickvm ");
Leigh B Stoller's avatar
Leigh B Stoller committed
96
97
98
	exit();
    }
    SPITHEADER(1);
99
100
    echo "<div class='align-center'>
            <p class='lead text-center'>
Leigh B Stoller's avatar
Leigh B Stoller committed
101
               Hmm, there seems to be a problem.
102
103
            </p>
          </div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
    SPITFOOTER();
    TBERROR("No slice for quickvm $uuid", 0);
    return;
}

#
# Deal with ajax requests.
#
if (isset($ajax_request)) {
    if ($ajax_method == "status") {
	SPITAJAX_RESPONSE($quickvm->status());
    }
    elseif ($ajax_method == "terminate") {
	SUEXEC("nobody", "nobody", "webquickvm -k $uuid",
	       SUEXEC_ACTION_IGNORE);
	SPITAJAX_RESPONSE("");
    }
    elseif ($ajax_method == "manifest") {
	SPITAJAX_RESPONSE($quickvm->manifest());
    }
    elseif ($ajax_method == "gettopomap") {
	$experiment = Experiment::LookupByUUID($slice->uuid());
	if (!$experiment) {
	    return "";
	}
	$pid = $experiment->pid();
	$eid = $experiment->eid();
	SPITAJAX_RESPONSE(GetTopoMap($creator->uid(), $pid, $eid));
    }
133
134
    elseif ($ajax_method == "ssh_authobject") {
	SPITAJAX_RESPONSE(SSHAuthObject($creator->uid(), $ajax_argument));
Leigh B Stoller's avatar
Leigh B Stoller committed
135
    }
Leigh B Stoller's avatar
Leigh B Stoller committed
136
    elseif ($ajax_method == "request_extension") {
Leigh B Stoller's avatar
Leigh B Stoller committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
        # Only extend for 24 hours. More later.
	$expires_time = strtotime($slice->expires());
	if ($expires_time > time() + (3600 * 36)) {
	    SPITAJAX_ERROR(1, "You still have lots of time left!");
	    return;
	}
	
	$retval =
	    SUEXEC("nobody", "nobody", "webquickvm -e " . 3600 * 24 . " $uuid",
		   SUEXEC_ACTION_CONTINUE);

	if ($retval == 0) {
	    # Refresh. 
	    $slice = GeniSlice::Lookup("sa", $quickvm->slice_uuid());
151
	    $new_expires = gmdate("Y-m-d H:i:s",strtotime($slice->expires()));
Leigh B Stoller's avatar
Leigh B Stoller committed
152
153
154
155
156
157
158
	    
	    SPITAJAX_RESPONSE($new_expires);

	    TBMAIL($creator->email(),
		   "APT Extension: $uuid",
		   "A request to extend your APT experiment was made and ".
		   "granted.\n".
Leigh B Stoller's avatar
Leigh B Stoller committed
159
		   "Your reason was:\n\n". $ajax_argument . "\n\n".
Leigh B Stoller's avatar
Leigh B Stoller committed
160
161
162
163
164
165
		   "Your experiment will now expire at $new_expires\n",
		   "CC: $TBMAIL_OPS");
	}
	else {
	    SPITAJAX_ERROR(-1, "Internal Error. Please try again later");
	}
Leigh B Stoller's avatar
Leigh B Stoller committed
166
167
    }
    elseif ($ajax_method == "extend") {
Leigh B Stoller's avatar
Leigh B Stoller committed
168
	SPITAJAX_ERROR(1, "Not implemented yet!");
Leigh B Stoller's avatar
Leigh B Stoller committed
169
    }
Leigh B Stoller's avatar
Leigh B Stoller committed
170
171
172
173
174
175
    exit();
}
SPITHEADER(1);

$style = "style='border: none;'";
$slice_urn       = $slice->urn();
176
$slice_expires   = gmdate("Y-m-d H:i:s", strtotime($slice->expires()));
Leigh B Stoller's avatar
Leigh B Stoller committed
177
178
179
180
181
182
183
$quickvm_status  = $quickvm->status();
$sshkey          = chunk_split($creator->SSHKey(), 40);
$creator_uid     = $creator->uid();
$creator_email   = $creator->email();
$quickvm_profile = $quickvm->profile();
$slice_url       = "";
$color           = "";
Leigh B Stoller's avatar
Leigh B Stoller committed
184
$disabled        = "disabled";
Leigh B Stoller's avatar
Leigh B Stoller committed
185
186
187
188
189
190
191
192
$spin            = 1;
if ($quickvm_status == "failed") {
    $color = "color=red";
    $spin  = 0;
}
elseif ($quickvm_status == "ready") {
    $color = "color=green";
    $spin  = 0;
Leigh B Stoller's avatar
Leigh B Stoller committed
193
    $disabled = "";
Leigh B Stoller's avatar
Leigh B Stoller committed
194
195
196
197
198
199
200
201
}
elseif ($quickvm_status == "created") {
    $spinwidth = "33";
}
elseif ($quickvm_status == "provisioned") {
    $spinwidth = "66";
}

202
203
204
205
echo "<div class='row'>
      <div class='col-lg-6  col-lg-offset-3
                  col-md-8  col-md-offset-2
                  col-sm-8  col-sm-offset-2
206
                  col-xs-12 col-xs-offset-0'>\n";
207
208
209
echo "<div class='panel panel-default'>\n";
echo "<div class='panel-body'>\n";
echo "<table class='table table-condensed' $style>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
210
211
if ($spin) {
    echo "<tr>\n";
212
    echo "<td colspan=2 $style>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
213
214
    echo "<div id='quickvm_spinner'>\n";
    echo " <div id='quickvm_progress'
215
216
                class='progress progress-striped active'>\n";
    echo "  <div class='progress-bar' role='progressbar'
Leigh B Stoller's avatar
Leigh B Stoller committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
                 id='quickvm_progress_bar'
                 style='width: ${spinwidth}%;'></div>\n";
    echo " </div>\n";
    echo "</div>\n";
    echo "</td>\n";
    echo "</tr>\n";
}
echo "<tr>\n";
echo "<td class='uk-width-1-5' $style>URN:</td>\n";
echo "<td class='uk-width-4-5' $style>$slice_urn</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='uk-width-1-5' $style>State:</td>\n";
echo "<td id='quickvm_status'
          class='uk-width-4-5' $style>
          <font $color>$quickvm_status</font>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='uk-width-1-5' $style>Profile:</td>\n";
echo "<td class='uk-width-4-5' $style>$quickvm_profile</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='uk-width-1-5' $style>Expires:</td>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
241
242
echo "<td class='uk-width-4-5' $style>
         <span id='quickvm_expires'>$slice_expires</span> - Time left: 
Leigh B Stoller's avatar
Leigh B Stoller committed
243
244
245
         <span id='quickvm_countdown'></span></td>\n";
echo "</tr>\n";
echo "</table>\n";
246
247
echo "<div class='pull-right'>\n";
echo "  <button class='btn btn-primary'
Leigh B Stoller's avatar
Leigh B Stoller committed
248
249
250
           id='register_button' type=button
           onclick=\"ShowModal('#register_modal'); return false;\">
           Register</button>\n";
251
echo "  <button class='btn btn-success' $disabled
Leigh B Stoller's avatar
Leigh B Stoller committed
252
253
254
           id='extend_button' type=button
           onclick=\"ShowModal('#extend_modal'); return false;\">
           Extend</button>\n";
255
echo "  <button class='btn btn-danger' $disabled
Leigh B Stoller's avatar
Leigh B Stoller committed
256
           id='terminate_button' type=button
Leigh B Stoller's avatar
Leigh B Stoller committed
257
           onclick=\"ShowModal('#terminate_modal'); return false;\">
Leigh B Stoller's avatar
Leigh B Stoller committed
258
259
260
           Terminate</button>\n";
echo "</div>\n";
echo "</div>\n";
261
262
263
echo "</div>\n";
echo "</div>\n";
echo "</div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
264

Leigh B Stoller's avatar
Leigh B Stoller committed
265
266
267
#
# The topo diagram goes inside this div, when it becomes available.
#
268
echo "<div class='row'>
269
270
271
      <div class='col-lg-10  col-lg-offset-1
                  col-md-10  col-md-offset-1
                  col-sm-10  col-sm-offset-1
272
                  col-xs-12 col-xs-offset-0'>\n";
273
274
echo "<div class='panel panel-default invisible' id='showtopo_container'>\n";
echo "<div class='panel-body'>\n";
275
echo "<div id='quicktabs_div'>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
276
echo "<div id='showtopo_div'></div>\n";
277
SpitToolTip("Click on a node to SSH to that node.\n".
Leigh B Stoller's avatar
Leigh B Stoller committed
278
	    "Click and drag on a node to move things around.");
279
280
281
282
283
echo "</div>\n"; # showtopo
echo "</div>\n"; # quicktabs
echo "</div>\n"; # container
echo "</div>\n"; # cols
echo "</div>\n"; # row
Leigh B Stoller's avatar
Leigh B Stoller committed
284
285

#
Leigh B Stoller's avatar
Leigh B Stoller committed
286
# A modal to tell people how to register
Leigh B Stoller's avatar
Leigh B Stoller committed
287
288
#
echo "<!-- This is a modal -->
289
290
291
292
293
294
      <div id='register_modal' class='modal fade'>
        <div class='modal-dialog'>
        <div class='modal-content'>
        <div class='modal-header'>
          <button type='button' class='close' data-dismiss='modal'
                   aria-hidden='true'>&times;</button>
Leigh B Stoller's avatar
Leigh B Stoller committed
295
          <h3>Register for an account</h3>
296
297
        </div>
        <div class='modal-body'>
Leigh B Stoller's avatar
Leigh B Stoller committed
298
299
300
301
302
          <p>If you want to design your own experiments, have more then
             one active experiment at a time, or extend the life of an
             experiment longer, you should register for a full account.
             Click on the link below to take you to the registration page.
          </p><br>
303
               <button class='btn btn-primary align-center'
Leigh B Stoller's avatar
Leigh B Stoller committed
304
305
306
                  onclick=\"RegisterAccount('$creator_uid',
                              '$creator_email'); return false;\"
                  type='submit' name='register'>Register</button>
Leigh B Stoller's avatar
Leigh B Stoller committed
307
        </div>
308
309
        </div>
        </div>
Leigh B Stoller's avatar
Leigh B Stoller committed
310
311
312
313
314
315
      </div>\n";

#
# A modal to tell people how to extend their experiment
#
echo "<!-- This is a modal -->
316
317
318
319
320
321
322
323
324
      <div id='extend_modal' class='modal fade'>
        <div class='modal-dialog'>
        <div class='modal-content'>
         <div class='modal-body'>
          <button type='button' class='close' data-dismiss='modal'
                   aria-hidden='true'>&times;</button>
          <div class='row'>
            <div class='col-lg-7 col-md-7'
                 style='padding-right:20px; border-right: 1px solid #ccc;'>
Leigh B Stoller's avatar
Leigh B Stoller committed
325
                If you want to extend this experiment so that it does
Leigh B Stoller's avatar
Leigh B Stoller committed
326
327
328
                not self-terminate at the time shown, just tell us why
                and we will extend it for another 24 hours.
		Watch for an email message that says its been done. 
329
330
              <form id='extend_request_form' role='form'>
               <div class='row'>
Leigh B Stoller's avatar
Leigh B Stoller committed
331
                <div class='col-lg-12 col-md-12'>
Leigh B Stoller's avatar
Leigh B Stoller committed
332
                <textarea id='why_extend' name='why_extend'
333
                          class='form-control'
Leigh B Stoller's avatar
Leigh B Stoller committed
334
                          placeholder='Tell us a good story please.'
Leigh B Stoller's avatar
Leigh B Stoller committed
335
                          class='align-center-inline'
Leigh B Stoller's avatar
Leigh B Stoller committed
336
                          rows=5></textarea>
337
               </div></div>
Leigh B Stoller's avatar
Leigh B Stoller committed
338
               <br>
339
               <button class='btn btn-primary btn-sm align-center'
Leigh B Stoller's avatar
Leigh B Stoller committed
340
341
342
343
                       onclick=\"RequestExtension('$uuid'); return false;\"
                       type='submit' name='request'>Request Extension</button>
              </form>
            </div>
Leigh B Stoller's avatar
Leigh B Stoller committed
344
            <div class='col-lg-5 col-md-5 invisible'>
Leigh B Stoller's avatar
Leigh B Stoller committed
345
346
347
               To extend your experiment for more then another 24 hours,
               you need an extension code. If you do not have a code then
               you need not worry about it.
348
               <form id='extend_form' role='form'>
Leigh B Stoller's avatar
Leigh B Stoller committed
349
                <input id='extend_code' name='extend_code' 
350
                    class='align-center'
Leigh B Stoller's avatar
Leigh B Stoller committed
351
                    placeholder='Extension code' autofocus type='text' />
Leigh B Stoller's avatar
Leigh B Stoller committed
352
                <br>
353
                <button class='btn btn-primary btn-sm align-center'
Leigh B Stoller's avatar
Leigh B Stoller committed
354
355
356
357
                       onclick=\"Extend('$uuid'); return false;\"
                       type='submit' name='extend'>Extend</button>
              </form>
            </div>
358
359
            </div>
            </div>
Leigh B Stoller's avatar
Leigh B Stoller committed
360
361
362
363
           </div>
        </div>
      </div>\n";

Leigh B Stoller's avatar
Leigh B Stoller committed
364
365
366
367
#
# A modal to verify termination.
#
echo "<!-- This is a modal -->
368
369
370
371
372
373
374
375
376
377
378
379
380
      <div id='terminate_modal' class='modal fade'>
        <div class='modal-dialog'>
        <div class='modal-content'>
        <div class='modal-body'>
         <button type='button' class='close' data-dismiss='modal'
                   aria-hidden='true'>&times;</button>
         <p>Are you sure you want to terminate this experiment? 
            Click on the button below if you are really sure.</p><br>
             <button class='btn btn-primary align-center'
                onclick=\"Terminate('$uuid', 'quickvm.php'); return false;\"
                type='submit' name='terminate'>Terminate</button>
        </div>
        </div>
Leigh B Stoller's avatar
Leigh B Stoller committed
381
382
383
        </div>
      </div>\n";

384
echo "<script src='d3.v3.js'></script>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
385
echo "<SCRIPT LANGUAGE=JavaScript>
386
                 InitQuickVM('$uuid', '$slice_expires');
Leigh B Stoller's avatar
Leigh B Stoller committed
387
388
389
390
              </SCRIPT>\n";

SPITFOOTER();
?>