diff options
author | root <root@frank.tg14.gathering.org> | 2014-04-16 16:08:49 +0200 |
---|---|---|
committer | root <root@frank.tg14.gathering.org> | 2014-04-16 16:08:49 +0200 |
commit | 4723868223679e038161c2c7e0a1e384f0f8d2cc (patch) | |
tree | 8f6678a2f825bb69ad342f6feacc3b4905fc6dfc | |
parent | 3430d3f965ddac5d24890d56462049b4402084cd (diff) |
Several improvements to dlink-ng.
-rwxr-xr-x | dlink-ng/dlink-ng-config.pm.dist | 29 | ||||
-rwxr-xr-x | dlink-ng/dlink-ng.pl | 88 | ||||
-rwxr-xr-x | dlink-ng/make-dlink-config.pl | 9 |
3 files changed, 65 insertions, 61 deletions
diff --git a/dlink-ng/dlink-ng-config.pm.dist b/dlink-ng/dlink-ng-config.pm.dist index cfeaf7a..82abbf6 100755 --- a/dlink-ng/dlink-ng-config.pm.dist +++ b/dlink-ng/dlink-ng-config.pm.dist @@ -1,6 +1,7 @@ #!/usr/bin/perl use strict; use warnings; +no warnings 'closure'; # remove "Variable $foo will not stay shared" :-D package dlinkng::config; # Common config @@ -18,10 +19,13 @@ our $dlink_host_suffix = "_DGS-3100"; # Suffix for hostname on the D-Link switc our $default_coreswos = "ios"; # Default OS on coresw our $dlink_lacp_start = '45'; # First port for LACP-group on D-Links our $dlink_lacp_end = '48'; # Last port for LACP-group on D-Links -our $skip_last_port = 0; # Skip last port -- set up as access port -our $use_ssh_cisco = 1; # Use SSH towards Cisco-boxes +our $configure_last_port = 0; # Configure last port differently than the rest +our $last_port_regex = '^e([1-8][1-9]|[2-8][0-9])-'; # Regex to use in combination with $configure_last_port +our $use_ssh_cisco = 0; # Use SSH towards Cisco-boxes our $use_ssh_dlink = 0; # Use SSH towards D-Link switches -our $access_vlan = '3602'; # VLAN to use for skipped port +our $cdp_enable = 0; # Enable or disable CDP on each port +our $save_config = 1; # Save configuration to Cisco switch +our $access_vlan = '3602'; # VLAN to use for last port # Specific config -- just declare empty our $cisco_user = ""; # Username used when logging into the swithces @@ -40,14 +44,12 @@ sub set_variables{ # Custom Portchannel-config $po_config = { ios => [ + "ip directed-broadcast 2699", + "ip pim sparse-mode", + "ip pim bsr-border", "logging event link-status", - #"ip access-group end-user-protection in", - #"ip directed-broadcast 2000", - #"ipv6 nd prefix default 300 300 no-autoconfig", - #"ipv6 nd managed-config-flag", - #"ipv6 nd other-config-flag", - #"ipv6 dhcp relay destination $dhcprelay6_pri", - #"ipv6 dhcp relay destination $dhcprelay6_sec" + "ipv6 nd other-config-flag", + "ipv6 dhcp server sexdhcp", ], nx => [ "", @@ -116,7 +118,7 @@ sub load_bylan_config{ $bylan_dir = "$FindBin::Bin"; # Assume working-folder is the path where this script resides } use lib $bylan_dir; - use bylan; + eval "use bylan"; use Getopt::Long; # Load config @@ -138,9 +140,10 @@ sub load_bylan_config{ # Load TG related configuration sub load_tg_config{ - my $tg_dir = '/root/tgmanage'; + my $tg_dir; BEGIN { - require "$tg_dir/include/config.pm"; + $tg_dir = '/root/tgmanage'; + require "$tg_dir/include/config.pm"; eval { require "$tg_dir/include/config.local.pm"; }; diff --git a/dlink-ng/dlink-ng.pl b/dlink-ng/dlink-ng.pl index 8369e05..5d9efa0 100755 --- a/dlink-ng/dlink-ng.pl +++ b/dlink-ng/dlink-ng.pl @@ -1,17 +1,4 @@ #!/usr/bin/perl -# -# USAGE: -# -# On all switches; -# dlink-ng/make-dlink-config.pl switches.txt patchlist.txt | dlink-ng/dlink-ng.pl -# -# On a specific switch; -# dlink-ng/make-dlink-config.pl switches.txt patchlist.txt | dlink-ng/dlink-ng.pl -s e11-1 -# -# On multiple switches; -# dlink-ng/make-dlink-config.pl switches.txt patchlist.txt | grep -E "11-1|11-2|13-1|13-2" | dlink-ng/dlink-ng.pl -# -# use strict; use warnings; use Net::Telnet::Cisco; @@ -44,16 +31,14 @@ my $DLINK_TEMPLATE; # Filehandle used for reading D-Link template $| = 1; # Get options -my ($cisco_config, $single_switch, $dlink_config, $save_config, $skipped_port_only, $skipped_port_desc_only, $no_skip); +my ($cisco_config, $single_switch, $dlink_config, $last_port_config, $last_port_desc); if (@ARGV > 0) { GetOptions( 'c|cisco|ciscoconfig' => \$cisco_config, # Configure on the Cisco-side only (Portchannel, interfaces, etc) 's|switch=s' => \$single_switch, # Configure a single switch 'd|dlink|dlinkconfig=s' => \$dlink_config, # Push D-Link-template-config to D-Link (not used @ TG) - 'w|write' => \$save_config, # Write config on Cisco-side - 'portskip' => \$skipped_port_only, # Configure the skipped port only (Cisco-side) - 'skipdesc' => \$skipped_port_desc_only, # Configure the skipped port description only (Cisco-side) - 'noskip' => \$no_skip # Override $dlinkng::config::skip_last_port + 'lastport' => \$last_port_config, # Configure the last port only (Cisco-side) + 'lastportdesc' => \$last_port_desc, # Configure the description on the last port (Cisco-side) ) } @@ -64,19 +49,21 @@ if ($dlink_config){ } } -# Exit if $cisco_config and $skipped_port_only or $skipped_port_desc_only is set -if ($cisco_config && ($skipped_port_only || $skipped_port_desc_only)){ - die("\$cisco_config and \$skipped_port_only (or \$skipped_port_desc_only) can't be used together.\n"); +# Exit if $cisco_config and $last_port_config or $last_port_desc is set +if ($cisco_config && ($last_port_config || $last_port_desc)){ + die("\$cisco_config and \$last_port_config (or \$last_port_desc) can't be used together.\n"); } -# Update $dlinkng::config::skip_last_port if $no_skip is set -if ($no_skip){ - $dlinkng::config::skip_last_port = 0; +# If $last_port_desc, assume $last_port_config +if ($last_port_desc){ + $last_port_config = 1; } -# If skipdesc, assume $skipped_port_only -if ($skipped_port_desc_only){ - $skipped_port_only = 1; +# Exit if we give $last_port_config or $last_port_desc parameters, but $configure_last_port is not set +if ($last_port_config || $last_port_desc){ + unless($dlinkng::config::configure_last_port){ + die("\$configure_last_port not set, but expected due to either \$last_port_config or \$last_port_desc.\n"); + } } # Print stuff @@ -600,20 +587,23 @@ sub setup{ my $vrf = threads->tid(); # use thread ID as VRF-number # Remove last port if we're skipping it - my $skipped_port; - if ($dlinkng::config::skip_last_port){ - $skipped_port = pop(@{$switch->{ports}}); + my $last_port; + if ($dlinkng::config::configure_last_port){ + # assume we want to skip a port, so we check against regex + if($switch->{switchname} =~ m/$dlinkng::config::last_port_regex/){ + $last_port = pop(@{$switch->{ports}}); + } } - if($skipped_port_only){ - info($switch->{switchname}, "Configuring skipped port only."); + if($last_port_config){ + info($switch->{switchname}, "Configuring last port only."); } if($cisco_config){ info($switch->{switchname}, "Configuring things on the Cisco-side only."); } - unless($cisco_config || $skipped_port_only){ + unless($cisco_config || $last_port_config){ info($switch->{switchname}, "Starting configuration of $switch->{switchname} ($switch->{ipv4address})."); info($switch->{switchname}, "Trying to ping $switch->{ipv4address}."); @@ -696,7 +686,7 @@ sub setup{ telnet_cmd($switch, $cisco, "terminal length 0") or return abort($switch->{switchname}, $cisco); - unless($cisco_config || $skipped_port_only){ + unless($cisco_config || $last_port_config){ # Prepare ports reset_interfaces($switch, $cisco) or return abort($switch->{switchname}, $cisco); @@ -872,7 +862,7 @@ sub setup{ $dlink->close; } - unless($skipped_port_only){ + unless($last_port_config){ # Configure final IOS stuff info($switch->{switchname}, "Final IOS config phase. Setting up all interfaces + Port-Channel."); @@ -913,6 +903,12 @@ sub setup{ or return abort($switch->{switchname}, $cisco); telnet_cmd($switch, $cisco, "description D-Link $switch->{switchname}; RJ-45; 1G;") or return abort($switch->{switchname}, $cisco); + + # disable CDP if specified + unless($dlinkng::config::cdp_enable){ + telnet_cmd($switch, $cisco, "no cdp enable") + or return abort($switch->{switchname}, $cisco); + } # Assign to Etherchannel if(is_xr($switch->{coreswos})){ @@ -1039,26 +1035,26 @@ sub setup{ } # If we skipped last port at the start, we configure it now - if (($dlinkng::config::skip_last_port && $skipped_port && defined($skipped_port)) || ($skipped_port_only && defined($skipped_port_only))){ - if ($skipped_port_desc_only){ - info($switch->{switchname}, "Configuring skipped port... (description only)"); + if ($dlinkng::config::configure_last_port && $last_port){ + if ($last_port_desc){ + info($switch->{switchname}, "Configuring last port... (description only)"); } else { - info($switch->{switchname}, "Configuring skipped port..."); + info($switch->{switchname}, "Configuring last port..."); } telnet_cmd($switch, $cisco, "conf t") or return abort($switch->{switchname}, $cisco); - unless ($skipped_port_desc_only){ - telnet_cmd($switch, $cisco, "default int $skipped_port") + unless ($last_port_desc){ + telnet_cmd($switch, $cisco, "default int $last_port") or return abort($switch->{switchname}, $cisco); } - telnet_cmd($switch, $cisco, "int $skipped_port") + telnet_cmd($switch, $cisco, "int $last_port") or return abort($switch->{switchname}, $cisco); telnet_cmd($switch, $cisco, "description AP \@ D-Link $switch->{switchname}; RJ-45; 1G;") or return abort($switch->{switchname}, $cisco); - unless ($skipped_port_desc_only){ + unless ($last_port_desc){ foreach my $cmd (@{$dlinkng::config::last_port_config->{$switch->{coreswos}}}){ telnet_cmd($switch, $cisco, $cmd) or return abort($switch->{switchname}, $cisco); @@ -1085,7 +1081,7 @@ sub setup{ # Check if all is OK, but not if configuring skipped port only my $return = 0; - if ($skipped_port_only){ + if ($last_port_config){ info($switch->{switchname}, "Done doing skipped port config. Not checking if anything is online."); $return = 1; } else { @@ -1114,7 +1110,7 @@ sub setup{ } } - if($save_config && !is_xr($switch->{coreswos})){ + if($dlinkng::config::save_config && !is_xr($switch->{coreswos})){ # save the cisco-config, but not if IOS-XR info($switch->{switchname}, "Saving config on core-switch ($switch->{coreswip})."); telnet_cmd($switch, $cisco, "write") @@ -1177,7 +1173,7 @@ sub process_switches { # Let's start my $time_start = time(); log_it("INFO", "yellow", "dlink-ng", "Starting dlink-ng with $dlinkng::config::max_threads threads..."); -log_it("INFO", "yellow", "dlink-ng", "Configured to skip last port on all switches.") if $dlinkng::config::skip_last_port; +log_it("INFO", "yellow", "dlink-ng", "Configured to skip last port on all switches.") if $dlinkng::config::configure_last_port; # Let's add all switches to the queue while (<STDIN>){ diff --git a/dlink-ng/make-dlink-config.pl b/dlink-ng/make-dlink-config.pl index f210a51..7a20820 100755 --- a/dlink-ng/make-dlink-config.pl +++ b/dlink-ng/make-dlink-config.pl @@ -38,7 +38,12 @@ while (<PATCH>) { my ($o1, $o2, $o3, $o4) = split(/\./, $network); # portchannel per distro - $portchannels{$coregw} = $portchannel_start unless ($portchannels{$coregw} && defined($portchannels{$coregw})); + if($coregw =~ m/distro0/){ + # TG14-fix for distro0 + $portchannels{$coregw} = 15 unless ($portchannels{$coregw} && defined($portchannels{$coregw})); + } else { + $portchannels{$coregw} = $portchannel_start unless ($portchannels{$coregw} && defined($portchannels{$coregw})); + } if ($o4 eq "0") { $letter = "a"; @@ -63,4 +68,4 @@ while (<PATCH>) { $portchannels{$coregw}++; die("NO MORE ETHERCHANNELS!") if($portchannels{$coregw} > 64); # IOS-XE 4500 only supports 64 portchannels -}
\ No newline at end of file +} |