]> git.sesse.net Git - nms/commitdiff
zyxelNG fixes, it works now... I think.
authorEirik Nygaard <eirikn@space>
Tue, 3 Apr 2007 15:34:33 +0000 (17:34 +0200)
committerEirik Nygaard <eirikn@space>
Tue, 3 Apr 2007 15:34:33 +0000 (17:34 +0200)
clients/ciscong.pl
clients/zyxelng.pl

index 80d67ddc1d8918f6ec81ed7f98c851eadda5096c..3107943c51d4c376038f5ae27acacc699c7411d6 100644 (file)
@@ -12,6 +12,10 @@ use Net::Ping;
 
 use Data::Dumper;
 
+#my $patchlist = "/home/eirikn/patchlist.txt";
+#my $switches = "/home/eirikn/switches.txt";
+my $patchlist = "/home/eirikn/patchlist.txt.eirik";
+my $switches = "/home/eirikn/switches.txt.eirik";
 
 BEGIN {
        require "../include/config.pm";
@@ -28,17 +32,22 @@ sub ios_getroute {
        return 1;
 }
 
-my $ios_server = "noc-gw.net.tg07.gathering.org";
-my $vlannumber = 16;
+#my $ios_server = "noc-gw.net.tg07.gathering.org";
+#my $vlannumber = 16;
 
 #my $ios = nms::ios_connect($ios_server, $nms::config::ios_user, $nms::config::ios_pass)
 #      or die "Unable to connect to cisco";
 
-my $ios = Net::Telnet::Cisco->new(Host => $ios_server,
-                                  Errmode => 'return',
-                                  Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/');
-$ios->login($nms::config::ios_user, $nms::config::ios_pass);
-$ios->enable;
+
+
+sub do_distro {
+       my ($dip, $newip, $vlan) = @_;
+
+       my $ios = Net::Telnet::Cisco->new(Host => $dip,
+                       Errmode => 'return',
+                       Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/');
+       $ios->login($nms::config::ios_user, $nms::config::ios_pass);
+       $ios->enable;
 
 #nms::ios_enable($ios);
 #$ios->cmd();
@@ -48,46 +57,90 @@ $ios->enable;
 #nms::ios_close($ios);
 
 # Disable paging
-$ios->cmd("terminal length 0");
+       $ios->cmd("terminal length 0");
 
 #my @routes = $ios->cmd("show ip route");
 
-die "Already routed up 192.168.1.0/24" if (ios_getroute($ios, "192.168.1.0") == 1);
+       if (ios_getroute($ios, "192.168.1.0") == 1) {
+               print "Already routed up 192.168.1.0/24\n" ;
+               return;
+       }
 
+       $ios->cmd("conf t");
+       $ios->cmd("int vlan $vlan");
+       $ios->cmd("ip add 192.168.1.254 255.255.255.0 secondary");
+       $ios->cmd("exit");
+       $ios->cmd("exit");
 
-
-$ios->cmd("conf t");
-$ios->cmd("int vlan $vlannumber");
-$ios->cmd("ip add 192.168.1.254 255.255.255.0 secondary");
-$ios->cmd("exit");
-$ios->cmd("exit");
-
-my $zyxeloldip = "192.168.1.1";
+       my $zyxeloldip = "192.168.1.1";
 
 ### Do things
 ## ZyxelNG connect
 
+       my $p = Net::Ping->new();
+       printf "Waiting for zyxel to come up...\n";
+       while (1) {
+               last if $p->ping($zyxeloldip);
+               print "pinging...\n";
+               sleep 1;
+       }
+       print "Zyxel is alive..\n";
+       $p->close();
+
+       system("perl ./zyxelng.pl 192.168.1.1 $newip");
+
+####
+
+       $ios->cmd("conf t");
+       $ios->cmd("int vlan $vlan");
+       $ios->cmd("no ip add 192.168.1.254 255.255.255.0 secondary");
+       $ios->cmd("exit");
+       $ios->cmd("exit");
+
+
+       $ios->close();
 
-my $p = Net::Ping->new();
-printf "Waiting for zyxel to come up...\n";
-while (1) {
-       last if $p->ping($zyxeloldip);
-       print "pinging...\n";
-       sleep 1;
 }
-print "Zyxel is alive..\n";
-$p->close();
 
-system("perl ./zyxelng.pl 192.168.1.1 192.168.2.1");
 
-####
+## Collect switch ips
+
+my %switchips;
+
+open(SWITCHES, $switches) or die "Unable to open switches";
+while(<SWITCHES>) {
+       my ($ip, $net, $name) = split;
+
+       print $name."\n";
+       if ($name =~ /e\d+-\d/) {
+               die "We only support /26 nets for now you wanted $net" if ($net ne "26");
+               $switchips{$name} = $ip;
+       }
+}
+close(SWITCHES);
+
+
+open(PATCHLIST, $patchlist) or die "Unable to open patchlist";
+while (<PATCHLIST>) {
+       my ($switch, $distro, $port) = split;
+       
+       $switch =~ /e(\d+)-(\d)/;
+       my ($row, $place) = ($1, $2);
+       my $ipnet = $switchips{$switch};
+       my $vlan = $row . $place;
+       print "Switch: $switch, Distro: $distro, vlan: $vlan\n";
+       print "Ip net: $ipnet\n";
+       my ($first, $second, $third, $fourth) = split(/\./, $ipnet);
+       my $ip = "$first.$second.$third.".(int($fourth)+2);
+       print "Ip: $ip\n";
+       my $dip = $distro.".net.tg07.gathering.org";
+
+       do_distro($dip, $ip, $vlan);
+#      my ($dip, $newip, $vlan) = @_;
+}
+close(PATCHLIST);
+
 
-$ios->cmd("conf t");
-$ios->cmd("int vlan $vlannumber");
-$ios->cmd("no ip add 192.168.1.254 255.255.255.0 secondary");
-$ios->cmd("exit");
-$ios->cmd("exit");
 
-$ios->close();
 
 
index c3d08fcfa505017c723ceefd606145606b3ba13d..a5ec109939eb74d527d683c21373984d1230c3dc 100644 (file)
@@ -78,7 +78,7 @@ foreach (split(/\n+/, $cmds1)) {
 my $cmd;
 #$cmd = "ip ifconfig swif0 192.168.1.1/24" if $one;
 #$cmd = "ip ifconfig swif0 192.168.2.150/24" unless $one;
-$cmd = "ip ifconfig swif0 $newip/24";
+$cmd = "ip ifconfig swif0 $newip/30";
 
 print "Sending '$cmd'\n";
 my $pid = fork();