pexpect--example--hive.py interpretation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.