Skip to content

Commit 4d00b2a

Browse files
committed
CA-421635 Show the real NTP servers in dhcp NTP mode
Get the servers form `chronyc -c sources`. The output is the csv format. Signed-off-by: Changlei Li <changlei.li@cloud.com>
1 parent 767b0f1 commit 4d00b2a

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

XSConsoleData.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,19 @@ def SetTimeManually(self, date):
672672
getstatusoutput("date --set='%s'" % timestring)
673673
getstatusoutput("hwclock --utc --systohc")
674674

675+
def GetNTPServersFromChronyc(self):
676+
servers =[]
677+
(status, output) = getstatusoutput("chronyc -c sources")
678+
# output is csv format: ^,*,10.79.16.11,5,7,377,13,-0.000067081,-0.000084192,0.172569677
679+
if status == 0:
680+
for line in output.split("\n"):
681+
fields = line.split(",")
682+
if len(fields) >= 3:
683+
server = fields[2].strip()
684+
if server != "":
685+
servers.append(server)
686+
return servers
687+
675688
def SaveToResolveConf(self):
676689
# Double-check authentication
677690
Auth.Inst().AssertAuthenticated()

plugins-base/XSFeatureNTP.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,7 @@ def StatusUpdateHandler(cls, inPane):
428428

429429
servers = data.ntp.servers([])
430430
if ntpMethod == "DHCP":
431-
gateway = data.ManagementGateway()
432-
if gateway is None:
433-
gateway = "Refreshing..."
434-
435-
servers = [Lang(str(gateway) + " (DHCP)")]
431+
servers = data.GetNTPServersFromChronyc()
436432

437433
inPane.NewLine()
438434

0 commit comments

Comments
 (0)