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 1.91 KB
Newer Older
Mac Newbold's avatar
Mac Newbold committed
1 2
#!/usr/local/bin/perl -w
use Mysql;
3
use English;
Mac Newbold's avatar
Mac Newbold committed
4

5 6 7 8 9 10 11
#
# Configure variables
#
my $TB     = "@prefix@/bin";
my $DBNAME = "@TBDBNAME@";

my $dbh = Mysql->connect("localhost",$DBNAME,"script","none");
Mac Newbold's avatar
Mac Newbold committed
12

13
if ($#ARGV < 1) {die("Usage: nalloc <pid> <eid> <node> <node> <...>\n");}
Mac Newbold's avatar
Mac Newbold committed
14

15
my $consetup="$TB/console_setup";
16
my $error = 0;
17
my $pid = shift;
Mac Newbold's avatar
Mac Newbold committed
18 19 20 21 22 23 24 25
my $eid = shift;
my @node_names=@ARGV;
my @machines = @node_names;
foreach my $m (@machines) { $m = "node_id='".$m."'"; }
my $list= join(" or ",@machines);

my $cmd = "";
my $sth = "";
26

27 28 29 30 31
my $self = (getpwuid($UID))[0]
  || die "Cannot figure out who you are!\n";

$cmd = "select uid from proj_memb as pm left join experiments as e on ".
  "e.pid=pm.pid where e.eid='$eid' and uid='$self' and e.pid='$pid'";
32
$sth = $dbh->query($cmd);
33 34
if ( ($sth->numrows < 1) && ($UID != 0) && ($EUID != 0)) {	
  die("You are not a member of experiment '$eid' in project '$pid'.\n");
35
}
Mac Newbold's avatar
Mac Newbold committed
36 37
 
foreach my $n (@node_names) { 
38 39 40 41 42 43
  $sth = $dbh->query("select * from reserved where node_id='$n'");
  if ($sth->numrows > 0) {
    $cmd="select * from reserved where node_id='$n' and eid='$eid' and pid='$pid'";
    $sth = $dbh->query($cmd);
    if ($sth->numrows > 0) {	
      print "You have already reserved node '$n'.\n";
44
      # Do not increment error code since that throws off tbprerun.
Mac Newbold's avatar
Mac Newbold committed
45
    } else {
46
      print "Someone else has already reserved node '$n'.\n";
47
      $error++;
48 49 50 51 52 53
    }
    next;
  } else {
    $sth = $dbh->query("select * from nodes where node_id='$n'");
    if ($sth->numrows < 1) {	
      print "Node '$n' does not exist.\n";
54
      $error++;
55
      next;
Mac Newbold's avatar
Mac Newbold committed
56
    }
57 58 59 60
  }
  print "Reserving node '$n'...";
  $cmd = "insert into reserved (node_id,pid,eid) values ('$n','$pid','$eid')";
  $sth = $dbh->query($cmd) && print "Succeeded.\n"
61 62
    || (print "Failed Command:\n$cmd\nError string is:".$dbh->errstr."\n"
      && $error++);
63 64
  system("$consetup $n") == 0 or
      print STDERR "WARNING: $consetup $n failed!";
Mac Newbold's avatar
Mac Newbold committed
65
}
66 67

exit($error);