def test_delete_dir(self):
     hosts = ['localhost', '127.0.0.1', 'st2build001']
     client = ParallelSSHClient(hosts=hosts,
                                user='******',
                                pkey_file='~/.ssh/id_rsa',
                                connect=True)
     client.delete_dir('/remote/stuff/', force=True)
     expected_kwargs = {'force': True, 'timeout': None}
     for host in hosts:
         hostname, _ = client._get_host_port_info(host)
         client._hosts_client[hostname].delete_dir.assert_called_with(
             '/remote/stuff/', **expected_kwargs)
Пример #2
0
 def test_delete_dir(self):
     hosts = ["localhost", "127.0.0.1", "st2build001"]
     client = ParallelSSHClient(hosts=hosts,
                                user="******",
                                pkey_file="~/.ssh/id_rsa",
                                connect=True)
     client.delete_dir("/remote/stuff/", force=True)
     expected_kwargs = {"force": True, "timeout": None}
     for host in hosts:
         hostname, _ = client._get_host_port_info(host)
         client._hosts_client[hostname].delete_dir.assert_called_with(
             "/remote/stuff/", **expected_kwargs)
Пример #3
0
 def test_delete_dir(self):
     hosts = ['localhost', '127.0.0.1', 'st2build001']
     client = ParallelSSHClient(hosts=hosts,
                                user='******',
                                pkey_file='~/.ssh/id_rsa',
                                connect=True)
     client.delete_dir('/remote/stuff/', force=True)
     expected_kwargs = {
         'force': True,
         'timeout': None
     }
     for host in hosts:
         hostname, _ = client._get_host_port_info(host)
         client._hosts_client[hostname].delete_dir.assert_called_with('/remote/stuff/',
                                                                      **expected_kwargs)
Пример #4
0
def main(user, pkey, password, hosts_str, cmd, file_path, dir_path,
         delete_dir):
    hosts = hosts_str.split(",")
    client = ParallelSSHClient(user=user,
                               pkey_file=pkey,
                               password=password,
                               hosts=hosts)
    pp = pprint.PrettyPrinter(indent=4)

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

    if dir_path:
        if not os.path.exists(dir_path):
            raise Exception("File not found.")
        results = client.put(dir_path, "/home/lakshmi/", mode="0660")
        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 delete_dir:
        results = client.delete_dir(delete_dir, force=True)
        pp.pprint("Delete results: \n%s" % results)