]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: add format arg to Responder's extra args
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 11 Apr 2022 19:16:34 +0000 (15:16 -0400)
committerAdam King <adking@redhat.com>
Sat, 21 May 2022 23:21:51 +0000 (19:21 -0400)
To ensure that the Responder can make use of a user provided `--format=`
parameter even if the programmer doesn't explicitly add one to the
args of an endpoint function we set the `extra_args` attribute on
our wrapper function so that CLICommand can later extract it.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit efee0d7ebc5d990338eb6d256fe23717bafe128d)

src/pybind/mgr/object_format.py

index fb89e9034ee9baa644214d388fb2c81466e30d8d..2df6584b908090b9c4b13371e72d91f9ca7cd6ea 100644 (file)
@@ -278,7 +278,11 @@ class Responder:
 
     A function that returns a Python object will have the object converted into
     a return value and formatted response body, based on the `format` argument
-    passed to the mgr.
+    passed to the mgr. When used from the ceph cli tool the `--format=[name]`
+    argument is mapped to a `format` keyword argument. The decorated function
+    may provide a `format` argument (type str). If the decorated function does
+    not provide a `format` argument itself, the Responder decorator will
+    implicitly add one to the MGR's "CLI arguments" handling stack.
 
     The Responder object is callable and is expected to be used as a decorator.
     """
@@ -344,4 +348,8 @@ class Responder:
                 return e.format_response()
             return retval, body, ""
 
+        # set the extra args on our wrapper function. this will be consumed by
+        # the CLICommand decorator and added to the set of optional arguments
+        # on the ceph cli/api
+        setattr(_format_response, "extra_args", {"format": str})
         return _format_response