Commit 6c685f91 authored by Robert Ricci's avatar Robert Ricci

New script, deletenode. Does what it sounds like. Scrubs tables

of all references to a node. Mainly intended for when you have a
mishap with the newnode stuff and need to clean it up.

Added a big list of which tables contain information about physical
nodes to libdb, so that this and other scripts can find it all.
parent 78b2ddf7
......@@ -1334,7 +1334,7 @@ fi
# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
# ./install, which can be erroneously created by make from ./install.sh.
echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
echo "configure:1337: checking for a BSD compatible install" >&5
echo "configure:1338: checking for a BSD compatible install" >&5
if test -z "$INSTALL"; then
if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
......@@ -1488,6 +1488,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
utils/cvsupd.pl utils/newnode utils/grantnodetype \
utils/nsgen/GNUmakefile utils/nsgen/webnsgen \
utils/link_config utils/import_commitlog utils/dhcpd_wrapper \
utils/deletenode \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 \
www/swish.conf www/websearch \
vis/GNUmakefile vis/webvistopology vis/dbvistopology \
......
......@@ -527,6 +527,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
utils/cvsupd.pl utils/newnode utils/grantnodetype \
utils/nsgen/GNUmakefile utils/nsgen/webnsgen \
utils/link_config utils/import_commitlog utils/dhcpd_wrapper \
utils/deletenode \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 \
www/swish.conf www/websearch \
vis/GNUmakefile vis/webvistopology vis/dbvistopology \
......
......@@ -141,6 +141,8 @@ use vars qw(@ISA @EXPORT);
TBDB_LOWVPORT TBDB_MAXVPORT TBDB_PORTRANGE
TBDB_PHYSICAL_NODE_TABLES
TBAdmin TBProjAccessCheck TBNodeAccessCheck TBOSIDAccessCheck
TBImageIDAccessCheck TBExptAccessCheck ExpLeader MarkNodeDown
SetNodeBootStatus OSFeatureSupported IsShelved NodeidToExp NodeidToExpOldReserved
......@@ -595,6 +597,55 @@ sub TBDB_CHECKDBSLOT_NOFLAGS() { 0x0; }
sub TBDB_CHECKDBSLOT_WARN() { 0x1; }
sub TBDB_CHECKDBSLOT_ERROR() { 0x2; }
#
# A hash of all tables that contain information about physical nodes - the
# value for each key is the list of columns that could contain the node's ID.
#
sub TBDB_PHYSICAL_NODE_TABLES() {
return (
'current_reloads' => [ 'node_id' ],
'delays' => [ 'node_id' ],
'iface_counters' => [ 'node_id' ],
'interfaces' => [ 'node_id' ],
'interface_settings' => [ 'node_id' ],
'last_reservation' => [ 'node_id' ],
'linkdelays' => [ 'node_id' ],
'location_info' => [ 'node_id' ],
'next_reserve' => [ 'node_id' ],
'node_activity' => [ 'node_id' ],
'node_auxtypes' => [ 'node_id' ],
'node_features' => [ 'node_id' ],
'node_hostkeys' => [ 'node_id' ],
'node_idlestats' => [ 'node_id' ],
'node_status' => [ 'node_id' ],
'node_rusage' => [ 'node_id' ],
'nodeipportnum' => [ 'node_id' ],
'nodelog' => [ 'node_id' ],
'nodes' => [ 'node_id', 'phys_nodeid' ],
'nodeuidlastlogin' => [ 'node_id' ],
'ntpinfo' => [ 'node_id' ],
'outlets' => [ 'node_id' ],
'partitions' => [ 'node_id' ],
'plab_slice_nodes' => [ 'node_id' ],
'port_counters' => [ 'node_id' ],
'reserved' => [ 'node_id' ],
'scheduled_reloads' => [ 'node_id' ],
'state_triggers' => [ 'node_id' ],
'switch_stacks' => [ 'node_id' ],
'tiplines' => [ 'node_id' ],
'tmcd_redirect' => [ 'node_id' ],
'tunnels' => [ 'node_id' ],
'uidnodelastlogin' => [ 'node_id' ],
'v2pmap' => [ 'node_id' ],
'veth_interfaces' => [ 'node_id' ],
'widearea_accounts' => [ 'node_id' ],
'widearea_delays' => [ 'node_id1', 'node_id2' ],
'widearea_nodeinfo' => [ 'node_id' ],
'widearea_recent' => [ 'node_id1', 'node_id2' ],
'wires' => [ 'node_id1', 'node_id2' ],
);
}
#
# Auth stuff.
#
......
......@@ -16,7 +16,8 @@ SUBDIRS = nsgen
BIN_SCRIPTS = delay_config sshtb create_image node_admin link_config
SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
eventping grantnodetype import_commitlog dhcpd_wrapper
eventping grantnodetype import_commitlog dhcpd_wrapper \
deletenode
LIBEXEC_SCRIPTS = webcreateimage newnode
#
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004 University of Utah and the Flux Group.
# All rights reserved.
#
#
# deletenode - a script for deleting a node from the database
#
use lib '@prefix@/lib';
use libdb;
# Turn off line buffering on output
$| = 1;
#
# A list of all the tables we have to delete this node from, and the name of
# the column(s) in that table that contains a node name
#
my %clean_tables = TBDB_PHYSICAL_NODE_TABLES;
if (!TBAdmin()) {
die "Sorry, only testbed administrators can run this script!\n";
}
my $node = shift @ARGV;
if (!$node || @ARGV) {
die "usage: deletenode <node>\n";
}
#
# Start off with some serious sanity checks
#
#
# First, make sure the node exists, and only let them delete experimental nodes
#
my $result = DBQueryFatal("select role from nodes where node_id='$node'");
if ($result->num_rows() != 1) {
die "Node $node does not exist!\n";
}
my ($role) = $result->fetch_row();
if ($role ne "testnode") {
die "Node $node is not a testnode!\n";
}
#
# Don't let 'em delete a node that is allocated, except to hwdown
#
my ($pid, $eid);
my $allocated = NodeidToExp($node,\$pid,\$eid);
if ($allocated && (($pid ne NODEDEAD_PID) || ($eid ne NODEDEAD_EID))) {
die "Node must be free, or in the " . NODEDEAD_PID . "/" . NODEDEAD_EID .
"experiment!\n";
}
#
# Make sure they know what they are getting themselves into
#
print "*** WARNING:\n";
print "This will erase all evidence that $node ever existed in the testbed!\n";
print "Are you SURE you want to continue? ";
my $answer = <>;
if ($answer !~ /^y/i) {
print "Okay, aborting...\n";
exit(1);
}
#
# Okay, let's clean out them tables
#
while (my ($table, $clist) = each %clean_tables) {
foreach my $column (@$clist) {
print "Removing from table $table, column $column\n";
print "DELETE FROM $table WHERE $column='$node';\n";
}
}
exit 0;
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