tbend.in 2.84 KB
Newer Older
Leigh Stoller's avatar
Leigh Stoller committed
1
#!/usr/bin/perl -w
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2010, 2017 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 Stoller's avatar
Leigh Stoller committed
23
#
24
use strict;
25
use English;
26
use Getopt::Std;
Leigh Stoller's avatar
Leigh Stoller committed
27

28
#
Leigh Stoller's avatar
Leigh 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 Stoller's avatar
Leigh 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 Stoller's avatar
Leigh Stoller committed
50

51
# Untaint the path
Leigh Stoller's avatar
Leigh 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 Stoller's avatar
Leigh 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 Stoller's avatar
Leigh 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 Stoller's avatar
Leigh 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 Stoller's avatar
Leigh 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 Stoller's avatar
Leigh Stoller committed
97

98
print "Beginning cleanup for $pid/$eid. " . TBTimeStamp() . "\n";
Leigh Stoller's avatar
Leigh 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 Stoller's avatar
Leigh Stoller committed
103
}
104 105

print "Clearing out virtual state.\n";
106
$experiment->RemoveVirtualState() == 0 or $errors++;
Leigh Stoller's avatar
Leigh Stoller committed
107

108
# This will kill a running prerender.
Chad Barb's avatar
Chad Barb committed
109
print "Removing visualization data...\n";
110
system("prerender -r $pid $eid");
Chad Barb's avatar
Chad Barb committed
111

112 113 114
system("$dbcontrol delexpdb $pid $eid")
    if ($OPSDBSUPPORT);

115
print "Cleanup finished! " . TBTimeStamp() . "\n";
Leigh Stoller's avatar
Leigh Stoller committed
116

Leigh Stoller's avatar
Leigh Stoller committed
117
exit $errors;
118