diff options
Diffstat (limited to 'scripts')
-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); -} |