]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Add new ssh_keyscan() method
authorZack Cerza <zack@cerza.org>
Tue, 20 May 2014 23:26:29 +0000 (18:26 -0500)
committerZack Cerza <zack.cerza@inktank.com>
Mon, 25 Aug 2014 17:14:37 +0000 (11:14 -0600)
This is just a cleaner implementation that will replace the existing
one(s).

Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/lock.py

index 350eeadcc965b847bfcd90eef8fab161c4b16745..4ce5f42f6d2f13d013700ad934edda53697b0e92 100644 (file)
@@ -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: