diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/vyatta-cfg-cmd-wrapper | 4 | ||||
-rw-r--r-- | scripts/vyatta-comment-config.pl | 92 | ||||
-rwxr-xr-x | scripts/vyatta-config-loader.pl | 28 | ||||
-rwxr-xr-x | scripts/vyatta-load-config.pl | 37 |
4 files changed, 160 insertions, 1 deletions
diff --git a/scripts/vyatta-cfg-cmd-wrapper b/scripts/vyatta-cfg-cmd-wrapper index 3b2f040..4941e37 100755 --- a/scripts/vyatta-cfg-cmd-wrapper +++ b/scripts/vyatta-cfg-cmd-wrapper @@ -220,6 +220,10 @@ case "$1" in /opt/vyatta/sbin/vyatta-activate-config.pl activate "${@:2}" RET_STATUS=$? ;; + comment) + /opt/vyatta/sbin/vyatta-comment-config.pl "${@:2}" + RET_STATUS=$? + ;; commit) # debug file /tmp/bar should be deleted before release /opt/vyatta/sbin/my_commit -a >> /tmp/bar diff --git a/scripts/vyatta-comment-config.pl b/scripts/vyatta-comment-config.pl new file mode 100644 index 0000000..d19268e --- /dev/null +++ b/scripts/vyatta-comment-config.pl @@ -0,0 +1,92 @@ +#!/usr/bin/perl + +# Author: Michael Larson <mike@vyatta.com> +# Date: 2010 +# Description: Perl script for adding comments to portions of the configuration + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2006, 2007, 2008, 2009, 2010 Vyatta, Inc. +# All Rights Reserved. +# **** End License **** + +use strict; +use warnings; +use File::Find; +use lib "/opt/vyatta/share/perl5"; + + +sub usage() { + print "Usage: $0 <path>\n"; + exit 0; +} + +if ($#ARGV == 0) { + exit 0; +} + +#adjust for leaf node +my $i = 0; +my @path = @ARGV[0..$#ARGV-1]; +foreach my $elem (@path) { + $elem =~ s/\//%2F/g; + $elem =~ s/\s+/\//g; + $path[$i++] = $elem; +} +my $path = join '/', @path; + +my $full_path = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path"; + +if (! -e $full_path) { + $path = join '/', @path[0..$#path-1]; + my $leaf = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path/node.val"; + if (-e $leaf) { + $full_path = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path"; + } + else { + `echo \"Path is not valid\n\"`; + exit 0; + } +} +#else { +# print "echo \"$ARGV[$#ARGV]\" > $full_path/node.comment\n"; +# `echo \"$ARGV[$#ARGV]\" > $full_path/node.comment`; +#} + +if ($ARGV[$#ARGV] eq '') { + `rm -f $full_path/.comment`; +} +else { + `echo \"$ARGV[$#ARGV]\" > $full_path/.comment`; +} + +#first let's check and ensure that there is not another child .disable node... +#also needs to be enforced when committing +#my $active_dir = "$ENV{VYATTA_ACTIVE_CONFIGURATION_DIR}/$path"; +#my $local_dir = $full_path; +#if (-e $active_dir) { +# find( \&wanted, $active_dir ); +#} +#if (-e $local_dir) { +# find( \&wanted, $local_dir ); +#} +#`touch $full_path/node.comment`; + +#if this is activate +# make sure no activate subnodes +# create .disable file in node +#else +# ensure .disable file exists +# remove node + +print "Done\n"; +exit 0; diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl index 7a3df2b..b8e594e 100755 --- a/scripts/vyatta-config-loader.pl +++ b/scripts/vyatta-config-loader.pl @@ -46,7 +46,7 @@ sub restore_fds { } # get a list of all config statement in the startup config file -my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0]); +my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0],'true'); if (scalar(@all_nodes) == 0) { # no config statements restore_fds(); @@ -72,6 +72,32 @@ foreach (@all_nodes) { my ($path_ref, $rank) = @$_; my @pr = @$path_ref; + if (@pr[0] =~ /^comment$/) { + my $ct = 0; + my $rel_path; + foreach my $rp (@pr[1..$#pr]) { + $ct++; + my $tmp_path = $rel_path . "/" . $rp; + my $node_path = "/opt/vyatta/share/vyatta-cfg/templates/" . $tmp_path . "/node.def"; + if ($rp eq '"') { + last; + } + elsif ($rp eq '""') { + last; + } + elsif (!-e $node_path) { + #pop this element + delete @pr[$ct]; + last; + } + $rel_path = $tmp_path; + } + + my $comment_cmd = "$CWRAPPER " . join(" ",@pr) ; + `$comment_cmd`; + next; + } + if (@pr[0] eq '!') { @pr = @pr[1..$#pr]; my $deactivate_cmd = "$CWRAPPER deactivate " . (join ' ', @pr) . " 1>/dev/null"; diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index ab5a47e..62d6e8b 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -191,6 +191,7 @@ if ( scalar( keys %cfg_hier ) == 0 ) { my %cfg_diff = Vyatta::ConfigLoad::getConfigDiff( \%cfg_hier ); my @set_list = @{ $cfg_diff{'set'} }; my @deactivate_list = @{ $cfg_diff{'deactivate'} }; +my @comment_list = @{ $cfg_diff{'comment'} }; if ($merge_mode eq 'false') { my @delete_list = @{ $cfg_diff{'delete'} }; @@ -226,6 +227,42 @@ foreach (@deactivate_list) { #ignore error on complaint re: nested nodes } +foreach (@comment_list) { + my ( $cmd_ref ) = $_; + #apply comment if it doesn't have an empty element at the array and a .comment file exists and this is not a merge + if ($merge_mode eq 'false' && $cmd_ref =~ /\"\"$/) { + my @cmd_array = split(" ",$cmd_ref); + pop(@cmd_array); + my $rel_path = join '/', @cmd_array; + my $path = "/opt/vyatta/config/active/" . $rel_path . "/.comment"; + if (-e $path) { + my @cmd = ( "$sbindir/vyatta-comment-config.pl ", $cmd_ref ); + my $cmd_str = join ' ', @cmd; + system("$cmd_str 1>/dev/null"); + } + else { + #not found, maybe a leaf? + pop(@cmd_array); + $rel_path = join '/', @cmd_array; + my $leaf = "/opt/vyatta/config/active/" . $rel_path . "/node.val"; + if (-e $leaf) { + $path = "/opt/vyatta/config/active/" . $rel_path . "/.comment"; + if (-e $path) { + my @cmd = ( "$sbindir/vyatta-comment-config.pl ", $cmd_ref ); + my $cmd_str = join ' ', @cmd; + system("$cmd_str 1>/dev/null"); + } + } + } + } + else { + my @cmd = ( "$sbindir/vyatta-comment-config.pl ", $cmd_ref ); + my $cmd_str = join ' ', @cmd; + system("$cmd_str 1>/dev/null"); + } + #ignore error on complaint re: nested nodes +} + system("$sbindir/my_commit"); if ( $? >> 8 ) { print "Load failed (commit failed)\n"; |