Basic script to collect ssh_rsa_keys for all nodes and dump into a known_hosts
authorStephen Soltesz <soltesz@cs.princeton.edu>
Fri, 21 Mar 2008 17:26:49 +0000 (17:26 +0000)
committerStephen Soltesz <soltesz@cs.princeton.edu>
Fri, 21 Mar 2008 17:26:49 +0000 (17:26 +0000)
file.  Problems:

 * needs to be updated periodically.
 * needs to co-exist with a user's non-pl entries in known_hosts
 * there doesn't seem to be a way to configure ssh to read two known_hosts files.

getsshkeys.py [new file with mode: 0755]

diff --git a/getsshkeys.py b/getsshkeys.py
new file mode 100755 (executable)
index 0000000..460e5c4
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+
+import os
+import sys
+import string
+import time
+import soltesz
+import plc
+
+def main():
+
+       l_nodes = plc.getNodes() 
+       d_nodes = {}
+       nokey_list = []
+       for host in l_nodes:
+               name = host['hostname']
+               d_nodes[name] = host
+
+       f = open("known_hosts", 'w')
+       for host in d_nodes:
+               node = d_nodes[host]
+               key = node['ssh_rsa_key']
+               if key == None:
+                       nokey_list += [node]
+               else:
+                       l_nw = plc.getNodeNetworks({'nodenetwork_id':node['nodenetwork_ids']})
+                       if len(l_nw) > 0:
+                               ip = l_nw[0]['ip']
+                               key = key.strip()
+                               # TODO: check for '==' at end of key.
+                               if key[-1] != '=':
+                                       print "Host with corrupt key! for %s %s" % (node['boot_state'], node['hostname'])
+                               s_date = time.strftime("%Y/%m/%d_%H:%M:%S",time.gmtime(time.time()))
+                               print >>f, "%s,%s %s %s" % (host,ip, key, "PlanetLab_%s" % (s_date))
+       f.close()
+
+       for node in nokey_list:
+               print "%5s %s" % (node['boot_state'], node['hostname'])
+       
+if __name__ == '__main__':
+       import os
+       main()