]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
lock/cli: show up/down status when --brief 1528/head
authorKyr Shatskyy <kyrylo.shatskyy@suse.com>
Tue, 30 Jun 2020 17:51:45 +0000 (19:51 +0200)
committerKyr Shatskyy <kyrylo.shatskyy@suse.com>
Thu, 16 Jul 2020 14:05:13 +0000 (16:05 +0200)
This change makes --brief option to display 'up' and 'down' statuses.

Fixes: https://tracker.ceph.com/issues/45569
Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@suse.com>
teuthology/lock/cli.py

index ecb8374a457ae754347c94e2545cb7a90edc1dfd..9cc8210a22d20ccd964671305fee3a41f0568669 100644 (file)
@@ -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': {}}