Seperate snapshoting from get_device in Disk class
[snf-image-creator] / image_creator / disk.py
index 6b69aad..ef53799 100644 (file)
@@ -32,8 +32,7 @@
 # or implied, of GRNET S.A.
 
 from image_creator.util import get_command
-from image_creator.util import warn, progress, success, output
-from image_creator import FatalError
+from image_creator.util import warn, progress, success, output, FatalError
 
 import stat
 import os
@@ -94,11 +93,9 @@ class Disk(object):
             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)
@@ -142,7 +139,12 @@ class Disk(object):
         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
@@ -276,11 +278,11 @@ class DiskDevice(object):
         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)