diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2008-04-01 11:07:06 -0700 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2008-04-01 11:07:06 -0700 |
commit | 2ad53e3ae6bd073785df8f99121b89683df744a2 (patch) | |
tree | 387f711e92ced1641e8887b843997b36bddbfcd2 /scripts | |
parent | 7b6cc54983fc930787b8c30d552454727ac4f606 (diff) | |
download | vyatta-cfg-2ad53e3ae6bd073785df8f99121b89683df744a2.tar.gz vyatta-cfg-2ad53e3ae6bd073785df8f99121b89683df744a2.zip |
add function to delete watchlink exclude entries based on ID.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/vyatta-watchlink-exclude.pl | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/scripts/vyatta-watchlink-exclude.pl b/scripts/vyatta-watchlink-exclude.pl index 9805463..048946c 100755 --- a/scripts/vyatta-watchlink-exclude.pl +++ b/scripts/vyatta-watchlink-exclude.pl @@ -34,13 +34,13 @@ # parameters: # --id="" : owner of exclude line (e.g. vrrp, ha) [required] # --action="" : add or remove [required] -# --intf="" : interface [required] +# --intf="" : interface [required for add] # --ipaddr="" : ip address or network to execlude [optional] # --signal : should watchlink get signaled [optional] # # Expected format of exclude file: # -# [interface] ([ipv4addr]|ipv4net]) # id +# <interface> [ <ipv4addr> | <ipv4net> ] # id # use Getopt::Long; @@ -76,6 +76,24 @@ sub write_exclude_file { close($FILE); } +sub remove_exclude_id { + my ($id, @lines) = @_; + + my @new_lines; + my $match = 0; + foreach my $line (@lines) { + if ($line =~ /# $id$/) { + $match++; + } else { + push @new_lines, $line; + } + } + if ($match < 1) { + die "Error: no match found for $id"; + } + return @new_lines; +} + sub remove_exclude_line { my ($remove_line, @lines) = @_; @@ -108,14 +126,18 @@ GetOptions("id=s" => \$opt_id, "signal!" => \$opt_signal, ); -if (!(defined $opt_id and defined $opt_action and defined $opt_intf) ) { - die "Error: parameters --id --intf --action must be set"; +if (!(defined $opt_id and defined $opt_action)) { + die "Error: parameters --id --action must be set"; } if ($opt_action ne "add" and $opt_action ne "remove") { die "Error: --action must be \"add\" or \"remove\" "; } +if ($opt_action eq "add" and !defined($opt_intf)) { + die "Error: --intf must be set for \"add\""; +} + my @lines = read_exclude_file(); my $new_line = "$opt_intf "; if (defined $opt_ipaddr) { @@ -127,8 +149,10 @@ if (defined $opt_id) { if ($opt_action eq "add") { push @lines, $new_line; -} else { +} elsif (defined $opt_intf) { @lines = remove_exclude_line($new_line, @lines); +} else { + @lines = remove_exclude_id($opt_id, @lines); } write_exclude_file(@lines); |