10 use Net::Telnet::Cisco;
15 my $patchlist = "/root/patchlist.txt";
16 my $switches = "/root/switches.txt";
17 #my $patchlist = "/home/eirikn/patchlist.txt.eirik";
18 #my $switches = "/home/eirikn/switches.txt.eirik";
19 #my $patchlist = "/root/patchlist.txt.d05";
20 #my $switches = "/root/switches.txt.d05";
22 open LOG, ">>/tmp/zyxel.could.not.connect" or die "Could not open log";
26 require "../include/config.pm";
28 require "../include/config.local.pm";
35 $t->cmd("show ip route".($net ? " $net" : '')) or return 0;;
40 #my $ios_server = "noc-gw.net.tg07.gathering.org";
43 #my $ios = nms::ios_connect($ios_server, $nms::config::ios_user, $nms::config::ios_pass)
44 # or die "Unable to connect to cisco";
48 my ($ios, $vlan) = @_;
51 $ios->cmd("int vlan $vlan");
52 $ios->cmd("ip add 192.168.1.254 255.255.255.0 secondary");
58 my ($ios, $vlan) = @_;
61 $ios->cmd("int vlan $vlan");
62 $ios->cmd("no ip add 192.168.1.254 255.255.255.0 secondary");
70 my ($dip, $newip, $vlan, $switchname) = @_;
72 my $ios = Net::Telnet::Cisco->new(Host => $dip,
74 Prompt => '/\S+[#>]/');
75 # Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/');
77 print "Could not connect to $dip";
80 $ios->login($nms::config::ios_user, $nms::config::ios_pass);
83 #nms::ios_enable($ios);
85 #nms::ios_getroute($ios, "192.168.1.0");
88 #nms::ios_close($ios);
91 $ios->cmd("terminal length 0");
93 #my @routes = $ios->cmd("show ip route");
95 if (ios_getroute($ios, "192.168.1.0") == 1) {
96 print "Already routed up 192.168.1.0/24\n" ;
100 my $zyxeloldip = "192.168.1.1";
101 start_vlan($ios, $vlan);
106 my $p = Net::Ping->new();
107 printf "Waiting for zyxel to come up...\n";
111 print "Waiting for zyxel on $dip:$vlan timed out, wanted to set ip: $newip\n";
112 print LOG "Could not connect to $switchname\n";
113 stop_vlan($ios, $vlan);
116 last if $p->ping($zyxeloldip);
117 print "pinging...\n";
121 print "Zyxel is alive..\n";
124 system("perl ./zyxelng.pl 192.168.1.1 $newip $switchname");
128 stop_vlan($ios, $vlan);
135 ## Collect switch ips
139 open(SWITCHES, $switches) or die "Unable to open switches";
141 my ($ip, $net, $name) = split;
143 if ($name =~ /e\d+-\d/) {
144 die "We only support /26 nets for now you wanted $net" if ($net ne "26");
145 $switchips{$name} = $ip;
151 my ($switch, $distro, $port) = @_;
153 $switch =~ /e(\d+)-(\d)/;
154 my ($row, $place) = ($1, $2);
155 my $ipnet = $switchips{$switch};
156 my $vlan = $row . $place;
157 my ($first, $second, $third, $fourth) = split(/\./, $ipnet);
158 my $ip = "$first.$second.$third.".(int($fourth)+2);
159 my $dip = $distro.".net.tg07.gathering.org";
161 return ($row, $place, $ipnet, $vlan, $ip, $dip);
166 open(PATCHLIST, $patchlist) or die "Unable to open patchlist";
167 while (<PATCHLIST>) {
168 my ($switch, $distro, $port) = split;
170 #print "Testing: ".$ARGV[1]." $switch\n";
171 next if (defined($ARGV[1]) and $ARGV[1] ne $switch);
173 print "First run...\n";
174 my ($row, $place, $ipnet, $vlan, $ip, $dip) = switch_info($switch, $distro, $port);
175 print "Switch: $switch, Distro: $distro, vlan: $vlan\n";
176 print "Ip net: $ipnet\n";
179 do_distro($dip, $ip, $vlan, $switch);
180 # my ($dip, $newip, $vlan) = @_;
186 open(PATCHLIST, $patchlist) or die "Unable to open patchlist";
187 while (<PATCHLIST>) {
188 print "Verify run....\n";
189 my ($switch, $distro, $port) = split;
191 if ($switch eq "e71-6") {
192 print "There is no e71-6\n";
196 my ($row, $place, $ipnet, $vlan, $ip, $dip) = switch_info($switch, $distro, $port);
197 print "Switch: $switch, Distro: $distro, vlan: $vlan\n";
198 print "Ip net: $ipnet\n";
201 my $p = Net::Ping->new();
202 printf "Checking if zyxel is up $dip:$vlan $ip...\n";
206 print "No answer from $dip:$vlan $ip, trying to route it up\n";
207 do_distro($dip, $ip, $vlan, $switch);
211 system("perl ./ciscong2.pl $switch");
216 last if $p->ping($ip);
217 print "pinging...\n";
222 # my ($dip, $newip, $vlan) = @_;