console_reset.in 1.41 KB
Newer Older
1
2
3
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl -wT
use English;

#
# usage: console_reset
#
sub usage()
{
    print STDOUT "Usage: console_reset\n";
    exit(-1);
}

#
# Configure variables
#
my $TB		= "@prefix@";

#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;

# Turn off line buffering on output
$| = 1; 

my $consetup = "$TB/libexec/console_setup";
my @row;
my @nodes    = ();
my %shelves  = ();

# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

if (@ARGV) {
    usage();
}

#
# Only root or admins should run this script.
#
if ($UID && !TBAdmin($UID)) {
    die("Only root or TB admins can run this script.");

}

#
# Get a list of all of the experimental nodes.
#
my $query_result =
Leigh B. Stoller's avatar
Leigh B. Stoller committed
53
54
    DBQueryFatal("select node_id from nodes where role='testnode' ".
		 "order by priority");
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

while (@row = $query_result->fetchrow_array()) {
    my $node = $row[0];
    push(@nodes, $node);
}

#
# Issue small batches of setup.
#
while (@nodes) {
    my @batch = ();
    my $i = 0;

    while ($i < 10 && @nodes > 0) {
	my $node = shift(@nodes);
	
	#
	# Another classic shark hack. Only add shelves to the list.
	# 
	if ($node =~ /(sh\d+)-\d+/) {
	    if (defined($shelves{$1})) {
		next;
	    }
	    $shelves{$1} = $1;
	    $node = $1;
	}
	    
	push(@batch, $node);
	$i++;
    }
    
    print "Issuing console_setup for @batch ...\n";

    system("$consetup @batch");
}

exit 0;