Commit a7a0199d authored by Mac Newbold's avatar Mac Newbold
Browse files

The new database system.

parent d662df2f
#!/usr/local/bin/perl -w
use Mysql;
my $d = 0; #debug mode
if ($#ARGV >= 0 && $ARGV[0] =~ /^-?h/i ) {
die("Usage:\navail [help] [type[=<type>]] [OS[=<OS>]] [ver[=<OS_ver>]]\n".
"\t[extras=<extra[,extra,...]>]".
# " [fixes=<fix_name[,fix_name,...]>]".
"\n".
"Type \t\t= pc | shark\n"."OS \t\t= Linux | FreeBSD | NetBSD | ...\n".
"ver \t\t= 6.2 | 3.4 | 4.0 | 5.2 | ...\n"."extras \t\t= anetd | ...\n".
# "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"
);
}
my $dbh = Mysql->connect("localhost","tbdb","script","none");
print "Got ARGS = ",join(" ",@ARGV),"\n" if $d;
my %args = ();
while ($#ARGV >= 0) {
$_ = shift;
if ( ! grep '=' ) {
$args{$_}='=';
}
@_ = split('=',$_);
my ($opt,$val) = @_ if ($#_ >= 0);
if (!defined($val)) { $val=""; }
$args{$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";
my $cols= "a.node_id,a.type";
my $cond= "b.node_id is null and a.type!='switch'";
my $img = 0;
if (defined($args{"type"})) { $cond .= " and a.type='".$args{"type"}."'"; }
if (defined($args{"OS"})) {
$img = 1;
$cols .= ",d.OS";
$cond .= " and d.OS='".$args{"OS"}."'";
}
if (defined($args{"ver"})) {
$img = 1;
$cols .= ",d.ver";
$cond .= " and d.ver='".$args{"ver"}."'";
}
if (defined($args{"extras"})) {
$img = 1;
$cols .= ",d.extras";
$cond .= " and d.extras='".$args{"extras"}."'";
}
#if (defined($args{"fixes"})) {
# $join .= "";
# $cols .= ",d.fix_name";
# $cond .= " and fix_name=";
#}
if ($img) {
$join .= " left join SW_Table as c on a.node_id=c.node_id";
$join .= " left join disk_images as d on c.image_id=d.image_id";
}
my $cmd = "select $cols from $join where $cond";
print "Sending cmd:\n$cmd\n" if $d;
my $sth = $dbh->
query($cmd);
print $sth->as_string();
#FIG 3.2
Landscape
Center
Inches
Letter
100.00
Single
-2
1200 2
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
3600 600 4800 600 4800 1500 3600 1500 3600 600
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
6900 2850 7800 2850
2 1 0 3 0 7 100 0 -1 8.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
6900 6900 7800 7800
2 1 4 2 0 7 100 0 -1 6.000 0 0 -1 0 0 7
1200 3900 1200 9000 5100 9000 5100 5700 3000 5700 3000 3900
1200 3900
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
4800 4650 5700 4650
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
4200 5100 4200 6000
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
2700 4650 3600 4650
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
2100 5100 2100 6000
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
4200 6900 4200 7800
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
2700 8250 3600 8250
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
2100 6900 2100 7800
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
4200 3300 4200 4200
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
2700 2850 3600 2850
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
4800 4200 5700 3300
2 1 0 3 0 7 100 0 -1 8.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
4800 5100 5700 6000
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
9000 2850 9900 2850
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
9000 6450 9900 6450
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
8400 5100 8400 6000
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
8400 3300 8400 4200
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
10500 3300 10500 4200
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
10500 5100 10500 6000
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
8400 6900 8400 7800
2 1 2 2 0 7 100 0 -1 3.000 0 0 -1 0 0 7
7500 2100 7500 9000 9300 9000 9300 7200 11400 7200 11400 2100
7500 2100
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
1500 2400 2700 2400 2700 3300 1500 3300 1500 2400
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
3600 2400 4800 2400 4800 3300 3600 3300 3600 2400
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
1500 4200 2700 4200 2700 5100 1500 5100 1500 4200
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
1500 6000 2700 6000 2700 6900 1500 6900 1500 6000
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
1500 7800 2700 7800 2700 8700 1500 8700 1500 7800
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
3600 7800 4800 7800 4800 8700 3600 8700 3600 7800
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
3600 6000 4800 6000 4800 6900 3600 6900 3600 6000
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
3600 4200 4800 4200 4800 5100 3600 5100 3600 4200
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
5700 4200 6900 4200 6900 5100 5700 5100 5700 4200
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
5700 6000 6900 6000 6900 6900 5700 6900 5700 6000
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
7800 6000 9000 6000 9000 6900 7800 6900 7800 6000
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
7800 7800 9000 7800 9000 8700 7800 8700 7800 7800
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
9900 6000 11100 6000 11100 6900 9900 6900 9900 6000
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
9900 4200 11100 4200 11100 5100 9900 5100 9900 4200
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
7800 4200 9000 4200 9000 5100 7800 5100 7800 4200
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
7800 2400 9000 2400 9000 3300 7800 3300 7800 2400
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
9900 2400 11100 2400 11100 3300 9900 3300 9900 2400
2 2 0 1 0 7 100 0 -1 0.000 0 0 -1 0 0 5
5700 2400 6900 2400 6900 3300 5700 3300 5700 2400
2 1 0 3 0 7 100 0 -1 0.000 0 0 -1 1 1 2
1 1 3.00 90.00 180.00
1 1 3.00 90.00 180.00
4200 1500 4200 2400
2 1 1 2 0 7 100 0 -1 6.000 0 0 -1 0 0 13
1200 2100 1200 3600 3300 3600 3300 5400 5400 5400 5400 7200
7200 7200 7200 3900 5100 3900 5100 300 3300 300 3300 2100
1200 2100
4 0 0 100 0 0 10 0.0000 4 135 675 3750 4950 Node, type\001
4 0 0 100 0 0 10 0.0000 4 135 1020 5850 4950 mhz, RAM, HD\001
4 0 0 100 0 0 10 0.0000 4 135 960 5850 3150 node,user,event\001
4 0 0 100 0 0 10 0.0000 4 135 465 10050 3150 uid, gid\001
4 0 0 100 0 0 10 0.0000 4 135 525 7950 3150 uid, data\001
4 0 0 100 0 0 10 0.0000 4 135 525 10050 4950 gid, data\001
4 0 0 100 0 0 10 0.0000 4 135 465 7950 4950 pid, uid\001
4 0 0 100 0 0 10 0.0000 4 135 465 10200 6750 pid, gid\001
4 0 0 100 0 0 10 0.0000 4 135 525 7950 6750 pid, data\001
4 0 0 100 0 0 10 0.0000 4 135 510 7950 8550 eid, data\001
4 0 0 100 0 0 10 0.0000 4 135 540 5850 6750 node, eid\001
4 0 0 100 0 0 10 0.0000 4 135 720 3750 6750 node, image\001
4 0 0 100 0 0 10 0.0000 4 135 690 3750 8550 image, data\001
4 0 0 100 0 0 10 0.0000 4 150 825 1650 8550 fix_id, image\001
4 0 0 100 0 0 10 0.0000 4 150 720 1650 6750 fix_id, data\001
4 0 0 100 0 0 10 0.0000 4 150 750 1650 4950 node, fix_id\001
4 0 0 100 0 0 18 0.0000 4 195 990 2100 9300 Software\001
4 0 0 100 0 0 12 0.0000 4 135 420 5100 4500 * to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 3000 4500 * to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 4350 5550 1 to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 2250 5550 * to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 4350 7350 * to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 3000 8100 1 to *\001
4 0 0 100 0 0 12 0.0000 4 135 420 2250 7350 1 to *\001
4 0 0 100 0 0 12 0.0000 4 135 420 4950 3600 1 to *\001
4 0 0 100 0 0 12 0.0000 4 135 420 4350 3750 * to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 3000 2700 1 to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 5400 5550 1 to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 8550 7350 1 to *\001
4 0 0 100 0 0 12 0.0000 4 135 420 9300 2700 1 to *\001
4 0 0 100 0 0 12 0.0000 4 135 420 10650 3750 * to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 8550 3750 1 to *\001
4 0 0 100 0 0 12 0.0000 4 135 420 8550 5550 * to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 9300 6300 1 to *\001
4 0 0 100 0 0 12 0.0000 4 135 420 10650 5550 1 to *\001
4 0 0 100 0 0 12 0.0000 4 135 420 7200 2700 * to 1\001
4 0 0 100 0 0 12 0.0000 4 135 420 7350 7200 * to 1\001
4 0 0 100 0 0 18 0.0000 4 255 1530 8400 2100 Users/Groups\001
4 0 0 100 0 0 12 0.0000 4 180 810 1650 4650 Fixed_List\001
4 0 0 100 0 0 12 0.0000 4 180 930 1650 6450 Fixes_Table\001
4 0 0 100 0 0 12 0.0000 4 180 915 1650 8250 Fix_Compat\001
4 0 0 100 0 0 12 0.0000 4 180 1005 3750 8250 Disk_Images\001
4 0 0 100 0 0 12 0.0000 4 180 795 3750 6450 SW_Table\001
4 0 0 100 0 0 12 0.0000 4 135 720 5850 6450 Reserved\001
4 0 0 100 0 0 12 0.0000 4 180 810 7950 6450 Proj_Table\001
4 0 0 100 0 0 12 0.0000 4 180 870 7950 8250 Expt_Table\001
4 0 0 100 0 0 12 0.0000 4 180 945 10050 6450 Proj_Groups\001
4 0 0 100 0 0 12 0.0000 4 180 975 10050 4650 Group_Table\001
4 0 0 100 0 0 12 0.0000 4 180 870 7950 4650 Proj_Memb\001
4 0 0 100 0 0 12 0.0000 4 180 885 7950 2850 User_Table\001
4 0 0 100 0 0 12 0.0000 4 180 855 10050 2850 Grp_Memb\001
4 0 0 100 0 0 12 0.0000 4 180 885 5850 2850 Logs_Table\001
4 0 0 100 0 0 12 0.0000 4 135 465 1650 2850 Wires\001
4 0 0 100 0 0 10 0.0000 4 105 645 1650 3150 IF1 to IF2\001
4 0 0 100 0 0 12 0.0000 4 135 780 3750 2850 Interfaces\001
4 0 0 100 0 0 10 0.0000 4 135 1005 3750 3150 Node,IF, MAC\001
4 0 0 100 0 0 18 0.0000 4 195 1080 1800 2100 Hardware\001
4 0 0 100 0 0 12 0.0000 4 180 555 3750 1050 IP_List\001
4 0 0 100 0 0 12 0.0000 4 135 420 4350 1950 1 to 1\001
4 0 0 100 0 0 10 0.0000 4 135 780 3750 1350 Node, IF, IP\001
4 0 0 100 0 0 12 0.0000 4 135 495 3750 4650 Nodes\001
4 0 0 100 0 0 12 0.0000 4 180 960 5850 4650 Node_Types\001
#!/usr/local/bin/perl -w
my $d=0; #debug
die("The database is already set up. This is a very dangerous thing to do,\n".
"and I'm not going to let you get away with it. Try again next week.\n")
if !$d; #die if I'm not debugging.... no one else should do this
use Mysql;
my $v = 0; # Verbose
my $dbh = Mysql->connect("localhost","tbdb","script","none");
my @tbls = $dbh->listtables;
my $sth ="";
my $cmd ="";
sub failed {
my ($cmd, $errstr) = @_;
print "Failed Command:\n$cmd\nError string is:$errstr\n";
}
print "Connected. Found tables: ",join (" ",@tbls),"\n" if $v;
print "Do you want to delete these tables:\n",join (" ",@tbls),
"\n(Y/N) ? ";
if ( <> =~ /^[Yy]/ ) {
print "Removing tables..." if $v;
foreach my $tbl ( @tbls ) {
$sth = $dbh->query("drop table $tbl")
|| &failed("drop table $tbl",$sth->errstr);
}
print "Database Cleaned.\n" if $v;
} else { die("Then don't try to reinitialize! Sheesh...\n") };
print "Initializing tables...";
my $id_len=10;
my @types = ("'pc'","'shark'","'switch'");
my @procs = ("'PIII'","'StrongArm'","'Intel510T'");
my @speed = ("600","233","0");
my @IFCs = ("5","1","24");
my @RAM = ("128","32","0");
my @HD = ("13.0","0.0","0.0");
my @sw_list = ("alpha", "beta", "gamma", "delta", "control");
$cmd = "create table nodes (".
"node_id char($id_len) NOT NULL PRIMARY KEY,".
"type enum(".join(",",@types)."));";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table node_types (".
"type enum(".join(",",@types).") NOT NULL PRIMARY KEY,".
"proc enum(".join(",",@procs)."),".
"speed smallint UNSIGNED,".
"IFCs tinyint UNSIGNED,".
"RAM smallint UNSIGNED,".
"HD float);";
$sth = $dbh->query($cmd)|| &failed($cmd,$sth->errstr);
$cmd = "create table interfaces (".
"node_id char($id_len) NOT NULL,".
"IFC tinyint UNSIGNED NOT NULL,".
"PRIMARY KEY (node_id,IFC),".
"MAC char(12));";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table IP_list (".
"node_id char($id_len) NOT NULL,".
"IFC tinyint UNSIGNED NOT NULL,".
"PRIMARY KEY (node_id,IFC),".
"IP char(15));";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table wires (".
"node_id1 char($id_len) NOT NULL,".
"IFC1 tinyint UNSIGNED NOT NULL,".
"PRIMARY KEY (node_id1,IFC1),".
"node_id2 char($id_len) NOT NULL,".
"IFC2 tinyint UNSIGNED NOT NULL,".
"KEY (node_id2,IFC2));";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table reserved (".
"node_id char($id_len) NOT NULL PRIMARY KEY,".
"eid char($id_len) NOT NULL,".
"rsrv_time timestamp);";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table SW_Table (".
"node_id char($id_len) NOT NULL PRIMARY KEY,".
"image_id char($id_len) NOT NULL,".
"quick_clean tinyint,".
"trusted tinyint);";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table disk_images (".
"image_id char($id_len) NOT NULL PRIMARY KEY,".
"img_desc text,".
"OS char($id_len),".
"ver char($id_len),".
"extras text,".
# "free_space float,".
# "free_space_type char($id_len),".
# "time_install_exp time,".
# "time_install_node time,".
# "time_boot_exp time,".
# "time_boot_node time,".
"img_path text NOT NULL);";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table fixes_table (".
"fix_id char($id_len) NOT NULL PRIMARY KEY,".
"fix_name char($id_len) NOT NULL,".
"fix_desc text,".
"fix_path text NOT NULL);";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table fix_compat (".
"image_id char($id_len) NOT NULL,".
"fix_id char($id_len) NOT NULL,".
"PRIMARY KEY (image_id,fix_id));";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table fixed_list (".
"node_id char($id_len) NOT NULL,".
"fix_id char($id_len) NOT NULL,".
"PRIMARY KEY (node_id,fix_id));";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table log (".
"entry_id int UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,".
"node_id char($id_len),".
"uid char($id_len),".
"entry_time timestamp,".
"log_type ENUM('powercycle','error','message','note','critical'".
",'segfault'),".
"message text);";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table users (".
"uid char($id_len) NOT NULL PRIMARY KEY,".
"usr_created datetime,".
"usr_expires datetime,".
"usr_name tinytext,".
"usr_email tinytext,".
"usr_addr tinytext,".
"usr_phones tinytext,".
"trust_level tinyint);";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table groups (".
"gid char($id_len) NOT NULL PRIMARY KEY,".
"grp_created datetime,".
"grp_expires datetime,".
"grp_name tinytext,".
"grp_URL tinytext,".
"grp_affil tinytext,".
"grp_addr tinytext,".
"grp_head_uid char($id_len) NOT NULL,".
"cntrl_node char($id_len));";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table projects (".
"pid char($id_len) NOT NULL PRIMARY KEY,".
"proj_created datetime,".
"proj_expires datetime,".
"proj_name tinytext,".
"proj_head_uid char($id_len) NOT NULL);";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table experiments (".
"eid char($id_len) NOT NULL PRIMARY KEY,".
"pid char($id_len) NOT NULL,".
"expt_created datetime,".
"expt_expires datetime,".
"expt_name tinytext,".
"expt_head_uid char($id_len) NOT NULL,".
"expt_start datetime,".
"expt_end datetime);";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table grp_memb (".
"uid char($id_len) NOT NULL,".
"gid char($id_len) NOT NULL,".
"PRIMARY KEY (uid,gid));";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table proj_memb (".
"uid char($id_len) NOT NULL,".
"pid char($id_len) NOT NULL,".
"PRIMARY KEY (uid,pid));";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "create table proj_grps (".
"pid char($id_len) NOT NULL,".
"gid char($id_len) NOT NULL,".
"PRIMARY KEY (pid,gid));";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
print "Tables Created.\nFilling...";
my $n=0;
foreach $n ( @sw_list) {
$cmd = "insert into nodes ".
"(node_id,type) values ('$n','switch');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
}
foreach $n (1..40) {
if (length ($n) < 2 ) { $n = "0".$n; }
$cmd = "insert into nodes ".
"(node_id,type) values ('tbpc$n','pc');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
$cmd = "insert into SW_Table (node_id,image_id) values ".
"('tbpc$n','".($n % 4 + 1)."');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
}
foreach $n (1..20) {
use integer;
if (length ($n) < 2 ) { $n = "0".$n; }
foreach my $m (1..8) {
$cmd = "insert into nodes ".
"(node_id,type) values ('tbsh$n-$m','shark');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
$cmd = "insert into SW_Table (node_id,image_id) values ".
"('tbsh$n-$m','".(($n-1)/10 + 5)."');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
}
}
foreach $n (0 .. $#types) {
$cmd = "insert into node_types ".
"(type,proc,speed,IFCs,RAM,HD) values ".
"(".$types[$n].",".$procs[$n].",".$speed[$n].",".$IFCs[$n].",".
$RAM[$n].",".$HD[$n].");";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
}
if ( -e "/usr/testbed/etc/macslist") {
open(FILE,"/usr/testbed/etc/macslist")
|| die("Couldn't open /usr/testbed/etc/macslist\n");
} elsif ( -e "macslist" ) {
open(FILE,"macslist")
|| die("Couldn't open macslist\n");
} elsif ( -e "/home/newbold/switch/macslist" ) {
open(FILE,"/home/newbold/switch/macslist")
|| die("Couldn't open /home/newbold/switch/macslist\n");
} else {
print "Couldn't locate macslist configuration file.\n",
"Tables 'interfaces' and 'wires' will not be filled.\n";
}
while ( <FILE> ) {
chop;
s/(( )+|\t)/ /g;
s/(( )+|\t)/ /g;
@_ = split(/ /,$_);
my ($node,$IF) = split (":",$_[0]);
if (!defined $IF) { $IF = 1; } #its a dnard
# print "Got Node $node, and interface $IF.\n";
if ($IF eq "c") { $IF = 4; }
my $mac = $_[1];
$cmd = "insert into interfaces ".
"(node_id,IFC,MAC) values ('$node',$IF,'$mac');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
my $switch="";
my $port="";
if ( defined $_[3] ) {
$switch = $_[2];
$switch =~ s/155\.99\.214\.17//;
$port = $_[3];
} else {
$switch = 4;
if ($node =~ /^tbpc(\d+)/) { $port = $1; }
else {
$node =~ /^tbsh(\d+)-(\d)/;
$port = 40 + 8 * ($1-1) + $2;
}
}
$switch = $sw_list[$switch];
$cmd = "insert into wires ".
"(node_id1,IFC1,node_id2,IFC2) values ('$node',$IF,'$switch',$port);";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
}
close(FILE);
foreach $n (1..40) {
if (length ($n) < 2 ) { $n = "0".$n; }
my $ip="155.99.214.1".$n;
$cmd = "insert into IP_list ".
"(node_id,IFC,IP) values ('tbpc$n',4,'$ip');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr) && last;
}
$cmd = "insert into disk_images ".
"(image_id,img_desc,OS,ver,extras,img_path) values ".
"('1','Standard FreeBSD 4.0 image','FreeBSD','4.0','','');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "insert into disk_images ".
"(image_id,img_desc,OS,ver,extras,img_path) values ".
"('2','Standard FreeBSD 3.4 image','FreeBSD','3.4','anetd','');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "insert into disk_images ".
"(image_id,img_desc,OS,ver,extras,img_path) values ".
"('3','Redhat Linux 6.2 image','Linux','6.2','','');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "insert into disk_images ".
"(image_id,img_desc,OS,ver,extras,img_path) values ".
"('4','Redhat Linux 5.2 image','Linux','5.2','anetd','');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "insert into disk_images ".
"(image_id,img_desc,OS,ver,extras,img_path) values ".
"('5','NetBSD 4.0 dnard image','NetBSD','4.0','','');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
$cmd = "insert into disk_images ".
"(image_id,img_desc,OS,ver,extras,img_path) values ".
"('6','NetBSD 4.0 dnard anetd image','NetBSD','4.0','anetd','');";
$sth = $dbh->query($cmd) || &failed($cmd,$sth->errstr);
print "Tables Ready.\n";
if ($v) {
@tbls = $dbh->listtables;
foreach $tb ( @tbls ) {
print "\nTable $tb set up as:\n";
$sth = $dbh->query("select * from $tb");
print $sth->as_string();
}
print "\nTables in database are:\n",join("\t",@tbls);