#!/usr/bin/perl -w # # EMULAB-COPYRIGHT # Copyright (c) 2000-2003 University of Utah and the Flux Group. # All rights reserved. # # # avail - prints a list of all available nodes # # # Configure variables # use lib '@prefix@/lib'; use libdb; my $d = 0; #debug mode if ($#ARGV >= 0 && $ARGV[0] =~ /^-?h/i ) { die("Usage:\navail [help] [type[=]] [OS[=]] [ver[=]]\n". " [[includevirt] or [virtonly[=]]] [rand] [limit=N]". "\n". "\n". "type \t= pc | shark\n"."OS \t= Linux | FreeBSD | NetBSD | ...\n". "ver \t= 6.2 | 3.4 | 4.0 | 5.2 | ...\n".#"deltas \t= anetd | ...\n". "includevirt: Include virtual nodes\n". "rand: Randomize result order\n". "limit: Limit count to N nodes\n". "A field name alone will show that field in the display of available\n". "nodes. 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; if ( ! /=/ ) { $args{"\L$_"}='='; } else { @_ = split('=',$_); my ($opt,$val) = @_ if ($#_ >= 0); if (!defined($val)) { $val=""; } $args{"\L$opt"}=$val if (defined($opt)); } } if ( $d ) { print "Parsed args to:\n"; foreach my $opt (keys %args) { print "$opt:\t$args{$opt}\n"; } } 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"; my $cond= "b.node_id is null "; if ($args{"virtonly"}) { $cond .= " and ( a.role='virtnode' "; if ($args{"virtonly"} ne '=') { $cond .= " and a.phys_nodeid='" . $args{"virtonly"} . "' "; } $cond .= " ) "; } else { $cond .= " and ( a.role='testnode' "; if ($args{"includevirt"}) { $cond .= " or a.role='virtnode' "; } $cond .= " ) "; } if ($args{"rand"}) { $order = "rand()"; } else { $order = "priority"; } if ($args{"limit"}) { $limit = "limit " . $args{"limit"}; } else { $limit = ""; } my $os = 0; my $delta = 0; if (defined($args{"type"})) { # Make it a like, so if they type 'pc' they get pc850 and pc600... $cond .= " and (a.type='".$args{"type"}."' or nt.class='".$args{"type"}."')" if $args{"type"} ne '='; } if (defined($args{"os"})) { $os = 1; $cols .= ",d.OS"; $cond .= " and d.OS='".$args{"os"}."'" if $args{"os"} ne '='; } if (defined($args{"ver"})) { $os = 1; $cols .= ",d.version"; $cond .= " and d.version='".$args{"ver"}."'" if $args{"ver"} ne '='; } # if (defined($args{"deltas"})) { # $os = 1; # $delta=1; # $cols .= ",e.delta_id"; # $cond .= " and e.delta_id='".$args{"deltas"}."'" if $args{"deltas"} ne '='; # } if ($os) { $join .= " left join partitions as c on a.node_id=c.node_id"; $join .= " left join os_info as d on c.osid=d.osid"; } # if ($delta) { # $join .= " left join delta_inst as e on c.node_id=e.node_id ". # "and c.partition=e.partition"; # } my $cmd = "select $cols from $join where $cond order by $order $limit"; print "Sending cmd:\n$cmd\n" if $d; my $result = DBQueryFatal($cmd); print $result->as_string(); # Hacky. Batch daemon depends on this exit code. exit($result->numrows);