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
时间: 2024-08-30 05:10:39

Pexpect--example--hive.py解读的相关文章

tensorflow serving 之minist_saved_model.py解读

最近在学习tensorflow serving,但是就这样平淡看代码可能觉得不能真正思考,就想着写个文章看看,自己写给自己的,就像自己对着镜子演讲一样,写个文章也像自己给自己讲课,这样思考的比较深,学到的也比较多,有错欢迎揪出, minist_saved_model.py 是tensorflow的第一个例子,里面有很多serving的知识,还不了解,现在看.下面是它的入口函数,然后直接跳转到main if __name__ == '__main__': tf.app.run() 在main函数里

ansible源码解读

Ansible源码获取 Ansible Github:https://github.com/ansible Ansible目录结构 $ tree -L 2 ansible-2.0.0.0 ansible-2.0.0.0 |-- bin # 可执行程序存放目录 | |-- ansible | |-- ansible-doc -> ansible | |-- ansible-galaxy -> ansible | |-- ansible-playbook -> ansible | |-- a

tensorflow serving目录解读

tf_serving-----WORKSPACE | -----tensorflow-serving/----BUILD |                      | |                      -----workspace.bzl |                      | |                      -----example/-------BUILD |                                  | |          

Ambari Hive 无法正常查询 问题分析处理

1.今天遇到一个错误,在连接到hive之后,无法执行任何命令. $ beeline -u "jdbc:hive2://hostname.domain.cn:10000/default;principal=hive/[email protected];" Connecting to jdbc:hive2://hostname.domain.cn:10000/default;principal=hive/[email protected]; Connected to: Apache Hiv

Django开发之html交互

html中用户输入信息,由Django的view.py处理,大致用到了以下几类格式: 1. 文本框 <input type="text" name="vid" size="10" height="20"> 或由bootcss修饰的 <div class="col-sm-2" > <input type="text" class="form-cont

Hdp安装问题杂解

5.在安装的时候遇到的问题 5.1使用ambari-server start的时候出现ERROR: Exiting with exit code -1. 5.1.1REASON: Ambari Server java process died with exitcode 255. Check /var/log/ambari-server/ambari-server.out for more information 解决: 由于是重新安装,所以在使用/etc/init.d/postgresql 

Java学习体系

一.JavaSE1.Java开发环境搭建2.Java基础语法3.Java面向对象4.异常5.数组/算法6.常用类7.集合/数据结构8.IO流9.线程10.反射机制11.网络编程12.注解Annotation13.MySQL初级14.JDBC 二.JavaWeb初级1.HTML/HTML52.CSS/CSS33.JavaScript4.jQuery5.Bootstrap6.XML+XPath7.Servlet8.Jsp9.EL10.JSTL11.Filter12.Listener13.Servle

Hive sql 语法解读

一. 创建表 在官方的wiki里,example是这种: Sql代码 CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_name [(col_name data_type [COMMENT col_comment], ...)] [COMMENT table_comment] [PARTITIONED BY (col_name data_type [COMMENT col_comment], ...)] [CLUSTERED BY (col_name, 

Hadoop Hive基础sql语法

Hive 是基于Hadoop 构建的一套数据仓库分析系统,它提供了丰富的SQL查询方式来分析存储在Hadoop 分布式文件系统中的数据,可以将结构化的数据文件映射为一张数据库表,并提供完整的SQL查询功能,可以将SQL语句转换为MapReduce任务进行运行,通过自己的SQL 去查询分析需要的内容,这套SQL 简称Hive SQL,使不熟悉mapreduce 的用户很方便的利用SQL 语言查询,汇总,分析数据.而mapreduce开发人员可以把己写的mapper 和reducer 作为插件来支持