Commit 4c444cd5 authored by Leigh Stoller's avatar Leigh Stoller

More bits and pieces for exporting images from one Emulab to another.

image_metadata.php will return an Emulab style image descriptor in XML
format. A remote emulab, given an image URL, will grab this XML
description and use it to create a local descriptor. Inside the
descriptor is an additional URL that is used to download ndz file.

The dumpdescriptor script is now web accessible, and takes a new -e
(export) option that adds the extra URL and other bits that are needed
to import the descriptor and the image.

On the Show Image page, show the metadata URL, which is suitable for
using in an NS file or an rspec (when that code is committed).
parent 1517aa14
......@@ -33,7 +33,7 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
addvpubaddr imageinfo ctrladdr
WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \
webwanodecheckin webspewimage
webwanodecheckin webspewimage webdumpdescriptor
WEB_BIN_SCRIPTS = webcreate_image websetdest weblinkmon_ctl webspewevents \
webdelay_config
LIBEXEC_SCRIPTS = spewleds webcopy spewsource webcvsweb xlogin webviewvc \
......
......@@ -15,12 +15,14 @@ use Data::Dumper;
#
sub usage()
{
print("Usage: dumpimage [-d] [-i <imageid> [-t]] | [-o <osid>] \n");
print("Usage: dumpdescriptor ".
"[-d] [-e] [-i <imageid> [-t]] | [-o <osid>]\n");
exit(-1);
}
my $optlist = "di:o:t";
my $optlist = "di:o:te";
my $debug = 0;
my $dotypes = 0;
my $export = 0;
#
# Configure variables
......@@ -30,6 +32,7 @@ my $TBOPS = "@TBOPSEMAIL@";
my $TBAUDIT = "@TBAUDITEMAIL@";
my $TBGROUP_DIR = "@GROUPSROOT_DIR@";
my $TBPROJ_DIR = "@PROJROOT_DIR@";
my $TBBASE = "@TBBASE@";
#
# Untaint the path
......@@ -72,6 +75,9 @@ if (defined($options{"d"})) {
if (defined($options{"t"})) {
$dotypes = 1;
}
if (defined($options{"e"})) {
$export = 1;
}
if (@ARGV) {
usage();
}
......@@ -104,16 +110,38 @@ sub DumpImage($)
my %xmlfields = ();
$xmlfields{"imagename"} = $image->imagename();
$xmlfields{"pid"} = $image->pid();
$xmlfields{"gid"} = $image->gid();
if (!$export) {
$xmlfields{"pid"} = $image->pid();
$xmlfields{"gid"} = $image->gid();
}
$xmlfields{"description"} = $image->description();
$xmlfields{"loadpart"} = $image->loadpart();
$xmlfields{"global"} = $image->global();
$xmlfields{"shared"} = $image->shared();
$xmlfields{"path"} = $image->path()
if (defined($image->path()) && $image->path() ne "");
$xmlfields{"hash"} = $image->hash()
if ($export && defined($image->hash()) && $image->hash() ne "");
$xmlfields{"mbr_version"} = $image->mbr_version();
if ($export) {
my $imageid = $image->imageid();
my $access_key = $image->access_key();
if (!defined($access_key) || $access_key eq "") {
$access_key = TBGenSecretKey();
if ($image->Update({'access_key' => $access_key})) {
fatal("Could not initialize access key");
}
}
#
# Generate a url that allows the image to be downloaded.
#
my $url = "$TBBASE/spewimage.php".
"?imageid=$imageid&access_key=$access_key";
$xmlfields{"imagefile_url"} = $url;
}
sub MapOS($) {
my ($osid) = @_;
return "none"
......@@ -152,7 +180,8 @@ sub DumpImage($)
$xmlfields{"wholedisk"} = 1;
# find the partition which has an osid defined
for (my $i = 1; $i <= 4; $i++) {
my $foo = $image->field("part${i}_osid");
my $func = "part${i}_osid";
my $foo = $image->$func();
if (defined($foo)) {
$xmlfields{"loadpart"} = $i;
last;
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2003-2012 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include_once("imageid_defs.php");
function SPITERROR($code, $msg)
{
header("HTTP/1.0 $code $msg");
exit();
}
#
# Verify page arguments.
#
$reqargs = RequiredPageArguments("uuid", PAGEARG_STRING);
$image = Image::LookupByUUID($uuid);
if (! isset($image)) {
SPITERROR(404, "Could not find $uuid!");
}
if (! $image->isglobal()) {
SPITERROR(403, "No permission to access image");
}
$fp = popen("$TBSUEXEC_PATH nobody nobody webdumpdescriptor ".
"-e -i " . $image->imageid(), "r");
if (! $fp) {
SPITERROR(404, "Could not get metadata for $uuid!");
}
header("Content-Type: text/plain; charset=us-ascii");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
flush();
while (!feof($fp)) {
$string = fgets($fp, 1024);
echo "$string";
flush();
}
pclose($fp);
$fp = 0;
?>
......@@ -79,6 +79,20 @@ class Image
return Image::Lookup($row["imageid"]);
}
function LookupByUUID($uuid) {
$safe_uuid = addslashes($uuid);
$query_result =
DBQueryFatal("select imageid from images ".
"where uuid='$safe_uuid'");
if (mysql_num_rows($query_result) == 0) {
return null;
}
$row = mysql_fetch_array($query_result);
return Image::Lookup($row["imageid"]);
}
#
# Refresh an instance by reloading from the DB.
#
......@@ -308,6 +322,8 @@ class Image
function updated() { return $this->field("updated"); }
function mbr_version() { return $this->field("mbr_version"); }
function hash() { return $this->field("hash"); }
function metadata_url() { return $this->field("metadata_url"); }
function imagefile_url() { return $this->field("imagefile_url"); }
# Return the DB data.
function DBData() { return $this->image; }
......@@ -454,6 +470,8 @@ class Image
}
function Show($showperms = 0) {
global $TBBASE;
$imageid = $this->imageid();
$imagename = $this->imagename();
$pid = $this->pid();
......@@ -476,6 +494,16 @@ class Image
$mbr_version = $this->mbr_version();
$hash = $this->hash();
#
# An imported image has a metadata_url, and at the moment I
# do want to worry about exporting an imported image.
#
$imagefile_url = $this->imagefile_url();
$metadata_url = $this->metadata_url();
if (! $metadata_url) {
$metadata_url = "$TBBASE/image_metadata.php?uuid=$uuid";
}
if (!$description)
$description = "&nbsp;";
if (!$path)
......@@ -646,6 +674,18 @@ class Image
<td class=left>$uuid</td>
</tr>\n";
echo "<tr>
<td>Metadata URL: </td>
<td class=left><a href='$metadata_url'>https:// ...</a></td>
</tr>\n";
if ($imagefile_url) {
echo "<tr>
<td>Image File URL: </td>
<td class=left><a href='$imagefile_url'>https:// ...</a></td>
</tr>\n";
}
#
# Show who all can access this image outside the project.
#
......
......@@ -451,20 +451,25 @@ class OSinfo
<td class=left>
Mapped via DB table: osid_map</td></tr>\n";
}
else
else {
$nextosinfo = OSinfo::Lookup($nextosid);
$nextosname = $nextosinfo->osname();
echo "<tr>
<td>Next Osid: </td>
<td class=left>
<a href='showosinfo.php3?osid=$nextosid'>
$nextosid</a></td>
$nextosname</a></td>
</tr>\n";
}
}
if ($def_parentosid) {
$nextosinfo = OSinfo::Lookup($def_parentosid);
$nextosname = $nextosinfo->osname();
echo "<tr>
<td>Parent Osid: </td>
<td class=left>
<a href='showosinfo.php3?osid=$def_parentosid'>
$def_parentosid</a></td>
$nextosname</a></td>
</tr>\n";
}
if ($ezid) {
......
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