Seperate snapshoting from get_device in Disk class
authorNikos Skalkotos <skalkoto@grnet.gr>
Fri, 20 Apr 2012 08:29:59 +0000 (11:29 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Fri, 20 Apr 2012 08:29:59 +0000 (11:29 +0300)
image_creator/disk.py
image_creator/main.py

index 01ff41d..ef53799 100644 (file)
@@ -93,11 +93,9 @@ class Disk(object):
             job, args = self._cleanup_jobs.pop()
             job(*args)
 
             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)
         """
 
         output("Examining source media `%s'..." % self.source, False)
@@ -141,7 +139,12 @@ class Disk(object):
         finally:
             os.unlink(table)
         success('done')
         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
         self._devices.append(new_device)
         new_device.enable()
         return new_device
index 22fddf0..d073946 100755 (executable)
@@ -161,7 +161,9 @@ def image_creator():
 
     disk = Disk(options.source)
     try:
 
     disk = Disk(options.source)
     try:
-        dev = disk.get_device()
+        snapshot = disk.snapshot()
+
+        dev = disk.get_device(snapshot)
         dev.mount()
 
         osclass = get_os_class(dev.distro, dev.ostype)
         dev.mount()
 
         osclass = get_os_class(dev.distro, dev.ostype)
@@ -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:
             output("Uploading image to pithos...", False)
             kamaki = Kamaki(options.account, options.token)
         if options.upload:
             output("Uploading image to pithos...", False)
             kamaki = Kamaki(options.account, options.token)
-            kamaki.upload(dev.device, size, options.upload)
+            kamaki.upload(snapshot, size, options.upload)
             output("done")
 
     finally:
             output("done")
 
     finally: