delvnodes.pl 1.11 KB
Newer Older
1
#!/usr/bin/perl -w
Mike Hibler's avatar
Mike Hibler committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2003-2011 University of Utah and the Flux Group.
Mike Hibler's avatar
Mike Hibler committed
5 6 7
# All rights reserved.
#

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use English;
use Errno;

use lib "/usr/testbed/lib";
use libdb;
use libtestbed;

DBQueryFatal("lock tables reserved write, nodes write");

my $query_result =
    DBQueryFatal("select nodes.node_id from nodes ".
		 "left join reserved on nodes.node_id=reserved.node_id ".
		 "where reserved.node_id is null and ".
		 "      (nodes.type='pcvm' or nodes.type='pcplab')");

23 24 25
# Need to do this when we want to seek around inside the results.
$query_result = $query_result->WrapForSeek();

26 27 28 29 30 31 32 33 34 35 36 37 38 39
while (my ($vnodeid) = $query_result->fetchrow_array()) {
    DBQueryWarn("delete from reserved where node_id='$vnodeid'");
    DBQueryWarn("delete from nodes where node_id='$vnodeid'");
}

DBQueryFatal("unlock tables");

$query_result->dataseek(0);

while (my ($vnodeid) = $query_result->fetchrow_array()) {
    DBQueryWarn("delete from node_hostkeys where node_id='$vnodeid'");
    DBQueryWarn("delete from node_status where node_id='$vnodeid'");
    DBQueryWarn("delete from node_rusage where node_id='$vnodeid'");
}