Commit 346d23bf authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Add extrypoint to export the Openstack stats file from the controller

node. The caller says what node (via the vname, not the nodeid).
parent 3c6e6308
......@@ -63,6 +63,7 @@ my $MAINSITE = @TBMAINSITE@;
my $OURDOMAIN = "@OURDOMAIN@";
my $IDLESTATS = "$TB/bin/idlestats";
my $SUDO = "/usr/local/bin/sudo";
my $SSH = "/usr/bin/ssh";
my $WAP = "$TB/sbin/withadminprivs";
my $API_VERSION = 1.0;
......@@ -439,5 +440,65 @@ sub SliceIdleData($)
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $output);
}
#
# Return openstack data for the nodes in a slice.
#
sub SliceOpenstackData($)
{
my ($argref) = @_;
my $slice_urn = $argref->{'slice_urn'};
my $client_id = $argref->{'client_id'};
my %blob = ();
my $hasperm = CheckPermission();
return $hasperm
if (GeniResponse::IsError($hasperm));
if ($client_id !~ /^[-\w]+$/) {
return GeniResponse->Create(GENIRESPONSE_BADARGS)
}
my $slice = GeniSlice->Lookup($slice_urn);
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED)
if (!defined($slice));
my $experiment = $slice->GetExperiment();
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"No experiment for $slice")
if (!defined($experiment));
my $node = $experiment->VnameToNode($client_id);
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"No such controller node for $slice")
if (!defined($node));
my $node_id = $node->node_id();
my $sshopts = "-o ServerAliveInterval=10 -o ServerAliveCountMax=1 ";
$sshopts .= "-o ConnectTimeout=10 ";
$sshopts .= "-o BatchMode=yes -o StrictHostKeyChecking=no ";
my $sshcmd = "cat /root/setup/cloudlab-openstack-stats.json";
$EUID = $UID = 0;
my $output = GeniUtil::ExecQuiet("$SUDO $SSH $sshopts $node_id '$sshcmd'");
if ($?) {
GeniUtil::FlipToGeniUser();
print STDERR "Error getting json from $node_id: $output\n";
#
# See if it is cause the file does not exist, we want to tell
# the caller so it does not keep asking.
#
if ($output =~ /No such file/im) {
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"No json file on $node_id");
}
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Error getting json from $node_id: $output");
}
GeniUtil::FlipToGeniUser();
#
# We get a json encoded string back.
#
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $output);
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -242,6 +242,7 @@ ProtoGeniDefs::AddModule("cluster",
"PreReservations" => \&GeniCluster::PreReservations,
"SliceUtilizationData" => \&GeniCluster::SliceUtilizationData,
"SliceIdleData" => \&GeniCluster::SliceIdleData,
"SliceOpenstackData" => \&GeniCluster::SliceOpenstackData,
}},
});
......
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