All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

tbend.in 2.97 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1
#!/usr/bin/perl -w
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
#
3
# Copyright (c) 2000-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
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
23
#
24
use strict;
25
use English;
26
use Getopt::Std;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
27

28
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
29 30 31
# This is the fourth and final program in the
# tbprerun/tbswapin/tbswapout/.../tbend sequences.  It's purpose is to
# reverse what tbprerun did.  I.e. clear the virt_nodes and virt_lans
32
# tables.
33
#
34 35
sub usage()
{
36
    print STDERR "Usage: $0 [-f] -e eid\n";
37 38
    exit(-1);
}
39 40 41
my $optlist = "fe:";
my $pideid;
my $force   = 0;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
42

43 44 45
#
# Configure variables
#
46 47 48
my $TBROOT       = "@prefix@";
my $OPSDBSUPPORT = @OPSDBSUPPORT@;
my $dbcontrol    = "$TBROOT/sbin/opsdb_control";
49
my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
50

51
# Untaint the path
Leigh B. Stoller's avatar
Leigh B. Stoller committed
52
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" . 
Chad Barb's avatar
 
Chad Barb committed
53
    ":$TBROOT/libexec/vis:$TBROOT/sbin:$TBROOT/bin";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
54

55 56 57 58 59
#
# Turn off line buffering on output
#
$| = 1;

60 61 62
#
# Testbed Support libraries
#
63
use lib "@prefix@/lib";
64 65
use libdb;
use libtestbed;
66 67
use libtblog;
use Experiment;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
68

69
#
70 71
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
72
#
73 74 75
my %options = ();
if (! getopts($optlist, \%options)) {
    usage();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
76
}
77 78 79 80 81 82 83
if (defined($options{"f"})) {
    $force = 1;
}
if (defined($options{"e"})) {
    $pideid = $options{"e"};
}
if (!defined($pideid) || @ARGV) {
84
    usage();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
85
}
86 87 88 89 90 91 92 93 94 95 96

# Slowly convert to using Experiment module.
my $experiment = Experiment->Lookup($pideid);
if (!defined($experiment)) {
    tbdie("Could not lookup experiment object for $pideid!")
}
# Need these below.
my $pid      = $experiment->pid();
my $eid      = $experiment->eid();
my $state    = $experiment->state();
my $errors   = 0;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
97

98
print "Beginning cleanup for $pid/$eid. " . TBTimeStamp() . "\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
99

100 101
# Sanity check the state.
if (!$force && $state ne EXPTSTATE_TERMINATING) {
102
    tbdie("Experiment is in the wrong state: $state.\n");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
103
}
104

105
if ($PGENISUPPORT) {
106 107
    require libGeni;

108 109 110 111
    if (libGeni::UnRegister($experiment)) {
	tbdie("Could not delete protogeni slice\n");
    }
}
112
print "Clearing out virtual state.\n";
113
$experiment->RemoveVirtualState() == 0 or $errors++;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
114

115
# This will kill a running prerender.
Chad Barb's avatar
 
Chad Barb committed
116
print "Removing visualization data...\n";
117
system("prerender -r $pid $eid");
Chad Barb's avatar
 
Chad Barb committed
118

119 120 121
system("$dbcontrol delexpdb $pid $eid")
    if ($OPSDBSUPPORT);

122
print "Cleanup finished! " . TBTimeStamp() . "\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
123

Leigh B. Stoller's avatar
Leigh B. Stoller committed
124
exit $errors;
125