def gather(): '''Check how the nodes we're responsible for are doing. To keep the architecture simple, for now the nodes are arranged in a unidirectional ring. Each node is responsible for watching the node below it, skipping over any nodes it detects as down or not having monitord running. ''' lookup = {True: {True:'up -monitord', False:'up -ssh -monitord'}, False:{True:'-ping +ssh', False:'down'}} data = {} nodes = neighbours.nodes print 'Pinging downstream nodes:' count=0 for node in nodes: count+=1 if count>conf.MAX_WATCH_NODES: break up = ping.ping(node) ssh = ping.has_ssh(node) mond = ping.has_monitord(node) # if it's got monitord, it can handle things further down the list if mond: break # otherwise, we need to keep the server informed and keep scanning state=lookup[up][ssh] # don't bother telling the server things it knows if node in cache: if cache[node]==state: continue # do tell it new stuff, but cache it for later cache[node] = data[node] = state print '\tnode',node,'is',state return data
def deploy_single(hostname, password, command, src_file, dst_file='/home/usf_ubcslice5/', username='******', keyfile='id_rsa' ): 'Single-node deployment.' # test for SSH if not ping.has_ssh(hostname, timeout=7.5): print 'Node doesn''t have port 22 open. No SSH?' return (False,"no ssh") # upload if src_file: #print 'Uploading...' ok = ssh.upload(src_file, dst_file, password, username, keyfile, hostname) if ok: #print '[PASS]' pass else: #print '[FAIL]' #print 'Moving on to the next node!' return (False,"upload fail") # run command #print 'Executing Command...', ok = ssh.command(command, password, username, keyfile, hostname) if ok: #print '[PASS]' return (True,ok) else: #print '[FAIL]' return (False,"cmd fail")