Commit 1c7d69df authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Checkpoint.

parent c319751e
...@@ -852,6 +852,35 @@ sub IsBound($$) ...@@ -852,6 +852,35 @@ sub IsBound($$)
return $query_result->numrows(); return $query_result->numrows();
} }
#
# Helper function for expiration.
#
sub AddToExpiration($$)
{
my ($self, $increment) = @_;
return undef
if (!defined($self->expires()));
my $new_expires = str2time($self->expires()) + $increment;
return $self->SetExpiration($new_expires);
}
#
# Return expiration in GMT time format.
#
sub ExpirationGMT($)
{
my ($self) = @_;
return undef
if (!defined($self->expires()));
return POSIX::strftime("20%y-%m-%dT%H:%M:%S GMT",
gmtime(str2time($self->expires())));
}
# #
# Set the expiration time for a slice. # Set the expiration time for a slice.
# #
......
...@@ -41,13 +41,15 @@ sub usage() ...@@ -41,13 +41,15 @@ sub usage()
{ {
print "Usage: quickvm <xmlfile>\n"; print "Usage: quickvm <xmlfile>\n";
print "Usage: quickvm -k <uuid>\n"; print "Usage: quickvm -k <uuid>\n";
print "Usage: quickvm -e <seconds> <uuid>\n";
exit(1); exit(1);
} }
my $optlist = "dkv"; my $optlist = "dkve:";
my $debug = 0; my $debug = 0;
my $verbose = 1; my $verbose = 1;
my $killit = 0; my $killit = 0;
my $xmlfile; my $xmlfile;
my $extend;
my $quickuuid; my $quickuuid;
# Protos # Protos
...@@ -55,6 +57,7 @@ sub fatal($); ...@@ -55,6 +57,7 @@ sub fatal($);
sub UserError($); sub UserError($);
sub GiveMeRspec($); sub GiveMeRspec($);
sub Terminate($); sub Terminate($);
sub Extend($$);
# #
# Configure variables # Configure variables
...@@ -112,12 +115,21 @@ if (defined($options{"v"})) { ...@@ -112,12 +115,21 @@ if (defined($options{"v"})) {
if (defined($options{"k"})) { if (defined($options{"k"})) {
$killit = 1; $killit = 1;
} }
if (defined($options{"e"})) {
$extend = $options{"e"};
}
if (@ARGV != 1) { if (@ARGV != 1) {
usage(); usage();
} }
if ($killit) { if ($killit) {
$quickuuid = shift(@ARGV); $quickuuid = shift(@ARGV);
} }
elsif ($extend) {
if ($extend !~ /^\d*$/) {
usage();
}
$quickuuid = shift(@ARGV);
}
else { else {
$xmlfile = shift(@ARGV); $xmlfile = shift(@ARGV);
...@@ -154,7 +166,7 @@ else { ...@@ -154,7 +166,7 @@ else {
} }
# Email record. # Email record.
AuditStart(0, undef, LIBAUDIT_NODELETE()) AuditStart(0, undef)
if (! $debug); if (! $debug);
# Connect to the SA DB. # Connect to the SA DB.
...@@ -197,6 +209,9 @@ if (!defined($cm_authority)) { ...@@ -197,6 +209,9 @@ if (!defined($cm_authority)) {
if ($killit) { if ($killit) {
exit(Terminate($quickuuid)); exit(Terminate($quickuuid));
} }
elsif ($extend) {
exit(Extend($quickuuid, $extend));
}
# #
# Must wrap the parser in eval since it exits on error. # Must wrap the parser in eval since it exits on error.
...@@ -464,8 +479,6 @@ if (!$debug) { ...@@ -464,8 +479,6 @@ if (!$debug) {
# All of the logging magic happens in here. # All of the logging magic happens in here.
libaudit::AuditFork(); libaudit::AuditFork();
} }
print STDERR "Child pid $PID\n";
my $rspecstr = GiveMeRspec($imageid); my $rspecstr = GiveMeRspec($imageid);
# #
...@@ -504,6 +517,9 @@ GeniDB::DBQueryWarn("update quickvms set ". ...@@ -504,6 +517,9 @@ GeniDB::DBQueryWarn("update quickvms set ".
" status='provisioned', manifest=$safe_manifest ". " status='provisioned', manifest=$safe_manifest ".
"where uuid='$quickvm_uuid'"); "where uuid='$quickvm_uuid'");
print STDERR "\n";
print STDERR "$manifest\n\n";
# #
# but have to wait for the sliver to be ready, which means polling. # but have to wait for the sliver to be ready, which means polling.
# #
...@@ -676,3 +692,63 @@ sub Terminate($) ...@@ -676,3 +692,63 @@ sub Terminate($)
DBQueryWarn("delete from quickvms where uuid=$safe_uuid"); DBQueryWarn("delete from quickvms where uuid=$safe_uuid");
exit(0); exit(0);
} }
#
# Extend a quick VM.
#
sub Extend($$)
{
my ($uuid, $seconds) = @_;
my $safe_uuid = DBQuoteSpecial($uuid);
my $query_result =
DBQueryWarn("select * from quickvms where uuid=$safe_uuid");
if (! ($query_result && $query_result->numrows)) {
fatal("No such quick VM: $uuid");
}
my $row = $query_result->fetchrow_hashref();
my $geniuser = GeniUser->Lookup($row->{'creator_uuid'}, 0);
if (!defined($geniuser)) {
fatal("No creator for quick VM: $uuid");
}
my $slice = GeniSlice->Lookup($row->{'slice_uuid'});
if (!defined($slice)) {
fatal("No slice for quick VM: $uuid");
}
# Need to update slice before creating new credential.
$slice->AddToExpiration($extend);
my $new_expires = $slice->ExpirationGMT();
# Create a slice credential
my $slice_credential =
GeniCredential->CreateSigned($slice,
$geniuser,
$GeniCredential::LOCALSA_FLAG);
if (!defined($slice_credential)) {
fatal("Could not create credential for $slice");
}
my $speaksfor_credential = GeniCredential->Create($geniuser, $sa_authority);
fatal("Could not create speaksfor credential")
if (!defined($speaksfor_credential));
$speaksfor_credential->SetType("speaksfor");
fatal("Could not sign speaksfor credential")
if ($speaksfor_credential->Sign($GeniCredential::LOCALSA_FLAG));
my $response =
Genixmlrpc::CallMethod($cm_authority->url(), undef,
"RenewSlice",
{ "slice_urn" => $slice->urn(),
"expiration" => $new_expires,
"credentials" =>
[$slice_credential->asString(),
$speaksfor_credential->asString()]});
if (!defined($response) || $response->code() != GENIRESPONSE_SUCCESS) {
fatal("RenewSlice failed: ".
(defined($response) ? $response->output() : "") . "\n");
}
$slice->SetExpiration($new_expires);
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