1651
1650
"virtual_size=%(virtual_size)d block_size=%(block_size)d"),
1654
with open(src_path, "r") as src:
1655
with open(dst_path, "w") as dst:
1656
data = src.read(min(block_size, left))
1658
if data == EMPTY_BLOCK:
1659
dst.seek(block_size, os.SEEK_CUR)
1661
bytes_read += block_size
1662
skipped_bytes += block_size
1665
data_len = len(data)
1667
bytes_read += data_len
1672
data = src.read(min(block_size, left))
1653
# NOTE(sirp): we need read/write access to the devices; since we don't have
1654
# the luxury of shelling out to a sudo'd command, we temporarily take
1655
# ownership of the devices.
1656
with utils.temporary_chown(src_path):
1657
with utils.temporary_chown(dst_path):
1658
with open(src_path, "r") as src:
1659
with open(dst_path, "w") as dst:
1660
data = src.read(min(block_size, left))
1662
if data == EMPTY_BLOCK:
1663
dst.seek(block_size, os.SEEK_CUR)
1665
bytes_read += block_size
1666
skipped_bytes += block_size
1669
data_len = len(data)
1671
bytes_read += data_len
1676
data = src.read(min(block_size, left))
1674
1678
duration = time.time() - start_time
1675
1679
compression_pct = float(skipped_bytes) / bytes_read * 100
1745
1749
"""Callback which runs with the image VDI attached"""
1746
1750
# NB: Partition 1 hardcoded
1747
1751
dev_path = utils.make_dev_path(device, partition=1)
1748
tmpdir = tempfile.mkdtemp()
1752
with utils.tempdir() as tmpdir:
1750
1753
# Mount only Linux filesystems, to avoid disturbing NTFS images
1751
1754
err = _mount_filesystem(dev_path, tmpdir)
1766
1769
LOG.info(_('Failed to mount filesystem (expected for '
1767
1770
'non-linux instances): %s') % err)
1769
# remove temporary directory
1773
1773
def _prepare_injectables(inst, networks_info):