Commit 11f64c77 authored by Leigh Stoller's avatar Leigh Stoller

Add an instageni (CM) specific call to get the magic console URL

that will allow the caller to access a console line (for a brief
moment in time).
parent d7933e6c
......@@ -31,7 +31,7 @@ use vars qw(@ISA @EXPORT $AUTOLOAD @EXPORT_OK);
# Configure variables
use vars qw($TB $BOSSNODE $WOL $OSSELECT $IPOD $ISUTAH $CONTROL_NETMASK
$TBOPS $JAILIPMASK);
$TBOPS $JAILIPMASK $TBBASE);
$TB = "@prefix@";
$BOSSNODE = "@BOSSNODE@";
$TBOPS = "@TBOPSEMAIL@";
......@@ -43,6 +43,7 @@ $ISUTAH = @TBMAINSITE@;
# Need this for jail ip assignment.
$CONTROL_NETMASK = "@CONTROL_NETMASK@";
$JAILIPMASK = "@JAILIPMASK@";
$TBBASE = "@TBBASE@";
use libdb;
use libtestbed;
......@@ -3706,5 +3707,35 @@ sub SendApod($$)
return -1;
}
#
# Generate a hash value to store in the tiplines table for the node,
# The hash can only be used once and is valid for a short time
# (say, 30 seconds).
#
sub GenTipAclUrl($)
{
my ($self) = @_;
my $node_id = $self->node_id();
my $hash = TBGenSecretKey();
if (!defined($hash)) {
print STDERR "Error creating new hash code\n";
return undef;
}
DBQueryWarn("update tiplines set urlhash='$hash', ".
" urlstamp=UNIX_TIMESTAMP(now()) ".
"where node_id='$node_id'")
or return undef;
return "$TBBASE/nodetipacl.php3?node_id=$node_id&key=$hash";
}
sub ClrTipAclUrl($)
{
my ($self) = @_;
my $node_id = $self->node_id();
DBQueryWarn("update tiplines set urlhash=NULL,urlstamp=0 ".
"where node_id='$node_id'");
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -2860,5 +2860,74 @@ sub ShareLanAux($$)
return GeniResponse->Create(GENIRESPONSE_SUCCESS);
}
#
# Emulab specific function to ask for a URL to access the console.
#
sub ConsoleURL($)
{
my ($argref) = @_;
my $slice_urn = $argref->{'slice_urn'};
my $credentials = $argref->{'credentials'};
my $sliver_urn = $argref->{'sliver_urn'};
if (! (defined($credentials) &&
defined($slice_urn) && defined($sliver_urn))) {
return GeniResponse->MalformedArgsResponse("Missing arguments");
}
my ($credential,$speaksfor) = GeniStd::CheckCredentials($credentials);
return $credential
if (GeniResponse::IsResponse($credential));
my $user = GeniCM::CreateUserFromCertificate($credential);
return $user
if (GeniResponse::IsResponse($user));
my ($slice, $aggregate) = Credential2SliceAggregate($credential);
return $slice
if (defined($slice) && GeniResponse::IsResponse($slice));
if (! (defined($slice) && defined($aggregate))) {
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"Slice does not exist");
}
main::AddLogfileMetaDataFromSlice($slice);
if ($slice_urn ne $slice->urn()) {
return GeniResponse->Create(GENIRESPONSE_FORBIDDEN(), undef,
"Credential does not match the URN");
}
my $sliver = GeniSliver->Lookup($sliver_urn);
if (!defined($sliver)) {
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"Sliver does not exist");
}
if ($sliver->slice_uuid() ne $slice->uuid()) {
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"Sliver is not in slice");
}
my $node_id = $sliver->resource_id();
my $node = Node->Lookup($node_id);
if (!defined($node)) {
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"No node for sliver urn");
}
my $experiment = $slice->GetExperiment();
if (!defined($experiment)) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"No local experiment for slice");
}
my $pid = $experiment->pid();
if (! $experiment->SameExperiment($node->Reservation())) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Node is not in the proper experiment");
}
my $url = $node->GenTipAclUrl();
if (!defined($url)) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Internal error generating URL");
}
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $url);
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -105,6 +105,7 @@ elsif ($GENI_VERSION eq "2.0") {
"ShareLan" => \&GeniCMV2::ShareLan,
"UnShareLan" => \&GeniCMV2::UnShareLan,
"ListActiveSlivers" => \&GeniCMV2::ListActiveSlivers,
"ConsoleURL" => \&GeniCMV2::ConsoleURL,
};
}
......
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