listhistory.in 4.57 KB
Newer Older
1 2
#!/usr/bin/perl -w
#
Leigh Stoller's avatar
Leigh Stoller committed
3
# Copyright (c) 2009-2010 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# 
# {{{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.
# 
# }}}
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#
use strict;
use English;
use Getopt::Std;
use Data::Dumper;

#
# Ask all components managers for a list of tickets issued.
# 
sub usage()
{
    print "Usage: listusage [cm ...]\n";
    exit(1);
}
my $optlist    = "";
my $errors     = 0;
my @managers;
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();
}
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;

if (@ARGV) {
    while (@ARGV) {
Leigh Stoller's avatar
Leigh Stoller committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
	my $urn = shift(@ARGV);

	my $manager = GeniAuthority->Lookup($urn);
	print STDERR "Could not lookup up CM $urn\n"
	    if (!defined($manager));

	push(@managers, $manager);
    }
}
else {
    #
    # List of all CMs.
     #
    my $query_result =
	GeniDB::DBQueryWarn("select uuid from geni_authorities ".
			    "where type='cm'");
    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));

	push(@managers, $manager);
114 115 116 117 118 119
    }
}

#
# The RPC context for this script is as the CH
#
Leigh Stoller's avatar
Leigh Stoller committed
120
my $certificate = GeniRegistry::ClearingHouse->GetCertificate();
121
if (!defined($certificate)) {
Leigh Stoller's avatar
Leigh Stoller committed
122
    fatal("Could not load ClearingHouse certificate");
123 124 125 126
}
Genixmlrpc->SetContext(Genixmlrpc->Context($certificate));
Genixmlrpc->SetTimeout(15);

Leigh Stoller's avatar
Leigh Stoller committed
127
my $authority = GeniAuthority->Lookup($certificate->urn());
128
if (!defined($authority)) {
Leigh Stoller's avatar
Leigh Stoller committed
129
    fatal("Could not locate ClearingHouse authority object");
130 131 132
}

#
Leigh Stoller's avatar
Leigh Stoller committed
133
# Use a self signed clearinghouse credential.
134
#
Leigh Stoller's avatar
Leigh Stoller committed
135 136 137 138
my $credential = GeniCredential->GetSelfCredential($authority);
if (!defined($credential)) {
    fatal("Could not create self signed clearinghouse credential");
}
139

Leigh Stoller's avatar
Leigh Stoller committed
140 141 142 143 144 145 146
#
# Call ListHistory on a CM.
#
sub ListHistory($)
{
    my ($manager) = @_;
    
147 148 149 150 151
    print "$manager\n";
	
    my $response =
	Genixmlrpc::CallMethod($manager->url(), undef,
			       "ListHistory",
Leigh Stoller's avatar
Leigh Stoller committed
152 153 154
			       { "type"        => "",
				 "credential"  => $credential->asString(),
				 "credentials" => [$credential->asString()]});
155 156
    if (!defined($response) || $response->code() != GENIRESPONSE_SUCCESS) {
	print STDERR
Leigh Stoller's avatar
Leigh Stoller committed
157 158
	    "Could not listusage on $manager: ".
	    (defined($response) ? $response->output() : "") . "\n";
159
	    $errors++;
Leigh Stoller's avatar
Leigh Stoller committed
160
	return;
161 162 163 164 165 166 167 168 169 170 171 172 173
    }
    foreach my $ref (@{$response->value()}) {
	my $owner_hrn = $ref->{'owner_hrn'};
	my $slice_hrn = $ref->{'slice_hrn'};
	my $created   = $ref->{'created'};
	my $redeemed  = $ref->{'redeemed'};
	my $expired   = $ref->{'expired'};
	my $released  = $ref->{'released'};
	my $rspec     = $ref->{'rspec'};

	print "$owner_hrn,$slice_hrn,$created,$redeemed,$expired,$released\n";
	print "$rspec\n";
    }
Leigh Stoller's avatar
Leigh Stoller committed
174 175 176
}
foreach my $manager (@managers) {
    ListHistory($manager);
177 178 179 180 181 182 183 184 185
}
exit($errors);

sub fatal($) {
    my ($msg) = @_;

    print STDERR "$msg\n";
    exit(1);
}