From 13d1e3e26bcbd0f48d043d4c21512295c75685c9 Mon Sep 17 00:00:00 2001 From: Gerald Elder-Vass Date: Tue, 19 Mar 2024 13:34:16 +0000 Subject: [PATCH] Use hardcoded default NTP servers, don't remove default servers when changing servers --- Makefile | 1 + XSConsoleConstants.py | 7 ++++++- XSConsoleData.py | 7 ++----- plugins-base/XSFeatureNTP.py | 5 +---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 6950a6a..80615e2 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ SCRIPTS += XSConsole.py SCRIPTS += XSConsoleAuth.py SCRIPTS += XSConsoleBases.py SCRIPTS += XSConsoleConfig.py +SCRIPTS += XSConsoleConstants.py SCRIPTS += XSConsoleCurses.py SCRIPTS += XSConsoleData.py SCRIPTS += XSConsoleDataUtils.py diff --git a/XSConsoleConstants.py b/XSConsoleConstants.py index fb1697d..2b98e7b 100644 --- a/XSConsoleConstants.py +++ b/XSConsoleConstants.py @@ -1,2 +1,7 @@ # Default NTP domains are .[centos|xenserver].pool.ntp.org -DEFAULT_NTP_DOMAINS = [".centos.pool.ntp.org", ".xenserver.pool.ntp.org"] +CENTOS_NTP_POOL_DOMAIN = "centos.pool.ntp.org" +DEFAULT_NTP_DOMAINS = [CENTOS_NTP_POOL_DOMAIN, "xenserver.pool.ntp.org"] + +NUM_DEFAULT_NTP_SERVERS = 4 + +DEFAULT_NTP_SERVERS = ["%d.%s" % (i, CENTOS_NTP_POOL_DOMAIN) for i in range(NUM_DEFAULT_NTP_SERVERS)] diff --git a/XSConsoleData.py b/XSConsoleData.py index 3266910..d68f9f0 100644 --- a/XSConsoleData.py +++ b/XSConsoleData.py @@ -506,7 +506,7 @@ def UpdateFromNTPConf(self): self.data['ntp']['method'] = "Manual" servers = self.data['ntp']['servers'] - if len(servers) == 4 and all( + if len(servers) == NUM_DEFAULT_NTP_SERVERS and all( inDefaultNTPDomains(server) for server in self.data['ntp']['servers'] ): @@ -590,10 +590,7 @@ def AddDHCPNTP(self): def ResetDefaultNTPServers(self): # Double-check authentication Auth.Inst().AssertAuthenticated() - - Data.Inst().NTPServersSet( - ["%d%s" % (i, DEFAULT_NTP_DOMAINS[0]) for i in range(4)] - ) + Data.Inst().NTPServersSet(DEFAULT_NTP_SERVERS) def GetDHClientInterfaces(self): try: diff --git a/plugins-base/XSFeatureNTP.py b/plugins-base/XSFeatureNTP.py index 1d33b9e..9297a59 100644 --- a/plugins-base/XSFeatureNTP.py +++ b/plugins-base/XSFeatureNTP.py @@ -67,7 +67,7 @@ def CreateMANUALPane(self): data.UpdateFromNTPConf() servers = data.ntp.servers([]) - if data.ntp.method("") == "Manual" and len(servers) > 0: + if len(servers) > 0: choiceDefs.append( ChoiceDef( Lang("Remove Server"), lambda: self.HandleManualChoice("REMOVE") @@ -302,9 +302,6 @@ def HandleKeyADD(self, inKey): IPUtils.AssertValidNetworkName(inputValues['name']) data=Data.Inst() - if data.ntp.method("") == "Default": - data.NTPServersSet([server for server in data.ntp.servers([]) if not inDefaultNTPDomains(server)]) - data.RemoveDHCPNTP() servers = data.ntp.servers([])