def get_choose(self): while True: # '''execute commands''' resultes = dict(OK=[],NO=[]) self.print_choose() opt = raw_input("Please input choice : ").strip() if opt == "1": cmd2exec = self.get_execute2cmds() if not cmd2exec: # print "Error..." continue for hosts in self.hosts_list: hosts['cmd2exec'] = cmd2exec if ExecCMD.exec_cmd(hosts): resultes["OK"].append(hosts['ip']) else: resultes["NO"].append(hosts['ip']) # '''transfer file''' elif opt == "2": (local_file_path,remote_file_path) = self.get_file2transfer() for hosts in self.hosts_list: hosts['file2put'] = local_file_path hosts['file2save'] = remote_file_path if PutFile.put_file(hosts): resultes["OK"].append(hosts['ip']) else: resultes["NO"].append(hosts['ip']) # '''transfer dictory''' elif opt == "3": (local_dir_path,remote_dir_path) = self.get_dir2transfer() for hosts in self.hosts_list: hosts['dir2put'] = local_dir_path hosts['dir2save'] = remote_dir_path if PutDIR.put_dir(hosts): resultes["OK"].append(hosts['ip']) else: resultes["NO"].append(hosts['ip']) elif opt == "4": pass else : continue self.print_results(resultes)
def exec_cmd_test(hosts): hosts['cmd2exec'] = "cp -raf /usr/local/nginx /usr/local/nginx2" ExecCMD.exec_cmd(hosts)