nodecontrol_list.php3 11.6 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5
6
# All rights reserved.
#
7
8
include("defs.php3");

9
10
11
12
13
14
#
# This page is used for both admin node control, and for mere user
# information purposes. Be careful about what you do outside of
# $isadmin tests.
# 

15
16
17
#
# Standard Testbed Header
#
18
PAGEHEADER("Node Control Center");
19

20
21
22
#
# Only known and logged in users can do this.
#
23
$uid = GETLOGIN();
24
LOGGEDINORDIE($uid);
25
$isadmin = ISADMIN($uid);
26
27
28
29
30
31

#
# Admin users can control nodes.
#
$isadmin = ISADMIN($uid);

32
33
echo "<b>Show: <a href='nodecontrol_list.php3?showtype=summary'>summary</a>,
               <a href='nodecontrol_list.php3?showtype=pcs'>pcs</a>,
34
35
36
37
38
39
40
               <a href='nodecontrol_list.php3?showtype=widearea'>widearea</a>";

if ($isadmin) {
    echo    ", <a href='nodecontrol_list.php3?showtype=virtnodes'>virtual</a>,
               <a href='nodecontrol_list.php3?showtype=physical'>physical</a>,
               <a href='nodecontrol_list.php3?showtype=all'>all</a>";
}
41
echo ".</b><br>\n";
42
43

if (!isset($showtype)) {
44
    $showtype='summary';
45
46
}

Chad Barb's avatar
   
Chad Barb committed
47
48
49
$additionalVariables = "";
$additionalLeftJoin  = "";

50
51
52
53
54
55
56
if (! strcmp($showtype, "summary")) {
    # Separate query below.
    $role   = "";
    $clause = "";
    $view   = "Free Node Summary";
}
elseif (! strcmp($showtype, "all")) {
57
58
59
    $role   = "(role='testnode' or role='virtnode')";
    $clause = "";
    $view   = "All";
60
61
}
elseif (! strcmp($showtype, "pcs")) {
62
63
64
    $role   = "(role='testnode')";
    $clause = "and (nt.class='pc')";
    $view   = "PCs";
65
}
66
67
68
69
elseif (! strcmp($showtype, "sharks")) {
    $role   = "(role='testnode')";
    $clause = "and (nt.class='shark')";
    $view   = "Sharks";
70
71
}
elseif (! strcmp($showtype, "virtnodes")) {
72
73
74
75
    $role   = "(role='virtnode')";
    $clause = "";
    $view   = "Virtual Nodes";
}
76
77
78
79
80
elseif (! strcmp($showtype, "physical")) {
    $role   = "";
    $clause = "(nt.isvirtnode=0)";
    $view   = "Physical Nodes";
}
81
82
83
elseif (! strcmp($showtype, "widearea")) {
    $role   = "(role='testnode')";
    $clause = "and (nt.isremotenode=1)";
Chad Barb's avatar
   
Chad Barb committed
84
85
86
87
88
89
90

    $additionalVariables = ",".
			   "wani.machine_type,".
			   "REPLACE(CONCAT_WS(', ',".
			   "wani.city,wani.state,wani.country,wani.zip), ".
		 	   "'USA, ','')".
			   "AS location, ".
91
92
	 		   "wani.connect_type, ".
			   "wani.hostname";
Chad Barb's avatar
   
Chad Barb committed
93
94
95
    $additionalLeftJoin = "LEFT JOIN widearea_nodeinfo AS wani ".
			  "ON n.node_id=wani.node_id";

96
    $view   = "Widearea";
97
98
}
else {
99
100
101
    $role   = "(role='testnode')";
    $clause = "and (nt.class='pc')";
    $view   = "PCs";
102
}
103
104
105
106
107
# If admin or widearea, show the vname too. 
$showvnames = 0;
if ($isadmin || !strcmp($showtype, "widearea")) {
    $showvnames = 1;
}
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#
# Summary info very different.
# 
if (! strcmp($showtype, "summary")) {
    # Get permissions table so as not to show nodes the user is not allowed
    # to see.
    $perms = array();
    
    if (!$isadmin) {
	$query_result =
	    DBQueryFatal("select type from nodetypeXpid_permissions");

	while ($row = mysql_fetch_array($query_result)) {
	    $perms{$row[0]} = 0;
	}
    
	$query_result =
	    DBQueryFatal("select distinct type from group_membership as g ".
			 "left join nodetypeXpid_permissions as p ".
			 "     on g.pid=p.pid ".
			 "where uid='$uid'");
	
	while ($row = mysql_fetch_array($query_result)) {
	    $perms{$row[0]} = 1;
	}
    }
    
    # Get totals by type.
    $query_result =
	DBQueryFatal("select n.type,count(*) from nodes as n ".
		     "left join node_types as nt on n.type=nt.type ".
		     "where (role='testnode') and ".
		     "      (nt.class!='shark' and nt.class!='pcRemote' ".
		     "      and nt.class!='pcplabphys') ".
		     "group BY n.type");

    $totals    = array();
    $freecount = array();

    while ($row = mysql_fetch_array($query_result)) {
	$type  = $row[0];
	$count = $row[1];

	$totals[$type]    = $count;
	$freecounts[$type] = 0;
    }

    # Get free totals by type.
    $query_result =
	DBQueryFatal("select 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 ".
		     "      (nt.class!='shark' and nt.class!='pcRemote' ".
		     "      and nt.class!='pcplabphys') ".
		     "      and r.pid is null ".
		     "group BY n.type");

    while ($row = mysql_fetch_array($query_result)) {
	$type  = $row[0];
	$count = $row[1];

	$freecounts[$type] = $count;
    }

    echo "<center>
          <b>Free Node Summary</b>
          <br>
          <table>
          <tr>
             <th>Type</th>
             <th align=center>Free<br>Nodes</th>
             <th align=center>Total<br>Nodes</th>
          </tr>\n";

    foreach($totals as $key => $value) {
	$freecount = $freecounts[$key];

	# Check perm entry.
	if (isset($perms[$key]) && !$perms[$key])
	    continue;
	
191
192
193
194
195
196
	echo "<tr>\n";
	if ($isadmin)
	    echo "<td><a href=editnodetype.php3?node_type=$key>\n";
	else
	    echo "<td><a href=shownodetype.php3?node_type=$key>\n";
	echo "           $key</a></td>
197
198
199
200
              <td align=center>$freecount</td>
              <td align=center>$value</td>
              </tr>\n";
    }
201
202
203
204
205
    if ($isadmin) {
	# Give admins the option to create a new type
	echo "<th colspan=3><a href=editnodetype.php3?new_type=1>Create a " .
		"new type</a></th>\n";
    }
206
207
208
209
210
    echo "</table>\n";
    PAGEFOOTER();
    exit();
}

211
212
213
#
# Suck out info for all the nodes.
# 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
214
$query_result =
215
    DBQueryFatal("select n.node_id,n.phys_nodeid,n.type,ns.status, ".
216
		 "   n.def_boot_osid,r.pid,r.eid,nt.class,r.vname ".
Chad Barb's avatar
   
Chad Barb committed
217
218
		 "$additionalVariables ".
		 "from nodes as n ".
219
		 "left join node_types as nt on n.type=nt.type ".
220
		 "left join node_status as ns on n.node_id=ns.node_id ".
221
		 "left join reserved as r on n.node_id=r.node_id ".
Chad Barb's avatar
   
Chad Barb committed
222
		 "$additionalLeftJoin ".
223
224
		 "where $role $clause ".
		 "ORDER BY priority");
225
226
227
228
229

if (mysql_num_rows($query_result) == 0) {
    echo "<center>Oops, no nodes to show you!</center>";
    PAGEFOOTER();
}
230

231
#
232
# First count up free nodes as well as status counts.
233
#
234
235
236
237
238
$num_free = 0;
$num_up   = 0;
$num_pd   = 0;
$num_down = 0;
$num_unk  = 0;
239
$freetypes= array();
240

241
242
243
while ($row = mysql_fetch_array($query_result)) {
    $pid                = $row[pid];
    $status             = $row[status];
244
    $type               = $row[type];
245

246
247
248
    if (! isset($freetypes[$type])) {
	$freetypes[$type] = 0;
    }
249
250
251
    if (!$pid) {
	$num_free++;
	$freetypes[$type]++;
252
	continue;
253
    }
254
255
256
257
258
259
260
261
262
263
264
265
266
267
    switch ($status) {
    case "up":
	$num_up++;
	break;
    case "possibly down":
    case "unpingable":
	$num_pd++;
	break;
    case "down":
	$num_down++;
	break;
    default:
	$num_unk++;
	break;
268
269
    }
}
270
$num_total = ($num_free + $num_up + $num_down + $num_pd + $num_unk);
271
272
mysql_data_seek($query_result, 0);

273
274
275
276
277
278
if (! strcmp($showtype, "widearea")) {
    echo "<a href=tutorial/docwrapper.php3?docname=widearea.html>
             Widearea Usage Notes</a>\n";
}

echo "<br><center><b>
279
       View: $view\n";
280
281
282

if (! strcmp($showtype, "widearea")) {
    echo "<br>
283
          <a href=widearea_nodeinfo.php3>(Widearea Link Metrics)</a><br>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
284
          <a href=plabmetrics.php3>(PlanetLab Node Metrics)</a>\n";
285
286
287
}

echo "</b></center><br>\n";
288

289
290
291
SUBPAGESTART();

echo "<table>
292
293
294
       <tr><td align=right>
           <img src='/autostatus-icons/greenball.gif' alt=up>
           <b>Up</b></td>
295
296
           <td align=left>$num_up</td>
       </tr>
297
298
299
       <tr><td align=right nowrap>
           <img src='/autostatus-icons/yellowball.gif' alt='possibly down'>
           <b>Possibly Down</b></td>
300
301
           <td align=left>$num_pd</td>
       </tr>
302
303
304
       <tr><td align=right>
           <img src='/autostatus-icons/blueball.gif' alt=unknown>
           <b>Unknown</b></td>
305
306
           <td align=left>$num_unk</td>
       </tr>
307
308
309
       <tr><td align=right>
           <img src='/autostatus-icons/redball.gif' alt=down>
           <b>Down</b></td>
310
311
           <td align=left>$num_down</td>
       </tr>
312
313
314
       <tr><td align=right>
           <img src='/autostatus-icons/whiteball.gif' alt=free>
           <b>Free</b></td>
315
316
           <td align=left>$num_free</td>
       </tr>
317
318
319
       <tr><td align=right><b>Total</b></td>
           <td align=left>$num_total</td>
       </tr>
320
321
322
323
324
       <tr><td colspan=2 nowrap align=center>
               <b>Free Subtotals</b></td></tr>\n";

foreach($freetypes as $key => $value) {
    echo "<tr>
325
           <td align=right><a href=shownodetype.php3?node_type=$key>
326
                           $key</a></td>
327
328
329
330
           <td align=left>$value</td>
          </tr>\n";
}
echo "</table>\n";
331
332
333
SUBMENUEND_2B();

echo "<table border=2 cellpadding=2 cellspacing=2>\n";
334
335

echo "<tr>
336
337
338
339
340
341
342
          <th align=center>ID</th>\n";

if ($showvnames) {
    echo "<th align=center>Name</th>\n";
}

echo "    <th align=center>Type (Class)</th>
Chad Barb's avatar
   
Chad Barb committed
343
          <th align=center>Up?</th>\n";
344
345

if ($isadmin) {
Chad Barb's avatar
   
Chad Barb committed
346
347
348
    echo "<th align=center>PID</th>
          <th align=center>EID</th>
          <th align=center>Default<br>OSID</th>\n";
349
}
350
351
elseif (strcmp($showtype, "widearea")) {
    # Widearea nodes are always "free"
Chad Barb's avatar
   
Chad Barb committed
352
    echo "<th align=center>Free?</th>\n";
Chad Barb's avatar
   
Chad Barb committed
353
354
355
356
357
358
359
360
}

if (!strcmp($showtype, "widearea")) {
    echo "<th align=center>Processor</th>
	  <th align=center>Connection</th>
	  <th align=center>Location</th>\n";
}
    
361
echo "</tr>\n";
362

363
364
while ($row = mysql_fetch_array($query_result)) {
    $node_id            = $row[node_id]; 
365
    $phys_nodeid        = $row[phys_nodeid]; 
366
    $type               = $row[type];
367
    $class              = $row["class"];
368
    $def_boot_osid      = $row[def_boot_osid];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
369
370
    $pid                = $row[pid];
    $eid                = $row[eid];
371
    $vname              = $row[vname];
372
    $hostname           = $row[hostname];
373
    $status             = $row[status];
374

Chad Barb's avatar
   
Chad Barb committed
375
376
377
378
    if (!strcmp($showtype, "widearea")) {	
	$machine_type = $row[machine_type];
	$location = $row[location];
	$connect_type = $row[connect_type];
379
	$vname        = $row[hostname];
Chad Barb's avatar
   
Chad Barb committed
380
381
    } 

382
    echo "<tr>";
383

384
385
386
387
388
389
    # Admins get a link to expand the node.
    if ($isadmin) {
	echo "<td><A href='shownode.php3?node_id=$node_id'>$node_id</a> " .
	    (!strcmp($node_id, $phys_nodeid) ? "" :
	     "(<A href='shownode.php3?node_id=$phys_nodeid'>$phys_nodeid</a>)")
	    . "</td>\n";
390
391
    }
    else {
392
393
394
	echo "<td>$node_id " .
  	      (!strcmp($node_id, $phys_nodeid) ? "" : "($phys_nodeid)") .
	      "</td>\n";
395
    }
396
397
398
399
400
401
402

    if ($showvnames) {
	if ($vname)
	    echo "<td>$vname</td>\n";
	else
	    echo "<td>--</td>\n";
    }
403
    
404
405
    echo "   <td>$type ($class)</td>\n";

406
407
408
409
    if (!$pid)
	echo "<td align=center>
                  <img src='/autostatus-icons/whiteball.gif' alt=free></td>\n";
    elseif (!$status)
410
411
412
	echo "<td align=center>
                  <img src='/autostatus-icons/blueball.gif' alt=unk></td>\n";
    elseif ($status == "up")
413
414
	echo "<td align=center>
                  <img src='/autostatus-icons/greenball.gif' alt=up></td>\n";
415
    elseif ($status == "down")
416
417
	echo "<td align=center>
                  <img src='/autostatus-icons/redball.gif' alt=down></td>\n";
418
419
420
    else
	echo "<td align=center>
                  <img src='/autostatus-icons/yellowball.gif' alt=unk></td>\n";
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436

    # Admins get pid/eid/vname, but mere users yes/no.
    if ($isadmin) {
	if ($pid) {
	    echo "<td>$pid</td>
                  <td>$eid</td>\n";
	}
	else {
	    echo "<td>--</td>
   	          <td>--</td>\n";
	}
	if ($def_boot_osid && TBOSInfo($def_boot_osid, $osname, $ospid))
	    echo "<td>$osname</td>\n";
	else
	    echo "<td>&nbsp</td>\n";
    }
437
    elseif (strcmp($showtype, "widearea")) {
438
	if ($pid)
439
	    echo "<td>--</td>\n";
440
441
442
	else
	    echo "<td>Yes</td>\n";
    }
Chad Barb's avatar
   
Chad Barb committed
443
444
445
446
447
448

    if (!strcmp($showtype, "widearea")) {	
	echo "<td>$machine_type</td>
	      <td>$connect_type</td>
	      <td><font size='-1'>$location</font></td>\n";
    }
449
    
450
    echo "</tr>\n";
451
452
453
}

echo "</table>\n";
454
SUBPAGEEND();
455
456
457
458
459

#
# Standard Testbed Footer
# 
PAGEFOOTER();
460
461
462
?>