URL: https://github.com/freeipa/freeipa/pull/3030
Author: Tiboris
 Title: #3030: [Backport][ipa-4-7] Support interactive prompt for ntp options
Action: opened

PR body:
"""
This PR is a manual backport of https://github.com/freeipa/freeipa/pull/2464 
please wait for CI before pushing.
In case of questions or problems contact @Tiboris who is author of the original 
PR.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/3030/head:pr3030
git checkout pr3030
From 7846f2a8a252c72333eb7a1130ca983dab282e23 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tibor=20Dudl=C3=A1k?= <tdud...@redhat.com>
Date: Wed, 17 Oct 2018 16:45:12 +0200
Subject: [PATCH] Support interactive prompt for ntp options

As the FreeIPA server is no longer a NTP service
providing instance its clients and replicas
configuration of time service can not be handled
as it was before change to chrony. Configuration
using master FQDN or autodiscovery for DNS record
would make no difference because every FreeIPA
instance is only chrony client now and does not
update DNS _ntp._udp record.

FreeIPA now asks user for NTP source server
or pool address in interactive mode if there is
no server nor pool specified and autodiscovery
has not found any NTP source in DNS records.

Resolves: https://pagure.io/freeipa/issue/7747
Reviewed-By: Christian Heimes <chei...@redhat.com>
Reviewed-By: Rob Crittenden <rcrit...@redhat.com>
---
 ipaclient/install/client.py   | 17 ++++++++++-------
 ipaclient/install/timeconf.py | 31 +++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/ipaclient/install/client.py b/ipaclient/install/client.py
index 6125588802..a4aa39be5b 100644
--- a/ipaclient/install/client.py
+++ b/ipaclient/install/client.py
@@ -2472,18 +2472,21 @@ def sync_time(options, fstore, statestore):
     # disable other time&date services first
     timeconf.force_chrony(statestore)
 
-    logger.info('Synchronizing time')
-
-    if not options.ntp_servers:
+    if not options.ntp_servers and not options.ntp_pool:
         ds = ipadiscovery.IPADiscovery()
         ntp_servers = ds.ipadns_search_srv(cli_domain, '_ntp._udp',
                                            None, break_on_first=False)
-    else:
-        ntp_servers = options.ntp_servers
+        if not ntp_servers and not options.unattended:
+            options.ntp_servers, options.ntp_pool = timeconf.get_time_source()
+        else:
+            options.ntp_servers = ntp_servers
+
+    logger.info('Synchronizing time')
 
     configured = False
-    if ntp_servers or options.ntp_pool:
-        configured = timeconf.configure_chrony(ntp_servers, options.ntp_pool,
+    if options.ntp_servers or options.ntp_pool:
+        configured = timeconf.configure_chrony(options.ntp_servers,
+                                               options.ntp_pool,
                                                fstore, statestore)
     else:
         logger.warning("No SRV records of NTP servers found and no NTP server "
diff --git a/ipaclient/install/timeconf.py b/ipaclient/install/timeconf.py
index 57ab50a3f5..4afe5b32c9 100644
--- a/ipaclient/install/timeconf.py
+++ b/ipaclient/install/timeconf.py
@@ -28,6 +28,7 @@
 from ipaplatform.tasks import tasks
 from ipaplatform import services
 from ipaplatform.paths import paths
+from ipapython.ipautil import user_input
 
 logger = logging.getLogger(__name__)
 
@@ -39,6 +40,36 @@ def __backup_config(path, fstore=None):
         shutil.copy(path, "%s.ipasave" % (path))
 
 
+def get_time_source():
+    """
+    While in interactive installation user has to specify NTP server or pool
+    to be used in chrony configuration. This method asks user input on these
+    values in case that they were not specified before installation start.
+    """
+    ntp_servers = []
+    ntp_pool = ""
+
+    if ipautil.user_input("Do you want to configure chrony "
+                          "with NTP server or pool address?", False):
+        servers = user_input("Enter NTP source server addresses separated by "
+                             "comma, or press Enter to skip", allow_empty=True)
+        if servers:  # if user input is not '' (empty)
+            logger.debug("User provided NTP server(s):")
+            # cut possible multiple servers separated by comma into list
+            for server in servers.split(","):
+                # users tend to separate servers by ", " so strip() whitespaces
+                server = server.strip()
+                ntp_servers.append(server)
+                logger.debug("\t%s", server)
+
+        ntp_pool = user_input("Enter a NTP source pool address, "
+                              "or press Enter to skip", allow_empty=True)
+        if ntp_pool:  # if user input is not '' (empty)
+            logger.debug("User provided NTP pool:\n\t%s", ntp_pool)
+
+    return ntp_servers, ntp_pool
+
+
 def sync_chrony():
     """
     This method enables chronyd service on boot and restarts it to reload
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org

Reply via email to