Commit 3c757149 authored by Leigh B Stoller's avatar Leigh B Stoller

Add ListImages(creator_urn) method to AM and CM. You can get a list

of your own images or anyone else from your SA. Or if your are local
admin, anyone at all. Returns a list of hashes:

[{'url': 'https://www.emulab.net/dev/stoller/image_metadata.php?uuid=d29a5bf0-b0c6-11e1-a37b-001143e453fe',
  'urn': 'urn:publicid:IDN+emulab.net+image+emulab-net:booboo'
 },
 {'url': 'https://www.emulab.net/dev/stoller/image_metadata.php?uuid=456df426-1990-11e2-9f72-001143e453fe',
  'urn': 'urn:publicid:IDN+emulab.net+image+emulab-net:lbsimage'
 },
]

Then you can use the URN to delete your images!
parent d3a30ef8
......@@ -46,6 +46,7 @@ my $CONTROL = "@USERNODE@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBAUDIT = "@TBAUDITEMAIL@";
my $TBBASE = "@TBBASE@";
my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
my $TBWWW = "@TBWWW@";
# Cache of instances to avoid regenerating them.
......@@ -1164,5 +1165,35 @@ sub RecordImageHistory($$$$$$)
return 0;
}
#
# List of images created by a user urn.
#
sub ListForURN($$)
{
my ($class, $urn) = @_;
my @result = ();
return undef
if (! $PGENISUPPORT);
require GeniHRN;
return undef
if (! GeniHRN::IsValid($urn));
my $query_result =
DBQueryWarn("select imageid from images ".
"where creator_urn='$urn'");
while (my ($imageid) = $query_result->fetchrow_array()) {
my $image = Image->Lookup($imageid);
next
if (!defined($image));
push(@result, $image);
}
return @result;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -766,6 +766,22 @@ sub DeleteImage()
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $coder->boolean(1));
}
sub ListImages()
{
my ($user_urn, $credentials, $options) = @_;
if (! defined($user_urn) || ! defined($credentials) ||
(! defined($options) && $API_VERSION > 1)) {
return GeniResponse->MalformedArgsResponse("Missing arguments");
}
my $args = {
'user_urn' => $user_urn,
'credentials' => $credentials
};
my $response = GeniCMV2::ListImages($args);
return $response;
}
###############################################################################
# AM API V3
###############################################################################
......
#!/usr/bin/perl -wT
#
# Copyright (c) 2008-2012 University of Utah and the Flux Group.
# Copyright (c) 2008-2013 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
......@@ -1309,6 +1309,79 @@ sub List($)
return GeniResponse->Create(GENIRESPONSE_SUCCESS, \@results);
}
#
# Active slivers.
#
sub ListActiveSlivers($)
{
my ($argref) = @_;
my $cred = $argref->{'credential'};
if (! (defined($cred))) {
return GeniResponse->MalformedArgsResponse("credential");
}
my $authority = GeniAuthority->Lookup($ENV{'MYURN'});
if (!defined($authority)) {
print STDERR "Could not find local authority object\n";
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
my $credential = CheckCredential($cred, $authority);
return $credential
if (GeniResponse::IsResponse($credential));
$credential->HasPrivilege("readhistory") or
return GeniResponse->Create( GENIRESPONSE_FORBIDDEN, undef,
"Insufficient privilege" );
my $query_result =
DBQueryWarn("select a.*,m.manifest from aggregate_history as a ".
"left join manifest_history as m on ".
" m.aggregate_urn=a.urn ".
"where a.destroyed is null");
return GeniResponse->Create(GENIRESPONSE_ERROR)
if (!$query_result);
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"Mo matching records")
if (! $query_result->numrows);
my @results = ();
while (my $row = $query_result->fetchrow_hashref()) {
my %blob = ();
$row->{'slice_urn'} = $row->{'slice_hrn'}
if (!defined($row->{'slice_urn'}));
$blob{'index'} = $row->{'idx'};
$blob{'uuid'} = $row->{'uuid'};
$blob{'urn'} = $row->{'urn'};
$blob{'slice_urn'} = $row->{'slice_urn'};
$blob{'slice_uuid'} = $row->{'slice_uuid'};
$blob{'creator_urn'} = $row->{'creator_urn'};
$blob{'creator_uuid'} = $row->{'creator_uuid'};
$blob{'created'} = $row->{'created'};
if (defined($row->{'destroyed'})) {
$blob{'destroyed'}= $row->{'destroyed'};
}
else {
$blob{'destroyed'}= '';
}
if (defined($row->{'manifest'})) {
$blob{'manifest'} = $row->{'manifest'};
}
else {
$blob{'manifest'} = "";
}
push(@results, \%blob);
}
# Slow down the GMOC queries.
sleep(10);
return GeniResponse->Create(GENIRESPONSE_SUCCESS, \@results);
}
#
# Read the history records. Only a CH or delegated CH credential
# is allowed to do this.
......
......@@ -2569,5 +2569,71 @@ sub DeleteImage($)
return GeniResponse->Create(GENIRESPONSE_SUCCESS);
}
#
# List images for a user. If no user supplied, when for the caller.
# If user is supplied, then it must be the caller of from the same
# SA.
#
sub ListImages($)
{
my ($argref) = @_;
my $user_urn = $argref->{'user_urn'};
my $credentials = $argref->{'credentials'};
require Image;
if (! defined($credentials)) {
return GeniResponse->MalformedArgsResponse("Missing arguments");
}
if (defined($user_urn) && !GeniHRN::IsValid($user_urn)) {
return GeniResponse->MalformedArgsResponse("Invalid User URN");
}
my $credential = CheckCredentials($credentials);
return $credential
if (GeniResponse::IsResponse($credential));
my $user = GeniCM::CreateUserFromCertificate($credential);
return $user
if (GeniResponse::IsResponse($user));
my $authority = GeniCM::CreateAuthorityFromCertificate($credential);
return $authority
if (GeniResponse::IsResponse($authority));
#
# This is a convenience for testing. If a local user and that
# user is an admin person, then do whatever it says. This is
# easier then trying to do this with credential privs.
#
my $isadmin = ($user->IsLocal() && $user->admin() ? 1 : 0);
if (defined($user_urn) && $user->urn() ne $user_urn) {
my ($userauth,undef,undef) = GeniHRN::Parse($user_urn);
my ($thisauth,undef,undef) = GeniHRN::Parse($authority->urn());
return GeniResponse->Create(GENIRESPONSE_FORBIDDEN, undef,
"No permission to list images")
if ($userauth ne $thisauth && !$isadmin);
}
else {
$user_urn = $user->urn();
}
my @images = Image->ListForURN($user_urn);
return GeniResponse->Create(GENIRESPONSE_SUCCESS, [])
if (!@images);
my @result = ();
foreach my $image (@images) {
my $image_urn = GeniHRN::Generate($OURDOMAIN, "image",
$image->pid() . "//" . $image->imagename());
my $image_url = "$TBBASE/image_metadata.php?uuid=" . $image->uuid();
push(@result, {"urn" => $image_urn,
"url" => $image_url});
}
print STDERR "Image for $user_urn:\n";
print STDERR Dumper(\@result);
return GeniResponse->Create(GENIRESPONSE_SUCCESS, \@result);
}
# _Always_ make sure that this 1 is at the end of the file...
1;
#! /usr/bin/env python
#
# Copyright (c) 2008-2013 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
# GENI Public License
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and/or hardware specification (the "Work") to
# deal in the Work without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Work, and to permit persons to whom the Work
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Work.
#
# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
# IN THE WORK.
#
# }}}
#
#
#
import sys
import pwd
import getopt
import os
import re
import xmlrpclib
def Usage():
print "usage: " + sys.argv[ 0 ] + " [option...] [creator_urn]"
print "Options:"
BaseOptions()
pass
execfile( "test-common.py" )
if len(REQARGS) > 1:
Usage()
sys.exit(1)
pass
#
# Get a credential for myself, that allows me to do things at the SA.
#
mycredential = get_self_credential()
print "Got my SA credential"
#
# Lookup images for user.
#
params = {}
if len( args ) == 1:
params["user_urn"] = args[0]
pass
params["credentials"] = (mycredential,)
rval,response = do_method("cm", "ListImages", params, version="2.0")
if rval:
Fatal("Could not list images")
pass
print str(response["value"])
......@@ -63,6 +63,7 @@ if ($GENI_VERSION eq "1.0" || $GENI_VERSION eq "2.0") {
"Shutdown" => \&GeniAM::ShutdownV2,
"CreateImage" => \&GeniAM::CreateImage,
"DeleteImage" => \&GeniAM::DeleteImage,
"ListImages" => \&GeniAM::ListImages,
};
} elsif ($GENI_VERSION eq "3.0") {
$GENI_METHODS = {
......@@ -80,6 +81,7 @@ if ($GENI_VERSION eq "1.0" || $GENI_VERSION eq "2.0") {
"Cancel" => \&GeniAM::Cancel,
"CreateImage" => \&GeniAM::CreateImage,
"DeleteImage" => \&GeniAM::DeleteImage,
"ListImages" => \&GeniAM::ListImages,
};
}
......
#!/usr/bin/perl -w
#
# Copyright (c) 2008-2012 University of Utah and the Flux Group.
# Copyright (c) 2008-2013 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
......@@ -101,6 +101,7 @@ elsif ($GENI_VERSION eq "2.0") {
"InjectEvent" => \&GeniCMV2::InjectEvent,
"CreateImage" => \&GeniCMV2::CreateImage,
"DeleteImage" => \&GeniCMV2::DeleteImage,
"ListImages" => \&GeniCMV2::ListImages,
};
}
......
......@@ -478,6 +478,7 @@ if (!defined($GENI_METHODS->{$method})) {
# Too much output.
if ($method eq "ListResources" ||
$method eq "GetVersion" ||
$method eq "ListUsage" ||
$method eq "GetKeys" ||
$method eq "RegisterSliver" ||
$method eq "UnRegisterSliver" ||
......
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