Commit 3802c0dc authored by Leigh Stoller's avatar Leigh Stoller

More image version fixes and changes.

1. Fixes to allow specific versions of images to be exported; the existing
   path was reverting back to the highest numbered version. So far this has
   not come up, but will with APT and Cloud.

2. Add version argument to image_metadata.php, mostly as a convenience. So
   rather then using the version specific uuid, you can use the image uuid,
   with a version argument. This is actually more sensible, except for one
   important fact; it is not possible to locate a deleted image this way,
   since the image descriptor is gone (only the version descriptors are in
   the DB).

   But I went ahead and did it cause there is still some question as to
   whether we care about being able to export a deleted image. We do not
   expose these URLs at this time, but you can use one.
parent 62a0f9ad
#!/usr/bin/perl -w
#
# Copyright (c) 2010-2012 University of Utah and the Flux Group.
# Copyright (c) 2010-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -143,6 +143,7 @@ sub DumpImage($)
if ($export) {
my $imageid = $image->imageid();
my $uuid = $image->uuid();
my $access_key = $image->access_key();
if (!defined($access_key) || $access_key eq "") {
$access_key = TBGenSecretKey();
......@@ -154,7 +155,7 @@ sub DumpImage($)
# Generate a url that allows the image to be downloaded.
#
my $url = "$TBBASE/spewimage.php".
"?imageid=$imageid&access_key=$access_key";
"?imageid=$uuid&access_key=$access_key";
$xmlfields{"imagefile_url"} = $url;
}
......
<?php
#
# Copyright (c) 2003-2012 University of Utah and the Flux Group.
# Copyright (c) 2003-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -33,9 +33,13 @@ function SPITERROR($code, $msg)
#
# Verify page arguments.
#
$reqargs = RequiredPageArguments("uuid", PAGEARG_STRING);
$reqargs = RequiredPageArguments("uuid", PAGEARG_STRING);
$optargs = OptionalPageArguments("version", PAGEARG_INTEGER);
if (!isset($version)) {
$version = NULL;
}
$image = Image::LookupByUUID($uuid);
$image = Image::LookupByUUID($uuid, $version);
if (! isset($image)) {
SPITERROR(404, "Could not find $uuid!");
}
......@@ -43,8 +47,9 @@ if (! $image->isglobal()) {
SPITERROR(403, "No permission to access image");
}
# Pass imageid:version to backend script.
$fp = popen("$TBSUEXEC_PATH nobody nobody webdumpdescriptor ".
"-e -i " . $image->imageid(), "r");
"-e -i " . $image->versid(), "r");
if (! $fp) {
SPITERROR(404, "Could not get metadata for $uuid!");
}
......
......@@ -138,7 +138,7 @@ class Image
return Image::Lookup($imageid, $row["version"]);
}
function LookupByUUID($uuid) {
function LookupByUUID($uuid, $version = NULL) {
$safe_uuid = addslashes($uuid);
#
......@@ -149,7 +149,18 @@ class Image
$query_result =
DBQueryFatal("select i.imageid,i.version from images as i ".
"where i.uuid='$safe_uuid'");
if (mysql_num_rows($query_result) == 0) {
if (mysql_num_rows($query_result)) {
if (!is_null($version)) {
#
# Specific version, but using the image UUID.
# Note that you cannot lookup a deleted image this way.
# Must have the version specific UUID.
#
$row = mysql_fetch_array($query_result);
return Image::Lookup($row["imageid"], $version);
}
}
else {
$query_result =
DBQueryWarn("select imageid,version from image_versions ".
"where uuid='$safe_uuid' and ".
......@@ -448,6 +459,9 @@ class Image
# and the types array
function Types() { reset($this->types); return $this->types; }
# Concat id/vers.
function versid() { return $this->imageid() . ":" . $this->version(); }
#
# Access Check, determines if $user can access $this record.
#
......@@ -629,7 +643,7 @@ class Image
$imagefile_url = $this->imagefile_url();
$metadata_url = $this->metadata_url();
if (! $metadata_url) {
$metadata_url = "$TBBASE/image_metadata.php?uuid=$image_uuid";
$metadata_url = "$TBBASE/image_metadata.php?uuid=$uuid";
}
if (!$description)
......
<?php
#
# Copyright (c) 2003-2013 University of Utah and the Flux Group.
# Copyright (c) 2003-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -78,6 +78,7 @@ register_shutdown_function("SPEWCLEANUP");
# Invoke backend script to do it all.
#
$imageid = $image->imageid();
$versid = $image->versid();
$access_key = escapeshellarg($access_key);
$arg = (isset($stamp) ? "-t " . escapeshellarg($stamp) : "");
$group = $image->Group();
......@@ -97,7 +98,7 @@ if ($_SERVER['REQUEST_METHOD'] == "HEAD") {
}
if ($fp = popen("$TBSUEXEC_PATH nobody $unix_pid,$unix_gid ".
"webspewimage $arg $headarg -k $access_key $imageid", "r")) {
"webspewimage $arg $headarg -k $access_key $versid", "r")) {
header("Content-Type: application/octet-stream");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
......
......@@ -576,12 +576,12 @@ function VerifyPageArguments($argspec, $required)
$imageid = $_REQUEST[URL_IMAGEID];
$yep = 1;
if (ValidateArgument($name, PAGEARG_IMAGE, $imageid)) {
$object = Image::Lookup($imageid, $version);
}
elseif (ValidateArgument($name, PAGEARG_UUID, $imageid)) {
if (ValidateArgument($name, PAGEARG_UUID, $imageid)) {
$object = Image::LookupByUUID($imageid);
}
elseif (ValidateArgument($name, PAGEARG_IMAGE, $imageid)) {
$object = Image::Lookup($imageid, $version);
}
}
elseif (isset($_REQUEST[$name]) && $_REQUEST[$name] != "") {
$imageid = $_REQUEST[$name];
......
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