From: Miroslav Lichvar <mlichvar(a)redhat.com>
With chrony-2.0 it is possible to specify a pool of NTP servers instead
of individual servers. It selects four servers from the addresses that
the pool name is resolved to and replaces them automatically when they
are unreachable or falsetickers. This is now used in the default Fedora
chrony configuration.
To avoid extending the ntp API and the date time spoke, pools are simply
presented as four separate servers with the same name.
Resolves: rhbz#1193389
---
pyanaconda/ntp.py | 25 +++++++++++++++++++++----
pyanaconda/ui/gui/spokes/datetime_spoke.py | 5 -----
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/pyanaconda/ntp.py b/pyanaconda/ntp.py
index 40263ae..4f3c9d1 100644
--- a/pyanaconda/ntp.py
+++ b/pyanaconda/ntp.py
@@ -39,7 +39,10 @@
#example line:
#server
0.fedora.pool.ntp.org iburst
-SRV_LINE_REGEXP = re.compile(r"^\s*server\s*([-a-zA-Z.0-9]+)\s*[a-zA-Z]+\s*$")
+SRV_LINE_REGEXP =
re.compile(r"^\s*(server|pool)\s*([-a-zA-Z.0-9]+)\s*[a-zA-Z]+\s*$")
+
+#treat pools as four servers with the same name
+SERVERS_PER_POOL = 4
class NTPconfigError(Exception):
"""Exception class for NTP related problems"""
@@ -90,7 +93,10 @@ def get_servers_from_config(conf_file_path=NTP_CONFIG_FILE,
for line in conf_file:
match = srv_regexp.match(line)
if match:
- ret.append(match.group(1))
+ if match.group(1) == "pool":
+ ret.extend([match.group(2)] * SERVERS_PER_POOL)
+ else:
+ ret.append(match.group(2))
except IOError as ioerr:
msg = "Cannot open config file %s for reading (%s)" % (conf_file_path,
@@ -141,9 +147,20 @@ def save_servers_to_config(servers, conf_file_path=NTP_CONFIG_FILE,
#write info about the origin of the following lines
new_conf_file.write(heading)
- #write new servers
+ #write new servers, use the pool directive for each group of
+ #SERVERS_PER_POOL servers with the same name
+ servers_done = set()
for server in servers:
- new_conf_file.write("server " + server + " iburst\n")
+ if server in servers_done:
+ continue
+ num = servers.count(server)
+ while num >= SERVERS_PER_POOL:
+ new_conf_file.write("pool " + server + " iburst\n")
+ num -= SERVERS_PER_POOL
+ while num > 0:
+ new_conf_file.write("server " + server + " iburst\n")
+ num -= 1
+ servers_done.add(server)
#copy non-server lines from the old config and skip our heading
for line in old_conf_file:
diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py
b/pyanaconda/ui/gui/spokes/datetime_spoke.py
index 8c20e13..1cb897b 100644
--- a/pyanaconda/ui/gui/spokes/datetime_spoke.py
+++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py
@@ -328,11 +328,6 @@ def _add_server(self, server):
"""
- for row in self._serversStore:
- if row[0] == server:
- #do not add duplicate items
- return
-
itr = self._serversStore.append([server, SERVER_QUERY, True])
#do not block UI while starting thread (may take some time)
--
To view this commit on github, visit
https://github.com/rhinstaller/anaconda/commit/7ec0e57e8d94872726e923cf11...