avail.in 2.62 KB
Newer Older
Mac Newbold's avatar
Mac Newbold committed
1
#!/usr/local/bin/perl -w
2
3
4
5
6
7
8
9
10
11

#
# avail - prints a list of all available nodes
#

#
# Configure variables
#
use lib '@prefix@/lib';
use libdb;
Mac Newbold's avatar
Mac Newbold committed
12

13
my $d = 0; #debug mode
Mac Newbold's avatar
Mac Newbold committed
14
15
16

if ($#ARGV >= 0 && $ARGV[0] =~ /^-?h/i ) { 
  die("Usage:\navail [help] [type[=<type>]] [OS[=<OS>]] [ver[=<OS_ver>]]\n".
17
      #"      [deltas=<delta[,delta,...]>]".
Mac Newbold's avatar
Mac Newbold committed
18
19
      #	" [fixes=<fix_name[,fix_name,...]>]".
      "\n".
Mac Newbold's avatar
Mac Newbold committed
20
      "type \t= pc | shark\n"."OS \t= Linux | FreeBSD | NetBSD | ...\n".
21
      "ver \t= 6.2 | 3.4 | 4.0 | 5.2 | ...\n".#"deltas \t= anetd | ...\n".
Mac Newbold's avatar
Mac Newbold committed
22
23
24
25
26
27
28
29
30
31
32
33
34
      #	"fixes \t\t= cron_off | sendmail_off | ...\n"
      "A field name alone will show that field in the display of available\n".
      "nodes. A field name with '=' will match nodes that have that field\n".
      "empty. A field name with '=' followed by a string will match nodes\n".
      "that have that string in that field.\n"
     );
}

print "Got ARGS = ",join(" ",@ARGV),"\n" if $d;

my %args = ();
while ($#ARGV >= 0) {
  $_ = shift;
Mac Newbold's avatar
Mac Newbold committed
35
  if ( ! /=/ ) { $args{"\L$_"}='='; } else {
36
37
38
    @_ = split('=',$_);
    my ($opt,$val) = @_ if ($#_ >= 0);
    if (!defined($val)) { $val=""; }
39
    $args{"\L$opt"}=$val if (defined($opt));
Mac Newbold's avatar
Mac Newbold committed
40
41
42
43
44
45
46
47
48
  }
}
if ( $d ) {
  print "Parsed args to:\n";
  foreach my $opt (keys %args) {
    print "$opt:\t$args{$opt}\n";
  }
}

49
50
51
my $join= "nodes as a left join reserved as b on a.node_id=b.node_id".
  " left join node_types as nt on a.type=nt.type";
my $cols= "a.node_id,a.type,nt.class";
52
my $cond= "b.node_id is null and a.role='testnode'";
Mac Newbold's avatar
Mac Newbold committed
53
54
my $os = 0;
my $delta = 0;
Mac Newbold's avatar
Mac Newbold committed
55

56
57
if (defined($args{"type"})) {
  # Make it a like, so if they type 'pc' they get pc850 and pc600...
58
59
  $cond .= " and (a.type='".$args{"type"}."' or nt.class='".$args{"type"}."')" 
    if $args{"type"} ne '=';
60
}
Mac Newbold's avatar
Mac Newbold committed
61
62
if (defined($args{"os"})) { 
  $os = 1;
Mac Newbold's avatar
Mac Newbold committed
63
  $cols .= ",d.OS";
Mac Newbold's avatar
Mac Newbold committed
64
  $cond .= " and d.OS='".$args{"os"}."'" if $args{"os"} ne '='; 
Mac Newbold's avatar
Mac Newbold committed
65
66
}
if (defined($args{"ver"})) { 
Mac Newbold's avatar
Mac Newbold committed
67
  $os = 1;
Mac Newbold's avatar
Mac Newbold committed
68
  $cols .= ",d.ver";
69
  $cond .= " and d.ver='".$args{"ver"}."'" if $args{"ver"} ne '='; 
Mac Newbold's avatar
Mac Newbold committed
70
}
71
72
73
74
75
76
# if (defined($args{"deltas"})) { 
#   $os = 1;
#   $delta=1;
#   $cols .= ",e.delta_id";
#   $cond .= " and e.delta_id='".$args{"deltas"}."'" if $args{"deltas"} ne '='; 
# }
Mac Newbold's avatar
Mac Newbold committed
77

Mac Newbold's avatar
Mac Newbold committed
78
79
if ($os) {
  $join .= " left join partitions as c on a.node_id=c.node_id";
80
  $join .= " left join os_info as d on c.osid=d.osid";
Mac Newbold's avatar
Mac Newbold committed
81
82
}

83
84
85
86
# if ($delta) {
#   $join .= " left join delta_inst as e on c.node_id=e.node_id ".
#     "and c.partition=e.partition";
# }
Mac Newbold's avatar
Mac Newbold committed
87
88


89
my $cmd = "select $cols from $join where $cond order by priority";
Mac Newbold's avatar
Mac Newbold committed
90
91
92

print "Sending cmd:\n$cmd\n" if $d;

93
my $result = DBQueryFatal($cmd);
Mac Newbold's avatar
Mac Newbold committed
94

95
print $result->as_string();
Mac Newbold's avatar
Mac Newbold committed
96

97
# Hacky. Batch daemon depends on this exit code.
98
exit($result->numrows);