From 6dc95ee700d271c420464837f68f7d2a3c255dd4 Mon Sep 17 00:00:00 2001 From: Eirik Nygaard Date: Tue, 3 Apr 2007 23:03:31 +0200 Subject: [PATCH] Update --- clients/ciscong.pl | 64 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/clients/ciscong.pl b/clients/ciscong.pl index 1a9c618..9d2dac2 100644 --- a/clients/ciscong.pl +++ b/clients/ciscong.pl @@ -14,8 +14,11 @@ use Data::Dumper; #my $patchlist = "/root/patchlist.txt"; #my $switches = "/root/switches.txt"; -my $patchlist = "/home/eirikn/patchlist.txt.eirik"; -my $switches = "/home/eirikn/switches.txt.eirik"; +#my $patchlist = "/home/eirikn/patchlist.txt.eirik"; +#my $switches = "/home/eirikn/switches.txt.eirik"; +my $patchlist = "/root/patchlist.txt.d01-1-2"; +my $switches = "/root/switches.txt.d01-1-2"; + BEGIN { require "../include/config.pm"; @@ -136,22 +139,31 @@ while() { } close(SWITCHES); +sub switch_info { + my ($switch, $distro, $port) = @_; + + $switch =~ /e(\d+)-(\d)/; + my ($row, $place) = ($1, $2); + my $ipnet = $switchips{$switch}; + my $vlan = $row . $place; + my ($first, $second, $third, $fourth) = split(/\./, $ipnet); + my $ip = "$first.$second.$third.".(int($fourth)+2); + my $dip = $distro.".net.tg07.gathering.org"; + + return ($row, $place, $ipnet, $vlan, $ip, $dip); +} + sub first_run { 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 "First run...\n"; + my ($row, $place, $ipnet, $vlan, $ip, $dip) = switch_info($switch, $distro, $port); 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, $switch); # my ($dip, $newip, $vlan) = @_; @@ -159,10 +171,44 @@ sub first_run { close(PATCHLIST); } +sub verify_run { + open(PATCHLIST, $patchlist) or die "Unable to open patchlist"; + while () { + print "Verify run....\n"; + my ($switch, $distro, $port) = split; + + my ($row, $place, $ipnet, $vlan, $ip, $dip) = switch_info($switch, $distro, $port); + print "Switch: $switch, Distro: $distro, vlan: $vlan\n"; + print "Ip net: $ipnet\n"; + print "Ip: $ip\n"; + + my $p = Net::Ping->new(); + printf "Checking if zyxel is up $dip:$vlan $ip...\n"; + my $counter = 0; + while (1) { + if ($counter > 10) { + print "No answer from $dip:$vlan $ip, trying to route it up\n"; + do_distro($dip, $ip, $vlan, $switch); + last; + } + last if $p->ping($ip); + print "pinging...\n"; + sleep 1; + $counter++; + } + +# my ($dip, $newip, $vlan) = @_; + } + close(PATCHLIST); +} + if ($#ARGV > -1) { first_run(); } +else { + verify_run(); +} -- 2.39.2