diff options
author | Stig Thormodsrud <stig@vyatta.com> | 2010-11-05 17:56:37 -0700 |
---|---|---|
committer | Stig Thormodsrud <stig@vyatta.com> | 2010-11-05 17:56:37 -0700 |
commit | 266ae832374d6231a0a662776c30ec597c6925aa (patch) | |
tree | 9b46ef4260cb4319eb13b21fdf56ca5af4c1fd7b | |
parent | a60321f3b38c93b200ff2705eebd4d274cda895d (diff) | |
download | vyatta-config-mgmt-266ae832374d6231a0a662776c30ec597c6925aa.tar.gz vyatta-config-mgmt-266ae832374d6231a0a662776c30ec597c6925aa.zip |
Fixes for config-mgmt.
- fix permission problems
- remove link on disable of commit-revisions.
- don't push if file hasn't changed or on boot
- save a baseline config when 1st starting the feature.
-rw-r--r-- | lib/Vyatta/ConfigMgmt.pm | 8 | ||||
-rwxr-xr-x | scripts/vyatta-commit-push.pl | 18 | ||||
-rwxr-xr-x | scripts/vyatta-commit-revs.pl | 8 | ||||
-rwxr-xr-x | scripts/vyatta-config-mgmt.pl | 6 | ||||
-rw-r--r-- | templates-cfg/system/config-mgmt/commit-revisions/node.def | 5 |
5 files changed, 38 insertions, 7 deletions
diff --git a/lib/Vyatta/ConfigMgmt.pm b/lib/Vyatta/ConfigMgmt.pm index a23b82b..1120fa4 100644 --- a/lib/Vyatta/ConfigMgmt.pm +++ b/lib/Vyatta/ConfigMgmt.pm @@ -30,7 +30,8 @@ our @EXPORT = qw(cm_commit_add_log cm_commit_get_log cm_get_archive_dir cm_get_lr_conf_file cm_get_lr_state_file cm_get_commit_hook_dir cm_write_file cm_read_file cm_commit_get_file cm_commit_get_file_name - cm_get_num_revs cm_get_last_commit_file); + cm_get_num_revs cm_get_last_commit_file + cm_get_last_push_file); use base qw(Exporter); use Vyatta::Config; @@ -48,6 +49,7 @@ my $lr_conf_file = "$archive_dir/lr.conf"; my $lr_state_file = "$archive_dir/lr.state"; my $commit_log_file = "$archive_dir/commits"; my $last_commit_file = "$archive_dir/config.boot"; +my $last_push_file = "$archive_dir/config.boot-push"; sub cm_get_commit_hook_dir { @@ -70,6 +72,10 @@ sub cm_get_last_commit_file { return $last_commit_file; } +sub cm_get_last_push_file { + return $last_push_file; +} + sub cm_read_file { my ($file) = @_; my @lines; diff --git a/scripts/vyatta-commit-push.pl b/scripts/vyatta-commit-push.pl index da6c29e..c375f27 100755 --- a/scripts/vyatta-commit-push.pl +++ b/scripts/vyatta-commit-push.pl @@ -33,8 +33,11 @@ use warnings; use lib '/opt/vyatta/share/perl5/'; use Vyatta::Config; +use Vyatta::ConfigMgmt; use POSIX; use File::Basename; +use File::Compare; +use File::Copy; use URI; use WWW::Curl::Easy; @@ -50,10 +53,18 @@ if (scalar(@uris) < 1) { exit 0; } -my $upload_file = '/opt/vyatta/etc/config/config.boot'; +my $last_push_file = cm_get_last_push_file(); +my $tmp_push_file = "/tmp/config.boot-push.$$"; + +my $cmd = 'cli-shell-api showCfg --show-active-only'; +system("$cmd > $tmp_push_file"); + +if (-e $last_push_file and compare($last_push_file, $tmp_push_file) == 0) { + exit 0; +} my $timestamp = strftime("_%Y%m%d_%H%M%S", localtime); -my $save_file = basename($upload_file) . $timestamp; +my $save_file = basename($tmp_push_file) . $timestamp; print "Archiving config...\n"; foreach my $uri (@uris) { @@ -70,7 +81,7 @@ foreach my $uri (@uris) { $remote .= "$scheme://$host"; $remote .= "$path" if defined $path; print " $remote "; - open(my $FILE, '<', $upload_file) or die "Error: read $!"; + open(my $FILE, '<', $tmp_push_file) or die "Error: read $!"; my $curl = new WWW::Curl::Easy; $curl->setopt(CURLOPT_NOPROGRESS, 1); $curl->setopt(CURLOPT_URL, "$uri/$save_file"); @@ -84,5 +95,6 @@ foreach my $uri (@uris) { print "Failed: " . $curl->strerror($retcode) . "\n"; } } +move($tmp_push_file, $last_push_file); exit 0; diff --git a/scripts/vyatta-commit-revs.pl b/scripts/vyatta-commit-revs.pl index edf0845..7749a52 100755 --- a/scripts/vyatta-commit-revs.pl +++ b/scripts/vyatta-commit-revs.pl @@ -35,6 +35,7 @@ use lib '/opt/vyatta/share/perl5/'; use Vyatta::Config; use Vyatta::ConfigMgmt; use File::Compare; +use File::Copy; # # main @@ -48,13 +49,14 @@ my $tmp_config_file = "/tmp/config.boot.$$"; if (! -d $archive_dir) { system("sudo mkdir $archive_dir"); + system("sudo chown vyatta:vyattacfg $archive_dir"); } - -system("/opt/vyatta/sbin/vyatta-save-config.pl $tmp_config_file > /dev/null"); +my $cmd = 'cli-shell-api showCfg --show-active-only'; +system("$cmd > $tmp_config_file"); if (compare($tmp_config_file, $last_commit_file) == 0) { exit 0; } -system("sudo mv $tmp_config_file $archive_dir/config.boot"); +move($tmp_config_file, "$archive_dir/config.boot"); system("sudo logrotate -f -s $lr_state_file $lr_conf_file"); my ($user) = getpwuid($<); cm_commit_add_log($user, 'cli', $ARGV[0]); diff --git a/scripts/vyatta-config-mgmt.pl b/scripts/vyatta-config-mgmt.pl index 94b9b57..d9e5052 100755 --- a/scripts/vyatta-config-mgmt.pl +++ b/scripts/vyatta-config-mgmt.pl @@ -151,6 +151,12 @@ if ($action eq 'update-revs') { $lr_conf .= "\t copy \n"; $lr_conf .= "}\n"; cm_write_file($lr_conf_file, $lr_conf); + my $num_revs = cm_get_num_revs(); + if ($num_revs == 0) { + # store a baseline config + system("$commit_revs_script baseline config.boot"); + system("sudo chown vyatta:vyattacfg $archive_dir/*"); + } exit 0; } exit 0; diff --git a/templates-cfg/system/config-mgmt/commit-revisions/node.def b/templates-cfg/system/config-mgmt/commit-revisions/node.def index e5da66a..854bb1e 100644 --- a/templates-cfg/system/config-mgmt/commit-revisions/node.def +++ b/templates-cfg/system/config-mgmt/commit-revisions/node.def @@ -6,6 +6,11 @@ update: sudo ${vyatta_sbindir}/vyatta-config-mgmt.pl \ --action=update-revs \ --revs="$VAR(@)" +delete: sudo ${vyatta_sbindir}/vyatta-config-mgmt.pl \ + --action=update-revs \ + --revs="0" + + val_help: u32:0-65535 ; Number of config backups to keep syntax:expression: $VAR(@) >= 0 && $VAR(@) <= 65535 ; \ |