[cisco-stats] Added cmdline option '--ignore_shutdown_interfaces' to generate_cisco_p...
authorMaximilian Wilhelm <max@rfc2324.org>
Tue, 25 Dec 2007 11:39:04 +0000 (12:39 +0100)
committerMaximilian Wilhelm <max@rfc2324.org>
Tue, 25 Dec 2007 11:39:04 +0000 (12:39 +0100)
  The new option '--ignore_shutdown_interfaces' will force
  generate_cisco_port_configuration_overview to remove an interface from
  the internal list as far as it is discovered that the interface is
  disabled.

  Currently this might result in printing unused vlan columns in the output
  table.

Signed-off-by: Maximilian Wilhelm <max@rfc2324.org>

cisco-stats/generate_cisco_port_configuration_overview

index 2f72a1f..5fd1fb2 100755 (executable)
 
 use strict;
 
+# Default configuration
+my $opt = {
+       ignore_shutdown_interfaces => undef,
+};
+
+
 # Try to get filename
 my $filename = shift @ARGV;
+
 my @include_ports_list = @ARGV;
+foreach my $arg (@ARGV) {
+       if ($arg =~ m/^--(.*)$/) {
+               my $arg_name = $1;
 
+               # Simple trick to simplfy argument handling
+               if (exists $opt->{$arg_name}) {
+                       $opt->{$arg_name} = 42;
+               }
+
+       } else {
+               push @include_ports_list, $arg;
+       }
+}
+
+
+# The device/hostname
 my $device_name = undef;
 
 # Hash with ports to be included
@@ -37,7 +59,7 @@ my $interfaces = {};
 my $vlans = {};
 
 if (! defined $filename) {
-       print "Usage: $0 filename [port1 [port2 [...]]]\n";
+       print "Usage: $0 filename [--ignore_shutdown_interfaces] [port1 [port2 [...]]]\n";
        exit 1;
 }
 
@@ -98,6 +120,10 @@ while (my $line = <RUNNING_CONFIG>) { # Read configuration {{{
 
 
                        $interfaces->{$type}->{$module}->{$port} = {
+                               type => $type,
+                               module => $module,
+                               port => $port,
+
                                name => $port_name,
                                access_vlan => undef,
                                trunk_allowed_vlans => undef,
@@ -200,6 +226,12 @@ while (my $line = <RUNNING_CONFIG>) { # Read configuration {{{
                        die "Error: Read 'shutdown' command for interface $current_int->{name} for the second time at line $line_num\n";
                }
 
+               if ($opt->{ignore_shutdown_interfaces}) {
+                       delete $interfaces->{$current_int->{type}}->{$current_int->{module}}->{$current_int->{port}};
+                       $current_int = undef;
+                       next;
+               }
+
                $current_int->{disabled} = 'shutdown';
        } # }}}