Esempio n. 1
0

# setup logging
#paramiko.util.log_to_file('demo.log')
#paramiko.util.log_to_file('/server/scripts/py/django/Coral/web01/logs/demo.log')

# now connect
try:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((hostname, port))
except Exception as error:
    print '*** Connect failed: ' + str(error)
    #traceback.print_exc()
    ''' record login faile to opslog table'''
    track_mark = MultiRunCounter.AddNumber()
    logger.RecordLogSummary('CREATE', 'TriConnector', track_mark, username,
                            connect_cmd, "1", django_loginuser, error, 0, 1)
    sys.exit(1)

try:
    t = paramiko.Transport(sock)
    try:
        t.start_client()
    except paramiko.SSHException:
        print '*** SSH negotiation failed.'
        sys.exit(1)

    try:
        keys = paramiko.util.load_host_keys(
            os.path.expanduser('~/.ssh/known_hosts'))
    except IOError:
        try:
Esempio n. 2
0
        track_num = MultiRunCounter.AddNumber()
    else:
        track_num = sys.argv[1]
except IndexError:
    print "argument error,try -h for help"
    sys.exit()

if __name__ == "__main__":
    run_user = sys.argv[4]
    raw_ip_list = sys.argv[2].split()
    remove_duplicate_ip = set(raw_ip_list)
    ip_list = list(remove_duplicate_ip)
    cmd = sys.argv[3]

    # batch run process
    logger.RecordLogSummary('CREATE', 'BatchRunCommand', track_num, run_user,
                            cmd, len(ip_list), '/tmp/opt_%s.log' % track_num)

    result = []

    def run(host):
        task = '''%s %s '%s' %s %s''' % (script, host, cmd, run_user,
                                         track_num)
        os.system(task)

    if len(ip_list) < 50:
        thread_num = len(ip_list)
    else:
        thread_num = 50
    pool = multiprocessing.Pool(processes=thread_num)

    for ip in ip_list:
Esempio n. 3
0
            script, host, run_user, '-s', local_file, remote_path, track_num)
    elif option == 'get':
        cmd = '''%s %s %s '%s' %s -t %s''' % (script, host, run_user, '-g',
                                              remote_file, track_num)
    os.system(cmd)


if len(ip_list) < 50:
    thread_num = len(ip_list)
else:
    thread_num = 50
pool = multiprocessing.Pool(processes=thread_num)
if option == '-s':
    log_msg = "send %s to remote path %s " % (local_file, remote_path)
    logger.RecordLogSummary('CREATE',
                            'BatchSendFile', track_num, run_user, log_msg,
                            len(ip_list), '/tmp/opt_%s.log' % track_num)
    for ip in ip_list:
        result.append(pool.apply_async(run, (ip, 'send')))
elif option == '-g':
    log_msg = "get file %s from remote servers" % remote_file
    logger.RecordLogSummary('CREATE',
                            'BatchGetFile', track_num, run_user, log_msg,
                            len(ip_list), '/tmp/opt_%s.log' % track_num)

    for ip in ip_list:
        result.append(pool.apply_async(run, (ip, 'get')))
#time.sleep(5)
#pool.terminate()

pool.close()