Merge branch 'develop'
[snf-image-creator] / image_creator / os_type / __init__.py
index 5298569..ce84130 100644 (file)
@@ -144,6 +144,22 @@ class OSBase(object):
         except RuntimeError:
             self._scrub_support = False
 
+    def inspect(self):
+        """Inspect the media to check if it is supported"""
+
+        if self.image.is_unsupported():
+            return
+
+        self.out.output('Running OS inspection:')
+        try:
+            if not self.mount(readonly=True):
+                raise FatalError("Unable to mount the media read-only")
+            self._do_inspect()
+        finally:
+            self.umount()
+
+        self.out.output()
+
     def collect_metadata(self):
         """Collect metadata about the OS"""
         try:
@@ -239,7 +255,7 @@ class OSBase(object):
             return
 
         for name, param in self.needed_sysprep_params.items():
-            self.out.output("\t%s (%s): %s" %
+            self.out.output("\t%s [%s]: %s" %
                             (param.description, name,
                              self.sysprep_params[name] if name in
                              self.sysprep_params else "(none)"))
@@ -247,12 +263,17 @@ class OSBase(object):
     def do_sysprep(self):
         """Prepare system for image creation."""
 
+        self.out.output('Preparing system for image creation:')
+
+        if self.image.is_unsupported():
+            self.out.warn(
+                "System preparation is disabled for unsupported media")
+            return
+
         try:
             if not self.mount(readonly=False):
                 raise FatalError("Unable to mount the media read-write")
 
-            self.out.output('Preparing system for image creation:')
-
             enabled = [task for task in self.list_syspreps() if task.enabled]
 
             size = len(enabled)
@@ -351,10 +372,20 @@ class OSBase(object):
             if has_ftype(f, ftype):
                 action(full_path)
 
+    def _do_inspect(self):
+        """helper method for inspect"""
+        pass
+
     def _do_collect_metadata(self):
         """helper method for collect_metadata"""
-        self.meta['ROOT_PARTITION'] = \
-            "%d" % self.image.g.part_to_partnum(self.root)
+
+        try:
+            self.meta['ROOT_PARTITION'] = \
+                "%d" % self.image.g.part_to_partnum(self.root)
+        except RuntimeError:
+            self.out.warn("Unable to identify the partition number from root "
+                          "partition: %s" % self.root)
+
         self.meta['OSFAMILY'] = self.image.g.inspect_get_type(self.root)
         self.meta['OS'] = self.image.g.inspect_get_distro(self.root)
         if self.meta['OS'] == "unknown":