+## Collect switch ips
+
+my %switchips;
+
+open(SWITCHES, $switches) or die "Unable to open switches";
+while(<SWITCHES>) {
+ my ($ip, $net, $name) = split;
+
+ 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);
+
+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 (<PATCHLIST>) {
+ my ($switch, $distro, $port) = split;
+
+ 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";
+ print "Ip: $ip\n";
+
+ do_distro($dip, $ip, $vlan, $switch);
+# my ($dip, $newip, $vlan) = @_;
+ }
+ close(PATCHLIST);
+}
+
+sub verify_run {
+ open(PATCHLIST, $patchlist) or die "Unable to open patchlist";
+ while (<PATCHLIST>) {
+ 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);
+}