URL: https://github.com/freeipa/freeipa/pull/2464
Author: Tiboris
 Title: #2464: Support interactive prompt for ntp options
Action: opened

PR body:
"""
FreeIPA will now ask 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.
"""

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

FreeIPA will now ask 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.
---
 ipaclient/install/client.py   | 13 ++++++++-----
 ipaclient/install/timeconf.py | 24 ++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/ipaclient/install/client.py b/ipaclient/install/client.py
index 2f47cbf295..3f08d01c33 100644
--- a/ipaclient/install/client.py
+++ b/ipaclient/install/client.py
@@ -2437,16 +2437,19 @@ def sync_time(options, fstore, 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:
+            timeconf.get_time_source(options)
+        else:
+            options.ntp_servers = ntp_servers
 
     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..2f5c0d12bb 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,29 @@ def __backup_config(path, fstore=None):
         shutil.copy(path, "%s.ipasave" % (path))
 
 
+def get_time_source(options):
+    """
+    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_src = ipautil.user_input("Do you want to configure chrony "
+                                 "with NTP [s]erver or [p]ool "
+                                 "address?", 's', allow_empty=False)
+    if ntp_src is 's':  # constants?
+        options.ntp_servers = user_input("NTP source server addresses",
+                                         allow_empty=False)
+        logger.debug("User provided NTP server(s): %s",
+                     options.ntp_servers)  # TODO handle multiple servers ?
+    elif ntp_src is 'p':  # constants?
+        options.ntp_pool = user_input("NTP source pool address",
+                                      allow_empty=False)
+        logger.debug("User provided NTP pool: %s",
+                     options.ntp_pool)
+    else:
+        raise RuntimeError("Failed to get user input")
+
+
 def sync_chrony():
     """
     This method enables chronyd service on boot and restarts it to reload
_______________________________________________
FreeIPA-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
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/[email protected]

Reply via email to