Pexpect--example--hive.py解读
python version 2.6.6 ; pexpect 2.3
login方法解读:
def login (args, cli_username=None, cli_password=None): # I have to keep a separate list of host names because Python dicts are 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)
for host_connect_string in args:
hcd = parse_host_connect_string (host_connect_string)
hostname = hcd['hostname']
port = hcd['port']
if port == '':
# port=22
port = None
if len(hcd['username']) > 0:
username = hcd['username']
elif cli_username is not None:
username = cli_username
else:
username = raw_input('%s username: ' % hostname)
if len(hcd['password']) > 0:
password = hcd['password']
elif cli_password is not None:
password = cli_password
else:
password = getpass.getpass('%s password: ' % hostname)
host_names.append(hostname)
hive_connect_info[hostname] = (hostname, username, password, port)
print hive_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.
for hostname in host_names:
print 'connecting to', hostname
try:
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'
print hive[hostname].before
hive[hostname].logfile = fout
print '- OK'
except Exception, e:
print '- ERROR',
print str(e)
print 'Skipping', hostname
hive[hostname] = None
return host_names, hive
上面代码 hive[hostname].login(*hive_connect_info[hostname]) 这行会出一个bug,不过还是很好修的,参考 http://stackoverflow.com/questions/21055943/pxssh-connecting-to-an-ssh-proxy-timeout-exceeded-in-read-nonblocking 可以找到解决办法:
修改 /usr/lib/python2.6/site-packages/pxssh.py 在第134行插入下面:
self.sendline() #Line 134
time.sleep(0.5) #Line 135
其下面几行正好是
self.read_nonblocking(size=10000,timeout=1) # GAS: Clear out the cache before getting the prompt
Pexpect--example--hive.py解读的更多相关文章
- python hive.py
#!/usr/bin/env python# -- coding:utf-8 -- import osimport sysfrom subprocess import call from pyspar ...
- tensorflow serving 之minist_saved_model.py解读
最近在学习tensorflow serving,但是就这样平淡看代码可能觉得不能真正思考,就想着写个文章看看,自己写给自己的,就像自己对着镜子演讲一样,写个文章也像自己给自己讲课,这样思考的比较深,学 ...
- python 读取hive数据
话不多说,直接上代码 from pyhive import hivedef pyhive(hql): conn = hive.Connection(host='HiveServer2 host', p ...
- ansible源码解读
Ansible源码获取 Ansible Github:https://github.com/ansible Ansible目录结构 $ tree -L 2 ansible-2.0.0.0 ansibl ...
- pyhive连接hive(失败)
一.安装pyhive pip install sasl(需要来下载至本地安装:https://download.lfd.uci.edu/pythonlibs/q4hpdf1k/sasl-0.2.1-c ...
- Django开发之html交互
html中用户输入信息,由Django的view.py处理,大致用到了以下几类格式: 1. 文本框 <input type="text" name="vid&quo ...
- 【原创】用python连接thrift Server 去执行sql的问题总汇
场景:python和现有产品的结合和应用——python的前瞻性调研 环境:centos7 0.首先确保安装了python和pyhive,下面是连接代码: #!/usr/bin/env python ...
- 【转】安装ambari的时候遇到的ambari和hadoop问题集
5.在安装的时候遇到的问题 5.1使用ambari-server start的时候出现ERROR: Exiting with exit code -1. 5.1.1REASON: Ambari Ser ...
- 三行代码辨别PS
三行代码辨别PS 博主的好友动态和朋友圈经常出现各种图片,博主很想知道这些图片有没有经过PS,于是选择了技术流-- 代码 先放代码为敬,返回结果为TRUE表示进行过PS. isPS.py #!/usr ...
随机推荐
- Java继承是复制还是共用?答案共用
继承是复制还是共用?例如 Dog类继承Animal类,在Dog中的属性修改,Animal中的属性也会一起改变吗?如果用Dog和Animal分别实例化对象,dog和animal,这两者的属性是公用还是各 ...
- What is Mocking?
Mocking is primarily used in unit testing. An object under test may have dependencies on other (comp ...
- nginx,wsgi,django的关系
http://blog.csdn.net/lihao21/article/details/52304119 wsgi用于连续 nginx和django,客户端发来的请求,先经过wsgi,然后再传给dj ...
- sql cast函数
一.语法: CAST (expression AS data_type) 参数说明: expression:任何有效的SQLServer表达式. AS:用于分隔两个参数,在AS之前的是要处理的数据,在 ...
- Win7下nginx默认80端口被System占用,造成nginx启动报错的解决方案
Win7下nginx默认80端口被System占用,造成nginx启动报错的解决方案 在win7 32位旗舰版下,启动1.0.8版本nginx,显示如下错误: [plain] 2012/04/0 ...
- WEB接口测试之Jmeter接口测试自动化 (三)(数据驱动测试) 接口测试与数据驱动
转载:http://www.cnblogs.com/chengtch/p/6576117.html 1简介 数据驱动测试,即是分离测试逻辑与测试数据,通过如excel表格的形式来保存测试数据,用测试脚 ...
- python可hash 不可hash类型
不可变类型是可hash #tuple str freezeset 可变类型是不可hash ##list set
- go语言25个关键字总结
var和const :变量和常量的声明var varName type 或者 varName : = valuepackage and import: 导入func: 用于定义函数和方法return ...
- python调度框架APScheduler使用详解
# coding=utf-8 """ Demonstrates how to use the background scheduler to schedule a job ...
- react-native 创建 ios 项目
创建React-Native项目 打开终端输入react-native init ProjectName,这里的ProjectName可以改成你想创建的项目名称.然后有两种方法启动项目 1.从终端开启 ...