#!/usr/bin/env python2.7

import argparse
import os
import pprint
import sys

import eventlet

from st2common.ssh.parallel_ssh import ParallelSSHClient

eventlet.monkey_patch(
    os=True,
    select=True,
    socket=True,
    thread=False if '--use-debugger' in sys.argv else True,
    time=True)


def main(user, pkey, hosts_str, cmd, path):
    hosts = hosts_str.split(",")
    client = ParallelSSHClient(user, pkey, hosts)
    pp = pprint.PrettyPrinter(indent=4)

    if path:
        if not os.path.exists(path):
            raise Exception('File not found.')
        results = client.put(path, '/home/lakshmi/test')
        pp.pprint('Copy results: \n%s' % results)
        results = client.run('ls -rlth')
        pp.pprint('ls results: \n%s' % results)

    if cmd:
        results = client.run(cmd)
        pp.pprint('cmd results: \n%s' % results)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Parallel SSH tester.')
    parser.add_argument('--hosts', required=True,
                        help='List of hosts to connect to')
    parser.add_argument('--private-key', required=True,
                        help='Private key to use.')
    parser.add_argument('--user', required=True,
                        help='SSH user name.')
    parser.add_argument('--cmd', required=False,
                        help='Command to run on host.')
    parser.add_argument('--path', required=False,
                        help='Path to copy to remote host.')
    args = parser.parse_args()

    main(user=args.user, pkey=args.private_key, hosts_str=args.hosts, cmd=args.cmd,
         path=args.path)

@@ -330,16 +330,31 @@
 r, cmd, 
+file_path, dir_
 path):%0A 
@@ -483,16 +483,21 @@
 %0A    if 
+file_
 path:%0A  
@@ -524,16 +524,21 @@
 .exists(
+file_
 path):%0A 
@@ -612,16 +612,21 @@
 ent.put(
+file_
 path, '/
@@ -642,17 +642,350 @@
 hmi/test
-'
+_file', mode=%220660%22)%0A        pp.pprint('Copy results: %5Cn%25s' %25 results)%0A        results = client.run('ls -rlth')%0A        pp.pprint('ls results: %5Cn%25s' %25 results)%0A%0A    if dir_path:%0A        if not os.path.exists(dir_path):%0A            raise Exception('File not found.')%0A        results = client.put(dir_path, '/home/lakshmi/', mode=%220660%22
 )%0A      
@@ -1761,20 +1761,138 @@
 ment('--
-path
+file', required=False,%0A                        help='Path of file to copy to remote host.')%0A    parser.add_argument('--dir
 ', requi
@@ -1937,16 +1937,23 @@
 p='Path 
+of dir 
 to copy 
@@ -2095,16 +2095,21 @@
         
+file_
 path=arg
@@ -2110,14 +2110,33 @@
 th=args.
-path
+file, dir_path=args.dir
 )%0A

Add support for testing dir copy