ipa client: make --ntp-server option multivalued

There can be more ntp servers in ntp.conf

Required for ticket: https://fedorahosted.org/freeipa/ticket/4981

Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
This commit is contained in:
Martin Basti 2015-04-14 18:56:47 +02:00 committed by Petr Vobornik
parent 9bd181b33d
commit e395bdb911
3 changed files with 18 additions and 14 deletions

View File

@ -127,7 +127,9 @@ def parse_options():
basic_group.add_option("", "--force-join", dest="force_join",
action="store_true", default=False,
help="Force client enrollment even if already enrolled")
basic_group.add_option("--ntp-server", dest="ntp_server", help="ntp server to use")
basic_group.add_option("--ntp-server", dest="ntp_servers", action="append",
help="ntp server to use. This option can be used "
"multiple times")
basic_group.add_option("-N", "--no-ntp", action="store_false",
help="do not configure ntp", default=True, dest="conf_ntp")
basic_group.add_option("", "--force-ntpd", dest="force_ntpd",
@ -2344,10 +2346,11 @@ def install(options, env, fstore, statestore):
# We assume that NTP servers are discoverable through SRV records in the DNS
# If that fails, we try to sync directly with IPA server, assuming it runs NTP
root_logger.info('Synchronizing time with KDC...')
ntp_servers = ds.ipadns_search_srv(cli_domain, '_ntp._udp', None, break_on_first=False)
ntp_srv_servers = ds.ipadns_search_srv(cli_domain, '_ntp._udp',
None, break_on_first=False)
synced_ntp = False
if ntp_servers:
for s in ntp_servers:
if ntp_srv_servers:
for s in ntp_srv_servers:
synced_ntp = ipaclient.ntpconf.synconce_ntp(s)
if synced_ntp:
break
@ -2849,11 +2852,11 @@ def install(options, env, fstore, statestore):
# disable other time&date services first
if options.force_ntpd:
ipaclient.ntpconf.force_ntpd(statestore)
if options.ntp_server:
ntp_server = options.ntp_server
if options.ntp_servers:
ntp_servers = options.ntp_servers
else:
ntp_server = cli_server[0]
ipaclient.ntpconf.config_ntp(ntp_server, fstore, statestore)
ntp_servers = cli_server
ipaclient.ntpconf.config_ntp(ntp_servers, fstore, statestore)
root_logger.info("NTP enabled")
if options.conf_ssh:

View File

@ -41,7 +41,7 @@ restrict -6 ::1
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server $SERVER
$SERVERS_BLOCK
#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
@ -84,7 +84,7 @@ SYNC_HWCLOCK=yes
NTPDATE_OPTIONS=""
"""
ntp_step_tickers = """# Use IPA-provided NTP server for initial time
$SERVER
$TICKER_SERVERS_BLOCK
"""
def __backup_config(path, fstore = None):
if fstore:
@ -97,12 +97,13 @@ def __write_config(path, content):
fd.write(content)
fd.close()
def config_ntp(server_fqdn, fstore = None, sysstore = None):
def config_ntp(ntp_servers, fstore = None, sysstore = None):
path_step_tickers = paths.NTP_STEP_TICKERS
path_ntp_conf = paths.NTP_CONF
path_ntp_sysconfig = paths.SYSCONFIG_NTPD
sub_dict = { }
sub_dict["SERVER"] = server_fqdn
sub_dict = {}
sub_dict["SERVERS_BLOCK"] = "\n".join("server %s" % s for s in ntp_servers)
sub_dict["TICKER_SERVERS_BLOCK"] = "\n".join(ntp_servers)
nc = ipautil.template_str(ntp_conf, sub_dict)
config_step_tickers = False

View File

@ -117,7 +117,7 @@ The hostname of this machine (FQDN). If specified, the hostname will be set and
Join the host even if it is already enrolled.
.TP
\fB\-\-ntp\-server\fR=\fINTP_SERVER\fR
Configure ntpd to use this NTP server.
Configure ntpd to use this NTP server. This option can be used multiple times.
.TP
\fB\-N\fR, \fB\-\-no\-ntp\fR
Do not configure or enable NTP.