diff options
author | Michael Larson <slioch@slioch.vyatta.com> | 2010-05-14 13:47:21 -0700 |
---|---|---|
committer | Michael Larson <slioch@slioch.vyatta.com> | 2010-05-14 13:47:21 -0700 |
commit | d36d0a6ea76d443c5e4072401eaa9dbf563c74bd (patch) | |
tree | 9daed3e19d3d5b8231a9894891ac00d4df9b9c3a /lib | |
parent | 91bb77e328c9cad994609aeeccb33971eca1486f (diff) | |
download | vyatta-cfg-d36d0a6ea76d443c5e4072401eaa9dbf563c74bd.tar.gz vyatta-cfg-d36d0a6ea76d443c5e4072401eaa9dbf563c74bd.zip |
initial checkin of comment feature for cli.
/* to create a comment */
> comment [PATH-TO-NODE] "my comments"
/* to delete a comment */
> comment [PATH-TO-NODE] ""
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Vyatta/Config.pm | 21 | ||||
-rwxr-xr-x | lib/Vyatta/ConfigLoad.pm | 41 | ||||
-rwxr-xr-x | lib/Vyatta/ConfigOutput.pm | 26 |
3 files changed, 81 insertions, 7 deletions
diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm index 82d835f..c0c8494 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 diff --git a/lib/Vyatta/ConfigLoad.pm b/lib/Vyatta/ConfigLoad.pm index 28e932e..5bad31d 100755 --- a/lib/Vyatta/ConfigLoad.pm +++ b/lib/Vyatta/ConfigLoad.pm @@ -58,6 +58,8 @@ sub applySingleQuote { return @return; } +my @comment_list = (); + sub enumerate_branch { my $cur_node = shift; my @cur_path = @_; @@ -72,14 +74,28 @@ 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 ($terminal) { my $val = $cur_node->{'value'}; @@ -111,6 +127,8 @@ sub getStartupConfigStatements { if (!defined($load_cfg)) { return (); } + + my $comments = shift; my $xcp = new XorpConfigParser(); $xcp->parse($load_cfg); @@ -120,6 +138,15 @@ sub getStartupConfigStatements { } enumerate_branch($root, ( )); + 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]; + } + } + } return @all_nodes; } @@ -354,6 +381,7 @@ sub findSetNodes { my @tmp = @plist[1..$#plist]; push @disable_list, [\@tmp, 0]; } + findSetNodes($new_ref->{$_}, [ @active_path, $_ ]); } # we recur regardless of whether it's in active. all changes will be @@ -392,6 +420,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; |