summaryrefslogtreecommitdiff
path: root/scripts/priority.pl
diff options
context:
space:
mode:
authorMichael Larson <slioch@slioch.vyatta.com>2010-04-22 13:34:17 -0700
committerMichael Larson <slioch@slioch.vyatta.com>2010-04-22 13:34:17 -0700
commitb72ddf64bc5d89487ffe9672f0ba89c5b90ac2e5 (patch)
tree23b4f9af8dfd915c8951729fd3bb0dbf9e658fb7 /scripts/priority.pl
parentd29097a8800e16899873bea1b70b85b0bd3586ab (diff)
downloadvyatta-cfg-b72ddf64bc5d89487ffe9672f0ba89c5b90ac2e5.tar.gz
vyatta-cfg-b72ddf64bc5d89487ffe9672f0ba89c5b90ac2e5.zip
support for PARENT reference in priority statements. Example:
priority: PARENT Means that this priority group will adopt the priority value of the parent. And the behavior on deletion of this priority root node will be deleted before the parent. On all other operations this node will be scheduled after the parent. This should fix problems in scheduling creation/deletion orders for priority groups so long as they are located within the same hierarchy. priority.pl has been updated as well.
Diffstat (limited to 'scripts/priority.pl')
-rw-r--r--scripts/priority.pl32
1 files changed, 30 insertions, 2 deletions
diff --git a/scripts/priority.pl b/scripts/priority.pl
index 4124987..0cadbc3 100644
--- a/scripts/priority.pl
+++ b/scripts/priority.pl
@@ -9,6 +9,7 @@ use warnings;
use File::Find;
my %priorities;
+my @parent_priorities;
# Open node file and extract priority and comment if any
sub get_priority {
@@ -19,7 +20,7 @@ sub get_priority {
while (<$f>) {
chomp;
- next unless m/^priority:\s(\d+)/;
+ next unless m/^priority:\s((PARENT)|(\d+))/;
$priority = $1;
$comment = $1 if (/#(.*)$/);
@@ -47,7 +48,12 @@ sub wanted {
if $comment;
# append line to list of entries with same priority
- push @{ $priorities{$priority} }, $dir;
+ if ($priority ne 'PARENT') {
+ push @{ $priorities{$priority} }, $dir;
+ }
+ else {
+ push(@parent_priorities, $dir);
+ }
return 1;
}
@@ -58,6 +64,28 @@ die "$cfgdir does not exist!" unless -d $cfgdir;
# walk config file tree
find( \&wanted, $cfgdir );
+#resolve parent dependencies
+foreach my $pp (@parent_priorities) {
+ my $tmp = $pp;
+ while (1) {
+ my $pos = rindex($tmp, "/");
+ if ($pos == -1) {
+ last;
+ }
+ $tmp = substr($tmp,0,$pos);
+
+ #search through second value in collection for match
+ foreach (keys %priorities) {
+ foreach my $a (@{ $priorities{$_} }) {
+ if ($a eq $tmp) {
+ push @{ $priorities{$_} }, $pp . " [PARENT]";
+ last;
+ }
+ }
+ }
+ }
+}
+
# display resulting priorities
foreach my $key ( sort { $a <=> $b } keys %priorities ) {
my @a = @{ $priorities{$key} };