#_*_coding:utf-8_*_
import multiprocessing
import paramiko
import getpass
import ConfigParser
class MultiTask(object):
'''handles all the multi task works'''
def __init__(self):
msg = self._interactive()
self.__run_cmd(msg)
def __show_cmd_list(self,msg):
'''show all available cmd list'''
help_content = '''
run_cmd run cmd on multiple hosts
run_cmd -u remote_user -g group1,group2 -cmd pwd
run_cmd -u remote_user -re regular expression -cmd pwd
'''
def _interactive(self):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
msg = []
nodes = []
#parse setting.conf
Config = ConfigParser.ConfigParser()
Config.read("./setting.conf")
groups = Config.sections()
print groups
# Input group name
while True:
try:
group = raw_input("\033[33;1mPlease Input Group Name:\033[0m").strip()
if len(group) == 0 : continue
elif group not in groups:
print "Wrong group name ! Please input again!"
continue
else :
871102_Hadoop'],['10.9.214.106','haohzhang','871102_Hadoop']]
for host in msg[0]:
p = pool.apply_async(run_task, args=(host,msg[1:],lock))
res_list.append(p)
pool.close()
pool.join()
print '--------All task are finished!-------'
def run_task(host,msg,lock):