os.close(cowfd)
self._add_cleanup(os.unlink, cow)
# Create 1G cow sparse file
- dd('if=/dev/null', 'of=%s' % cow, 'bs=1k', \
- 'seek=%d' % (1024 * 1024))
+ dd('if=/dev/null', 'of=%s' % cow, 'bs=1k', 'seek=%d' % (1024 * 1024))
cowdev = self._losetup(cow)
snapshot = uuid.uuid4().hex
last_partition = self.g.part_list(self.guestfs_device)[-1]
- if last_partition['part_num'] > 4:
+ if self.parttype == 'msdos' and last_partition['part_num'] > 4:
raise FatalError("This disk contains logical partitions. "
- "Only primary partitions are supported.")
+ "Only primary partitions are supported.")
part_dev = "%s%d" % (self.guestfs_device, last_partition['part_num'])
fs_type = self.g.vfs_type(part_dev)
if not re.match("ext[234]", fs_type):
- warn("Don't know how to resize %s partitions." % vfs_type)
- return self.size()
+ warn("Don't know how to resize %s partitions." % fs_type)
+ return self.size
self.g.e2fsck_f(part_dev)
self.g.resize2fs_M(part_dev)
self.g.part_add(self.guestfs_device, 'p', start, end)
self.size = (end + 1) * sector_size
- success("new image size is %dMB" %
- ((self.size + 2 ** 20 - 1) // 2 ** 20))
+ success("new size is %dMB" % ((self.size + 2 ** 20 - 1) // 2 ** 20))
if self.parttype == 'gpt':
ptable = GPTPartitionTable(self.real_device)
progress_size = (self.size + 2 ** 20 - 1) // 2 ** 20 # in MB
progressbar = progress("Dumping image file: ", 'mb')
progressbar.max = progress_size
- with open(self.real_device, 'r') as source:
- with open(outfile, "w") as dest:
+
+ with open(self.real_device, 'r') as src:
+ with open(outfile, "w") as dst:
left = self.size
offset = 0
progressbar.next()
while left > 0:
length = min(left, blocksize)
- sent = sendfile(dest.fileno(), source.fileno(), offset,
- length)
+ sent = sendfile(dst.fileno(), src.fileno(), offset, length)
offset += sent
left -= sent
progressbar.goto((self.size - left) // 2 ** 20)