]> git.sesse.net Git - nms/blob - config/make-port-config.pl
4da29638765a3dbfe7ed85a6ffdb1e0f69cb1d21
[nms] / config / make-port-config.pl
1 #! /usr/bin/perl
2 open PATCHLIST, "<patchlist.txt"
3         or die "patchlist.txt: $!";
4 my %distros = ();
5
6 while (<PATCHLIST>) {
7         chomp;
8         my ($name, $distro, $port) = split / /;
9
10         $name =~ /e(\d+)-(\d+)/;
11         my ($row, $switch) = ($1, $2);
12
13         my $ip;
14         if ($switch == 1) {
15                 $ip = "87.76." . ($row) . ".1";
16         } elsif ($switch == 2) {
17                 $ip = "87.76." . ($row) . ".65";
18         } elsif ($switch == 3) {
19                 $ip = "87.76." . ($row) . ".129";
20         } elsif ($switch == 4) {
21                 $ip = "87.76." . ($row + 1) . ".1";
22         } elsif ($switch == 5) {
23                 $ip = "87.76." . ($row + 1) . ".65";
24         } elsif ($switch == 6) {
25                 $ip = "87.76." . ($row + 1) . ".129";
26         }
27
28         my $vlan = "$row$switch";
29
30         $distros{$distro} .= <<"EOF";
31 vlan $vlan
32   name $name
33 !
34 default interface vlan $vlan
35 interface $vlan
36   description $name
37   ip address $ip 255.255.255.192
38   ip directed-broadcast 10
39   ip helper-address 87.76.254.2
40   no ip proxy-arp
41   ip access-group great-wall-of-tg in
42   no shutdown
43 !
44  
45 default interface $port
46 interface $port
47  description $name
48  switchport mode access
49  switchport access vlan $vlan
50
51  spanning-tree portfast
52  spanning-tree bpduguard enable
53
54  ip igmp snooping
55  storm-control broadcast level 2
56  no shutdown
57 !
58 EOF
59 }
60
61 for my $distro (keys %distros) {
62         open DISTRO, ">$distro-config"
63                 or die "$distro-config: $!";
64         print DISTRO $distros{$distro};
65         print DISTRO "end\n";
66         close DISTRO;
67 }