Commit 84165f33 authored by Leigh Stoller's avatar Leigh Stoller

Various web page changes to deal with image versions.

parent 8dde9408
......@@ -81,7 +81,7 @@ while ($row = mysql_fetch_array($types_result)) {
$types_array[] = "pcvm";
$osid_result =
DBQueryFatal("select o.osid,o.osname,o.pid from os_info as o ".
DBQueryFatal("select o.osid,v.vers,o.osname,o.pid from os_info as o ".
"left join os_info_versions as v on ".
" v.osid=o.osid and v.vers=o.version ".
"where (v.path='' or v.path is NULL) ".
......@@ -196,7 +196,7 @@ function SPITFORM($image, $formfields, $errors)
<td>Partition 1 OS: </td>
<td class=\"left\">";
if (isset($defaults["part1_osid"]))
SpitOSIDLink($defaults["part1_osid"]);
SpitOSIDLink($defaults["part1_osid"], $defaults["part1_vers"]);
else
echo "No OS";
echo " </td>
......@@ -206,7 +206,7 @@ function SPITFORM($image, $formfields, $errors)
<td>Partition 2 OS: </td>
<td class=\"left\">";
if (isset($defaults["part2_osid"]))
SpitOSIDLink($defaults["part2_osid"]);
SpitOSIDLink($defaults["part2_osid"], $defaults["part2_vers"]);
else
echo "No OS";
echo " </td>
......@@ -216,7 +216,7 @@ function SPITFORM($image, $formfields, $errors)
<td>Partition 3 OS: </td>
<td class=\"left\">";
if (isset($defaults["part3_osid"]))
SpitOSIDLink($defaults["part3_osid"]);
SpitOSIDLink($defaults["part3_osid"], $defaults["part3_vers"]);
else
echo "No OS";
echo " </td>
......@@ -226,7 +226,7 @@ function SPITFORM($image, $formfields, $errors)
<td>Partition 4 OS: </td>
<td class=\"left\">";
if (isset($defaults["part4_osid"]))
SpitOSIDLink($defaults["part4_osid"]);
SpitOSIDLink($defaults["part4_osid"], $defaults["part4_vers"]);
else
echo "No OS";
echo " </td>
......@@ -236,7 +236,7 @@ function SPITFORM($image, $formfields, $errors)
<td>Boot OS: </td>
<td class=\"left\">";
if (isset($defaults["default_osid"]))
SpitOSIDLink($defaults["default_osid"]);
SpitOSIDLink($defaults["default_osid"], $defaults["default_vers"]);
else
echo "No OS";
echo " </td>
......
......@@ -34,6 +34,9 @@ class Image
# Constructor by lookup on unique ID
#
function Image($id, $version = NULL) {
if (is_null($version)) {
list($id,$version) = preg_split('/:/', $id);
}
$safe_id = addslashes($id);
if (is_null($version)) {
......@@ -83,7 +86,7 @@ class Image
}
# Lookup by imageid
function Lookup($id,$version = NULL) {
function Lookup($id, $version = NULL) {
$foo = new Image($id,$version);
if (! $foo->IsValid())
......@@ -396,7 +399,12 @@ class Image
function part2_osid() { return $this->field("part2_osid"); }
function part3_osid() { return $this->field("part3_osid"); }
function part4_osid() { return $this->field("part4_osid"); }
function part1_vers() { return $this->field("part1_vers"); }
function part2_vers() { return $this->field("part2_vers"); }
function part3_vers() { return $this->field("part3_vers"); }
function part4_vers() { return $this->field("part4_vers"); }
function default_osid() { return $this->field("default_osid"); }
function default_vers() { return $this->field("default_vers"); }
function path() { return $this->field("path"); }
function magic() { return $this->field("magic"); }
function ezid() { return $this->field("ezid"); }
......@@ -573,7 +581,12 @@ class Image
$part2_osid = $this->part2_osid();
$part3_osid = $this->part3_osid();
$part4_osid = $this->part4_osid();
$part1_vers = $this->part1_vers();
$part2_vers = $this->part2_vers();
$part3_vers = $this->part3_vers();
$part4_vers = $this->part4_vers();
$default_osid = $this->default_osid();
$default_vers = $this->default_vers();
$path = $this->path();
$shared = $this->shared();
$globalid = $this->isglobal();
......@@ -707,7 +720,7 @@ class Image
echo "<tr>
<td>Partition 1 OS: </td>
<td class=\"left\">";
SpitOSIDLink($part1_osid);
SpitOSIDLink($part1_osid, $part1_vers);
echo " </td>
</tr>\n";
}
......@@ -716,7 +729,7 @@ class Image
echo "<tr>
<td>Partition 2 OS: </td>
<td class=\"left\">";
SpitOSIDLink($part2_osid);
SpitOSIDLink($part2_osid, $part2_vers);
echo " </td>
</tr>\n";
}
......@@ -725,7 +738,7 @@ class Image
echo "<tr>
<td>Partition 3 OS: </td>
<td class=\"left\">";
SpitOSIDLink($part3_osid);
SpitOSIDLink($part3_osid, $part3_vers);
echo " </td>
</tr>\n";
}
......@@ -734,7 +747,7 @@ class Image
echo "<tr>
<td>Partition 4 OS: </td>
<td class=\"left\">";
SpitOSIDLink($part4_osid);
SpitOSIDLink($part4_osid, $part4_vers);
echo " </td>
</tr>\n";
}
......@@ -743,7 +756,7 @@ class Image
echo "<tr>
<td>Boot OS: </td>
<td class=\"left\">";
SpitOSIDLink($default_osid);
SpitOSIDLink($default_osid, $default_vers);
echo " </td>
</tr>\n";
}
......@@ -854,7 +867,7 @@ class Image
}
if ($this->ezid()) {
$doesxen = 0;
$osinfo = OSinfo::Lookup($imageid);
$osinfo = $this->OSinfo();
if ($osinfo && $osinfo->def_parentosid()) {
$parentosinfo = OSinfo::Lookup($osinfo->def_parentosid());
if ($parentosinfo &&
......@@ -1040,4 +1053,7 @@ class Image
return $html;
}
function OSinfo() {
return OSinfo::Lookup($this->imageid(), $this->version());
}
}
......@@ -70,19 +70,19 @@ if (isset($node)) {
# of having the user figure it out. Note that only makes sense for
# EZ images.
#
$baseimage = Image::Lookup($node->def_boot_osid());
$baseimage = $node->def_boot_image();
#
# Try for at least an osinfo if no image.
#
if (! $baseimage) {
$baseosinfo = OSinfo::Lookup($node->def_boot_osid());
$baseosinfo = $node->def_boot_osinfo();
}
else {
$baseosinfo = OSinfo::Lookup($baseimage->imageid());
$baseosinfo = $baseimage->OSinfo();
}
}
elseif (isset($baseimage)) {
$baseosinfo = OSinfo::Lookup($baseimage->imageid());
$baseosinfo = $baseimage->OSinfo();
}
elseif ($ec2) {
$imagetype = "xen";
......@@ -922,7 +922,7 @@ if (!isset($submit)) {
# Use the base image to seed the form.
#
if (isset($baseimage)) {
$baseosinfo = OSinfo::Lookup($baseimage->imageid());
$baseosinfo = $baseimage->OSinfo();
if (! $baseosinfo) {
TBERROR("Could not lookup osinfo object for image " .
$baseimage->imageid(), 1);
......
......@@ -144,10 +144,13 @@ class Node
function phys_nodeid() {return $this->field("phys_nodeid"); }
function role() {return $this->field("role"); }
function def_boot_osid() {return $this->field("def_boot_osid"); }
function def_boot_osid_vers() {return $this->field("def_boot_osid_vers"); }
function def_boot_path() {return $this->field("def_boot_path"); }
function def_boot_cmd_line() {return $this->field("def_boot_cmd_line"); }
function temp_boot_osid() {return $this->field("temp_boot_osid"); }
function temp_boot_osid_vers() {return $this->field("temp_boot_osid_vers");}
function next_boot_osid() {return $this->field("next_boot_osid"); }
function next_boot_osid_vers() {return $this->field("next_boot_osid_vers");}
function next_boot_path() {return $this->field("next_boot_path"); }
function next_boot_cmd_line() {return $this->field("next_boot_cmd_line"); }
function pxe_boot_path() {return $this->field("pxe_boot_path"); }
......@@ -186,6 +189,15 @@ class Node
function boot_errno() {return $this->field("boot_errno"); }
function reserved_pid() {return $this->field("reserved_pid"); }
function def_boot_image() {
return Image::Lookup($this->def_boot_osid(),
$this->def_boot_osid_vers());
}
function def_boot_osinfo() {
return OSinfo::Lookup($this->def_boot_osid(),
$this->def_boot_osid_vers());
}
#
# Access Check, determines if $user can access $this record.
#
......@@ -515,9 +527,12 @@ class Node
$pid = $row["pid"];
$eid = $row["eid"];
$def_boot_osid = $row["def_boot_osid"];
$def_boot_osid_vers = $row["def_boot_osid_vers"];
$def_boot_cmd_line = $row["def_boot_cmd_line"];
$next_boot_osid = $row["next_boot_osid"];
$next_boot_osid_vers= $row["next_boot_osid_vers"];
$temp_boot_osid = $row["temp_boot_osid"];
$temp_boot_osid_vers= $row["temp_boot_osid_vers"];
$next_boot_cmd_line = $row["next_boot_cmd_line"];
$rpms = $row["rpms"];
$tarballs = $row["tarballs"];
......@@ -687,7 +702,7 @@ class Node
echo "<tr>
<td>Def Boot OS:</td>
<td class=left>";
SpitOSIDLink($def_boot_osid);
SpitOSIDLink($def_boot_osid, $def_boot_osid_vers);
echo " </td>
</tr>\n";
......@@ -828,7 +843,7 @@ class Node
<td class=left>";
if ($next_boot_osid)
SpitOSIDLink($next_boot_osid);
SpitOSIDLink($next_boot_osid, $next_boot_osid_vers);
else
echo "&nbsp;";
......@@ -845,7 +860,7 @@ class Node
<td class=left>";
if ($temp_boot_osid)
SpitOSIDLink($temp_boot_osid);
SpitOSIDLink($temp_boot_osid, $temp_boot_osid_vers);
else
echo "&nbsp;";
......
......@@ -87,7 +87,9 @@ if (($resrow = $node->ReservedTableEntry())) {
if ($isadmin) {
$osid_result =
DBQueryFatal("select o.osname, o.pid, o.osid as oosid, " .
"p.osid as posid from os_info as o ".
" o.vers as overs, " .
" p.osid as posid, p.osid_vers as pvers ".
" from os_info_versions as o ".
"left join partitions as p on o.osid=p.osid ".
"where p.node_id='$node_id' or ".
"(o.path!='' and o.path is not NULL) ".
......@@ -98,7 +100,9 @@ else {
$osid_result =
DBQueryFatal("select distinct o.osname, o.pid, o.osid as oosid," .
"p.osid as posid from os_info as o ".
" o.vers as overs, " .
" p.osid as posid, p.osid_vers as pvers ".
"from os_info_versions as o ".
"left join group_membership as m on m.pid=o.pid ".
"left join partitions as p on o.osid=p.osid ".
"where p.node_id='$node_id' or ".
......@@ -140,29 +144,34 @@ echo "<tr>
<td>*Def Boot OS:</td>";
echo " <td><select name=def_boot_osid>\n";
if ($def_boot_osid &&
($osinfo = OSinfo::Lookup($def_boot_osid))) {
($osinfo = $node->def_boot_osinfo())) {
$osname = $osinfo->osname();
$vers = $osinfo->vers();
$pid = $osinfo->pid();
echo "<option selected value='$def_boot_osid'>$pid - $osname </option>\n";
echo "<option selected value='$def_boot_osid:$vers'>$pid - $osname </option>\n";
}
while ($row = mysql_fetch_array($osid_result)) {
$osname = $row["osname"];
$oosid = $row["oosid"];
$overs = $row["overs"];
$posid = $row["posid"];
$pvers = $row["pvers"];
$pid = $row["pid"];
# Use the osid that came from the partitions table, if there
# was one - otherwise, go with the os_info table
if ($posid) {
$osid = $posid;
$vers = $pvers;
} else {
$osid = $oosid;
$vers = $overs;
}
if ($def_boot_osid == $osid) {
continue;
}
echo "<option value=$osid>$pid - $osname</option>\n";
echo "<option value='$osid:$vers'>$pid - $osname</option>\n";
}
if ($isadmin) {
echo "<option value=\"\">No OS</option>\n";
......@@ -189,23 +198,27 @@ if ($isadmin) {
while ($row = mysql_fetch_array($osid_result)) {
$osname = $row["osname"];
$oosid = $row["oosid"];
$overs = $row["overs"];
$posid = $row["posid"];
$pvers = $row["pvers"];
$pid = $row["pid"];
# Use the osid that came from the partitions table, if there
# was one - otherwise, go with the os_info table
if ($posid) {
$osid = $posid;
$vers = $pvers;
}
else {
$osid = $oosid;
$vers = $overs;
}
echo "<option ";
if ($next_boot_osid == $osid) {
echo "selected ";
}
echo "value=\"$osid\">$pid - $osname</option>\n";
echo "value='$osid:$vers'>$pid - $osname</option>\n";
}
echo " </select>";
echo " </td>
......@@ -228,23 +241,27 @@ if ($isadmin) {
while ($row = mysql_fetch_array($osid_result)) {
$osname = $row["osname"];
$oosid = $row["oosid"];
$overs = $row["overs"];
$posid = $row["posid"];
$pvers = $row["pvers"];
$pid = $row["pid"];
# Use the osid that came from the partitions table, if there
# was one - otherwise, go with the os_info table
if ($posid) {
$osid = $posid;
$vers = $pvers;
}
else {
$osid = $oosid;
$vers = $pvers;
}
echo "<option ";
if ($temp_boot_osid == $osid) {
echo "selected ";
}
echo "value=\"$osid\">$pid - $osname</option>\n";
echo "value='$osid:$vers'>$pid - $osname</option>\n";
}
echo " </select>";
echo " </td>
......
......@@ -29,14 +29,27 @@ class OSinfo
#
# Constructor by lookup on unique ID
#
function OSinfo($id) {
function OSinfo($id, $version = NULL) {
if (is_null($version)) {
list($id,$version) = preg_split('/:/', $id);
}
$safe_id = addslashes($id);
$query_result =
DBQueryWarn("select o.*,v.* from os_info as o ".
"left join os_info_versions as v on ".
" v.osid=o.osid and v.vers=o.version ".
"where o.osid='$safe_id'");
if (is_null($version)) {
$query_result =
DBQueryWarn("select o.*,v.* from os_info as o ".
"left join os_info_versions as v on ".
" v.osid=o.osid and v.vers=o.version ".
"where o.osid='$safe_id'");
}
else {
# This will get deleted images, but that is okay.
$safe_version = addslashes($version);
$query_result =
DBQueryWarn("select v.* from os_info_versions as v ".
"where v.osid='$safe_id' and ".
" v.vers='$safe_version'");
}
if (!$query_result || !mysql_num_rows($query_result)) {
$this->osinfo = NULL;
......@@ -51,8 +64,8 @@ class OSinfo
}
# Lookup by osid
function Lookup($id) {
$foo = new OSinfo($id);
function Lookup($id, $version = NULL) {
$foo = new OSinfo($id, $version);
if (! $foo->IsValid())
return null;
......@@ -675,9 +688,9 @@ class OSinfo
#
# Spit out an OSID link in user format.
#
function SpitOSIDLink($osid)
function SpitOSIDLink($osid, $vers)
{
$osinfo = OSInfo::Lookup($osid);
$osinfo = OSInfo::Lookup($osid, $vers);
if ($osinfo) {
$osname = $osinfo->osname();
......
......@@ -109,10 +109,10 @@ echo "<br>\n";
# get the pid and osname for the image, and use that to look into the
# virt_nodes table.
#
function SHOWIT($osid) {
function SHOWIT($osid, $vers) {
global $this_user;
if (! ($osinfo = OSinfo::Lookup($osid))) {
if (! ($osinfo = OSinfo::Lookup($osid, $vers))) {
TBERROR("Could not map osid to its object: $osid", 1);
}
echo "<h3 align='center'>Experiments using OS ";
......@@ -123,16 +123,16 @@ function SHOWIT($osid) {
}
if ($image->part1_osid()) {
SHOWIT($image->part1_osid());
SHOWIT($image->part1_osid(), $image->part1_vers());
}
if ($image->part2_osid()) {
SHOWIT($image->part2_osid());
SHOWIT($image->part2_osid(), $image->part2_vers());
}
if ($image->part3_osid()) {
SHOWIT($image->part3_osid());
SHOWIT($image->part3_osid(), $image->part3_vers());
}
if ($image->part4_osid()) {
SHOWIT($image->part4_osid());
SHOWIT($image->part4_osid(), $image->part4_vers());
}
SUBPAGEEND();
......
<?php
#
# Copyright (c) 2000-2013 University of Utah and the Flux Group.
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -133,13 +133,14 @@ if ($isadmin ||
}
if ($node->AccessCheck($this_user, $TB_NODEACCESS_LOADIMAGE)) {
$baseimage = Image::Lookup($node->def_boot_osid());
$baseimage = $node->def_boot_image();
if ($baseimage &&
$baseimage->AccessCheck($this_user, $TB_IMAGEID_DESTROY)) {
WRITESUBMENUBUTTON("Create a Disk Image",
"loadimage.php3?target=$node_id" .
"&imageid=" . $baseimage->imageid());
"&imageid=" . $baseimage->imageid() .
"&version=" . $baseimage->version());
}
else {
#
......
......@@ -257,6 +257,7 @@ function SHOWNODES($pid, $eid, $sortby, $showclass) {
$wasite = $row["site"];
$wahost = $row["hostname"];
$def_boot_osid = $row["def_boot_osid"];
$def_boot_osid_vers = $row["def_boot_osid_vers"];
$startstatus = $row["startstatus"];
$status = $row["nodestatus"];
$bootstate = $row["eventstate"];
......@@ -310,7 +311,7 @@ function SHOWNODES($pid, $eid, $sortby, $showclass) {
echo " <td>$type</td>\n";
if ($def_boot_osid) {
echo "<td>";
SPITOSINFOLINK($def_boot_osid);
SPITOSINFOLINK($def_boot_osid, $def_boot_osid_vers);
echo "</td>\n";
}
else
......@@ -406,14 +407,14 @@ function SHOWNODES($pid, $eid, $sortby, $showclass) {
#
# Spit out an OSID link in user format.
#
function SPITOSINFOLINK($osid)
function SPITOSINFOLINK($osid, $version)
{
if (! ($osinfo = OSinfo::Lookup($osid)))
if (! ($osinfo = OSinfo::Lookup($osid, $version)))
return;
$osname = $osinfo->osname();
echo "<a href='showosinfo.php3?osid=$osid'>$osname</a>\n";
echo "<a href='showosinfo.php3?osid=$osid&version=$version'>$osname</a>\n";
}
#
......
......@@ -295,14 +295,22 @@ function CreateURL($page_id)
case URLARG_IMAGEID:
$key = "imageid";
if (is_a($val, 'Image')) {
$val = $val->imageid();
$str = $val->imageid();
if (1 || $val->version()) {
$str .= ":" . $val->version();
}
$val = $str;
}
$val = rawurlencode($val);
break;
case URLARG_OSID:
$key = "osid";
if (is_a($val, 'OSinfo')) {
$val = $val->osid();
$str = $val->osid();
if (1 || $val->vers()) {
$str .= ":" . $val->vers();
}
$val = $str;
}
$val = rawurlencode($val);
break;
......@@ -582,12 +590,17 @@ function VerifyPageArguments($argspec, $required)
break;
case PAGEARG_OSINFO:
$version = NULL;
if (isset($_REQUEST[URL_VERS])) {
$version = $_REQUEST[URL_VERS];
ValidateArgument($name, PAGEARG_VERS, $version);
}
if (isset($_REQUEST[URL_OSID])) {
$osid = $_REQUEST[URL_OSID];
$yep = 1;
if (ValidateArgument($name, PAGEARG_OSINFO, $osid)) {
$object = OSinfo::Lookup($osid);
$object = OSinfo::Lookup($osid, $version);
}
}
break;
......@@ -733,7 +746,7 @@ function ValidateArgument($name, $type, $arg)
case PAGEARG_IMAGE:
case PAGEARG_OSID:
case PAGEARG_OSINFO:
if (preg_match("/^[-\w\.\+]+$/", "$arg")) {
if (preg_match("/^[-\w\.\+:]+$/", "$arg")) {
return 1;
}
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment