diff options
Diffstat (limited to 'lib/Vyatta/ConfigLoad.pm')
-rwxr-xr-x | lib/Vyatta/ConfigLoad.pm | 96 |
1 files changed, 57 insertions, 39 deletions
diff --git a/lib/Vyatta/ConfigLoad.pm b/lib/Vyatta/ConfigLoad.pm index 28e932e..183e598 100755 --- a/lib/Vyatta/ConfigLoad.pm +++ b/lib/Vyatta/ConfigLoad.pm @@ -30,6 +30,9 @@ use Vyatta::Config; my @all_nodes = (); my @all_naked_nodes = (); +my @disable_list = (); + + sub match_regex { my ($pattern, $str) = @_; $pattern =~ s/^(.*)$/\^$1\$/; @@ -58,6 +61,8 @@ sub applySingleQuote { return @return; } +my @comment_list = (); + sub enumerate_branch { my $cur_node = shift; my @cur_path = @_; @@ -72,31 +77,42 @@ sub enumerate_branch { } my $terminal = 0; if (!defined($cur_node->{'children'})) { - $terminal = 1; + $terminal = 1; } else { - foreach (@{$cur_node->{'children'}}) { - if (defined($_->{'name'})) { - enumerate_branch($_, @cur_path); - $terminal = 0; + my $comment; + foreach (@{$cur_node->{'children'}}) { + if (defined($_->{'comment'})) { + $comment = $_->{'comment'}; + } + + if (defined($_->{'name'})) { + if (defined $comment) { + push @comment_list, join(" ", (@cur_path, $_->{'name'}, "\"" . $comment . "\"")); + $comment = undef; + } + else { + #need to check for existance of .comment file here. + push @comment_list, join(" ", (@cur_path, $_->{'name'}, "\"\"")); + } + enumerate_branch($_, @cur_path); + $terminal = 0; + } + } - } } + + if (defined($cur_node->{'disable'})) { + push @disable_list, join(" ",@cur_path); + } + if ($terminal) { my $val = $cur_node->{'value'}; if (defined($val)) { push @cur_path, $val; } - if (defined $cur_node->{'disable'}) { - push @all_naked_nodes, [ '!', @cur_path ]; - my @qpath = applySingleQuote(@cur_path); - unshift(@qpath,'!'); - push @all_nodes, [\@qpath, 0]; - } - else { - push @all_naked_nodes, [ @cur_path ]; - my @qpath = applySingleQuote(@cur_path); - push @all_nodes, [\@qpath, 0]; - } + push @all_naked_nodes, [ @cur_path ]; + my @qpath = applySingleQuote(@cur_path); + push @all_nodes, [\@qpath, 0]; } } @@ -111,6 +127,8 @@ sub getStartupConfigStatements { if (!defined($load_cfg)) { return (); } + + my $comments = shift; my $xcp = new XorpConfigParser(); $xcp->parse($load_cfg); @@ -120,7 +138,20 @@ sub getStartupConfigStatements { } enumerate_branch($root, ( )); - return @all_nodes; + if (defined $comments && $comments eq 'true') { + #add comment commands to all nodes + foreach my $c (@comment_list) { + if ($c !~ /\"\"$/) { + my @pth = split(" ",'comment ' . $c); + push @all_nodes, [\@pth, 1]; + } + } + } + my %conf = ( + 'set' => \@all_nodes, + 'deactivate' => \@disable_list, + ); + return %conf; } my %node_order = (); @@ -221,7 +252,6 @@ sub getSortedMultiValues { my $active_cfg = undef; my $new_cfg_ref = undef; - my @delete_list = (); # find specified node's values in active config that have been deleted from @@ -278,7 +308,6 @@ sub findDeletedNodes { } my @set_list = (); -my @disable_list = (); # find specified node's values in active config that are set # (added or changed). @@ -326,9 +355,9 @@ sub findSetNodes { my %active_hash = map { $_ => 1 } @active_nodes; my $nref = $active_cfg->parseTmplAll(join ' ', @active_path); if (defined($nref->{type}) and !defined($nref->{tag})) { - # we are at a leaf node. - findSetValues($new_ref, \@active_path); - return; + # we are at a leaf node. + findSetValues($new_ref, \@active_path); + return; } foreach (sort keys %{$new_ref}) { if (scalar(keys %{$new_ref->{$_}}) == 0) { @@ -336,28 +365,16 @@ sub findSetNodes { # check if we need to add this node. if (!defined($active_hash{$_})) { my @plist = applySingleQuote(@active_path, $_); - if ($active_path[0] eq '!') { - my @tmp = @plist[1..$#plist]; - push @disable_list, [\@tmp, 0]; - push @set_list, [\@tmp, 0]; - } - else { - push @set_list, [\@plist, 0]; - } + push @set_list, [\@plist, 0]; } else { # node already present. do nothing. } next; } - if ($active_path[0] eq '!') { - my @plist = applySingleQuote(@active_path, $_); - my @tmp = @plist[1..$#plist]; - push @disable_list, [\@tmp, 0]; - } + # we recur regardless of whether it's in active. all changes will be + # handled when we reach leaf nodes (above). findSetNodes($new_ref->{$_}, [ @active_path, $_ ]); } - # we recur regardless of whether it's in active. all changes will be - # handled when we reach leaf nodes (above). } # compare the current active config with the specified hierarchy and return @@ -368,7 +385,7 @@ sub getConfigDiff { $active_cfg = new Vyatta::Config; $new_cfg_ref = shift; @set_list = (); - @disable_list = (); +# @disable_list = (); @delete_list = (); findDeletedNodes($new_cfg_ref, [ ]); findSetNodes($new_cfg_ref, [ ]); @@ -392,6 +409,7 @@ sub getConfigDiff { 'delete' => \@new_delete_list, 'set' => \@set_list, 'deactivate' => \@disable_list, + 'comment' => \@comment_list, ); return %diff; } |