Commit 2c2677b8 authored by Leigh B Stoller's avatar Leigh B Stoller

Fix up email sending to make sure that actual user gets the email

when deleting via the Geni path.
parent 8601701d
...@@ -59,6 +59,7 @@ my $TB = "@prefix@"; ...@@ -59,6 +59,7 @@ my $TB = "@prefix@";
my $PROJROOT = "@PROJROOT_DIR@"; my $PROJROOT = "@PROJROOT_DIR@";
my $TBOPS = "@TBOPSEMAIL@"; my $TBOPS = "@TBOPSEMAIL@";
my $friskiller = "$TB/sbin/frisbeehelper"; my $friskiller = "$TB/sbin/frisbeehelper";
my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
my $WITHPROVENANCE = @IMAGEPROVENANCE@; my $WITHPROVENANCE = @IMAGEPROVENANCE@;
my $doprovenance = 0; my $doprovenance = 0;
...@@ -91,6 +92,12 @@ use libEmulab; ...@@ -91,6 +92,12 @@ use libEmulab;
use libtestbed; use libtestbed;
use User; use User;
use OSImage; use OSImage;
if ($PGENISUPPORT) {
use vars qw($GENI_DBNAME);
$GENI_DBNAME = "geni-cm";
require GeniHRN;
require GeniUser;
}
# Protos # Protos
sub fatal($); sub fatal($);
...@@ -171,6 +178,30 @@ if ($versonly && defined($image->deleted())) { ...@@ -171,6 +178,30 @@ if ($versonly && defined($image->deleted())) {
fatal("Image version is already deleted"); fatal("Image version is already deleted");
} }
#
# We want to send email to the creator. Also, watch for an image created
# on the Geni path; the creator urn tells us who the creator is, rather
# then who is calling the script. When PROTOGENI_LOCALUSER=0 there is no
# local creator, but when set there is a local shadow user we can use.
#
my $notifyuser = $image->GetCreator();
if (!defined($notifyuser)) {
$notifyuser = $this_user;
}
if (defined($image->creator_urn())) {
my $geniuser = GeniUser->Lookup($image->creator_urn(), 1);
if (defined($geniuser) && $geniuser->IsLocal()) {
$notifyuser = $geniuser->emulab_user();
}
else {
# This is okay, it is just for email below.
$notifyuser = $geniuser;
}
}
if ($debug) {
print STDERR "Will send email to $notifyuser\n";
}
# #
# Need root to delete the image file later. # Need root to delete the image file later.
# #
...@@ -393,9 +424,9 @@ if (!$versonly) { ...@@ -393,9 +424,9 @@ if (!$versonly) {
if ($image->Delete() != 0) { if ($image->Delete() != 0) {
fatal("Could not delete image!"); fatal("Could not delete image!");
} }
$this_user->SendEmail("delete_image: Image has been deleted", $notifyuser->SendEmail("delete_image: Image has been deleted",
"Image $imagepid,$imagename ($imageid) has ". "Image $imagepid,$imagename ($imageid) has ".
"been deleted by $this_user\n"); "been deleted by $this_user\n");
} }
else { else {
if ($image->DeleteVersion() != 0) { if ($image->DeleteVersion() != 0) {
...@@ -403,9 +434,9 @@ else { ...@@ -403,9 +434,9 @@ else {
} }
# I know, we are unlocking something we just deleted. Its okay, relax. # I know, we are unlocking something we just deleted. Its okay, relax.
$image->Unlock(); $image->Unlock();
$this_user->SendEmail("delete_image: Image Version has been deleted", $notifyuser->SendEmail("delete_image: Image Version has been deleted",
"Version $imagevers of image $imagepid,$imagename". "Version $imagevers of image $imagepid,$imagename".
"($imageid)\nhas been deleted by $this_user\n"); "($imageid)\nhas been deleted by $this_user\n");
} }
exit(0); exit(0);
......
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