job, args = self._cleanup_jobs.pop()
job(*args)
- def get_device(self):
- """Returns a newly created DiskDevice instance.
-
- This instance is a snapshot of the original source media of
- the Disk instance.
+ def snapshot(self):
+ """Creates a snapshot of the original source media of the Disk
+ instance.
"""
output("Examining source media `%s'..." % self.source, False)
finally:
os.unlink(table)
success('done')
- new_device = DiskDevice("/dev/mapper/%s" % snapshot)
+ return "/dev/mapper/%s" % snapshot
+
+ def get_device(self, media):
+ """Returns a newly created DiskDevice instance."""
+
+ new_device = DiskDevice(media)
self._devices.append(new_device)
new_device.enable()
return new_device
def enable(self):
"""Enable a newly created DiskDevice"""
- self.progressbar = progress("Launching helper VM: ")
- self.progressbar.next()
+ self.progressbar = progress("Launching helper VM: ", "percent")
+ self.progressbar.max = 100
+ self.progressbar.goto(1)
eh = self.g.set_event_callback(self.progress_callback,
guestfs.EVENT_PROGRESS)
self.g.launch()
self.guestfs_enabled = True
self.g.delete_event_callback(eh)
if self.progressbar is not None:
- self.progressbar.send(100)
+ output("\rLaunching helper VM...\033[K", False)
+ success("done")
self.progressbar = None
output('Inspecting Operating System...', False)
self.root = roots[0]
self.ostype = self.g.inspect_get_type(self.root)
self.distro = self.g.inspect_get_distro(self.root)
- success('found a %s system' % self.distro)
+ success('found a(n) %s system' % self.distro)
def destroy(self):
"""Destroy this DiskDevice instance."""
position = array[2]
total = array[3]
- self.progressbar.send((position * 100) // total)
-
- if position == total:
- self.progressbar = None
+ self.progressbar.goto((position * 100) // total)
def mount(self):
"""Mount all disk partitions in a correct order."""
self.g.e2fsck_f(part_dev)
self.g.resize2fs_M(part_dev)
- output = self.g.tune2fs_l(part_dev)
+ out = self.g.tune2fs_l(part_dev)
block_size = int(
- filter(lambda x: x[0] == 'Block size', output)[0][1])
+ filter(lambda x: x[0] == 'Block size', out)[0][1])
block_cnt = int(
- filter(lambda x: x[0] == 'Block count', output)[0][1])
+ filter(lambda x: x[0] == 'Block count', out)[0][1])
sector_size = self.g.blockdev_getss(dev)
blocksize = 2 ** 22 # 4MB
size = self.size()
progress_size = (size + 2 ** 20 - 1) // 2 ** 20 # in MB
- progressbar = progress("Dumping image file: ", progress_size)
-
+ progressbar = progress("Dumping image file: ", 'mb')
+ progressbar.max = progress_size
source = open(self.device, "r")
try:
dest = open(outfile, "w")
length)
offset += sent
left -= sent
- for i in range((length + 2 ** 20 - 1) // 2 ** 20):
- progressbar.next()
+ progressbar.goto((size - left) // 2 ** 20)
finally:
dest.close()
finally:
source.close()
-
- success('Image file %s was successfully created' % outfile)
+ output("\rDumping image file...\033[K", False)
+ success('image file %s was successfully created' % outfile)
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :