Changeset 311
- Timestamp:
- Oct 21, 2017, 6:53:47 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r310 r311 7 7 use strict; 8 8 use warnings; 9 use version; our $VERSION = qv('0.7. 3');9 use version; our $VERSION = qv('0.7.4'); 10 10 11 11 use Readonly; … … 21 21 use List::Util 'shuffle'; 22 22 use Digest::SHA qw(sha512_base64); 23 use Text::Table; # libtext-table-perl http://blogs.perl.org/users/steven_haryanto/2014/07/benchmarking-several-ascii-table-generator-modules.html 23 24 24 25 # apt-get install snmp fping libnet-cidr-lite-perl libnet-netmask-perl libnet-snmp-perl libnetaddr-ip-perl libyaml-perl 25 # libcrypt-des-perl libcrypt-hcesha-perl libdigest-hmac-perl 26 # libcrypt-des-perl libcrypt-hcesha-perl libdigest-hmac-perl libtext-table-perl 26 27 # arping net-tools fping bind9-host arpwatch 27 28 … … 2847 2848 #--------------------------------------------------------------- 2848 2849 sub cmd_exportsw_txt { 2849 2850 2850 my $switch_connection = YAML::Syck::LoadFile("$KLASK_SW_FILE"); 2851 2851 … … 2854 2854 my %db_switch_connected_on_port = %{$switch_connection->{'connected_on_port'}}; 2855 2855 2856 print "Switch output port and parent port connection\n"; 2857 print "---------------------------------------------\n"; 2856 my $tb_child = Text::Table->new( # http://www.perlmonks.org/?node_id=988320 2857 {align => 'left', align_title => 'left', title => 'Child_Switch'}, 2858 {align => 'right', align_title => 'right', title => 'Output_Port'}, 2859 {align => 'center', align_title => 'center', title => 'Link'}, 2860 {align => 'left', align_title => 'left', title => 'Input_Port'}, 2861 {align => 'left', align_title => 'left', title => 'Parent_Switch'}, 2862 ); 2863 #print "Switch output port and parent port connection\n"; 2864 #print "---------------------------------------------\n"; 2858 2865 for my $sw (sort keys %db_switch_output_port) { 2859 my $arrow ='-- >';2860 $arrow ='== >' if $db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/;2866 my $arrow ='--->'; 2867 $arrow ='===>' if $db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/; 2861 2868 if (exists $db_switch_parent{$sw}) { 2862 printf "%-28s %8s %3s %-8s %-25s\n", $sw, $db_switch_output_port{$sw}, $arrow, $db_switch_parent{$sw}->{'port_hr'}, $db_switch_parent{$sw}->{'switch'}; 2869 #printf "%-28s %8s %3s %-8s %-25s\n", $sw, $db_switch_output_port{$sw}, $arrow, $db_switch_parent{$sw}->{'port_hr'}, $db_switch_parent{$sw}->{'switch'}; 2870 $tb_child->add($sw, $db_switch_output_port{$sw}, $arrow, $db_switch_parent{$sw}->{'port_hr'}, $db_switch_parent{$sw}->{'switch'}); 2871 2863 2872 } 2864 2873 else { 2865 printf "%-28s %8s %3s %-8s %-25s\n", $sw, $db_switch_output_port{$sw}, $arrow, '', 'router'; 2866 } 2867 } 2874 #printf "%-28s %8s %3s %-8s %-25s\n", $sw, $db_switch_output_port{$sw}, $arrow, '', 'router'; 2875 $tb_child->add($sw, $db_switch_output_port{$sw}, $arrow, '', 'router'); 2876 } 2877 } 2878 my @colrange = map { scalar $tb_child->colrange($_) } (0 .. 4); # force scaler context 2879 $tb_child->add(map { ' ' x $_ } reverse @colrange); # add empty line to force symetric table 2880 print $tb_child->title(); 2881 print $tb_child->rule('-'); 2882 print $tb_child->body(0, $tb_child->body_height()-1); # remove last fake line 2883 $tb_child->clear; 2884 2868 2885 print "\n"; 2869 2870 print "Switch parent and children port inter-connection\n"; 2871 print "------------------------------------------------\n"; 2886 my $tb_parent = Text::Table->new( # http://www.perlmonks.org/?node_id=988320 2887 {align => 'left', align_title => 'left', title => 'Parent_Switch'}, 2888 {align => 'right', align_title => 'right', title => 'Input_Port'}, 2889 {align => 'center', align_title => 'center', title => 'Link'}, 2890 {align => 'left', align_title => 'left', title => 'Output_Port'}, 2891 {align => 'left', align_title => 'left', title => 'Child_Switch'}, 2892 ); 2893 #print "Switch parent and children port inter-connection\n"; 2894 #print "------------------------------------------------\n"; 2872 2895 for my $swport (sort keys %db_switch_connected_on_port) { 2873 2896 my ($sw_connect, $port_connect) = split m/ $SEP_SWITCH_PORT /xms, $swport, 2; … … 2876 2899 $arrow ='<==' if $port_connect =~ m/^(Trk|Br|Po)/; 2877 2900 if (exists $db_switch_output_port{$sw}) { 2878 printf "%-28s %8s %3s %-8s %-25s\n", $sw_connect, $port_connect, $arrow, $db_switch_output_port{$sw}, $sw; 2901 #printf "%-28s %8s %3s %-8s %-25s\n", $sw_connect, $port_connect, $arrow, $db_switch_output_port{$sw}, $sw; 2902 $tb_parent->add($sw_connect, $port_connect, $arrow, $db_switch_output_port{$sw}, $sw); 2879 2903 } 2880 2904 else { 2881 printf "%-28s %8s %3s %-8s %-25s\n", $sw_connect, $port_connect, $arrow, '', $sw; 2905 #printf "%-28s %8s %3s %-8s %-25s\n", $sw_connect, $port_connect, $arrow, '', $sw; 2906 $tb_parent->add($sw_connect, $port_connect, $arrow, '', $sw); 2882 2907 } 2883 2908 } 2884 2909 } 2910 @colrange = map { scalar $tb_parent->colrange($_) } (0 .. 4); # force scaler context 2911 $tb_parent->add(map { ' ' x $_ } reverse @colrange); # add empty line to force symetric table 2912 print $tb_parent->title(); 2913 print $tb_parent->rule('-'); 2914 print $tb_parent->body(0, $tb_parent->body_height()-1); # remove last fake line 2915 $tb_parent->clear; 2916 2885 2917 return; 2886 2918 }
Note: See TracChangeset
for help on using the changeset viewer.