From 8048dc348cd0cce14e79bff58369727ffcf995fe Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 20 May 2014 18:26:29 -0500 Subject: [PATCH] Add new ssh_keyscan() method This is just a cleaner implementation that will replace the existing one(s). Signed-off-by: Zack Cerza --- teuthology/lock.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/teuthology/lock.py b/teuthology/lock.py index 350eeadcc..4ce5f42f6 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -342,6 +342,29 @@ def keyscan_check(machines): return (out, current_locks) +def ssh_keyscan(hostnames): + """ + Fetch the SSH public key of one or more hosts + """ + args = ['ssh-keyscan', '-t', 'rsa'] + if isinstance(hostnames, basestring): + args.append(hostnames) + else: + args.extend(hostnames) + p = subprocess.Popen( + args=args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + p.wait() + + keys_dict = dict() + for line in p.stdout.readlines(): + host, key = line.strip().split(' ', 1) + keys_dict[host] = key + return keys_dict + + def updatekeys(ctx): loglevel = logging.INFO if ctx.verbose: -- 2.47.3