remauthority.in 2.85 KB
Newer Older
1 2
#!/usr/bin/perl -w
#
3
# Copyright (c) 2008-2011 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
#
use strict;
use English;
use Data::Dumper;
use Getopt::Std;

#
# Remove an authority from the DB.
# 
sub usage()
{
40
    print "Usage: remauthority [-c | -m] <uuid>\n";
41 42
    exit(1);
}
43
my $optlist    = "cm";
44
my $asch       = 0;
45
my $ascm       = 0;
46 47 48 49 50 51 52 53 54 55 56 57 58

sub fatal($);

#
# Check args.
#
my %options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (defined($options{"c"})) {
    $asch = 1;
}
59 60 61
if (defined($options{"m"})) {
    $ascm = 1;
}
62 63 64 65 66 67 68 69 70
usage()
    if (@ARGV != 1);

my $uuid     = $ARGV[0];

use vars qw($GENI_DBNAME);
if ($asch) {
    $GENI_DBNAME = "geni-ch";
}
71 72 73
elsif ($ascm) {
    $GENI_DBNAME = "geni-cm";
}
74 75 76 77 78 79 80 81

# Now we can load the libraries after setting the proper DB.
use lib '@prefix@/lib';
require GeniDB;
require GeniCertificate;
require GeniAuthority;
require GeniSlice;
require GeniUser;
82
require GeniComponent;
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

my $authority = GeniAuthority->Lookup($uuid);
if (!defined($authority)) {
    fatal("No such authority in DB");
}
if ($authority->type() eq "cm") {
    if (GeniComponent->DeleteAll($authority) != 0) {
	fatal("Could not delete components for $authority");
    }
}
elsif ($authority->type() eq "sa") {
    if (GeniSlice->DeleteAll($authority) != 0) {
	fatal("Could not delete slices for $authority");
    }
    if (GeniUser->DeleteAll($authority) != 0) {
	fatal("Could not delete users for $authority");
    }
100
    GeniCertificate->DeleteCRL($authority);
101
}
Leigh Stoller's avatar
Leigh Stoller committed
102 103 104
elsif ($authority->type() eq "ses") {
    # Nothing to do.
}
105 106 107
elsif ($authority->type() eq "am") {
    # Nothing to do.
}
108 109 110
else {
    fatal("Do not know how to delete $authority");
}
111

112 113 114 115 116 117 118 119 120 121 122 123 124
if ($authority->Delete() != 0) {
    fatal("Could not delete components for $authority");
}

exit(0);

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

    die("*** $0:\n".
	"    $msg\n");
}