From c2c5ac0c54d8f84c11c08f557f4b1ca6897148e6 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 24 Aug 2011 10:03:43 -0700 Subject: [PATCH] lock: --list-targets: list locks and dump result in targets: yaml format. --- teuthology/lock.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/teuthology/lock.py b/teuthology/lock.py index d50411f0e4ad8..81937f699fb0b 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -108,6 +108,12 @@ Lock, unlock, or query lock status of machines. default=False, help='Show lock info for all machines, or only machines specified. Can be restricted by --owner and --status.', ) + group.add_argument( + '--list-targets', + action='store_true', + default=False, + help='Show lock info for all machines, or only machines specified, in targets: yaml format. Can be restricted by --owner and --status.', + ) group.add_argument( '--lock', action='store_true', @@ -200,13 +206,13 @@ Lock, unlock, or query lock status of machines. assert ctx.lock or ctx.unlock, \ '-f is only supported by --lock and --unlock' if ctx.machines: - assert ctx.lock or ctx.unlock or ctx.list or ctx.update, \ + assert ctx.lock or ctx.unlock or ctx.list or ctx.list_targets or ctx.update, \ 'machines cannot be specified with that operation' else: - assert ctx.num_to_lock or ctx.list, \ + assert ctx.num_to_lock or ctx.list or ctx.list_targets, \ 'machines must be specified for that operation' - if ctx.list: + if ctx.list or ctx.list_targets: assert ctx.desc is None, '--desc does nothing with --list' if machines: @@ -221,7 +227,13 @@ Lock, unlock, or query lock status of machines. if ctx.status is not None: statuses = [status for status in statuses \ if status['up'] == (ctx.status == 'up')] - print json.dumps(statuses, indent=4) + if ctx.list: + print json.dumps(statuses, indent=4) + else: + frag = { 'targets': {} } + for f in statuses: + frag['targets'][f['name']] = f['sshpubkey'] + print yaml.safe_dump(frag, default_flow_style=False) else: log.error('error retrieving lock statuses') ret = 1 -- 2.39.5