Python version 2.6.6; Pexpect 2.3
Login Method Interpretation:
defLogin (args, Cli_username=none, cli_password=None):#I have to keep a separate list of host names because Python Dicts is not ordered. #I want to keep the same order as in the args list.Host_names =[] Hive_connect_info={} hive= {} #build up the list of connection information (hostname, username, password, port) forHost_connect_stringinchARGS:HCD=parse_host_connect_string (host_connect_string) hostname= hcd['hostname'] Port= hcd['Port'] ifPort = ="':#port=22Port =NoneifLen (hcd['username']) >0:username= hcd['username'] elifCli_username is notNone:username=Cli_usernameElse: Username= Raw_input ('%s Username:'%hostname)ifLen (hcd['Password']) >0:password= hcd['Password'] elifCli_password is notNone:password=Cli_passwordElse: Password= Getpass.getpass ('%s Password:'%hostname) Host_names.append (hostname) Hive_connect_info[hostname]=(hostname, username, password, port)PrintHive_connect_info" "return result like this {' 192.168.100.245 ': (' 192.168.100.245 ', ' root ', ' pwdxxx ', None), ' 192.168.100 .246 ': (' 192.168.100.246 ', ' root ', ' pwdxxx ', None)}" " #build up the list of hive connections using the connection information. forHostnameinchHost_names:Print 'connecting to', hostnameTry: Fout= File ("Log_"+hostname,"W") 'Fout means Fileout'Hive[hostname]=pxssh.pxssh ()Print "Hive[hostname]:", Hive[hostname] Hive[hostname].login (*Hive_connect_info[hostname])'The exception happened on the last line' PrintHive[hostname].before Hive[hostname].logfile=FoutPrint '-OK' exceptException, E:Print '-ERROR', PrintStr (e)Print 'Skipping', hostname hive[hostname]=NonereturnHost_names, Hive
The above code hive[hostname].login (*hive_connect_info[hostname]) This line out a bug, but still very good repair, reference http://stackoverflow.com/ Questions/21055943/pxssh-connecting-to-an-ssh-proxy-timeout-exceeded-in-read-nonblocking can find a solution:
Modify the/usr/lib/python2.6/site-packages/pxssh.py in line 134th to insert the following:
self.sendline() #Line 134time.sleep(0.5) #Line 135
The next few lines are just
self.read_nonblocking(size=10000,timeout=1) # GAS: Clear out the cache before getting the prompt
pexpect--example--hive.py interpretation