diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-07-07 10:59:00 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-08-12 22:04:28 -0700 |
commit | e950d44cada84d0309a1dca74d8688ccb2531cc8 (patch) | |
tree | 6c442933233a2f053a8d985b89fd2d79b2d5020d | |
parent | 0b84adc1dbb527ea7ce39aaa5cd992f09056d07d (diff) | |
download | vyatta-op-e950d44cada84d0309a1dca74d8688ccb2531cc8.tar.gz vyatta-op-e950d44cada84d0309a1dca74d8688ccb2531cc8.zip |
Cleanup show bonding script
Use existing Vyatta::Misc module to find interfaces
-rwxr-xr-x | scripts/vyatta-show-bonding.pl | 42 |
1 files changed, 8 insertions, 34 deletions
diff --git a/scripts/vyatta-show-bonding.pl b/scripts/vyatta-show-bonding.pl index 62d503e..c34a89e 100755 --- a/scripts/vyatta-show-bonding.pl +++ b/scripts/vyatta-show-bonding.pl @@ -22,7 +22,11 @@ # # **** End License **** # + +use lib "/opt/vyatta/share/perl5/"; use Getopt::Long; +use Vyatta::Misc; +use Vyatta::Interface; use strict; use warnings; @@ -33,18 +37,6 @@ sub usage { exit 1; } -sub get_sysfs_value { - my ( $intf, $name ) = @_; - - open( my $statf, '<', "/sys/class/net/$intf/$name" ) - or die "Can't open file /sys/class/net/$intf/$name"; - - my $value = <$statf>; - chomp $value if defined $value; - close $statf; - return $value; -} - sub get_state_link { my $intf = shift; my $state; @@ -76,7 +68,7 @@ my @modes = ( "round-robin", ); sub show_brief { - my @interfaces = @_; + my @interfaces = grep { /^bond[\d]+$/ } getInterfaces(); my $format = "%-12s %-22s %-8s %-6s %s\n"; printf $format, 'Interface', 'Mode', 'State', 'Link', 'Slaves'; @@ -93,6 +85,7 @@ sub show_brief { printf $format, $intf, $mode, $state, $link, $slaves ? $slaves : ''; } + exit 0; } sub show { @@ -125,25 +118,6 @@ sub show { my $brief; GetOptions( 'brief' => \$brief, ) or usage(); -my @bond_intf = (); +show_brief() if ($brief); +show(@ARGV); -if ( $#ARGV == -1 ) { - my $sysfs = '/sys/class/net'; - opendir( my $sysdir, $sysfs ) || die "can't opendir $sysfs"; - foreach my $intf ( readdir($sysdir) ) { - if ( -d "$sysfs/$intf/bonding" ) { - unshift @bond_intf, $intf; - } - } - close $sysdir; -} -else { - @bond_intf = @ARGV; -} - -if ($brief) { - show_brief(@bond_intf); -} -else { - show(@bond_intf); -} |