Commit 983319dd authored by Leigh B Stoller's avatar Leigh B Stoller

Incorporate Shutdown() and fix for V2 API.

parent 27cd0e80
......@@ -82,6 +82,8 @@ my $VTOPGEN = "$TB/bin/vtopgen";
my $SNMPIT = "$TB/bin/snmpit";
my $PRERENDER = "$TB/libexec/vis/prerender";
my $EMULAB_PEMFILE = "@prefix@/etc/genicm.pem";
# Just one of these, at Utah.
my $GENICH_PEMFILE = "@prefix@/etc/genich.pem";
my $API_VERSION = 2;
......@@ -889,15 +891,73 @@ sub Shutdown($)
my $clear = $argref->{'clear'} || 0;
my $credentials = $argref->{'credentials'};
# For now, I am not worrying about the slice_urn argument.
if (! (defined($credentials))) {
if (! (defined($credentials) && defined($slice_urn))) {
return GeniResponse->MalformedArgsResponse("Missing arguments");
}
my $credential = CheckCredentials($credentials);
return $credential
if (GeniResponse::IsResponse($credential));
return GeniCM::ShutdownAux($credential, $clear);
$credential->HasPrivilege( "pi" ) or
$credential->HasPrivilege( "instantiate" ) or
$credential->HasPrivilege( "control" ) or
return GeniResponse->Create( GENIRESPONSE_FORBIDDEN, undef,
"Insufficient privilege" );
#
# The clearinghouse generates a different credential to do this.
#
if ($slice_urn ne $credential->target_urn()) {
my $certificate = GeniCertificate->LoadFromFile($GENICH_PEMFILE);
if (!defined($certificate)) {
print STDERR "Could not load certificate from $GENICH_PEMFILE\n";
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
# The caller has to match the clearinghouse.
if ($credential->owner_urn() ne $certificate->urn()) {
return GeniResponse->Create(GENIRESPONSE_FORBIDDEN, undef,
"Insufficient privilege");
}
}
#
# No slice here? Done.
#
my $slice = GeniSlice->Lookup($slice_urn);
if (!defined($slice)) {
return GeniResponse->Create(GENIRESPONSE_SUCCESS);
}
#
# Do not worry about locking when setting the shutdown time.
# This can lead to race though, if a clear shutdown comes in first.
# Seems unlikely though.
#
if (!$clear) {
# Do not overwrite original shutdown time
$slice->SetShutdown(1)
if (!defined($slice->shutdown()) || $slice->shutdown() eq "");
}
else {
$slice->SetShutdown(0);
}
# Always make sure the slice is shutdown.
if ($slice->shutdown()) {
# The expire daemon is going to look for this, so it will get
# taken care of shortly.
if ($slice->Lock() != 0) {
return GeniResponse->BusyResponse();
}
if (GeniCM::CleanupDeadSlice($slice, 0) != 0) {
SENDMAIL($TBOPS, "Emergency Shutdown failed",
"Emergency shutdown failed on $slice\n");
print STDERR "Could not shutdown $slice!\n";
# Lets call this a non-error since the local admin person
# is going to have to deal with it anyway.
}
$slice->UnLock();
}
return GeniResponse->Create(GENIRESPONSE_SUCCESS);
}
#
......@@ -1335,6 +1395,10 @@ sub ReleaseTicket($)
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"This ticket is for another slice");
}
#
# XXX Need to do a restore backup state operation if this ticket
# was the result of an update.
#
if ($ticket->Lock() != 0) {
return GeniResponse->BusyResponse("ticket");
}
......
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