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.d01-1-2";
20 my $switches = "/root/switches.txt.d01-1-2";
24 require "../include/config.pm";
26 require "../include/config.local.pm";
33 $t->cmd("show ip route".($net ? " $net" : '')) or return 0;;
38 #my $ios_server = "noc-gw.net.tg07.gathering.org";
41 #my $ios = nms::ios_connect($ios_server, $nms::config::ios_user, $nms::config::ios_pass)
42 # or die "Unable to connect to cisco";
46 my ($ios, $vlan) = @_;
49 $ios->cmd("int vlan $vlan");
50 $ios->cmd("ip add 192.168.1.254 255.255.255.0 secondary");
56 my ($ios, $vlan) = @_;
59 $ios->cmd("int vlan $vlan");
60 $ios->cmd("no ip add 192.168.1.254 255.255.255.0 secondary");
68 my ($dip, $newip, $vlan, $switchname) = @_;
70 my $ios = Net::Telnet::Cisco->new(Host => $dip,
72 Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/');
73 $ios->login($nms::config::ios_user, $nms::config::ios_pass);
76 #nms::ios_enable($ios);
78 #nms::ios_getroute($ios, "192.168.1.0");
81 #nms::ios_close($ios);
84 $ios->cmd("terminal length 0");
86 #my @routes = $ios->cmd("show ip route");
88 if (ios_getroute($ios, "192.168.1.0") == 1) {
89 print "Already routed up 192.168.1.0/24\n" ;
93 my $zyxeloldip = "192.168.1.1";
94 start_vlan($ios, $vlan);
99 my $p = Net::Ping->new();
100 printf "Waiting for zyxel to come up...\n";
103 if ($counter > 180) {
104 print "Waiting for zyxel on $dip:$vlan timed out, wanted to set ip: $newip";
105 stop_vlan($ios, $vlan);
108 last if $p->ping($zyxeloldip);
109 print "pinging...\n";
113 print "Zyxel is alive..\n";
116 system("perl ./zyxelng.pl 192.168.1.1 $newip $switchname");
120 stop_vlan($ios, $vlan);
127 ## Collect switch ips
131 open(SWITCHES, $switches) or die "Unable to open switches";
133 my ($ip, $net, $name) = split;
135 if ($name =~ /e\d+-\d/) {
136 die "We only support /26 nets for now you wanted $net" if ($net ne "26");
137 $switchips{$name} = $ip;
143 my ($switch, $distro, $port) = @_;
145 $switch =~ /e(\d+)-(\d)/;
146 my ($row, $place) = ($1, $2);
147 my $ipnet = $switchips{$switch};
148 my $vlan = $row . $place;
149 my ($first, $second, $third, $fourth) = split(/\./, $ipnet);
150 my $ip = "$first.$second.$third.".(int($fourth)+2);
151 my $dip = $distro.".net.tg07.gathering.org";
153 return ($row, $place, $ipnet, $vlan, $ip, $dip);
158 open(PATCHLIST, $patchlist) or die "Unable to open patchlist";
159 while (<PATCHLIST>) {
160 my ($switch, $distro, $port) = split;
162 print "First run...\n";
163 my ($row, $place, $ipnet, $vlan, $ip, $dip) = switch_info($switch, $distro, $port);
164 print "Switch: $switch, Distro: $distro, vlan: $vlan\n";
165 print "Ip net: $ipnet\n";
168 do_distro($dip, $ip, $vlan, $switch);
169 # my ($dip, $newip, $vlan) = @_;
175 open(PATCHLIST, $patchlist) or die "Unable to open patchlist";
176 while (<PATCHLIST>) {
177 print "Verify run....\n";
178 my ($switch, $distro, $port) = split;
180 my ($row, $place, $ipnet, $vlan, $ip, $dip) = switch_info($switch, $distro, $port);
181 print "Switch: $switch, Distro: $distro, vlan: $vlan\n";
182 print "Ip net: $ipnet\n";
185 my $p = Net::Ping->new();
186 printf "Checking if zyxel is up $dip:$vlan $ip...\n";
190 print "No answer from $dip:$vlan $ip, trying to route it up\n";
191 do_distro($dip, $ip, $vlan, $switch);
194 last if $p->ping($ip);
195 print "pinging...\n";
200 # my ($dip, $newip, $vlan) = @_;