cephadm: Add "--format" option to "ceph orch status"

Fixes: https://tracker.ceph.com/issues/46233

Signed-off-by: Ricardo Marques <rimarques@suse.com>
This commit is contained in:
Ricardo Marques 2020-06-26 18:44:45 +01:00
parent d3b8716e96
commit 83ff83157c
2 changed files with 20 additions and 8 deletions

View 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)

View 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()