当前位置: 首页>>代码示例>>Python>>正文


Python ParallelSSHClient.copy_file方法代码示例

本文整理汇总了Python中pssh.ParallelSSHClient.copy_file方法的典型用法代码示例。如果您正苦于以下问题:Python ParallelSSHClient.copy_file方法的具体用法?Python ParallelSSHClient.copy_file怎么用?Python ParallelSSHClient.copy_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pssh.ParallelSSHClient的用法示例。


在下文中一共展示了ParallelSSHClient.copy_file方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_pssh_client_copy_file_failure

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import copy_file [as 别名]
 def test_pssh_client_copy_file_failure(self):
     """Test failure scenarios of file copy"""
     test_file_data = 'test'
     local_test_path = 'directory_test'
     remote_test_path = 'directory_test_copied'
     for path in [local_test_path, remote_test_path]:
         mask = int('0700') if sys.version_info <= (2,) else 0o700
         if os.path.isdir(path):
             os.chmod(path, mask)
         for root, dirs, files in os.walk(path):
             os.chmod(root, mask)
             for _path in files + dirs:
                 os.chmod(os.path.join(root, _path), mask)
         try:
             shutil.rmtree(path)
         except OSError:
             pass
     os.mkdir(local_test_path)
     os.mkdir(remote_test_path)
     local_file_path = os.path.join(local_test_path, 'test_file')
     remote_file_path = os.path.join(remote_test_path, 'test_file')
     test_file = open(local_file_path, 'w')
     test_file.write('testing\n')
     test_file.close()
     # Permission errors on writing into dir
     mask = 0111 if sys.version_info <= (2,) else 0o111
     os.chmod(remote_test_path, mask)
     client = ParallelSSHClient([self.host], port=self.listen_port,
                                pkey=self.user_key)
     cmds = client.copy_file(local_test_path, remote_test_path, recurse=True)
     for cmd in cmds:
         try:
             cmd.get()
             raise Exception("Expected IOError exception, got none")
         except IOError:
             pass
     self.assertFalse(os.path.isfile(remote_file_path))
     # Create directory tree failure test
     local_file_path = os.path.join(local_test_path, 'test_file')
     remote_file_path = os.path.join(remote_test_path, 'test_dir', 'test_file')
     cmds = client.copy_file(local_file_path, remote_file_path, recurse=True)
     for cmd in cmds:
         try:
             cmd.get()
             raise Exception("Expected IOError exception on creating remote "
                             "directory, got none")
         except IOError:
             pass
     self.assertFalse(os.path.isfile(remote_file_path))
     mask = int('0600') if sys.version_info <= (2,) else 0o600
     os.chmod(remote_test_path, mask)
     for path in [local_test_path, remote_test_path]:
         shutil.rmtree(path)
开发者ID:,项目名称:,代码行数:55,代码来源:

示例2: test_pssh_client_directory

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import copy_file [as 别名]
 def test_pssh_client_directory(self):
     """Tests copying directories with SSH client. Copy all the files from
     local directory to server, then make sure they are all present."""
     test_file_data = 'test'
     local_test_path = 'directory_test'
     remote_test_path = 'directory_test_copied'
     for path in [local_test_path, remote_test_path]:
         try:
             shutil.rmtree(path)
         except OSError:
             pass
     os.mkdir(local_test_path)
     remote_file_paths = []
     for i in range(0, 10):
         local_file_path = os.path.join(local_test_path, 'foo' + str(i))
         remote_file_path = os.path.join(remote_test_path, 'foo' + str(i))
         remote_file_paths.append(remote_file_path)
         test_file = open(local_file_path, 'w')
         test_file.write(test_file_data)
         test_file.close()
     client = ParallelSSHClient([self.host], port=self.listen_port,
                                pkey=self.user_key)
     cmds = client.copy_file(local_test_path, remote_test_path, recurse=True)
     for cmd in cmds:
         cmd.get()
     for path in remote_file_paths:
         self.assertTrue(os.path.isfile(path))
     shutil.rmtree(local_test_path)
     shutil.rmtree(remote_test_path)
开发者ID:bentsi,项目名称:parallel-ssh,代码行数:31,代码来源:test_pssh_client.py

示例3: test_parallel

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import copy_file [as 别名]
def test_parallel():
    """Perform ls and copy file with ParallelSSHClient on localhost"""
    client = ParallelSSHClient(['localhost'])
    cmds = client.exec_command('ls -ltrh')
    output = [client.get_stdout(cmd, return_buffers=True) for cmd in cmds]
    print output
    cmds = client.copy_file('../test', 'test_dir/test')
    client.pool.join()
开发者ID:oceanhliu,项目名称:parallel-ssh,代码行数:10,代码来源:pssh_local.py

示例4: main

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import copy_file [as 别名]
def main():
    # cleanup just in case
    kill()

    # create new droplet and wait for it
    droplet = start()['droplet']
    print droplet

    while True:
        droplet = lookup(droplet['id'])

        # status
        s = droplet['status']
        assert(s in ['active', 'new'])

        # addr
        ip = None
        for addr in droplet["networks"]["v4"]:
            if addr["type"] == "public":
                ip = addr["ip_address"]
        
        print 'STATUS: %s, IP: %s' % (str(s), str(ip))
        if s == 'active' and ip != None:
            break

        time.sleep(3)

    hosts = [ip]
    client = ParallelSSHClient(hosts)

    client.copy_file('./test.sh', '/tmp/test.sh')

    url = 'https://raw.githubusercontent.com/open-lambda/open-lambda/master/testing/digitalocean/test.sh'
    output = client.run_command('wget %s; bash test.sh' % url, sudo=True)
    output = output.values()[0]
    for l in output["stdout"]:
        print l
    for l in output["stderr"]:
        print l

    # make sure we cleanup everything!
    kill()
开发者ID:sherlockwu,项目名称:open-lambda,代码行数:44,代码来源:test.py

示例5: test_sftp_exceptions

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import copy_file [as 别名]
 def test_sftp_exceptions(self):
     self.server.kill()
     # Make socket with no server listening on it on separate ip
     host = '127.0.0.3'
     _socket = make_socket(host)
     port = _socket.getsockname()[1]
     client = ParallelSSHClient([self.host], port=port, num_retries=1)
     cmds = client.copy_file("test", "test")
     client.pool.join()
     for cmd in cmds:
         self.assertRaises(ConnectionErrorException, cmd.get)
开发者ID:,项目名称:,代码行数:13,代码来源:

示例6: test_pssh_copy_file

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import copy_file [as 别名]
 def test_pssh_copy_file(self):
     """Test parallel copy file"""
     test_file_data = "test"
     local_filename = "test_file"
     remote_test_dir, remote_filename = "remote_test_dir", "test_file_copy"
     remote_filename = os.path.sep.join([remote_test_dir, remote_filename])
     test_file = open(local_filename, "w")
     test_file.writelines([test_file_data + os.linesep])
     test_file.close()
     client = ParallelSSHClient([self.host], port=self.listen_port, pkey=self.user_key)
     cmds = client.copy_file(local_filename, remote_filename)
     cmds[0].get()
     self.assertTrue(os.path.isdir(remote_test_dir), msg="SFTP create remote directory failed")
     self.assertTrue(os.path.isfile(remote_filename), msg="SFTP copy failed")
     for filepath in [local_filename, remote_filename]:
         os.unlink(filepath)
     del client
开发者ID:hokadiri,项目名称:parallel-ssh,代码行数:19,代码来源:test_pssh_client.py

示例7: test_parallel

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import copy_file [as 别名]
def test_parallel():
    """Perform ls and copy file with ParallelSSHClient on localhost.
    
    Two identical hosts cause the same command to be executed
    twice on the same host in two parallel connections.
    In printed output there will be two identical lines per printed per
    line of `ls -ltrh` output as output is printed by host_logger as it
    becomes available and commands are executed in parallel
    
    Host output key is de-duplicated so that output for the two
    commands run on the same host(s) is not lost
    """
    client = ParallelSSHClient(['localhost', 'localhost'])
    output = client.run_command('ls -ltrh')
    client.join(output)
    pprint(output)
    cmds = client.copy_file('../test', 'test_dir/test')
    client.pool.join()
开发者ID:UniqueLJH,项目名称:parallel-ssh,代码行数:20,代码来源:pssh_local.py

示例8: test_pssh_copy_file

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import copy_file [as 别名]
 def test_pssh_copy_file(self):
     """Test parallel copy file"""
     test_file_data = 'test'
     local_filename = 'test_file'
     remote_test_dir, remote_filename = 'remote_test_dir', 'test_file_copy'
     remote_filename = os.path.sep.join([remote_test_dir, remote_filename])
     test_file = open(local_filename, 'w')
     test_file.writelines([test_file_data + os.linesep])
     test_file.close()
     server = start_server({ self.fake_cmd : self.fake_resp },
                           self.listen_socket)
     client = ParallelSSHClient(['127.0.0.1'], port=self.listen_port,
                                pkey=self.user_key)
     cmds = client.copy_file(local_filename, remote_filename)
     cmds[0].get()
     self.assertTrue(os.path.isdir(remote_test_dir),
                     msg="SFTP create remote directory failed")
     self.assertTrue(os.path.isfile(remote_filename),
                     msg="SFTP copy failed")
     for filepath in [local_filename, remote_filename]:
         os.unlink(filepath)
     del client
     server.join()
开发者ID:oceanhliu,项目名称:parallel-ssh,代码行数:25,代码来源:test_pssh_client.py

示例9: SetupMultiVM

# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import copy_file [as 别名]
class SetupMultiVM(object):
    """
    Initiate parallel ssh connection and add basic methods like:
    file display, delete, execute, copy etc..
    """

    def __init__(self, hosts, args):
        self.hosts = hosts
        self.client = ParallelSSHClient(hosts, user=args['VM_LOGIN_USER'])
        self.ROOT_DIR = args['MULTIVM_ROOT_DIR']
        self.AIO_MODE = args['AIO_MODE']
        self.SCRIPT_NAMES = '{%s}' % ','.join(args['SCRIPT_NAMES'])
        self.UTIL_NAMES = '{%s}' % ','.join(args['UTIL_NAMES'])
        self.FILENAMES = ','.join(args['SCRIPT_NAMES'] + args['UTIL_NAMES'])

    def display_files(self, msg=''):
        print("\n%s\n" % msg)
        output = self.client.run_command('ls -lh ' + os.path.join(self.ROOT_DIR,
                                                        '{%s}' % self.FILENAMES))
        self.client.get_exit_codes(output)
        for host in self.hosts:
            print("host: %s -- exit_code: %s" %(host, output[host]['exit_code']))
            for line in output[host]['stdout']: print line
            print

    def make_executable(self):
        print("changing mode +x for all scripts..\n")
        output = self.client.run_command('chmod +x %s' %
                                            os.path.join(self.ROOT_DIR,
                                            self.SCRIPT_NAMES))
        self.client.get_exit_codes(output)
        for host in self.hosts:
            print("host: %s -- exit_code: %s" %(host, output[host]['exit_code']))
            try:
                for line in output[host]['stdout']: print line
            except:
                pass

    def copy_files(self):
        print("\ncopying files to VMs..\n")
        for filename in self.FILENAMES.split(','):
            self.client.copy_file('./%s' % (filename),
                            os.path.join(self.ROOT_DIR, '%s' % (filename)))
        # additionally copy the config file to /etc
        self.client.copy_file('./multivm.config', '/etc/multivm.config')
        # join pool and execute copy commands
        self.client.pool.join()

    def delete_files(self):
        print("\ndeleting existing files..\n")
        output = self.client.run_command('rm -f %s' %
                                            os.path.join(self.ROOT_DIR,
                                            '{%s}' % self.FILENAMES))
        self.client.get_exit_codes(output)
        for host in self.hosts:
            print("host: %s -- exit_code: %s" %(host, output[host]['exit_code']))

    def record_output(self, generator_object, vm_hostname, script_name):
        log_file = '/tmp/%s.%s.%s.log' % (self.AIO_MODE, vm_hostname, script_name)
        f = open(log_file, 'wb')
        print("Hold on.. Logging VM outputs to your host under: %s" % log_file)
        for line in generator_object:
            f.write(line.encode('utf-8') + "\n")
        f.close()

    def execute_script(self, script_name=None, script_args='', nohup=False):
        script_path =  os.path.join(self.ROOT_DIR, script_name)
        print("\nexecuting script: '%s %s'..\n" % (script_path, script_args))
        if nohup:
            CMD = 'nohup  %s %s > /tmp/%s.out 2> /tmp/%s.err < /dev/null &' % \
                            (script_path, script_args, script_name, script_name)
        else:
            CMD = '%s %s' % (script_path, script_args)

        output = self.client.run_command(CMD)
        self.client.get_exit_codes(output)
        for host in self.hosts:
            print("host: %s -- exit_code: %s" %(host, output[host]['exit_code']))
            # for line in output[host]['stdout']: print line
            self.record_output(output[host]['stdout'], host, script_name)
开发者ID:arcolife,项目名称:multivm_db_bench,代码行数:82,代码来源:multivm_setup_initiate.py


注:本文中的pssh.ParallelSSHClient.copy_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。