[Git][NTPsec/ntpsec][master] In pyntpq mrulist, impl;ement kod and limited options.

Eric S. Raymond gitlab at mg.gitlab.com
Thu Nov 3 21:50:43 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
dc8011ff by Eric S. Raymond at 2016-11-03T17:48:11-04:00
In pyntpq mrulist, impl;ement kod and limited options.

- - - - -


2 changed files:

- ntpq/pyntpq
- pylib/packet.py


Changes:

=====================================
ntpq/pyntpq
=====================================
--- a/ntpq/pyntpq
+++ b/ntpq/pyntpq
@@ -1195,6 +1195,27 @@ usage: config_from_file <configuration filename>
 
     def do_mrulist(self, line):
         "display the list of most recently seen source addresses, tags mincount=... resall=0x... resany=0x..."
+        cmdvars = {}
+        for item in line.split(" "):
+            if not item:
+                continue
+            print("Frobble: %s" % repr(item))
+            if '=' not in item:
+                cmdvars[item] = True
+            else:
+                eq = item.index("=")
+                var = item[:eq].strip()
+                val = item[eq+1:].strip()
+                try:
+                    val = int(val, 0)
+                except ValueError:
+                    try:
+                        val = float(val)
+                    except ValueError:
+                        if val[0] == '"' and val[-1] == '"':
+                            val = val[1:-1]
+                cmdvars[var] = val
+
 	self.say("Ctrl-C will stop MRU retrieval and display partial results.\n")
         if self.rawmode:
             mruhook = lambda v: self.printvars(variables=v,
@@ -1203,8 +1224,11 @@ usage: config_from_file <configuration filename>
         else:
             mruhook = None
         try:
-            span = self.session.mrulist(mruhook)
+            span = self.session.mrulist(variables=cmdvars, rawhook=mruhook)
             if not self.rawmode:
+                if not span.is_complete():
+                    self.say("mrulist retrieval interrupted by operator.\n"
+                             "Displaying partial client list.\n")
                 formatter = MRUSummary(interpreter.showhostnames)
                 self.say(MRUSummary.header + "\n")
                 self.say(("=" * MRUSummary.width) + "\n")


=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -249,7 +249,7 @@ SERR_BADKEY = "***Invalid key identifier"
 SERR_INVPASS = "***Invalid password"
 SERR_NOKEY = "***Key not found"
 SERR_BADNONCE = "***Unexpected nonce response format"
-SERR_BADPARM = "***Unknown parameter %s"
+SERR_BADPARAM = "***Unknown parameter '%s'"
 SERR_NOCRED = "***No credentials"
 SERR_SERVER = "***Server error code %d"
 SERR_STALL = "***No response, probably high-traffic server with low MRU limit"
@@ -749,13 +749,15 @@ class Mode6Session:
             raise Mode6Exception(SERR_BADNONCE)
         return self.response.strip()
 
-    def mrulist(self, variables, rawhook=None):
+    def mrulist(self, variables=None, rawhook=None):
         "Retrieve MRU list data"
 	nonce_uses = 0
 	restarted_count = 0
 	cap_frags = True
         warn = sys.stderr.write
         sorter = None
+        if variables is None:
+            variables = {}
 
         if variables:
             if "sort" in variables:
@@ -784,8 +786,12 @@ class Mode6Session:
                     continue
                 else:
                     raise Mode6Exception(SERR_BADPARAM % k)
-
-        # FIXME: Do the reslist parameter mappings from the C version
+            if 'kod' in variables:
+                variables['resany'] = variables.get('resany', 0) | RES_KOD
+                del variables['kod']
+            if 'limited' in variables:
+                variables['resany'] = variables.get('resany', 0) | RES_LIMITED
+                del variables['limited']
 
         nonce = self.fetch_nonce()
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/dc8011ffe5431fbd7d47f4b03e782e42bc50bb11
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161103/6d813b59/attachment.html>


More information about the vc mailing list