From: Sage Weil Date: Fri, 12 Jul 2019 21:34:37 +0000 (-0500) Subject: mgr/crash: make 'crash ls' a nice table with a NEW column X-Git-Tag: v15.1.0~2091^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c691f2f8763a9db081a0b61294c5eedf4e9c2cee;p=ceph.git mgr/crash: make 'crash ls' a nice table with a NEW column Signed-off-by: Sage Weil --- diff --git a/qa/workunits/rados/test_crash.sh b/qa/workunits/rados/test_crash.sh index 6e7aaaaba634..04597c195375 100755 --- a/qa/workunits/rados/test_crash.sh +++ b/qa/workunits/rados/test_crash.sh @@ -29,5 +29,5 @@ sudo systemctl restart ceph-crash sleep 30 # must be 3 crashdumps registered and moved to crash/posted -[ $(ceph crash ls | wc -l) = 3 ] || exit 1 +[ $(ceph crash ls | wc -l) = 4 ] || exit 1 # 4 here bc of the table header [ $(sudo find /var/lib/ceph/crash/posted/ -name meta | wc -l) = 3 ] || exit 1 diff --git a/src/pybind/mgr/crash/module.py b/src/pybind/mgr/crash/module.py index df2771bf156a..df298fbc5062 100644 --- a/src/pybind/mgr/crash/module.py +++ b/src/pybind/mgr/crash/module.py @@ -4,6 +4,7 @@ import errno import json import six from collections import defaultdict +from prettytable import PrettyTable DATEFMT = '%Y-%m-%dT%H:%M:%S.%f' @@ -83,12 +84,23 @@ class Module(MgrModule): return 0, '', '' def do_ls(self, cmd, inbuf): - keys = [] + r = [] for k, meta in self.timestamp_filter(lambda ts: True): - entity_name = meta.get('entity_name', 'unknown') - keys.append("%s %s" % (k.replace('crash/', ''), entity_name)) - keys.sort() - return 0, '\n'.join(keys), '' + r.append(meta) + if cmd.get('format') == 'json' or cmd.get('format') == 'json-pretty': + return 0, json.dumps(r, indent=4), '' + else: + table = PrettyTable(['ID', 'ENTITY', 'NEW'], + border=False) + table.left_padding_width = 0 + table.right_padding_width = 1 + table.align['ID'] = 'l' + table.align['ENTITY'] = 'l' + for c in r: + table.add_row([c.get('crash_id'), + c.get('entity_name','unknown'), + '' if 'archived' in c else '*']) + return 0, table.get_string(), '' def do_rm(self, cmd, inbuf): crashid = cmd['id']