merge from improvements on the 1.0 branch:
[monitor.git] / getsshkeys.py
index fc306e4..68d2945 100755 (executable)
@@ -5,17 +5,30 @@ import sys
 import string
 import time
 import xml, xmlrpclib
+try:
+       from monitor import config
+       auth = {'Username'   : config.API_AUTH_USER,
+               'AuthMethod' : "password",
+                       'AuthString' : config.API_AUTH_PASSWORD}
+except:
+       import traceback
+       print traceback.print_exc()
+       auth = {'AuthMethod' : "anonymous"}
 
 args = {}
 args['known_hosts'] =  os.environ['HOME'] + os.sep + ".ssh" + os.sep + "known_hosts"
-args['XMLRPC_SERVER'] = 'https://www.planet-lab.org/PLCAPI/'
+try:
+       import config
+       args['XMLRPC_SERVER'] = config.API_SERVER
+except:
+       args['XMLRPC_SERVER'] = 'https://boot.planet-lab.org/PLCAPI/'
+       print "Using default API server %s" %  args['XMLRPC_SERVER']
 
 class SSHKnownHosts:
        def __init__(self, args = args):
                self.args = args
                self.read_knownhosts()
-               self.auth = {}
-               self.auth['AuthMethod'] = "anonymous"
+               self.auth = auth
                self.api = xmlrpclib.Server(args['XMLRPC_SERVER'], verbose=False, allow_none=True)
                self.nodenetworks = {}
 
@@ -154,7 +167,7 @@ class SSHKnownHosts:
 
                key = key.strip()
                # TODO: check for '==' at end of key.
-               if key[-1] != '=':
+               if len(key) > 0 and 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()))