Commit aea29c15 authored by Leigh Stoller's avatar Leigh Stoller

Add ListActiveSlivers() to CM api for GPO monitoring.

parent 33001716
......@@ -2724,5 +2724,89 @@ sub ListImages($)
return GeniResponse->Create(GENIRESPONSE_SUCCESS, \@result);
}
#
# Active slivers.
#
sub ListActiveSlivers($)
{
my ($argref) = @_;
my $credentials = $argref->{'credentials'};
if (! (defined($credentials))) {
return GeniResponse->MalformedArgsResponse("credential");
}
my $authority = GeniAuthority->Lookup($ENV{'MYURN'});
if (!defined($authority)) {
print STDERR "Could not find local authority object\n";
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
my $credential = CheckCredentials($credentials);
return $credential
if (GeniResponse::IsResponse($credential));
$credential->HasPrivilege("readhistory") or
return GeniResponse->Create( GENIRESPONSE_FORBIDDEN, undef,
"Insufficient privilege" );
my $certificate = GeniRegistry::ClearingHouse->GetCertificate();
if (!defined($certificate)) {
print STDERR "Could not load clearinghouse certificate\n";
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
# The target has to match the clearinghouse (delegated credential).
if ($credential->target_urn() ne $certificate->urn()) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Only the clearinghouse can do this!");
}
my $query_result =
DBQueryWarn("select a.idx,m.manifest from geni_aggregates as a ".
"left join geni_manifests as m on ".
" m.slice_uuid=a.slice_uuid ".
"where a.type='Aggregate'");
return GeniResponse->Create(GENIRESPONSE_ERROR)
if (!$query_result);
return GeniResponse->Create(GENIRESPONSE_SEARCHFAILED, undef,
"Mo matching records")
if (! $query_result->numrows);
my @results = ();
while (my ($idx,$manifest) = $query_result->fetchrow_array()) {
my $aggregate = GeniAggregate->Lookup($idx);
next
if (!defined($aggregate));
my $slice = $aggregate->GetSlice();
next
if (!defined($slice));
my %blob = ();
$blob{'sliver_uuid'} = $aggregate->uuid();
$blob{'sliver_urn'} = $aggregate->urn();
$blob{'slice_urn'} = $slice->urn();
$blob{'slice_uuid'} = $slice->uuid();
$blob{'creator_urn'} = $slice->creator_urn();
$blob{'creator_uuid'} = $slice->creator_uuid();
$blob{'created'} = $aggregate->created();
$blob{'expires'} = $aggregate->expires();
$blob{'status'} = $aggregate->status();
$blob{'state'} = $aggregate->state();
if (defined($manifest)) {
$blob{'manifest'} = $manifest;
}
else {
$blob{'manifest'} = "";
}
push(@results, \%blob);
}
# Slow down the GMOC queries.
sleep(5);
return GeniResponse->Create(GENIRESPONSE_SUCCESS, \@results);
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -44,7 +44,7 @@ PSBIN_STUFF = register_resources expire_daemon gencrl postcrl \
getchcredential genallow_extcred advt-merge.py \
reservevlans delgeniuser delegatecredential \
updatecert fixcerts initcerts cacontrol webcacontrol \
genextend_lifetime rspeclint chstats \
genextend_lifetime rspeclint chstats listactive \
maptoslice webmaptoslice
ifeq ($(ISCLEARINGHOUSE),1)
......
#!/usr/bin/perl -w
#
# Copyright (c) 2009-2013 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
# GENI Public License
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and/or hardware specification (the "Work") to
# deal in the Work without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Work, and to permit persons to whom the Work
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Work.
#
# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
# IN THE WORK.
#
# }}}
#
use strict;
use English;
use Getopt::Std;
use Data::Dumper;
#
# Ask all components managers for a list of resources used.
#
sub usage()
{
print "Usage: listactive [urn]\n";
exit(1);
}
my $optlist = "";
my $errors = 0;
sub fatal($);
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
#
# Check args.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
my $urn = $ARGV[0]
if (@ARGV == 1);
use vars qw($GENI_DBNAME);
$GENI_DBNAME = "geni-ch";
# Now we can load the libraries after setting the proper DB.
use lib '@prefix@/lib';
use libtestbed;
require GeniDB;
require Genixmlrpc;
use GeniResponse;
require GeniCertificate;
require GeniCredential;
require GeniAuthority;
require GeniSlice;
require GeniRegistry;
#
# The RPC context for this script is as the CH
#
my $certificate = GeniRegistry::ClearingHouse->GetCertificate();
if (!defined($certificate)) {
fatal("Could not load ClearingHouse certificate");
}
Genixmlrpc->SetContext(Genixmlrpc->Context($certificate));
Genixmlrpc->SetTimeout(15);
my $authority = GeniAuthority->Lookup($certificate->urn());
if (!defined($authority)) {
fatal("Could not locate ClearingHouse authority object");
}
#
# Use a self signed clearinghouse credential.
#
my $credential = GeniCredential->GetSelfCredential($authority);
if (!defined($credential)) {
fatal("Could not create self signed clearinghouse credential");
}
#
# Call listactive on a CM.
#
sub ListActive($)
{
my ($manager) = @_;
print "$manager\n";
my $response =
Genixmlrpc::CallMethod($manager->url(), undef,
"ListActiveSlivers",
{ "credential" => $credential->asString(),
"credentials" => [$credential->asString()]});
if (!defined($response) || $response->code() != GENIRESPONSE_SUCCESS) {
print STDERR
"Could not listusage on $manager: ".
(defined($response) ? $response->output() : "") . "\n";
$errors++;
return;
}
foreach my $ref (@{$response->value()}) {
print Dumper($ref);
}
}
if (defined($urn)) {
my $manager = GeniAuthority->Lookup($urn);
fatal("Could not find manager in the DB")
if (!defined($manager));
ListActive($manager);
}
else {
#
# List of all CMs.
#
my $query_result =
GeniDB::DBQueryWarn("select uuid from geni_authorities ".
"where type='cm' and disabled=0");
fatal("Could not lookup CM list")
if (!defined($query_result));
fatal("No managers listed in the DB; is this a ClearingHouse?")
if (!$query_result->numrows);
while (my ($manager_uuid) = $query_result->fetchrow_array()) {
my $manager = GeniAuthority->Lookup($manager_uuid);
print STDERR "Could not lookup up CM $manager_uuid\n"
if (!defined($manager));
ListActive($manager);
}
}
exit($errors);
sub fatal($) {
my ($msg) = @_;
print STDERR "$msg\n";
exit(1);
}
......@@ -102,6 +102,7 @@ elsif ($GENI_VERSION eq "2.0") {
"CreateImage" => \&GeniCMV2::CreateImage,
"DeleteImage" => \&GeniCMV2::DeleteImage,
"ListImages" => \&GeniCMV2::ListImages,
"ListActiveSlivers" => \&GeniCMV2::ListActiveSlivers,
};
}
......
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