From: Stephen Soltesz Date: Fri, 21 Mar 2008 17:26:49 +0000 (+0000) Subject: Basic script to collect ssh_rsa_keys for all nodes and dump into a known_hosts X-Git-Tag: Monitor-1.0-0~8 X-Git-Url: http://git.onelab.eu/?p=monitor.git;a=commitdiff_plain;h=a2661849e55fb43b549b567a6750c025d94b9257 Basic script to collect ssh_rsa_keys for all nodes and dump into a known_hosts 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. --- diff --git a/getsshkeys.py b/getsshkeys.py new file mode 100755 index 0000000..460e5c4 --- /dev/null +++ b/getsshkeys.py @@ -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()