[Git][NTPsec/ntpsec][master] 2 commits: Changed DataSource to take a hostname argument for the ntpd to contact.
Ian Bruene
gitlab at mg.gitlab.com
Fri Feb 16 20:23:00 UTC 2018
Ian Bruene pushed to branch master at NTPsec / ntpsec
Commits:
1eaf916e by Ian Bruene at 2018-02-16T14:01:10-06:00
Changed DataSource to take a hostname argument for the ntpd to contact.
- - - - -
e694bc00 by Ian Bruene at 2018-02-16T14:22:15-06:00
Added option to connect to remote NTP servers.
- - - - -
1 changed file:
- ntpclients/ntpsnmpd.py
Changes:
=====================================
ntpclients/ntpsnmpd.py
=====================================
--- a/ntpclients/ntpsnmpd.py
+++ b/ntpclients/ntpsnmpd.py
@@ -41,7 +41,7 @@ DEFHOST = "localhost" # For now only know how to talk to the local ntp
class DataSource: # This will be broken up in future to be less NTP-specific
- def __init__(self):
+ def __init__(self, hostname=DEFHOST):
node = ax.mibnode
# This is defined as a dict tree because it is simpler, and avoids
# certain edge cases
@@ -250,7 +250,8 @@ class DataSource: # This will be broken up in future to be less NTP-specific
# ntpEntNotifGroup NOTIFICATIONS {...}
3: node(None, None, True, None)})})}
self.session = ntp.packet.ControlSession()
- self.session.openhost(DEFHOST) # only local for now
+ self.hostname = hostname if hostname else DEFHOST
+ self.session.openhost(self.hostname)
# Cache so we don't hammer ntpd, default 1 second timeout
# Timeout default pulled from a hat: we don't want it to last for
# long, just not flood ntpd when we don't need to.
@@ -1484,10 +1485,10 @@ def connect(address):
return sock
-def mainloop(masterAddress=None):
+def mainloop(masterAddress=None, host=None):
dolog("initing loop\n", 1)
sock = connect(masterAddress)
- dbase = DataSource()
+ dbase = DataSource(host)
control = PacketControl(sock, dbase)
control.loopCallback = dbase.checkNotifications
control.initNewSession()
@@ -1519,7 +1520,7 @@ def daemonize(runfunc, *runArgs):
usage = """
-USAGE: ntpsnmpd [-n]
+USAGE: ntpsnmpd [-n] [ntp host]
Flg Arg Option-Name Description
-n no no-fork Do not fork and daemonize.
-x Adr master-addr Specify address for connecting to the master agent
@@ -1579,7 +1580,9 @@ if __name__ == "__main__":
logfp.close()
logfp = open(val, "a", 1) # 1 => line buffered
+ hostname = arguments[0] if arguments else DEFHOST
+
if nofork is True:
- mainloop(masterAddr)
+ mainloop(masterAddr, hostname)
else:
- daemonize(mainloop, masterAddr)
+ daemonize(mainloop, masterAddr, hostname)
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/8d50caeb41e2bbbf6d5c411a6bd47d16132908f0...e694bc002417c0ddf6e22b89bfa6434b0988273e
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/8d50caeb41e2bbbf6d5c411a6bd47d16132908f0...e694bc002417c0ddf6e22b89bfa6434b0988273e
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180216/acadf383/attachment.html>
More information about the vc
mailing list