Commit f9bd2d55 authored by Leigh B Stoller's avatar Leigh B Stoller

Add DeleteImage() to the CM and AM, and add a test script to

demonstrate usage.
parent 37c6d88a
......@@ -740,6 +740,31 @@ sub CreateImage()
return $response;
}
sub DeleteImage()
{
my ($image_urn, $credentials, $options) = @_;
if (! defined($image_urn) || ! defined($credentials) ||
(! defined($options) && $API_VERSION > 1)) {
return GeniResponse->MalformedArgsResponse("Missing arguments");
}
my $args = {
'image_urn' => $image_urn,
'credentials' => $credentials
};
$args->{'creator_urn'} = $options->{'creator_urn'}
if (defined($options) && exists($options->{'creator_urn'}));
my $response = GeniCMV2::DeleteImage($args);
if (GeniResponse::IsError($response)) {
return $response;
}
# Return an XML-RPC boolean
my $coder = Frontier::RPC2->new();
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $coder->boolean(1));
}
###############################################################################
# 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
#
......@@ -94,6 +94,7 @@ my $VTOPGEN = "$TB/bin/vtopgen";
my $SNMPIT = "$TB/bin/snmpit";
my $CLONEIMAGE = "$TB/sbin/clone_image";
my $CREATEIMAGE = "$TB/bin/create_image";
my $DELETEIMAGE = "$TB/sbin/delete_image";
my $XMLLINT = "/usr/local/bin/xmllint";
my $PRERENDER = "$TB/libexec/vis/prerender";
my $EMULAB_PEMFILE = "@prefix@/etc/genicm.pem";
......@@ -2375,7 +2376,6 @@ sub CreateImage($)
if (exists($argref->{'global'})) {
$opt .= " -g " . ($argref->{'global'} ? "1" : "0");
}
my $output =
GeniUtil::ExecQuiet("$CLONEIMAGE $opt -s $imagename $node_id");
# Not a typical op, so always print debugging info;
......@@ -2437,11 +2437,105 @@ sub CreateImage($)
if ($user->email()) {
libtestbed::SENDMAIL($user->email(),
"Finished cloning image",
"Image URN: $image_urn\n".
"Image URL: $image_url\n".
"\n".
"-----------------------------------------\n".
"$output\n");
}
$slice->UnLock();
return 0;
}
#
# Delete image created above.
#
sub DeleteImage($)
{
my ($argref) = @_;
my $image_urn = $argref->{'image_urn'};
my $credentials = $argref->{'credentials'};
my $overide_urn = (exists($argref->{'creator_urn'}) ?
$argref->{'creator_urn'} : undef);
my ($imagename,$imagepid);
require Image;
if (! (defined($credentials) && defined($image_urn))) {
return GeniResponse->MalformedArgsResponse("Missing arguments");
}
if (! GeniHRN::IsValid($image_urn)) {
return GeniResponse->MalformedArgsResponse("Invalid 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));
my ($auth,undef,$id) = GeniHRN::Parse($image_urn);
return GeniResponse->MalformedArgsResponse("Malformed URN")
if (!defined($id));
if ($id =~ m{(.*)//(.*)}) {
$imagepid = $1;
$imagename = $2;
}
else {
return GeniResponse->MalformedArgsResponse("Could not parse $id");
}
#
# Make sure we can get the image descriptor.
#
my $image = Image->Lookup($imagepid, $imagename);
if (!defined($image)) {
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"No such image");
}
my $imageid = $image->imageid();
my $creator_urn = $image->creator_urn();
#
# Need the project to compare the manager urn against the user SA.
#
my $project = $image->GetProject();
if (!defined($project)) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"No project for image");
}
if (! ((defined($creator_urn) && $creator_urn eq $user->urn()) ||
$project->nonlocal_id() eq $authority->urn())) {
return GeniResponse->Create(GENIRESPONSE_FORBIDDEN, undef,
"Not enough permission to delete image; wrong SA or user");
}
#
# If not the creator, then require override to prevent
# accidental removal of images not belonging to current user.
# Note that not all images have the creator_urn set (yet).
#
if (defined($creator_urn) && $creator_urn ne $user->urn()) {
return GeniResponse->Create(GENIRESPONSE_FORBIDDEN, undef,
"Not your image; please specify original creator urn")
if (!defined($overide_urn) || $overide_urn ne $creator_urn);
}
my $output = GeniUtil::ExecQuiet("$DELETEIMAGE -p $imageid");
print STDERR $output;
if ($?) {
print STDERR $output;
return GeniResponse->Create(GENIRESPONSE_ERROR, undef, $output);
}
# Print to get into the email log
print STDERR "Image $image deleted by $user\n";
return GeniResponse->Create(GENIRESPONSE_SUCCESS);
}
# _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 time
import re
debug = 0
impotent = 1
doglobal = 1
def Usage():
print "usage: " + sys.argv[ 0 ] + " [option...] image_urn [creator_urn]"
print "Options:"
BaseOptions()
pass
execfile( "test-common.py" )
if len(REQARGS) < 1 or len(REQARGS) > 2:
Usage()
sys.exit(1)
pass
imageurn = REQARGS[0]
#
# Get a credential for myself, that allows me to do things at the SA.
#
mycredential = get_self_credential()
print "Got my SA credential"
#
# Delete the image
#
print "Deleting the Image ..."
params = {}
params["credentials"] = (mycredential,)
params["image_urn"] = imageurn
if len(REQARGS) == 2:
params["creator_urn"] = REQARGS[1]
pass
rval,response = do_method("cm", "DeleteImage", params, version="2.0")
if rval:
Fatal("Could not delete image")
pass
#!/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
#
......@@ -62,6 +62,7 @@ if ($GENI_VERSION eq "1.0" || $GENI_VERSION eq "2.0") {
"RenewSliver" => \&GeniAM::RenewSliver,
"Shutdown" => \&GeniAM::ShutdownV2,
"CreateImage" => \&GeniAM::CreateImage,
"DeleteImage" => \&GeniAM::DeleteImage,
};
} elsif ($GENI_VERSION eq "3.0") {
$GENI_METHODS = {
......@@ -78,6 +79,7 @@ if ($GENI_VERSION eq "1.0" || $GENI_VERSION eq "2.0") {
"Update" => \&GeniAM::Update,
"Cancel" => \&GeniAM::Cancel,
"CreateImage" => \&GeniAM::CreateImage,
"DeleteImage" => \&GeniAM::DeleteImage,
};
}
......
......@@ -100,6 +100,7 @@ elsif ($GENI_VERSION eq "2.0") {
"ReserveVlanTags" => \&GeniCMV2::ReserveVlanTags,
"InjectEvent" => \&GeniCMV2::InjectEvent,
"CreateImage" => \&GeniCMV2::CreateImage,
"DeleteImage" => \&GeniCMV2::DeleteImage,
};
}
......
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