diff options
author | Alex Harpin <development@landsofshadow.co.uk> | 2015-02-28 10:32:29 +0000 |
---|---|---|
committer | Alex Harpin <development@landsofshadow.co.uk> | 2015-02-28 10:32:29 +0000 |
commit | 93afdd6e8d13450e5229ccb22474bdea86bf3d1d (patch) | |
tree | 527e0cc2296280090746ed460e7180ac4b10f069 /scripts/system/vyatta_update_ntp.pl | |
parent | 3cb22d19f5edf6e2968c54b8fe3cfc5c13f0bf67 (diff) | |
download | vyatta-cfg-system-93afdd6e8d13450e5229ccb22474bdea86bf3d1d.tar.gz vyatta-cfg-system-93afdd6e8d13450e5229ccb22474bdea86bf3d1d.zip |
vyatta-cfg-system: update new ntp updating routine to work with dhcp
Update the new NTP updating routines so they operate outside of
configuration mode (dhcp triggered updates). This also requires
changes to the vyatta-dhcp3 package (see Bug #500)
Bug #94 http://bugzilla.vyos.net/show_bug.cgi?id=94
Diffstat (limited to 'scripts/system/vyatta_update_ntp.pl')
-rwxr-xr-x | scripts/system/vyatta_update_ntp.pl | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/scripts/system/vyatta_update_ntp.pl b/scripts/system/vyatta_update_ntp.pl index 2f9b29f1..f32a9407 100755 --- a/scripts/system/vyatta_update_ntp.pl +++ b/scripts/system/vyatta_update_ntp.pl @@ -22,8 +22,12 @@ use strict; use lib "/opt/vyatta/share/perl5"; use Vyatta::Config; use NetAddr::IP; +use Getopt::Long; -die "$0 expects no arguments\n" if (@ARGV); +my $dhclient_script = 0; + +GetOptions("dhclient-script=i" => \$dhclient_script, +); sub ntp_format { my ($cidr_or_host) = @_; @@ -72,22 +76,36 @@ foreach my $line (@ntp) { } } -if ($cfg->exists("server")) { +my @servers; +my @clients; + +if ($dhclient_script == 1) { + @servers = $cfg->listOrigNodes("server"); + @clients = $cfg->returnOrigValues("client address"); +} else { + @servers = $cfg->listNodes("server"); + @clients = $cfg->returnValues("client address"); +} + +if (scalar(@servers) > 0) { print $output "# Servers\n\n"; - foreach my $server ($cfg->listNodes("server")) { + foreach my $server (@servers) { my $server_addr = ntp_format($server); print $output "server $server_addr iburst"; for my $property (qw(dynamic noselect preempt prefer)) { - print $output " $property" if ($cfg->exists("server $server $property")); + if ($dhclient_script == 1) { + print $output " $property" if ($cfg->existsOrig("server $server $property")); + } else { + print $output " $property" if ($cfg->exists("server $server $property")); + } } print $output "\nrestrict $server_addr nomodify notrap nopeer noquery\n"; } print $output "\n"; } -if ($cfg->exists("client")) { +if (scalar(@clients) > 0) { print $output "# Clients\n\n"; - my @clients = $cfg->returnValues("client address"); foreach my $client (@clients) { my $address = ntp_format($client); print $output "restrict $address nomodify notrap nopeer\n"; |