summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-04-23 20:30:35 +0200
committerGitHub <noreply@github.com>2021-04-23 20:30:35 +0200
commita86d0a713b1707d7beb0fe359bbfc71f4a9e2eed (patch)
tree5269b329430058e52b9de6dd3d156177f4e190c1
parentd437f023b7807a67439689ca33f96dce805497cc (diff)
parentb12811b7708ea5250590494001cda377fa6a3fbf (diff)
downloadvyatta-config-mgmt-a86d0a713b1707d7beb0fe359bbfc71f4a9e2eed.tar.gz
vyatta-config-mgmt-a86d0a713b1707d7beb0fe359bbfc71f4a9e2eed.zip
Merge pull request #5 from erkin/current
T3439: Migrate commit-confirm-notify.py to main repo
-rw-r--r--Makefile.am1
-rwxr-xr-xscripts/commit-confirm-notify.py30
-rwxr-xr-xscripts/vyatta-commit-push.pl49
-rwxr-xr-xscripts/vyatta-config-mgmt.pl2
4 files changed, 13 insertions, 69 deletions
diff --git a/Makefile.am b/Makefile.am
index 373865b..a753c21 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,7 +9,6 @@ curver_DATA = cfg-version/config-management@1
sbin_SCRIPTS = scripts/vyatta-commit-push.pl
sbin_SCRIPTS += scripts/vyatta-commit-revs.pl
sbin_SCRIPTS += scripts/vyatta-config-mgmt.pl
-sbin_SCRIPTS += scripts/commit-confirm-notify.py
bin_sudo_users_SCRIPTS =
diff --git a/scripts/commit-confirm-notify.py b/scripts/commit-confirm-notify.py
deleted file mode 100755
index eb7859f..0000000
--- a/scripts/commit-confirm-notify.py
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/env python3
-import os
-import sys
-import time
-
-# Minutes before reboot to trigger notification.
-intervals = [1, 5, 15, 60]
-
-def notify(interval):
- s = "" if interval == 1 else "s"
- time.sleep((minutes - interval) * 60)
- message = ('"[commit-confirm] System is going to reboot in '
- f'{interval} minute{s} to rollback the last commit.\n'
- 'Confirm your changes to cancel the reboot."')
- os.system("wall -n " + message)
-
-if __name__ == "__main__":
- # Must be run as root to call wall(1) without a banner.
- if len(sys.argv) != 2 or os.getuid() != 0:
- exit(1)
- minutes = int(sys.argv[1])
- # Drop the argument from the list so that the notification
- # doesn't kick in immediately.
- if minutes in intervals:
- intervals.remove(minutes)
- for interval in sorted(intervals, reverse=True):
- if minutes >= interval:
- notify(interval)
- minutes -= (minutes - interval)
- exit(0)
diff --git a/scripts/vyatta-commit-push.pl b/scripts/vyatta-commit-push.pl
index 2a1f495..bd8efc0 100755
--- a/scripts/vyatta-commit-push.pl
+++ b/scripts/vyatta-commit-push.pl
@@ -68,11 +68,17 @@ my $hostname = hostname();
$hostname = 'vyos' if ! defined $hostname;
my $save_file = "config.boot-$hostname" . $timestamp;
-my $source_addr = $config->returnEffectiveValue('source-address');
-my $src_opt = "";
-if( defined($source_addr) ) {
- $src_opt = "--interface $source_addr";
- print("Using source address $source_addr\n");
+# Was a source address specified?
+my $source_address = $config->returnEffectiveValue('source-address');
+# If so, we're going to pass that to the Python funcall.
+if (defined($source_address)) {
+ print("Using source address $source_address\n");
+ # The string needs to be wrapped in quotes.
+ $source_address = '"' . $source_address . '"';
+}
+# Otherwise, we're going to pass None.
+else {
+ $source_address = "None";
}
print "Archiving config...\n";
@@ -91,38 +97,7 @@ foreach my $uri (@uris) {
$remote .= "$path" if defined $path;
print " $remote ";
- my $rc = 0;
- if ($scheme =~ /^(scp|sftp)$/ ){
- $cmd = "curl -g -s -S -T $tmp_push_file $uri/$save_file";
- $rc = system($cmd);
- if( $rc >> 8 == 51 ){
- my $rsa_key = `ssh-keyscan -t rsa $host 2>/dev/null`;
- print "The authenticity of host '$host' can't be established.\n";
- my $fingerprint = `ssh-keygen -lf /dev/stdin <<< \"$rsa_key\" | awk {' print \$2 '}`;
- chomp $fingerprint;
- print "RSA key fingerprint is $fingerprint.\n";
- if (prompt("Are you sure you want to continue connecting (yes/no) [Yes]? ", -tynd=>"y")) {
- mkdir "$ENV{HOME}/.ssh/",0700 unless -d "$ENV{HOME}/.ssh";
- open(my $known_hosts, ">>", "$ENV{HOME}/.ssh/known_hosts")
- or die "Cannot open known_hosts: $!";
- print $known_hosts "$rsa_key\n";
- close($known_hosts);
- $cmd = "curl $src_opt -g -s -S -T $tmp_push_file $uri/$save_file";
- $rc = system($cmd);
- print "\n";
- }
- }
- } else {
- $cmd = "curl $src_opt -s -T $tmp_push_file $uri/$save_file";
- $rc = system($cmd);
- }
-
- print "cmd [$cmd]\n" if $debug;
- if ($rc eq 0) {
- print " OK\n";
- } else {
- print " Failed!\n";
- }
+ system("python3 -c 'from vyos.remote import upload; upload(\"$tmp_push_file\", \"$uri/$save_file\", source=$source_address)'");
}
move($tmp_push_file, $last_push_file);
diff --git a/scripts/vyatta-config-mgmt.pl b/scripts/vyatta-config-mgmt.pl
index 0a8528c..c940edb 100755
--- a/scripts/vyatta-config-mgmt.pl
+++ b/scripts/vyatta-config-mgmt.pl
@@ -386,7 +386,7 @@ if ($action eq 'commit-confirm') {
print "Reboot scheduled for commit-confirm. "
. "Confirm your changes to cancel the reboot.\n";
# Call the script to notify the users of the impending reboot.
- system("sudo -b /opt/vyatta/sbin/commit-confirm-notify.py ${minutes}");
+ system("sudo -b /usr/libexec/vyos/commit-confirm-notify.py ${minutes}");
exit 0;
}