Commit c9186058 authored by Leigh Stoller's avatar Leigh Stoller

Assorted little changes for exporting image history along with the image.

parent 996e8c70
#!/usr/bin/perl -wT
#
# Copyright (c) 2007-2015 University of Utah and the Flux Group.
# Copyright (c) 2007-2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -120,7 +120,8 @@ sub Lookup($$;$$)
if (!defined($arg2)) {
if ($arg1 =~ /^(\d*)$/) {
my $result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid, ".
" i.metadata_url as image_metadata_url ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid and v.version=i.version ".
......@@ -135,7 +136,8 @@ sub Lookup($$;$$)
# This will get deleted images, but that is okay.
#
my $result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid, ".
" i.metadata_url as image_metadata_url ".
" from image_versions as v ".
"left join images as i on ".
" v.imageid=i.imageid ".
......@@ -148,7 +150,8 @@ sub Lookup($$;$$)
elsif ($arg1 =~ /^([-\w]*),([-\w\.\+]*)$/ ||
$arg1 =~ /^([-\w]*)\/([-\w\.\+]*)$/) {
my $result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid, ".
" i.metadata_url as image_metadata_url ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid and v.version=i.version ".
......@@ -161,7 +164,8 @@ sub Lookup($$;$$)
elsif ($arg1 =~ /^([-\w]*),([-\w\.\+]*):(\d*)$/ ||
$arg1 =~ /^([-\w]*)\/([-\w\.\+]*):(\d*)$/) {
my $result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid, ".
" i.metadata_url as image_metadata_url ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid ".
......@@ -179,7 +183,8 @@ sub Lookup($$;$$)
# version with the uuid.
#
my $result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid, ".
" i.metadata_url as image_metadata_url ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid and v.version=i.version ".
......@@ -190,7 +195,8 @@ sub Lookup($$;$$)
if ($result->numrows);
$result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid, ".
" i.metadata_url as image_metadata_url ".
" from image_versions as v ".
"left join images as i on ".
" v.imageid=i.imageid ".
......@@ -209,7 +215,8 @@ sub Lookup($$;$$)
# This will get deleted images, but that is okay.
#
my $result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid, ".
" i.metadata_url as image_metadata_url ".
" from image_versions as v ".
"left join images as i on ".
" v.imageid=i.imageid ".
......@@ -221,7 +228,8 @@ sub Lookup($$;$$)
}
elsif ($arg1 =~ /^[-\w]*$/ && $arg2 =~ /^([-\w\.\+]*):(\d+)$/) {
my $result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid, ".
" i.metadata_url as image_metadata_url ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid ".
......@@ -234,7 +242,8 @@ sub Lookup($$;$$)
}
elsif ($arg1 =~ /^[-\w]*$/ && $arg2 =~ /^[-\w\.\+]*$/) {
my $result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid, ".
" i.metadata_url as image_metadata_url ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid and v.version=i.version ".
......@@ -250,7 +259,8 @@ sub Lookup($$;$$)
if ($arg1 =~ /^[-\w]*$/ &&
$arg2 =~ /^[-\w\.\+]*$/ && $arg3 =~ /^\d+$/) {
my $result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid, ".
" i.metadata_url as image_metadata_url ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid ".
......@@ -312,19 +322,36 @@ sub LookupByURL($$)
if (! ($url =~ /^(ftp|http|https):/));
my $safe_url = DBQuoteSpecial($url);
#
# First check for a non version specific URL (latest version).
#
my $query_result =
DBQueryWarn("select pid,imagename from image_versions ".
"where metadata_url=$safe_url and deleted is null");
DBQueryWarn("select pid,imagename from images ".
"where metadata_url=$safe_url");
return undef
if (!$query_result);
if ($query_result->numrows) {
my ($pid,$imagename) = $query_result->fetchrow_array();
# Want latest version.
return Image->Lookup($pid, $imagename);
}
#
# Then a version specific URL.
#
$query_result =
DBQueryWarn("select pid,imagename,version from image_versions ".
"where metadata_url=$safe_url and deleted is null");
return undef
if (!$query_result);
if ($query_result->numrows) {
my ($pid,$imagename,$version) = $query_result->fetchrow_array();
return Image->Lookup($pid, $imagename, $version);
}
else {
#
# If the URL points back to ourself, find the image it refers
......@@ -365,6 +392,26 @@ sub LookupByName($$)
return Image->Lookup(TBOPSPID(), $imagename);
}
#
# Lookup by Origin UUID.
#
sub LookupByOriginUUID($$$)
{
my ($class, $pid, $uuid) = @_;
my $safe_uuid = DBQuoteSpecial($uuid);
my $safe_pid = DBQuoteSpecial($pid);
my $query_result =
DBQueryWarn("select imageid from image_versions ".
"where pid=$safe_pid ".
" origin_uuid=$safe_uuid and deleted is null");
return undef
if (!$query_result || !$query_result->numrows);
my ($imageid) = $query_result->fetchrow_array();
return Image->Lookup($imageid);
}
#
# Get a list of all running frisbee images.
# XXX if this is actually used, it will have to be fixed; DB no longer
......@@ -2337,6 +2384,25 @@ sub SetNoVersioning($$)
return 0;
}
sub SetImageMetadataURL($$)
{
my ($self, $url) = @_;
$url = DBQuoteSpecial($url);
# Must be a real reference.
return -1
if (! ref($self));
my $imageid = $self->imageid();
return -1
if (! DBQueryWarn("update images set metadata_url=$url " .
"where imageid='$imageid'"));
$self->{'IMAGE'}->{'image_metadata_url'} = $url;
return 0;
}
sub LocalURL($)
{
my ($self) = @_;
......
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