From: Eirik Nygaard Date: Tue, 3 Apr 2007 15:34:33 +0000 (+0200) Subject: zyxelNG fixes, it works now... I think. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=b7f4a767079d193a1429318eb6cf67e7aba60149;p=nms zyxelNG fixes, it works now... I think. --- diff --git a/clients/ciscong.pl b/clients/ciscong.pl index 80d67dd..3107943 100644 --- a/clients/ciscong.pl +++ b/clients/ciscong.pl @@ -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() { + 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 () { + 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(); diff --git a/clients/zyxelng.pl b/clients/zyxelng.pl index c3d08fc..a5ec109 100644 --- a/clients/zyxelng.pl +++ b/clients/zyxelng.pl @@ -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();