shownodetype.php3 5.75 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2016 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 93 94 95 96 97 98
if (isset($noderow["architecture"])) {
    $arch = $noderow["architecture"];
    echo "<tr>
            <td>Architecture:</td>
            <td class=left>$arch</td>
          </tr>\n";
}

99 100
foreach ($options as $option) {
    $value = $noderow[$option];
101

102 103 104 105
    if ($value) {
	echo "<tr>
               <td>$option:</td>
               <td class=left>Yes</td>
106
              </tr>\n";
107
    }
108 109
}

110 111 112
#
# And now all of the attributes ...
#
113 114 115 116 117 118 119 120 121 122 123 124
# 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"];
	
125
	if (preg_match("/_osid$/", $key)) {
126
	    if ($osinfo = OSinfo::Lookup($val)) {
127 128
		$name = $osinfo->osname();
		$val = "<a href=showosinfo.php3?osid=$val>$name</a>";
129
	    }
130
	}
131
	elseif ($key == "default_imageid") {
132 133 134
	    $inames = array();
	    foreach (explode(',', $val) as $imageid) {
		if ($image = Image::Lookup($imageid)) {
135 136
		    $name = $image->imagename();
		    $inames[] = "<a href=showimageid.php3?imageid=$imageid>$name</a>";
137
		}
138
	    }
139
	    $val = implode(',', $inames);
140
	}
141 142 143 144
	echo "<tr>\n";
	echo "<td>$key:</td>\n";
	echo "<td class=left>$val</td>\n";
	echo "</tr>\n";
145
    }
146
    echo "</table>\n";
147
}
148

Leigh Stoller's avatar
Leigh Stoller committed
149 150
#
# Suck out info for all the nodes of this type. We are going to show
151 152 153
# 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
154
$query_result =
155
    DBQueryFatal("select n.node_id,n.eventstate,ifnull(r.pid,rp.pid) as pid ".
Leigh Stoller's avatar
Leigh Stoller committed
156 157 158
		 "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 ".
159
		 "left join reserved as rp on n.phys_nodeid=rp.node_id ".
Leigh Stoller's avatar
Leigh Stoller committed
160 161 162 163 164 165 166 167
		 "where nt.type='$node_type' and ".
		 "      (role='testnode' or role='virtnode') ".
		 "ORDER BY priority");


if (mysql_num_rows($query_result)) {
    echo "<br>
          <center>
168 169
	  Nodes (<a href=nodecontrol_list.php3?showtype=$node_type>Show details</a>)
	  <br>
Leigh Stoller's avatar
Leigh Stoller committed
170 171 172 173 174 175 176
          <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"];
177
	$es      = $row["eventstate"];
Leigh Stoller's avatar
Leigh Stoller committed
178 179 180 181 182 183 184 185 186 187
	$pid     = $row["pid"];

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

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

	if (!$pid) {
188 189 190 191 192 193 194 195 196
	    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
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
	}
	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
216
          &nbsp; &nbsp; &nbsp;
Leigh Stoller's avatar
Leigh Stoller committed
217 218 219 220
          <img src=\"/autostatus-icons/redball.gif\" alt=free>&nbsp;Reserved
          </center>\n";
}

221 222 223 224 225 226 227 228 229
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>