Example #1
0
 def detect_fs_type(self, path):
     try:
         for line in open("/etc/mtab"):
             fields = line.split(' ')
             if (len(fields) >= 3) and (fields[1] == path):
                 return fields[2]
     except Exception, e:
         log.warning("Could not detect filesystem type for %s\n%s" % (path, e))
Example #2
0
    def _snapshot_system(self, start_fresh=False, verbose=False, clean=False):
        exists = self.image_exists()
        if clean:
            log.info("Cleaning existing snapshot first.")
            start_fresh=True
        elif not exists:
            log.info("No existing image found, creating a new one")
            start_fresh=True
        elif exists:
            log.info("Existing image found, attempting to use.")
            image_stats = self.stat(self.imagepath)
            log.debug("Image stats:\n%s" % (image_stats))
            if self.imagesize:
                # requested size does not match current size
                if self.imagesize != image_stats['size']:
                    log.warning("Requested size (%d) does not match current file (%d).  Starting from scratch." % (self.imagesize, image_stats['size']))
                    start_fresh = True
            else:
                # image size does not match partition size
                if image_stats['size'] != self.statvfs()['size']:
                    log.warning("Root partition size does not match image size.  Starting from scratch")
                    start_fresh = True

        if start_fresh:
            # makesure image is unmounted, then destroy and recreate image.
            log.info("Unmounting Image")
            self.umount_image()
            log.info("Destroying old files")
            self.destroy_files(self.imagepath, self.mountpoint)
            log.info("Creating new image")
            self.create_image(self.imagepath, self.imagesize)

 

        try:
            log.info("Syncing file system")
            self.mount_image()
            self.sync_fs(verbose)
            self.umount_image()
        except ImageUtilError, e:
            # Cleanup after failed sync
            self.umount_image()
            self.destroy_files(self.imagepath, self.mountpoint)
            raise e