From: Zack Cerza Date: Tue, 20 May 2014 23:26:29 +0000 (-0500) Subject: Add new ssh_keyscan() method X-Git-Tag: 1.1.0~1238 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8048dc348cd0cce14e79bff58369727ffcf995fe;p=teuthology.git Add new ssh_keyscan() method This is just a cleaner implementation that will replace the existing one(s). Signed-off-by: Zack Cerza --- 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: