def restore_image(self, image_id, host, filename): """ Processing image file: copy from source to destination, create glance image :param image_id: image ID from source :param image_host: host of image from source :param diff: diff file of root disk for instance :return: new image if image is created """ LOG.debug('Processing an image %s from host %s and filename %s', image_id, host, filename) image_file_info = self.src_cloud.qemu_img.get_info(filename, host) image_resource = self.dst_cloud.resources[utils.IMAGE_RESOURCE] runner = remote_runner.RemoteRunner(host, self.cfg.src.ssh_user, self.cfg.src.ssh_sudo_password, True) file_size = files.remote_file_size(runner, filename) with files.RemoteStdout( host, self.cfg.src.ssh_user, 'dd if={filename}', filename=image_file_info.backing_filename) as f: fp = file_proxy.FileProxy(f.stdout, name='image %s' % image_id, size=file_size) new_image = image_resource.create_image( id=image_id, name='restored image %s from host %s' % (image_id, host), container_format='bare', disk_format=image_file_info.format, is_public=True, data=fp) return new_image
def copy(self, context, source_object, destination_object): src_user = context.cfg.src.ssh_user dst_user = context.cfg.dst.ssh_user src_host = source_object.host dst_host = destination_object.host rr = remote_runner.RemoteRunner(src_host, src_user) ssh_opts = ('-o UserKnownHostsFile=/dev/null ' '-o StrictHostKeyChecking=no') try: progress_view = "" if files.is_installed(rr, "pv"): src_file_size = files.remote_file_size(rr, source_object.path) progress_view = "pv --size {size} --progress | ".format( size=src_file_size) copy = ("dd if={src_file} | {progress_view} " "ssh {ssh_opts} {dst_user}@{dst_host} " "'dd of={dst_device}'") rr.run(copy.format(src_file=source_object.path, dst_user=dst_user, dst_host=dst_host, ssh_opts=ssh_opts, dst_device=destination_object.path, progress_view=progress_view)) except remote_runner.RemoteExecutionError as e: msg = "Cannot copy {src_object} to {dst_object}: {error}" msg = msg.format(src_object=source_object, dst_object=destination_object, error=e.message) raise CopyFailed(msg)
def copy(self, context, source_object, destination_object): src_user = context.cfg.src.ssh_user dst_user = context.cfg.dst.ssh_user src_host = source_object.host dst_host = destination_object.host rr = remote_runner.RemoteRunner(src_host, src_user) ssh_opts = ('-o UserKnownHostsFile=/dev/null ' '-o StrictHostKeyChecking=no') try: progress_view = "" if files.is_installed(rr, "pv"): src_file_size = files.remote_file_size(rr, source_object.path) progress_view = "pv --size {size} --progress | ".format( size=src_file_size) copy = ("dd if={src_file} | {progress_view} " "ssh {ssh_opts} {dst_user}@{dst_host} " "'dd of={dst_device}'") rr.run( copy.format(src_file=source_object.path, dst_user=dst_user, dst_host=dst_host, ssh_opts=ssh_opts, dst_device=destination_object.path, progress_view=progress_view)) except remote_runner.RemoteExecutionError as e: msg = "Cannot copy {src_object} to {dst_object}: {error}" msg = msg.format(src_object=source_object, dst_object=destination_object, error=e.message) raise CopyFailed(msg)
def volume_size(self, cloud, path): """ Get size of vol_file in bytes. :return: int """ runner = _remote_runner(cloud) return files.remote_file_size(runner, path)
def verify(self, data): """ Verification that the file has been copied correctly. :param data: The dictionary with necessary information :return: True or False """ 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') src_size = files.remote_file_size(src_runner, src_path) dst_size = files.remote_file_size(dst_runner, dst_path) if src_size != dst_size: LOG.warning("The sizes of '%s' (%s) and '%s' (%s) are mismatch", src_path, sizeof_format.sizeof_fmt(src_size), dst_path, sizeof_format.sizeof_fmt(dst_size)) return False if CONF.migrate.copy_with_md5_verification: LOG.info("Running md5 checksum calculation on the file '%s' with " "size %s on host '%s'", src_path, sizeof_format.sizeof_fmt(src_size), src_host) src_md5 = files.remote_md5_sum(src_runner, src_path) LOG.info("Running md5 checksum calculation on the file '%s' with " "size %s on host '%s'", dst_path, sizeof_format.sizeof_fmt(dst_size), dst_host) dst_md5 = files.remote_md5_sum(dst_runner, dst_path) if src_md5 != dst_md5: LOG.warning("The md5 checksums of '%s' (%s) and '%s' (%s) are " "mismatch", src_path, src_md5, dst_path, dst_md5) return False return True