From: Kyr Shatskyy Date: Tue, 30 Jun 2020 17:51:45 +0000 (+0200) Subject: lock/cli: show up/down status when --brief X-Git-Tag: 1.1.0~63^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3db781c8ea0f3194f800dce08de896649ecc861a;p=teuthology.git lock/cli: show up/down status when --brief This change makes --brief option to display 'up' and 'down' statuses. Fixes: https://tracker.ceph.com/issues/45569 Signed-off-by: Kyr Shatskyy --- diff --git a/teuthology/lock/cli.py b/teuthology/lock/cli.py index ecb8374a4..9cc8210a2 100644 --- a/teuthology/lock/cli.py +++ b/teuthology/lock/cli.py @@ -122,13 +122,22 @@ def main(ctx): print(json.dumps(statuses, indent=4)) elif ctx.brief: + maxname = max((len(_['name'] or '') + for _ in statuses), default=0) + maxuser = max((len(_['locked_by'] or 'None') + for _ in statuses), default=0) + node_status_template = ( + '{{host:<{name}}} {{up:<4}} {{locked:<8}} ' + '{{owner:<{user}}} "{{desc}}"' + ).format(name=maxname, user=maxuser) for s in sorted(statuses, key=lambda s: s.get('name')): - locked = "un" if s['locked'] == 0 else " " + locked = 'unlocked' if s['locked'] == 0 else 'locked' + up = 'up' if s['up'] else 'down' mo = re.match('\w+@(\w+?)\..*', s['name']) host = mo.group(1) if mo else s['name'] - print('{host} {locked}locked {owner} "{desc}"'.format( - locked=locked, host=host, - owner=s['locked_by'], desc=s['description'])) + print(node_status_template.format( + up=up, locked=locked, host=host, + owner=s['locked_by'] or 'None', desc=s['description'])) else: frag = {'targets': {}}