shownodetype.php3 5.56 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2013 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/>.
# 
# }}}
23 24
#
include("defs.php3");
25
include("imageid_defs.php");
26 27 28

#
# Anyone can access this info, its a PUBLIC PAGE!
29
# Get current user if there is one.
30
#
31 32
$this_user = CheckLogin($check_status);
$reqargs   = RequiredPageArguments("node_type", PAGEARG_STRING);
33

Leigh Stoller's avatar
Leigh Stoller committed
34 35 36 37
# Sanitize.
if (!preg_match("/^[-\w]+$/", $node_type)) {
    PAGEARGERROR("Invalid characters in arguments.");
}
38

39 40 41 42 43
#
# Standard Testbed Header
#
PAGEHEADER("Node Type Information");

44 45 46 47 48
$query_result =
    DBQueryFatal("select * from node_types ".
		 "where type='$node_type'");

if (! mysql_num_rows($query_result) != 0) {
49
    USERERROR("No such node_type $node_type!", 1);
50
}
51 52 53 54 55 56 57 58 59 60 61 62 63 64
$noderow = mysql_fetch_array($query_result);

if ($this_user && ISADMIN()) {
    SUBPAGESTART();
    SUBMENUSTART("More Options");
    WRITESUBMENUBUTTON("Edit this type",
		       "editnodetype.php3?node_type=$node_type");
    WRITESUBMENUBUTTON("Create a PC type",
		       "editnodetype.php3?new_type=1&node_class=pc");
    WRITESUBMENUBUTTON("Create a Switch type",
		       "editnodetype.php3?new_type=1&node_class=switch");
    SUBMENUEND();
    SUBPAGEEND();
}
65 66 67 68

echo "<table border=2 cellpadding=0 cellspacing=2
             align=center>\n";

69
# Stuff from the node types table.
70 71 72 73 74 75 76 77 78 79
$class	 = $noderow["class"];
$options = array("isvirtnode",
		 "isdynamic",
		 "isjailed",
		 "isremotenode",
		 "issubnode",
		 "isplabdslice",
		 "isgeninode",
		 "isfednode",
		 "isswitch");
80 81 82 83 84 85 86 87 88 89 90

echo "<tr>
      <td>Type:</td>
      <td class=left>$node_type</td>
          </tr>\n";

echo "<tr>
      <td>Class:</td>
      <td class=left>$class</td>
          </tr>\n";

91 92
foreach ($options as $option) {
    $value = $noderow[$option];
93

94 95 96 97
    if ($value) {
	echo "<tr>
               <td>$option:</td>
               <td class=left>Yes</td>
98
              </tr>\n";
99
    }
100 101
}

102 103 104
#
# And now all of the attributes ...
#
105 106 107 108 109 110 111 112 113 114 115 116
# Grab the attributes for the type.
$query_result = DBQueryFatal("select * from node_type_attributes ".
			     "where type='$node_type' ".
			     "order by attrkey");
if (mysql_num_rows($query_result)) {
    echo "<tr></tr>\n";

    while ($row = mysql_fetch_array($query_result)) {
	$key      = $row["attrkey"];
	$val      = $row["attrvalue"];
	$attrtype = $row["attrtype"];
	
117
	if (preg_match("/_osid$/", $key)) {
118
	    if ($osinfo = OSinfo::Lookup($val)) {
119 120
		$name = $osinfo->osname();
		$val = "<a href=showosinfo.php3?osid=$val>$name</a>";
121
	    }
122
	}
123
	elseif ($key == "default_imageid") {
124 125 126
	    $inames = array();
	    foreach (explode(',', $val) as $imageid) {
		if ($image = Image::Lookup($imageid)) {
127 128
		    $name = $image->imagename();
		    $inames[] = "<a href=showimageid.php3?imageid=$imageid>$name</a>";
129
		}
130
	    }
131
	    $val = implode(',', $inames);
132
	}
133 134 135 136
	echo "<tr>\n";
	echo "<td>$key:</td>\n";
	echo "<td class=left>$val</td>\n";
	echo "</tr>\n";
137
    }
138
    echo "</table>\n";
139
}
140

Leigh Stoller's avatar
Leigh Stoller committed
141 142
#
# Suck out info for all the nodes of this type. We are going to show
143 144 145
# just a list of dots, in two color mode.  Note, we also check that the
# physical node is free, see note in nodecontrol_list.php3 for why.
#
Leigh Stoller's avatar
Leigh Stoller committed
146
$query_result =
147
    DBQueryFatal("select n.node_id,n.eventstate,ifnull(r.pid,rp.pid) as pid ".
Leigh Stoller's avatar
Leigh Stoller committed
148 149 150
		 "from nodes as n ".
		 "left join node_types as nt on n.type=nt.type ".
		 "left join reserved as r on n.node_id=r.node_id ".
151
		 "left join reserved as rp on n.phys_nodeid=rp.node_id ".
Leigh Stoller's avatar
Leigh Stoller committed
152 153 154 155 156 157 158 159
		 "where nt.type='$node_type' and ".
		 "      (role='testnode' or role='virtnode') ".
		 "ORDER BY priority");


if (mysql_num_rows($query_result)) {
    echo "<br>
          <center>
160 161
	  Nodes (<a href=nodecontrol_list.php3?showtype=$node_type>Show details</a>)
	  <br>
Leigh Stoller's avatar
Leigh Stoller committed
162 163 164 165 166 167 168
          <table class=nogrid cellspacing=0 border=0 cellpadding=5>\n";

    $maxcolumns = 4;
    $column     = 0;
    
    while ($row = mysql_fetch_array($query_result)) {
	$node_id = $row["node_id"];
169
	$es      = $row["eventstate"];
Leigh Stoller's avatar
Leigh Stoller committed
170 171 172 173 174 175 176 177 178 179
	$pid     = $row["pid"];

	if ($column == 0) {
	    echo "<tr>\n";
	}
	$column++;

	echo "<td align=left><nobr>\n";

	if (!$pid) {
180 181 182 183 184 185 186 187 188
	    if (($es == TBDB_NODESTATE_ISUP) ||
		($es == TBDB_NODESTATE_ALWAYSUP) ||
		($es == TBDB_NODESTATE_POWEROFF) ||
		($es == TBDB_NODESTATE_PXEWAIT)) {
		echo "<img src=\"/autostatus-icons/greenball.gif\" alt=free>\n";
	    }
	    else {
		echo "<img src=\"/autostatus-icons/yellowball.gif\" alt='unusable free'>\n";
	    }
Leigh Stoller's avatar
Leigh Stoller committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
	}
	else {
	    echo "<img src=\"/autostatus-icons/redball.gif\" alt=reserved>\n";
	}
	echo "&nbsp;";
#	echo "<a href=shownode.php3?node_id=$node_id>";
	echo "$node_id";
#	echo "</a>";
	echo "</nobr>
              </td>\n";
	
	if ($column == $maxcolumns) {
	    echo "</tr>\n";
	    $column = 0;
	}
    }
    echo "</table>\n";
    echo "<br>
          <img src=\"/autostatus-icons/greenball.gif\" alt=free>&nbsp;Free
208
          &nbsp; &nbsp; &nbsp;
Leigh Stoller's avatar
Leigh Stoller committed
209 210 211 212
          <img src=\"/autostatus-icons/redball.gif\" alt=free>&nbsp;Reserved
          </center>\n";
}

213 214 215 216 217 218 219 220 221
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>