Ejemplo n.º 1
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)
 def test_put(self):
     hosts = ['localhost', '127.0.0.1', 'st2build001']
     client = ParallelSSHClient(hosts=hosts,
                                user='******',
                                pkey_file='~/.ssh/id_rsa',
                                connect=True)
     client.put('/local/stuff', '/remote/stuff', mode=0744)
     expected_kwargs = {'mode': 0744, 'mirror_local_mode': False}
     for host in hosts:
         hostname, _ = client._get_host_port_info(host)
         client._hosts_client[hostname].put.assert_called_with(
             '/local/stuff', '/remote/stuff', **expected_kwargs)
Ejemplo n.º 3
0
 def test_put(self):
     hosts = ["localhost", "127.0.0.1", "st2build001"]
     client = ParallelSSHClient(hosts=hosts,
                                user="******",
                                pkey_file="~/.ssh/id_rsa",
                                connect=True)
     client.put("/local/stuff", "/remote/stuff", mode=0o744)
     expected_kwargs = {"mode": 0o744, "mirror_local_mode": False}
     for host in hosts:
         hostname, _ = client._get_host_port_info(host)
         client._hosts_client[hostname].put.assert_called_with(
             "/local/stuff", "/remote/stuff", **expected_kwargs)
Ejemplo n.º 4
0
 def test_put(self):
     hosts = ['localhost', '127.0.0.1', 'st2build001']
     client = ParallelSSHClient(hosts=hosts,
                                user='******',
                                pkey_file='~/.ssh/id_rsa',
                                connect=True)
     client.put('/local/stuff', '/remote/stuff', mode=0o744)
     expected_kwargs = {
         'mode': 0o744,
         'mirror_local_mode': False
     }
     for host in hosts:
         hostname, _ = client._get_host_port_info(host)
         client._hosts_client[hostname].put.assert_called_with('/local/stuff', '/remote/stuff',
                                                               **expected_kwargs)