Skip to content
Snippets Groups Projects
Commit e22aa3a9 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Seperate snapshoting from get_device in Disk class

parent 997ac76a
No related branches found
No related tags found
No related merge requests found
...@@ -93,11 +93,9 @@ class Disk(object): ...@@ -93,11 +93,9 @@ class Disk(object):
job, args = self._cleanup_jobs.pop() job, args = self._cleanup_jobs.pop()
job(*args) job(*args)
def get_device(self): def snapshot(self):
"""Returns a newly created DiskDevice instance. """Creates a snapshot of the original source media of the Disk
instance.
This instance is a snapshot of the original source media of
the Disk instance.
""" """
output("Examining source media `%s'..." % self.source, False) output("Examining source media `%s'..." % self.source, False)
...@@ -141,7 +139,12 @@ class Disk(object): ...@@ -141,7 +139,12 @@ class Disk(object):
finally: finally:
os.unlink(table) os.unlink(table)
success('done') 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) self._devices.append(new_device)
new_device.enable() new_device.enable()
return new_device return new_device
......
...@@ -161,7 +161,9 @@ def image_creator(): ...@@ -161,7 +161,9 @@ def image_creator():
disk = Disk(options.source) disk = Disk(options.source)
try: try:
dev = disk.get_device() snapshot = disk.snapshot()
dev = disk.get_device(snapshot)
dev.mount() dev.mount()
osclass = get_os_class(dev.distro, dev.ostype) osclass = get_os_class(dev.distro, dev.ostype)
...@@ -201,10 +203,13 @@ def image_creator(): ...@@ -201,10 +203,13 @@ def image_creator():
dev.dump(options.outfile) dev.dump(options.outfile)
# Destroy the device. We only need the snapshot from now on
disk.destroy_device(dev)
if options.upload: if options.upload:
output("Uploading image to pithos...", False) output("Uploading image to pithos...", False)
kamaki = Kamaki(options.account, options.token) kamaki = Kamaki(options.account, options.token)
kamaki.upload(dev.device, size, options.upload) kamaki.upload(snapshot, size, options.upload)
output("done") output("done")
finally: finally:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment