def transfer(self, data): src_host = data['host_src'] src_path = data['path_src'] dst_host = data['host_dst'] dst_path = data['path_dst'] src_runner = self.runner(src_host, 'src') dst_runner = self.runner(dst_host, 'dst') block_size = CONF.migrate.ssh_chunk_size file_size = files.remote_file_size_mb(src_runner, src_path) num_blocks = int(math.ceil(float(file_size) / block_size)) src_temp_dir = os.path.join(os.path.basename(src_path), '.cf.copy') dst_temp_dir = os.path.join(os.path.basename(dst_path), '.cf.copy') partial_files = [] with files.RemoteDir(src_runner, src_temp_dir) as src_temp, \ files.RemoteDir(dst_runner, dst_temp_dir) as dst_temp: for i in xrange(num_blocks): part = os.path.basename(src_path) + '.part{i}'.format(i=i) part_path = os.path.join(src_temp.dirname, part) files.remote_split_file(src_runner, src_path, part_path, i, block_size) gzipped_path = files.remote_gzip(src_runner, part_path) gzipped_filename = os.path.basename(gzipped_path) dst_gzipped_path = os.path.join(dst_temp.dirname, gzipped_filename) self.run_scp(src_runner, gzipped_path, dst_host, dst_gzipped_path) files.remote_unzip(dst_runner, dst_gzipped_path) partial_files.append(os.path.join(dst_temp.dirname, part)) for i in xrange(num_blocks): files.remote_join_file(dst_runner, dst_path, partial_files[i], i, block_size) if not self.verify(data): self.clean_dst(data) raise base.FileCopyError(**data)
def transfer(self, data): src_host = data['host_src'] src_path = data['path_src'] dst_host = data['host_dst'] dst_path = data['path_dst'] src_user = self.cfg.src.ssh_user dst_user = self.cfg.dst.ssh_user block_size = self.cfg.migrate.ssh_chunk_size num_retries = self.cfg.migrate.retry src_password = self.cfg.src.ssh_sudo_password dst_password = self.cfg.dst.ssh_sudo_password src_runner = remote_runner.RemoteRunner(src_host, src_user, password=src_password, sudo=True) dst_runner = remote_runner.RemoteRunner(dst_host, dst_user, password=dst_password, sudo=True) file_size = files.remote_file_size_mb(src_runner, src_path) partial_files = [] src_md5 = remote_md5_sum(src_runner, src_path) num_blocks = int(math.ceil(float(file_size) / block_size)) src_temp_dir = os.path.join(os.path.basename(src_path), '.cf.copy') dst_temp_dir = os.path.join(os.path.basename(dst_path), '.cf.copy') with files.RemoteDir(src_runner, src_temp_dir) as src_temp, \ files.RemoteDir(dst_runner, dst_temp_dir) as dst_temp: for i in xrange(num_blocks): part = os.path.basename(src_path) + '.part{i}'.format(i=i) part_path = os.path.join(src_temp.dirname, part) remote_split_file(src_runner, src_path, part_path, i, block_size) gzipped_path = remote_gzip(src_runner, part_path) gzipped_filename = os.path.basename(gzipped_path) dst_gzipped_path = os.path.join(dst_temp.dirname, gzipped_filename) verified_file_copy(src_runner, dst_runner, dst_user, gzipped_path, dst_gzipped_path, dst_host, num_retries) remote_unzip(dst_runner, dst_gzipped_path) partial_files.append(os.path.join(dst_temp.dirname, part)) for i in xrange(num_blocks): remote_join_file(dst_runner, dst_path, partial_files[i], i, block_size) dst_md5 = remote_md5_sum(dst_runner, dst_path) if src_md5 != dst_md5: message = ("Error copying file from '{src_host}:{src_file}' " "to '{dst_host}:{dst_file}'").format( src_file=src_path, src_host=src_host, dst_file=dst_path, dst_host=dst_host) LOG.error(message) remote_rm_file(dst_runner, dst_path) raise FileCopyFailure(message)