diff options
-rwxr-xr-x | lib/Vyatta/ConfigLoad.pm | 57 | ||||
-rw-r--r-- | scripts/vyatta-activate-config.pl | 78 | ||||
-rwxr-xr-x | scripts/vyatta-config-gen-sets.pl | 3 | ||||
-rwxr-xr-x | scripts/vyatta-config-loader.pl | 18 | ||||
-rwxr-xr-x | scripts/vyatta-load-config.pl | 7 |
5 files changed, 91 insertions, 72 deletions
diff --git a/lib/Vyatta/ConfigLoad.pm b/lib/Vyatta/ConfigLoad.pm index 5bad31d..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\$/; @@ -97,22 +100,19 @@ sub enumerate_branch { } } + + 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]; } } @@ -147,7 +147,11 @@ sub getStartupConfigStatements { } } } - return @all_nodes; + my %conf = ( + 'set' => \@all_nodes, + 'deactivate' => \@disable_list, + ); + return %conf; } my %node_order = (); @@ -248,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 @@ -305,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). @@ -353,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) { @@ -363,29 +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 @@ -396,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, [ ]); diff --git a/scripts/vyatta-activate-config.pl b/scripts/vyatta-activate-config.pl index 31165a4..3eca90f 100644 --- a/scripts/vyatta-activate-config.pl +++ b/scripts/vyatta-activate-config.pl @@ -27,15 +27,40 @@ use lib "/opt/vyatta/share/perl5"; sub wanted { return unless ( $_ eq '.disable' ); - print("Cannot set nested deactivated nodes\n"); + print("Cannot deactivate nested elements\n"); exit 1; } +sub check_parents { + my @p = @_; + my $l_dir = "$ENV{VYATTA_TEMP_CONFIG_DIR}/"; + my $a_dir = "$ENV{VYATTA_ACTIVE_CONFIGURATION_DIR}/"; + foreach my $sw (@p) { + $l_dir .= "/$sw"; + $a_dir .= "/$sw"; + + if (-e "$l_dir/.disable") { + return 1; + } + if (-e "$a_dir/.disable") { + return 1; + } + } + return 0; +} + sub usage() { print "Usage: $0 <path>\n"; exit 0; } +my $action = $ARGV[0]; + +if (!defined $ARGV[1] || $ARGV[1] eq '') { + print("Cannot activate/deactivate configuration root\n"); + exit 1; +} + #adjust for leaf node my $i = 0; my @path = @ARGV[1..$#ARGV]; @@ -53,7 +78,6 @@ if (! -e $full_path) { my $leaf = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path/node.val"; if (-e $leaf) { #prevent setting on leaf or multi, check for node.val -# $full_path = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path"; printf("Cannot activate/deactivate end node\n"); exit 1; } @@ -63,49 +87,53 @@ if (! -e $full_path) { } } +####################################################### +#now check for nesting of the activate/deactivate nodes +####################################################### +if ($action eq 'deactivate') { + my $active_dir = "$ENV{VYATTA_ACTIVE_CONFIGURATION_DIR}/$path"; + my $local_dir = $full_path; + if (-e $active_dir) { #checks active children + find( \&wanted, $active_dir ); + } + if (-e $local_dir) { #checks locally commit children + find( \&wanted, $local_dir ); + } + #final check that walks up tree and checks + if (check_parents(@path)) { #checks active and locally committed parents + print("Cannot deactivate nested elements\n"); + exit 1; + } +} -if ($ARGV[0] eq 'activate') { +####################################################### +#now apply the magic +####################################################### +if ($action eq 'activate') { $full_path .= "/.disable"; if (-e $full_path) { `rm -f $full_path`; } else { - printf("This element is not deactivated\n"); + printf("This element has not been deactivated\n"); exit 1; } } -elsif ($ARGV[0] eq 'deactivate') { +elsif ($action eq 'deactivate') { #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/.disable") { - printf("This node is already deactivated\n"); + if (-e "$active_dir/.disable" || -e "$local_dir/.disable") { + printf("This element has already been deactivated\n"); exit 1; } - elsif (-e $active_dir) { - find( \&wanted, $active_dir ); - } - if (-e $local_dir) { - find( \&wanted, $local_dir ); - } `touch $full_path/.disable`; } -elsif ($ARGV[0] eq 'complete') { - #provide match... - printf("complete\n"); -} else { - printf("incoming arg: " . $ARGV[0] . "\n"); + printf("bad argument: " . $action . "\n"); usage(); } -#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-gen-sets.pl b/scripts/vyatta-config-gen-sets.pl index e364dfa..7cf4feb 100755 --- a/scripts/vyatta-config-gen-sets.pl +++ b/scripts/vyatta-config-gen-sets.pl @@ -32,7 +32,8 @@ my $conf_file = '/opt/vyatta/etc/config/config.boot'; $conf_file = $ARGV[0] if defined $ARGV[0]; # get a list of all config statement in the startup config file -my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($conf_file); +my %cfg_hier = Vyatta::ConfigLoad::getStartupConfigStatements($conf_file); +my @all_nodes = @{ $cfg_hier{'set'} }; if (scalar(@all_nodes) == 0) { # no config statements exit 1; diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl index b8e594e..0aae55b 100755 --- a/scripts/vyatta-config-loader.pl +++ b/scripts/vyatta-config-loader.pl @@ -46,7 +46,9 @@ sub restore_fds { } # get a list of all config statement in the startup config file -my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0],'true'); +my %cfg_hier = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0],'true'); +my @all_nodes = @{ $cfg_hier{'set'} }; +my @deactivate_nodes = @{ $cfg_hier{'deactivate'} }; if (scalar(@all_nodes) == 0) { # no config statements restore_fds(); @@ -98,13 +100,6 @@ foreach (@all_nodes) { next; } - if (@pr[0] eq '!') { - @pr = @pr[1..$#pr]; - my $deactivate_cmd = "$CWRAPPER deactivate " . (join ' ', @pr) . " 1>/dev/null"; - system("$deactivate_cmd"); - #ignore these errors due to nesting warnings. - } - my $cmd = "$CWRAPPER set " . (join ' ', @pr); # this debug file should be deleted before release system("echo [$cmd] >> /tmp/foo"); @@ -116,6 +111,13 @@ foreach (@all_nodes) { # continue after set failure (or should we abort?) } } + +# Now deactivate these nodes +for (@deactivate_nodes) { + my $cmd = "$CWRAPPER deactivate " . $_ . " 1>/dev/null"; + system("$cmd"); +} + $ret = system("$commit_cmd"); if ($ret >> 8) { print OLDOUT "Commit failed at boot\n"; diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index 62d6e8b..296dc0d 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -220,10 +220,9 @@ foreach (@set_list) { } foreach (@deactivate_list) { - my ( $cmd_ref, $rank ) = @{$_}; - my @cmd = ( "$sbindir/vyatta-activate-config.pl deactivate", @{$cmd_ref} ); - my $cmd_str = join ' ', @cmd; - system("$cmd_str 1>/dev/null"); + #need to remove .disable nodes recursively in tree through activate command + my $cmd = "$sbindir/vyatta-activate-config.pl deactivate $_"; + system("$cmd 1>/dev/null"); #ignore error on complaint re: nested nodes } |