Commit d5b7e46e authored by Mac Newbold's avatar Mac Newbold

Merged into tbsetup

parent d251bc15
#Use this file as input to ifc_all - # is comment line,
# Machine IP |if#| New IP for the interface
# -----------------------------------------
155.99.214.101 0 192.168.1.1
155.99.214.101 1 192.168.2.1
155.99.214.101 2 192.168.3.1
155.99.214.101 3 192.168.4.1
155.99.214.102 0 192.168.1.2
155.99.214.102 1 192.168.2.2
155.99.214.102 2 192.168.3.2
155.99.214.102 3 192.168.4.2
155.99.214.103 0 192.168.1.3
155.99.214.103 1 192.168.2.3
155.99.214.103 2 192.168.3.3
155.99.214.103 3 192.168.4.3
155.99.214.104 0 192.168.1.4
155.99.214.104 1 192.168.2.4
155.99.214.104 2 192.168.3.4
155.99.214.104 3 192.168.4.4
155.99.214.105 0 192.168.1.5
155.99.214.105 1 192.168.2.5
155.99.214.105 2 192.168.3.5
155.99.214.105 3 192.168.4.5
155.99.214.106 0 192.168.1.6
155.99.214.106 1 192.168.2.6
155.99.214.106 2 192.168.3.6
155.99.214.106 3 192.168.4.6
155.99.214.107 0 192.168.1.7
155.99.214.107 1 192.168.2.7
155.99.214.107 2 192.168.3.7
155.99.214.107 3 192.168.4.7
155.99.214.108 0 192.168.1.8
155.99.214.108 1 192.168.2.8
155.99.214.108 2 192.168.3.8
155.99.214.108 3 192.168.4.8
155.99.214.109 0 192.168.1.9
155.99.214.109 1 192.168.2.9
155.99.214.109 2 192.168.3.9
155.99.214.109 3 192.168.4.9
155.99.214.110 0 192.168.1.10
155.99.214.110 1 192.168.2.10
155.99.214.110 2 192.168.3.10
155.99.214.110 3 192.168.4.10
#!/usr/bin/perl
my $rsh = "ssh";
if ( $#ARGV < 0) {
die("Usage: ifc_all <ifc_file>\n".
"Sets current network configurations.\n".
"(Changes lost when rebooted. See also ifc_boot.)\n");
}
open(WHO,"/usr/bin/whoami 2>&1 |");
$_ = <WHO>;
chop;
if ($_ ne "root") { die("This won't work unless you're root.\n"); }
if (-e "$ARGV[$0]" ) {
open(IN,$ARGV[$0]) || die("Couldn't open $ARGV[$0]\n");
} elsif (-e "/usr/testbed/etc/$ARGV[$0]") {
open(IN,"/usr/testbed/etc/$ARGV[$0]") ||
die("Couldn't open /usr/testbed/etc/$ARGV[$0]\n");
} else {
die ("Couldn't locate $ARGV[$0]\n");
}
my $last = "";
my $OS = "Unknown";
my $IP = "";
my $IF = 0;
my $ifstr = "";
my $newIP = "";
print "Reading input file...\n";
while (<IN>) {
chop;
s/\s*\#(.*)//;
s/^\s+$//;
s/\s+/ /g;
if ($_ eq "") {next;}
#print "Got $_\n";
($IP,$IF,$newIP)= split(" ",$_);
#print "Config $IP, interface $IF, to IP $newIP\n";
#if its not the same as the last one, get the OS
if ( $IP ne $last ) {
$last = $IP;
if (-e "/bin/ping") {
open(PING,"/bin/ping -c 1 $IP 2>&1 |");
} else {
open(PING,"/sbin/ping -c 1 $IP 2>&1 |");
}
do { } until ( <PING> =~ /transmitted, (\d*) packets received/ );
print "Got $1 ping packet(s) back from $IP.\n";
if ( $1 > 0 ) {
open(UNAME,"$rsh $IP uname -a 2>&1 |");
$_ = <UNAME>;
#print $_;
if ($_ ) { @temp = split(" ",$_); $OS = $temp[$0]; }
}
print "OS for $IP is $OS \t";
if ($OS eq "Linux") { $ifstr="eth"; }
elsif ($OS eq "FreeBSD") { $ifstr="fxp"; }
else { $ifstr = ""; }
if ($ifstr) { print "Using interface string '$ifstr'\n"; }
}
#Set up the interface
if ( $ifstr eq "" ) {
print "Can't configure OS '$OS' on $IP. Skipping interface $IF.\n";
next;
}
print "Setting $IP $ifstr$IF to $newIP...\n";
open(IFC,
"$rsh $IP /sbin/ifconfig $ifstr$IF inet $newIP ".
"netmask 255.255.255.0 2>&1 |"
);
while ( <IFC> ) {
print ">> $_";
}
close (IFC);
}
#!/usr/bin/perl -w
my $rsh = "ssh";
my $rcp = "scp";
$| = 1; #Turn off line buffering on output
if ( $#ARGV < 0) {
die("Usage: ifc_boot <ifc_file>\n".
"Sets network configurations for booting.\n".
"(Does not have any effect until rebooted. See also ifc_all.)\n");
}
open(WHO,"/usr/bin/whoami 2>&1 |");
$_ = <WHO>;
chop;
if ($_ ne "root") { die("This won't work unless you're root.\n"); }
close(WHO);
if (-e "$ARGV[0]" ) {
open(IN,$ARGV[0]) || die("Couldn't open $ARGV[0]\n");
} elsif (-e "/usr/testbed/etc/$ARGV[0]") {
open(IN,"/usr/testbed/etc/$ARGV[0]") ||
die("Couldn't open /usr/testbed/etc/$ARGV[0]\n");
} else {
die ("Couldn't locate $ARGV[0]\n");
}
my $last = "";
my $OS = "Unknown";
my $IP = "";
my $IF = 0;
my $ifstr = "";
my $newIP = "";
print "Reading input file...\n";
while (<IN>) {
chop;
s/\s*\#(.*)//;
s/^\s+$//;
s/\s+/ /g;
if ($_ eq "") {next;}
#print "Got $_\n";
($IP,$IF,$newIP)= split(" ",$_);
#print "Config $IP, interface $IF, to IP $newIP\n";
#if its not the same as the last one, get the OS
if ( $IP ne $last ) {
$last = $IP;
print "Pinging $IP...";
if (-e "/bin/ping") {
open(PING,"/bin/ping -c 1 $IP 2>&1 |");
} else {
open(PING,"/sbin/ping -c 1 $IP 2>&1 |");
}
do { } until ( <PING> =~ /transmitted, (\d*) packets received/ );
print "Got $1 ping packet(s) back from $IP.\n";
if ( $1 > 0 ) {
open(UNAME,"$rsh $IP uname -a 2>&1 |");
$_ = <UNAME>;
#print $_;
if ($_ ) { @temp = split(" ",$_); $OS = $temp[0]; }
} else {
print STDERR "Can't reach $IP with ping. Skipping interface $IF.\n";
$OS = "_NO_PING_";
next;
}
print "OS for $IP is $OS \t";
if ($OS eq "Linux") { $ifstr="eth"; }
elsif ($OS eq "FreeBSD") { $ifstr="fxp"; }
else { $ifstr = ""; }
if ($ifstr) { print "Using interface string '$ifstr'\n"; }
} else {
if ($OS eq "_NO_PING_") {
print STDERR "Can't reach $IP with ping. Skipping interface $IF.\n";
next;
}
}
#Set up the interface
if ( $ifstr eq "" ) {
print STDERR "Can't configure OS '$OS' on $IP. Skipping interface $IF.\n";
next;
} elsif ( $OS eq "Linux" ) {
@_ = split(/\./,$newIP);
my $network = join(".",@_[0..2]);
print "Setting $IP $ifstr$IF to $newIP...\n";
open(TEMP,">/tmp/ifc_boot_file");
print TEMP "DEVICE=$ifstr$IF\nIPADDR=$newIP\nNETMASK=255.255.255.0\n".
"NETWORK=$network.0\nBROADCAST=$network.255\nONBOOT=yes\n".
"BOOTPROTO=bootp\nUSERCTL=no\n";
close(TEMP);
open(IFC, "$rcp /tmp/ifc_boot_file ".
"$IP:/etc/sysconfig/network-scripts/ifcfg-$ifstr$IF 2>&1 |");
} elsif ($OS eq "FreeBSD") {
my $exists = 0;
print "Setting $IP $ifstr$IF to $newIP...\n";
open(EXISTS, "$rsh $IP ls /etc/rc.conf.local 2>&1 |");
while ( <EXISTS> ) { if ( ! /No such file/ ) { $exists = 1; } }
close(EXISTS);
open(TEMP,">/tmp/ifc_boot_file");
if ($exists) {
open(COPY, "$rcp $IP:/etc/rc.conf.local /etc/ifc_boot_input 2>&1 |");
while ( <COPY> ) { print "COPY>> $_"; }
close(COPY);
open(CONF,"/etc/ifc_boot_input");
while ( <CONF> ) {
# print "CONF>>$_";
if ( ! /ifconfig_fxp$IF=/ ) {
if ( /network_interfaces\s*=\s*\"([A-Za-z0-9_ ]*)\"/ ) {
$_ = $1;
s/\s+/ /g;
s/^\s+//g;
s/\s+$//g;
my @ifcs = split(" ",$_);
print TEMP "network_interfaces=\"";
foreach my $ifc (@ifcs) {
if ($ifc ne "fxp$IF") { print TEMP "$ifc "; }
}
print TEMP "fxp$IF\"\n";
}
print TEMP $_;
# print "KEPT\n";
}
}
close(CONF);
} else { print TEMP "network_interfaces=\"fxp$IF lo0\"\n"; }
print TEMP "ifconfig_fxp$IF=\"inet $newIP netmask 255.255.255.0\"\n";
close(TEMP);
open(IFC,"$rcp /tmp/ifc_boot_file $IP:/etc/rc.conf.local 2>&1 |");
} else {
print STDERR "Can't configure OS '$OS' on $IP. Skipping interface $IF.\n";
next;
}
while ( <IFC> ) {
print ">> $_";
}
close(IFC);
}
close(IN);
print "End of input file.\nDone.\n";
#!/bin/csh
#
# ifc_filegen
#
# Generates files for setting up interfaces (NICs) of testbed machines
#
# Range of machines to work with
if ($1 > 0) then
set first=$1
else
set first=1
endif
if ($1 > 0) then
set last=$2
else
set last=10
endif
if ( -e /home/newbold/bin ) then
set machines=`/home/newbold/bin/range $first $last`
else if ( -e /users/newbold/bin ) then
set machines=`/users/newbold/bin/range $first $last`
else
set machines
set i=$first
while ( $i <= $last )
set machines = "$machines $i"
set i=`expr $i + 1`
end
endif
# Usually use 192.168 (unroutable Internet testing subnet)
if ($3 > 0) then
set subnet=$3
else
set subnet=192.168
endif
echo "#Use this file as input to ifc_all - # is comment line,"
echo "# Machine IP |if#| New IP for the interface"
echo "# -----------------------------------------"
foreach m ( $machines ) # for each machine
#Control net IPs are 101, 102, ...
set control=`expr 100 + $m`
foreach i ( 0 1 2 3 ) # for each interface
# set newip=`expr $last \* $i + $m`
set newnet=`expr $i + 1`
#output a line with Control IP, interface, and IP for that interface
echo 155.99.214.$control $i $subnet.$newnet.$m
end
end
#clean up...
unset m i first last control newip last machines subnet newnet
#!/usr/bin/perl -w
my $rsh = "ssh";
my $rcp = "scp";
$| = 1; #Turn off line buffering on output
if ( $#ARGV < 0) {
die("Usage: ifc_boot <ifc_file>\n".
"Sets network interface configurations, both with ifconfig, and\n".
"in the boot configuration files.\n");
}
open(WHO,"/usr/bin/whoami 2>&1 |");
$_ = <WHO>;
chop;
if ($_ ne "root") { die("This won't work unless you're root.\n"); }
close(WHO);
if (-e "$ARGV[0]" ) {
open(IN,$ARGV[0]) || die("Couldn't open $ARGV[0]\n");
} elsif (-e "/usr/testbed/etc/$ARGV[0]") {
open(IN,"/usr/testbed/etc/$ARGV[0]") ||
die("Couldn't open /usr/testbed/etc/$ARGV[0]\n");
} else {
die ("Couldn't locate $ARGV[0]\n");
}
my $last = "";
my $OS = "Unknown";
my $IP = "";
my $IF = 0;
my $ifstr = "";
my $newIP = "";
print "Reading input file...\n";
while (<IN>) {
chop;
s/\s*\#(.*)//;
s/^\s+$//;
s/\s+/ /g;
if ($_ eq "") {next;}
#print "Got $_\n";
($IP,$IF,$newIP)= split(" ",$_);
#print "Config $IP, interface $IF, to IP $newIP\n";
#if its not the same as the last one, get the OS
if ( $IP ne $last ) {
$last = $IP;
print "Pinging $IP...";
if (-e "/bin/ping") {
open(PING,"/bin/ping -c 1 $IP 2>&1 |");
} else {
open(PING,"/sbin/ping -c 1 $IP 2>&1 |");
}
do { } until ( <PING> =~ /transmitted, (\d*) packets received/ );
print "Got $1 ping packet(s) back from $IP.\n";
if ( $1 > 0 ) {
open(UNAME,"$rsh $IP uname -a 2>&1 |");
$_ = <UNAME>;
#print $_;
if ($_ ) { @temp = split(" ",$_); $OS = $temp[0]; }
} else {
print STDERR "Can't reach $IP with ping. Skipping interface $IF.\n";
$OS = "_NO_PING_";
next;
}
print "OS for $IP is $OS \t";
if ($OS eq "Linux") { $ifstr="eth"; }
elsif ($OS eq "FreeBSD") { $ifstr="fxp"; }
else { $ifstr = ""; }
if ($ifstr) { print "Using interface string '$ifstr'\n"; }
} else {
if ($OS eq "_NO_PING_") {
print STDERR "Can't reach $IP with ping. Skipping interface $IF.\n";
next;
}
}
#Set up the interface
if ( $ifstr eq "" ) {
print STDERR "Can't configure OS '$OS' on $IP. Skipping interface $IF.\n";
next;
} elsif ( $OS eq "Linux" ) {
@_ = split(/\./,$newIP);
my $network = join(".",@_[0..2]);
print "Setting $IP $ifstr$IF to $newIP in boot configurations...\n";
open(TEMP,">/tmp/ifc_boot_file");
print TEMP "DEVICE=$ifstr$IF\nIPADDR=$newIP\nNETMASK=255.255.255.0\n".
"NETWORK=$network.0\nBROADCAST=$network.255\nONBOOT=yes\n".
"BOOTPROTO=bootp\nUSERCTL=no\n";
close(TEMP);
open(IFC, "$rcp /tmp/ifc_boot_file ".
"$IP:/etc/sysconfig/network-scripts/ifcfg-$ifstr$IF 2>&1 |");
} elsif ($OS eq "FreeBSD") {
my $exists = 0;
print "Setting $IP $ifstr$IF to $newIP in boot configurations...\n";
open(EXISTS, "$rsh $IP ls /etc/rc.conf.local 2>&1 |");
while ( <EXISTS> ) { if ( ! /No such file/ ) { $exists = 1; } }
close(EXISTS);
open(TEMP,">/tmp/ifc_boot_file");
if ($exists) {
open(COPY, "$rcp $IP:/etc/rc.conf.local /etc/ifc_boot_input 2>&1 |");
while ( <COPY> ) { print "COPY>> $_"; }
close(COPY);
open(CONF,"/etc/ifc_boot_input");
while ( <CONF> ) {
# print "CONF>>$_";
if ( ! /ifconfig_fxp$IF=/ ) {
if ( /network_interfaces\s*=\s*\"([A-Za-z0-9_ ]*)\"/ ) {
$_ = $1;
s/\s+/ /g;
s/^\s+//g;
s/\s+$//g;
my @ifcs = split(" ",$_);
print TEMP "network_interfaces=\"";
foreach my $ifc (@ifcs) {
if ($ifc ne "fxp$IF") { print TEMP "$ifc "; }
}
print TEMP "fxp$IF\"\n";
} else {
print TEMP $_;
}
# print "KEPT\n";
}
}
close(CONF);
} else { print TEMP "network_interfaces=\"fxp$IF lo0\"\n"; }
print TEMP "ifconfig_fxp$IF=\"inet $newIP netmask 255.255.255.0\"\n";
close(TEMP);
open(IFC,"$rcp /tmp/ifc_boot_file $IP:/etc/rc.conf.local 2>&1 |");
} else {
print STDERR "Can't configure OS '$OS' on $IP. Skipping interface $IF.\n";
next;
}
while ( <IFC> ) {
print ">> $_";
}
close(IFC);
print "Setting $IP $ifstr$IF to $newIP with ifconfig...\n";
open(IFC,
"$rsh $IP /sbin/ifconfig $ifstr$IF inet $newIP ".
"netmask 255.255.255.0 2>&1 |"
);
while ( <IFC> ) {
print ">> $_";
}
close(IFC);
}
close(IN);
print "End of input file.\nDone.\n";
#!/usr/local/bin/perl -w
#
# Takes input IR file on STDIN, and dumps IFC file to STDOUT.
#
my $d = 0; #debug
my $go=0;
my $ipsection=0;
my %ips = ();
my %nodes = ();
my %nodeips = ();
my %ifs = ();
while ( <> ) {
if ( /^start ip/i ) {
$ipsection=1;
print STDERR "Found IP section...\t" if $d;
}
elsif ( /^end ip/i ) { $ipsection=0; }
elsif ( /^start mac/i ) {
$go=1;
print STDERR "Found MAC section:\n" if $d;
}
elsif ( /^end mac/i ) { $go=0; }
elsif ( $go ) {
my ($mac,$ip) = split();
print STDERR "Read: $mac <==> $ip\n" if $d;
$ips{$mac} = $ip;
}
}
print STDERR "Input done.\n" if $d;
my $path="";
if ( -x "/usr/testbed/bin/mac2if" ) { $path="/usr/testbed/bin/" }
elsif ( -x "mac2if" ) { $path=""; }
elsif ( -x "./mac2if" ) { $path="./"; }
elsif ( -x "/home/newbold/db/mac2if" ) { $path="/home/newbold/db/"; }
my $cmd = "$path"."mac2if ".join(" ",keys %ips)." |";
print STDERR "Calling $cmd\n" if $d;
open(MAC2IF,$cmd);
while ( <MAC2IF> ) {
if (! /^\|/ ) {next;}
if ( /^\|node_id/ ) {next;}
s/ *|\t*//g;
s/^\|//;
my ($node,$ifc,$mac) = split(/\|/,$_);
print STDERR "Read $node:$ifc <==> $mac\n" if $d;
$nodes{$mac} = $node;
$ifs{$mac} = $ifc;
}
if ( -x "/usr/testbed/bin/nodeip" ) { $path="/usr/testbed/bin/" }
elsif ( -x "nodeip" ) { $path=""; }
elsif ( -x "./nodeip" ) { $path="./"; }
elsif ( -x "/home/newbold/db/nodeip" ) { $path="/home/newbold/db/"; }
$cmd = "$path"."nodeip ".join(" ",values %nodes)." |";
print STDERR "Calling $cmd\n" if $d;
open(NODEIP,$cmd);
while ( <NODEIP> ) {
if (! /^\|/ ) {next;}
if ( /^\|node_id/ ) {next;}
s/ *|\t*//g;
s/^\|//;
my ($node,$ifc,$ip) = split(/\|/,$_);
if ($node =~ /^tbpc/) { if ($ifc==4) { $nodeip{$node} = $ip; } }
else { if ($ifc==1) { $nodeip{$node} = $ip; } }
print STDERR "Read $node <==> $nodeip{$node}\n" if $d;
}
print "# This ifc file generated by ir2ifc\n";
foreach my $mac ( keys %ips ) {
if (defined $nodeip{$nodes{$mac}} ) {
if (defined $ifs{$mac} ) {
print $nodeip{$nodes{$mac}}," ",$ifs{$mac}," ",$ips{$mac},"\n";
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment