uid(); $isadmin = ISADMIN(); # # Verify page arguments. # $optargs = OptionalPageArguments("target_user", PAGEARG_USER, "showtype", PAGEARG_STRING, "bypid", PAGEARG_STRING); if (isset($target_user)) { if (! $target_user->AccessCheck($this_user, $TB_USERINFO_READINFO)) { USERERROR("You do not have permission to do this!", 1); } $target_uid = $target_user->uid(); $target_idx = $target_user->uid_idx(); } else { $target_uid = $uid; $target_idx = $this_user->uid_idx(); $target_user = $this_user; } echo "Show: summary, pcs, wireless maps, GNU USRP (software defined radio) maps, wireless list, robot maps, widearea"; if ($isadmin) { echo ", utilization, virtual, physical, all"; } echo ".
\n"; if (!isset($showtype)) { $showtype='summary'; } $additionalVariables = ""; $additionalLeftJoin = ""; if (! strcmp($showtype, "summary")) { # Separate query below. $role = ""; $clause = ""; $view = "Free Node Summary"; } elseif (! strcmp($showtype, "all")) { $role = "(role='testnode' or role='virtnode')"; $clause = ""; $view = "All"; } elseif (! strcmp($showtype, "pcs")) { $role = "(role='testnode')"; $clause = "and (nt.class='pc')"; $view = "PCs"; } elseif (! strcmp($showtype, "sharks")) { $role = "(role='testnode')"; $clause = "and (nt.class='shark')"; $view = "Sharks"; } elseif (! strcmp($showtype, "virtnodes")) { $role = "(role='virtnode')"; $clause = ""; $view = "Virtual Nodes"; } elseif (! strcmp($showtype, "physical")) { $role = ""; $clause = "(nt.isvirtnode=0)"; $view = "Physical Nodes"; } elseif (! strcmp($showtype, "widearea")) { $role = "(role='testnode')"; $clause = "and (nt.isremotenode=1)"; $additionalVariables = ",". "wani.machine_type,". "REPLACE(CONCAT_WS(', ',". "wani.city,wani.state,wani.country,wani.zip), ". "'USA, ','')". "AS location, ". "wani.connect_type, ". "wani.hostname, " . "wani.site"; $additionalLeftJoin = "LEFT JOIN widearea_nodeinfo AS wani ". "ON n.node_id=wani.node_id"; $view = "Widearea"; } elseif (! strcmp($showtype, "wireless")) { $role = "(role='testnode')"; $clause = "and (loc.node_id is not null)"; $additionalLeftJoin = "LEFT JOIN location_info AS loc ". "ON n.node_id=loc.node_id"; $view = "Wireless"; } else { $role = "(role='testnode')"; $clause = "and (nt.class='pc')"; $view = "PCs"; } # If admin or widearea, show the vname too. $showvnames = 0; if ($isadmin || !strcmp($showtype, "widearea")) { $showvnames = 1; } # # 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 || isset($bypid)) { $query_result = DBQueryFatal("select type from nodetypeXpid_permissions"); while ($row = mysql_fetch_array($query_result)) { $perms{$row[0]} = 0; } $pidclause = ""; if (isset($bypid)) { if ($bypid == "" || !TBvalid_pid($bypid)) { PAGEARGERROR("Invalid characters in 'bypid' argument!"); } if (! ($target_project = Project::Lookup($bypid))) { PAGEARGERROR("No such project '$bypid'!"); } if (!$target_project->AccessCheck($this_user, $TB_PROJECT_READINFO)){ USERERROR("You are not a member of project '$bypid!", 1); } $pidclause = "and g.pid='$bypid'"; } if ($isadmin) { $query_result = DBQueryFatal("select distinct type ". " from nodetypeXpid_permissions ". "where pid='$bypid'"); } else { $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='$target_idx' $pidclause"); } 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"); $alltotal = 0; $allfree = 0; $allunknown = 0; $totals = array(); $freecounts = array(); $unknowncounts = array(); while ($row = mysql_fetch_array($query_result)) { $type = $row[0]; $count = $row[1]; $totals[$type] = $count; $freecounts[$type] = 0; $unknowncounts[$type] = 0; } # 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 ". " (nt.class!='shark' and nt.class!='pcRemote' ". " and nt.class!='pcplabphys') ". " and r.pid is null and n.reserved_pid is null ". "group BY n.eventstate,n.type"); while ($row = mysql_fetch_array($query_result)) { $type = $row[1]; $count = $row[2]; # XXX Yeah, I'm a doofus and can't figure out how to do this in SQL. if (($row[0] == TBDB_NODESTATE_ISUP) || ($row[0] == TBDB_NODESTATE_PXEWAIT) || ($row[0] == TBDB_NODESTATE_ALWAYSUP) || ($row[0] == TBDB_NODESTATE_POWEROFF)) { $freecounts[$type] += $count; } else { $unknowncounts[$type] += $count; } } $projlist = $target_user->ProjectAccessList($TB_PROJECT_CREATEEXPT); if (count($projlist) > 1) { echo "By Project Permission: "; while (list($project) = each($projlist)) { echo "$project,\n"; } echo "". "combined membership.\n"; echo "
\n"; } echo "
Free Node Summary
\n"; if (isset($bypid)) { echo "($bypid)

\n"; } echo "\n"; foreach($totals as $key => $value) { $freecount = $freecounts[$key]; # Check perm entry. if (isset($perms[$key]) && !$perms[$key]) continue; $allfree += $freecount; $allunknown += $unknowncounts[$key]; $alltotal += $value; if ($unknowncounts[$key]) $ast = "*"; else $ast = ""; echo "\n"; if ($isadmin) echo "\n"; } echo "\n"; echo "\n"; if ($isadmin) { # Give admins the option to create a new type echo "\n"; echo "\n"; } echo "
Type Free
Nodes
Total
Nodes
\n"; else echo "\n"; echo " $key ${freecount}${ast} $value
Totals $allfree $alltotal
Create a new type
\n"; if ($allunknown > 0) { echo "
* - Some nodes ($allunknown) are ". "free, but currently in an unallocatable state."; } PAGEFOOTER(); exit(); } # # Suck out info for all the nodes. # $query_result = DBQueryFatal("select distinct n.node_id,n.phys_nodeid,n.type,ns.status, ". " n.def_boot_osid,r.pid,r.eid,nt.class,r.vname ". "$additionalVariables ". "from nodes as n ". "left join node_types as nt on n.type=nt.type ". "left join node_status as ns on n.node_id=ns.node_id ". "left join reserved as r on n.node_id=r.node_id ". "$additionalLeftJoin ". "where $role $clause ". "ORDER BY priority"); if (mysql_num_rows($query_result) == 0) { echo "
Oops, no nodes to show you!
"; PAGEFOOTER(); exit(); } # # First count up free nodes as well as status counts. # $num_free = 0; $num_up = 0; $num_pd = 0; $num_down = 0; $num_unk = 0; $freetypes= array(); while ($row = mysql_fetch_array($query_result)) { $pid = $row["pid"]; $status = $row["status"]; $type = $row["type"]; if (! isset($freetypes[$type])) { $freetypes[$type] = 0; } if (!$pid) { $num_free++; $freetypes[$type]++; continue; } switch ($status) { case "up": $num_up++; break; case "possibly down": case "unpingable": $num_pd++; break; case "down": $num_down++; break; default: $num_unk++; break; } } $num_total = ($num_free + $num_up + $num_down + $num_pd + $num_unk); mysql_data_seek($query_result, 0); if (! strcmp($showtype, "widearea")) { echo " Widearea Usage Notes\n"; } echo "
View: $view\n"; if (! strcmp($showtype, "widearea")) { echo "
(Widearea Link Metrics)
(PlanetLab Node Metrics)\n"; } echo "

\n"; SUBPAGESTART(); echo "\n"; foreach($freetypes as $key => $value) { echo "\n"; } echo "
up Up $num_up
possibly down Possibly Down $num_pd
unknown Unknown $num_unk
down Down $num_down
free Free $num_free
Total $num_total
Free Subtotals
$key $value
\n"; SUBMENUEND_2B(); echo "\n"; echo ""; echo "\n"; if ($showvnames) { echo "\n"; } echo " \n"; if ($isadmin) { echo "\n"; } elseif (strcmp($showtype, "widearea")) { # Widearea nodes are always "free" echo "\n"; } if (!strcmp($showtype, "widearea")) { echo ""; } echo "\n"; while ($row = mysql_fetch_array($query_result)) { $node_id = $row["node_id"]; $phys_nodeid = $row["phys_nodeid"]; $type = $row["type"]; $class = $row["class"]; $def_boot_osid = $row["def_boot_osid"]; $pid = $row["pid"]; $eid = $row["eid"]; $vname = $row["vname"]; $status = $row["status"]; if (!strcmp($showtype, "widearea")) { $site = $row["site"]; $machine_type = $row["machine_type"]; $location = $row["location"]; $connect_type = $row["connect_type"]; $vname = $row["hostname"]; } echo ""; # Admins get a link to expand the node. if ($isadmin || (OPSGUY() && (!$pid || $pid == $TBOPSPID))) { echo "\n"; } else { echo "\n"; } if ($showvnames) { if ($vname) echo "\n"; else echo "\n"; } echo " \n"; if (!$pid) echo "\n"; elseif (!$status) echo "\n"; elseif ($status == "up") echo "\n"; elseif ($status == "down") echo "\n"; else echo "\n"; # Admins get pid/eid/vname, but mere users yes/no. if ($isadmin) { if ($pid) { echo "\n"; } else { echo "\n"; } if ($def_boot_osid && ($osinfo = OSinfo::Lookup($def_boot_osid))) { $osname = $osinfo->osname(); echo "\n"; } else echo "\n"; } elseif (strcmp($showtype, "widearea")) { if ($pid) echo "\n"; else echo "\n"; } if (!strcmp($showtype, "widearea")) { echo "\n"; } echo "\n"; } echo "
IDNameType (Class) Up?PID EID Default
OSID
Free?Site Processor Connection Location
$node_id " . (!strcmp($node_id, $phys_nodeid) ? "" : "($phys_nodeid)") . "$node_id " . (!strcmp($node_id, $phys_nodeid) ? "" : "($phys_nodeid)") . "$vname--$type ($class) free unk up down unk$pid $eid-- --$osname --Yes$site $machine_type $connect_type $location
\n"; echo "\n"; SUBPAGEEND(); # # Standard Testbed Footer # PAGEFOOTER(); ?>