Add {enable, disable}_guestfs methods in image cls
[snf-image-creator] / image_creator / os_type / unix.py
index 001c90d..8779b76 100644 (file)
@@ -35,8 +35,6 @@
 
 """This module hosts OS-specific code common to all Unix-like OSs."""
 
-import re
-
 from image_creator.os_type import OSBase, sysprep
 
 
@@ -55,7 +53,7 @@ class Unix(OSBase):
         """Return mountpoints in the correct order.
         / should be mounted before /boot or /usr, /usr befor /usr/bin ...
         """
-        mps = self.g.inspect_get_mountpoints(self.root)
+        mps = self.image.g.inspect_get_mountpoints(self.root)
 
         def compare(a, b):
             if len(a[0]) > len(b[0]):
@@ -77,7 +75,7 @@ class Unix(OSBase):
         mopts = 'ro' if readonly else 'rw'
         for mp, dev in self._mountpoints():
             try:
-                self.g.mount_options(mopts, dev, mp)
+                self.image.g.mount_options(mopts, dev, mp)
             except RuntimeError as msg:
                 if mp in critical_mpoints:
                     self.out.warn('unable to mount %s. Reason: %s' % (mp, msg))
@@ -87,69 +85,55 @@ class Unix(OSBase):
 
         return True
 
-    @sysprep()
-    def cleanup_cache(self, print_header=True):
+    @sysprep('Removing files under /var/cache')
+    def cleanup_cache(self):
         """Remove all regular files under /var/cache"""
 
-        if print_header:
-            self.out.output('Removing files under /var/cache')
-
-        self._foreach_file('/var/cache', self.g.rm, ftype='r')
+        self._foreach_file('/var/cache', self.image.g.rm, ftype='r')
 
-    @sysprep()
-    def cleanup_tmp(self, print_header=True):
+    @sysprep('Removing files under /tmp and /var/tmp')
+    def cleanup_tmp(self):
         """Remove all files under /tmp and /var/tmp"""
 
-        if print_header:
-            self.out.output('Removing files under /tmp and /var/tmp')
+        self._foreach_file('/tmp', self.image.g.rm_rf, maxdepth=1)
+        self._foreach_file('/var/tmp', self.image.g.rm_rf, maxdepth=1)
 
-        self._foreach_file('/tmp', self.g.rm_rf, maxdepth=1)
-        self._foreach_file('/var/tmp', self.g.rm_rf, maxdepth=1)
-
-    @sysprep()
-    def cleanup_log(self, print_header=True):
+    @sysprep('Emptying all files under /var/log')
+    def cleanup_log(self):
         """Empty all files under /var/log"""
 
-        if print_header:
-            self.out.output('Emptying all files under /var/log')
-
-        self._foreach_file('/var/log', self.g.truncate, ftype='r')
+        self._foreach_file('/var/log', self.image.g.truncate, ftype='r')
 
-    @sysprep(enabled=False)
-    def cleanup_mail(self, print_header=True):
+    @sysprep('Removing files under /var/mail & /var/spool/mail', enabled=False)
+    def cleanup_mail(self):
         """Remove all files under /var/mail and /var/spool/mail"""
 
-        if print_header:
-            self.out.output('Removing files under /var/mail & /var/spool/mail')
+        if self.image.g.is_dir('/var/spool/mail'):
+            self._foreach_file('/var/spool/mail', self.image.g.rm_rf,
+                               maxdepth=1)
 
-        if self.g.is_dir('/var/spool/mail'):
-            self._foreach_file('/var/spool/mail', self.g.rm_rf, maxdepth=1)
+        self._foreach_file('/var/mail', self.image.g.rm_rf, maxdepth=1)
 
-        self._foreach_file('/var/mail', self.g.rm_rf, maxdepth=1)
-
-    @sysprep()
-    def cleanup_userdata(self, print_header=True):
+    @sysprep('Removing sensitive user data')
+    def cleanup_userdata(self):
         """Delete sensitive userdata"""
 
         homedirs = ['/root']
-        if self.g.is_dir('/home/'):
+        if self.image.g.is_dir('/home/'):
             homedirs += self._ls('/home/')
 
-        if print_header:
-            self.out.output("Removing sensitive user data under %s" %
-                            " ".join(homedirs))
-
-        action = self.g.rm_rf
+        action = self.image.g.rm_rf
         if self._scrub_support:
-            action = self.g.scrub_file
+            action = self.image.g.scrub_file
         else:
             self.out.warn("Sensitive data won't be scrubbed (not supported)")
+
         for homedir in homedirs:
             for data in self.sensitive_userdata:
                 fname = "%s/%s" % (homedir, data)
-                if self.g.is_file(fname):
+                if self.image.g.is_file(fname):
                     action(fname)
-                elif self.g.is_dir(fname):
+                elif self.image.g.is_dir(fname):
                     self._foreach_file(fname, action, ftype='r')
 
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :