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.

nalloc.in 3.7 KB
Newer Older
1
#!/usr/bin/perl -w
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3 4 5 6 7

#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
8
use English;
9
use Getopt::Std;
Mac Newbold's avatar
Mac Newbold committed
10

11 12 13 14 15 16
#
# nalloc - allocate nodes to an experiment. Takes a pid, and eid, and
# a list of nodes. Only nodes that are free can be allocated, and a
# special hack for sharks is included - allocating 'sh*' expands to
# allocation of the entire rack.
#
17

18 19 20
#
# Configure variables
#
21
my $TB       = "@prefix@";
22 23 24 25 26
use lib '@prefix@/lib';
use libdb;

my %opt = ();
getopts(\%opt,'v');
27

28 29 30 31
my $debug = 0;
if ($opt{v}) {
    $debug = 1;
}
Mac Newbold's avatar
Mac Newbold committed
32

33 34 35 36
if (@ARGV < 2) {
    die("Usage: nalloc [-v] <pid> <eid> <node> <node> <...>\n".
	 "		-v enables debugging output\n");
}
Mac Newbold's avatar
Mac Newbold committed
37

38 39
my $consetup="$TB/libexec/console_setup";
my $exportsetup="$TB/sbin/exports_setup";
40
my $error = 0;
41
my $pid = shift;
Mac Newbold's avatar
Mac Newbold committed
42 43
my $eid = shift;
my @node_names=@ARGV;
mac's avatar
mac committed
44 45
my @vals = ();
my @nodes= ();
Mac Newbold's avatar
Mac Newbold committed
46

47
if ($debug) { print "Expt '$eid', proj '$pid'\n"; }
48

49
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
50 51 52 53 54 55 56 57
# Experiment must exist.
# 
if (!ExpState($pid,$eid)) {
    die "There is no experiment $eid in project $pid\n";
}

#
# User must have permission to modify the experiment.
58
#
59
if ($UID) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
60 61
    if (!TBExptAccessCheck($UID, $pid, $eid, TB_EXPT_MODIFY)) {
        die("*** You not have permission to allocate nodes in $pid/$eid!\n");
62
    }
63
}
64 65 66 67 68 69 70

######################################################################
# Step 1 - Make a list of nodes to reserve
#
# We prune nodes that are already reserved, etc., from the list, and
# do expansion of shark shelves
######################################################################
71

72
DBQueryFatal("lock tables nodes read, reserved write");
mac's avatar
mac committed
73

74
foreach my $n (@node_names) {
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    # Shark hack
    if ($n =~ /(sh\d+)/ ) { $n = $1."-1"; }
    # End shark hack

    my ($r_pid, $r_eid);
    if (NodeidToExp($n,\$r_pid,\$r_eid)) {
	# Someone has already reserved this node
	if (($r_pid eq $pid) && ($r_eid eq $eid)) {
	    print "You have already reserved node '$n'.\n";
	    # Do not increment error code since that throws off tbprerun.
	} else {
	    print "Someone else has already reserved node '$n'.\n";
	    $error++;
	}
	next; # Go on to the next node if this one is reserved
90
    }
91 92 93

    my $result = DBQueryFatal("select * from nodes where node_id='$n'");
    if ($result->numrows() < 1) {
94
      print "Node '$n' does not exist.\n";
95
      $error++;
96
      next;
mac's avatar
mac committed
97
    } else {
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
	# No one has reserved it, and it exists, so add it to my list
	# Shark hack
	if ($n =~ /(sh\d+)/ ) {
	    # its a shark - do the whole shelf if its not done already.
	    my $shelf = $1;
	    if ( ! (join(",",@nodes) =~ /,$shelf-\d,/)) {
		# Shelf hasn't been done yet...
		foreach my $n ( 1 .. 8 ) {
		    push(@vals,"('$shelf-$n','$pid','$eid')");
		    push(@nodes,"$shelf-$n");
		}
	    }
	    # End shark hack
	} else {
	    # its not a shark - just add it in...
	    push(@vals,"('$n','$pid','$eid')");
	    push(@nodes,"$n");
115
	}
Mac Newbold's avatar
Mac Newbold committed
116 117
    }
}
118

119 120 121 122 123 124 125
if ($debug) { print "List Ready: @vals\nError=$error\n"; }

######################################################################
# Step 2 - Make the reservations in the database
#
# Uses the list built in step 1
######################################################################
126

mac's avatar
mac committed
127
if (!$error && @vals) {
128
  print "Reserving nodes...\n";
129 130
  my $cmd = "insert into reserved (node_id,pid,eid) values ".join(",",@vals);
  if (!DBQueryWarn($cmd)) { $error++; }
mac's avatar
mac committed
131 132
}

133 134 135 136 137 138 139
DBQueryFatal("unlock tables");

######################################################################
# Step 3 - Setup consoles
#
# Uses the list built in step 1
######################################################################
mac's avatar
mac committed
140

141
if (!$error && @nodes) {
142 143
    system("$consetup @nodes") == 0 or
	print STDERR "WARNING: $consetup @nodes failed!\n";
Mac Newbold's avatar
Mac Newbold committed
144 145
}

146
if ($debug) { print "Returning with value $error\n"; }
147
exit($error);