From 2e738a6404c640c2f6e4f54cb9ae19168434fc1d Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Sun, 8 Mar 2009 09:34:29 -0700 Subject: Fold name conflict checking into policy creation Eliminate need for begin, just check for name conflicts at create. --- scripts/vyatta-qos.pl | 23 ++++++++++++----------- templates/qos-policy/node.def | 1 - 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/vyatta-qos.pl b/scripts/vyatta-qos.pl index 1182089..4a76d60 100755 --- a/scripts/vyatta-qos.pl +++ b/scripts/vyatta-qos.pl @@ -17,6 +17,7 @@ use lib "/opt/vyatta/share/perl5"; use Vyatta::Config; use strict; +use warnings; use Getopt::Long; @@ -82,7 +83,6 @@ sub list_policy { } print join( ' ', @nodes ), "\n"; - exit 0; } ## delete_interface('eth0', 'out') @@ -97,7 +97,7 @@ sub delete_interface { } elsif (/^in$/) { qx(sudo /sbin/tc qdisc del dev "$interface" parent ffff: 2>/dev/null); } else { - die "bad direction $direction"; + croak "bad direction $direction"; } } } @@ -293,10 +293,9 @@ sub delete_policy { # can't delete active policy die "Must delete QoS policy from interfaces before deleting rules\n"; } - exit 0; } -sub check_conflict { +sub name_conflict { my $config = new Vyatta::Config; my %other = (); @@ -304,17 +303,22 @@ sub check_conflict { foreach my $type ( $config->listNodes() ) { foreach my $name ( $config->listNodes($type) ) { my $conflict = $other{$name}; - die "Policy $name used by $conflict and $type\n" if ($conflict); + if ($conflict) { + warn "Policy $name used by $conflict and $type\n"; + return $name; + } $other{$name} = $type; } } + return; } sub create_policy { my ($shaper, $name) = @_; my $config = new Vyatta::Config; - # Syntax check + exit 1 if name_conflict(); + make_policy($config, $shaper, $name); } @@ -344,8 +348,7 @@ sub apply_changes { sub usage { print < \$check, "apply" => \$apply, "start-interface=s" => \$start, "update-interface=s{3}" => \@updateInterface, @@ -377,7 +379,6 @@ GetOptions( ) or usage(); apply_changes() if $apply; -check_conflict() if $check; delete_interface(@deleteInterface) if ( $#deleteInterface == 1 ); update_interface(@updateInterface) if ( $#updateInterface == 2 ); diff --git a/templates/qos-policy/node.def b/templates/qos-policy/node.def index 991b5f5..8651fd7 100644 --- a/templates/qos-policy/node.def +++ b/templates/qos-policy/node.def @@ -1,3 +1,2 @@ help: Configure Quality of Service (QOS) policy type -begin: /opt/vyatta/sbin/vyatta-qos.pl --check end: /opt/vyatta/sbin/vyatta-qos.pl --apply -- cgit v1.2.3