Add diagnose() method in OSBase derived classes
[snf-image-creator] / image_creator / image.py
index 2eb97dd..bbc53ae 100644 (file)
@@ -95,23 +95,19 @@ class Image(object):
             self.distro = "unsupported"
             self.guestfs_device = '/dev/sda'
             self.size = self.g.blockdev_getsize64(self.guestfs_device)
+
             if len(roots) > 1:
-                self.unsupported = "Multiple operating systems found on the " \
-                    "media. We only support images with one OS."
+                reason = "Multiple operating systems found on the media."
             else:
-                self.unsupported = \
-                    "Unable to detect any operating system on the media"
+                reason = "Unable to detect any operating system on the media."
 
-            self.meta['UNSUPPORTED'] = "Reason: %s" % self.unsupported
-            self.out.warn('Media is not supported. %s' %
-                          self.meta['UNSUPPORTED'])
+            self.set_unsupported(reason)
             return
 
         self.root = roots[0]
-        self.guestfs_device = self.g.part_to_dev(self.root)
+        self.meta['PARTITION_TABLE'] = self.g.part_get_parttype('/dev/sda')
+        self.guestfs_device = '/dev/sda'  # self.g.part_to_dev(self.root)
         self.size = self.g.blockdev_getsize64(self.guestfs_device)
-        self.meta['PARTITION_TABLE'] = \
-            self.g.part_get_parttype(self.guestfs_device)
 
         self.ostype = self.g.inspect_get_type(self.root)
         self.distro = self.g.inspect_get_distro(self.root)
@@ -119,6 +115,20 @@ class Image(object):
             'found a(n) %s system' %
             self.ostype if self.distro == "unknown" else self.distro)
 
+        # Run OS-specific diagnostics
+        self.os.diagnose()
+
+    def set_unsupported(self, reason):
+        """Flag this image us ansupported"""
+
+        self._unsupported = reason
+        self.meta['UNSUPPORTED'] = reason
+        self.out.warn('Media is not supported. Reason: %s' % reason)
+
+    def is_unsupported(self):
+        """Returns if this image is unsupported"""
+        return hasattr(self, '_unsupported')
+
     def enable_guestfs(self):
         """Enable the guestfs handler"""
 
@@ -278,8 +288,8 @@ class Image(object):
 
         self.out.output("Shrinking image (this may take a while) ...", False)
 
-        if hasattr(self, "unsupported"):
-            self.out.warn("Unable to shrink unsupported image")
+        if self.is_unsupported():
+            self.out.warn("Shrinking is disabled for unsupported images")
             return self.size
 
         sector_size = self.g.blockdev_getss(self.guestfs_device)