diff options
Diffstat (limited to 'lib/Vyatta')
-rwxr-xr-x | lib/Vyatta/Config.pm | 23 | ||||
-rwxr-xr-x | lib/Vyatta/ConfigLoad.pm | 96 | ||||
-rwxr-xr-x | lib/Vyatta/ConfigOutput.pm | 26 |
3 files changed, 105 insertions, 40 deletions
diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm index 82d835f..e4d74bb 100755 --- a/lib/Vyatta/Config.pm +++ b/lib/Vyatta/Config.pm @@ -329,6 +329,27 @@ sub returnValue { return $tmp; } +## returnComment("node") +# returns the value of "node" or undef if the node doesn't exist . +# node is relative +sub returnComment { + my ( $self, $node ) = @_; + my $tmp = undef; + + $node =~ s/\//%2F/g; + $node =~ s/\s+/\//g; + + return unless + open my $file, '<', + "$self->{_new_config_dir_base}/$node/.comment"; + + read $file, $tmp, 16384; + close $file; + + $tmp =~ s/\n$//; + return $tmp; +} + ## returnOrigPlusComValue("node") # returns the value of "node" or undef if the node doesn't exist . # node is relative @@ -808,6 +829,8 @@ sub parseTmplAll { } } elsif (/^help:\s+(\S.*)$/) { $ret{help} = $1; + } elsif (/^enumeration:\s+(\S+)$/) { + $ret{enum} = $1; } } close($tmpl); 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; } diff --git a/lib/Vyatta/ConfigOutput.pm b/lib/Vyatta/ConfigOutput.pm index caa9356..99a0da8 100755 --- a/lib/Vyatta/ConfigOutput.pm +++ b/lib/Vyatta/ConfigOutput.pm @@ -82,6 +82,7 @@ sub displayValues { my $HIDE_PASSWORD = '****************'; $config->setLevel(join ' ', @cur_path); + if ($is_multi) { my @ovals = $config->returnOrigValues(''); my @nvals = $config->returnValues(''); @@ -201,6 +202,11 @@ sub displayDeletedOrigChildren { if (!defined $is_tag) { my $path = join(' ',( @cur_path, $child )); + my $comment = $config->returnComment($path); + if (defined $comment) { + print "$prefix /* $comment */\n"; + } + my ($state, $n) = $config->getDeactivated($path); if (defined $state) { $dis = '! '; @@ -211,6 +217,7 @@ sub displayDeletedOrigChildren { } $config->setLevel(join ' ', (@cur_path, $child)); + my @cnames = sort $config->listOrigNodesNoDef(); if ($cnames[0] eq 'node.val') { @@ -227,8 +234,14 @@ sub displayDeletedOrigChildren { next; } - #need separate check here my $path = join(' ',( @cur_path, $child, $cname )); + + my $comment = $config->returnComment($path); + if (defined $comment) { + print "$prefix /* $comment */\n"; + } + + #need separate check here my ($state, $n) = $config->getDeactivated($path); if (defined $state) { $dis = '! '; @@ -288,6 +301,11 @@ sub displayChildren { if (!defined($is_tag)) { my $path = join(' ',( @cur_path, $child )); + my $comment = $config->returnComment($path); + if (defined $comment) { + print "$prefix /* $comment */\n"; + } + my ($state, $n) = $config->getDeactivated($path); if (defined $state) { $dis = '! '; @@ -325,6 +343,11 @@ sub displayChildren { } my $path = join(' ',( @cur_path, $child, $cname )); + my $comment = $config->returnComment($path); + if (defined $comment) { + print "$prefix /* $comment */\n"; + } + my ($state, $n) = $config->getDeactivated($path); if (defined $state) { $dis = '! '; @@ -388,6 +411,7 @@ sub outputNewConfig { $config = new Vyatta::Config; $config->setLevel(join ' ', @_); my %rnodes = $config->listNodeStatus(undef,'true'); + if (scalar(keys %rnodes) > 0) { my @rn = keys %rnodes; |