]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: Add "--format" option to "ceph orch status" 35898/head
authorRicardo Marques <rimarques@suse.com>
Fri, 26 Jun 2020 17:44:45 +0000 (18:44 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Tue, 14 Jul 2020 09:39:06 +0000 (11:39 +0200)
Fixes: https://tracker.ceph.com/issues/46233
Signed-off-by: Ricardo Marques <rimarques@suse.com>
(cherry picked from commit 83ff83157c3c5bc3c825d09c8724310e02aea988)

qa/tasks/cephadm_cases/test_cli.py
src/pybind/mgr/orchestrator/module.py

index a953efc7b88462051bac6cf75b34ccda134f7b6e..b06e276b1a920db498e248b42c47b0987125eac8 100644 (file)
@@ -35,3 +35,5 @@ class TestCephadmCLI(MgrTestCase):
         out = self._orch_cmd('ps', '--format', 'yaml')
         self.assertNotIn('!!python', out)
 
+        out = self._orch_cmd('status', '--format', 'yaml')
+        self.assertNotIn('!!python', out)
index 0c66f9b68cd496eca479726658ca10c44c0b19e3..3096d0fe8907080d8261e0bc4ac1f38213f65d87 100644 (file)
@@ -1241,21 +1241,31 @@ Usage:
 
     @_cli_read_command(
         'orch status',
+        'name=format,type=CephChoices,strings=plain|json|json-pretty|yaml,req=false',
         desc='Report configured backend and its status')
-    def _status(self):
+    def _status(self, format='plain'):
         o = self._select_orchestrator()
         if o is None:
             raise NoOrchestrator()
 
         avail, why = self.available()
-        if avail is None:
-            # The module does not report its availability
-            return HandleCommandResult(stdout="Backend: {0}".format(o))
+        result = {
+            "backend": o
+        }
+        if avail is not None:
+            result['available'] = avail
+            if not avail:
+                result['reason'] = why
+
+        if format != 'plain':
+            output = to_format(result, format, many=False, cls=None)
         else:
-            return HandleCommandResult(stdout="Backend: {0}\nAvailable: {1}{2}".format(
-                                           o, avail,
-                                           " ({0})".format(why) if not avail else ""
-                                       ))
+            output = "Backend: {0}".format(result['backend'])
+            if 'available' in result:
+                output += "\nAvailable: {0}".format(result['available'])
+                if 'reason' in result:
+                    output += ' ({0})'.format(result['reason'])
+        return HandleCommandResult(stdout=output)
 
     def self_test(self):
         old_orch = self._select_orchestrator()