From 4cd540436f0b946ca6b8206d7166c56094a6e9e4 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 11 Jun 2009 16:55:29 -0700 Subject: Cleanup how qos-policy change detection works The CLI end: node does work correctly, so don't need to go walking configuration manually Bug 4545 (cherry picked from commit 377896b296827e4d7c3c20debb3487605c45bbe3) --- scripts/vyatta-qos.pl | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-qos.pl b/scripts/vyatta-qos.pl index 86b8fe2..e0a1b0f 100755 --- a/scripts/vyatta-qos.pl +++ b/scripts/vyatta-qos.pl @@ -192,12 +192,16 @@ sub interfaces_using { foreach my $name ( getInterfaces() ) { my $intf = new Vyatta::Interface($name); next unless $intf; - $config->setLevel($intf->path() . ' qos-policy'); + my $level = $intf->path() . ' qos-policy'; + $config->setLevel($level); foreach my $direction ($config->listNodes()) { my $cur = $config->returnValue($direction); next unless $cur; - push @inuse, $name if ($cur eq $policy); + + # these are arguments to update_interface() + push @inuse, [ $name, $direction, $name ] + if ($cur eq $policy); } } return @inuse; @@ -224,19 +228,17 @@ sub create_policy { # Configuration changed, reapply to all interfaces. sub apply_policy { - my $config = new Vyatta::Config; - - while ( my $name = shift ) { - foreach my $device ( interfaces_using($name) ) { - my $intf = new Vyatta::Interface($device); - - $config->setLevel( $intf->path() ); - foreach my $direction ( $config->listNodes('qos-policy') ) { - next unless $config->exists("qos-policy $direction $name"); + my ( $policy, $name ) = @_; + my @usedby = interfaces_using($name); - update_interface( $device, $direction, $name ); - } - } + if (@usedby) { + foreach my $args (@usedby) { + update_interface( @$args ); + } + } else { + # Recheck the policy, might have new errors. + my $shaper = make_policy( $policy, $name ); + exit 1 unless $shaper; } } @@ -245,7 +247,7 @@ sub usage { usage: vyatta-qos.pl --list-policy direction vyatta-qos.pl --create-policy policy-type policy-name vyatta-qos.pl --delete-policy policy-name - vyatta-qos.pl --apply-policy policy-name + vyatta-qos.pl --apply-policy policy-type policy-name vyatta-qos.pl --update-interface interface direction policy-name vyatta-qos.pl --delete-interface interface direction @@ -270,7 +272,7 @@ GetOptions( "list-policy=s" => \@listPolicy, "delete-policy=s" => \@deletePolicy, "create-policy=s{2}" => \@createPolicy, - "apply-policy=s" => \@applyPolicy, + "apply-policy=s{2}" => \@applyPolicy, ) or usage(); delete_interface(@deleteInterface) if ( $#deleteInterface == 1 ); -- cgit v1.2.3