+ self.guestfs_enabled = False
+
+ def enable(self):
+ """Enable a newly created Image instance"""
+
+ self.enable_guestfs()
+
+ self.out.output('Inspecting Operating System ...', False)
+ roots = self.g.inspect_os()
+ if len(roots) == 0:
+ raise FatalError("No operating system found")
+ if len(roots) > 1:
+ raise FatalError("Multiple operating systems found."
+ "We only support images with one OS.")
+ self.root = roots[0]
+ self.guestfs_device = 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)
+ self.out.success(
+ 'found a(n) %s system' %
+ self.ostype if self.distro == "unknown" else self.distro)
+
+ def enable_guestfs(self):
+ """Enable the guestfs handler"""
+
+ if self.guestfs_enabled:
+ self.out.warn("Guestfs is already enabled")
+ return
+
+ # Before version 1.18.4 the behaviour of kill_subprocess was different
+ # and you need to reset the guestfs handler to relaunch a previously
+ # shut down qemu backend
+ if check_guestfs_version(self.g, 1, 18, 4) < 0:
+ self.g = guestfs.GuestFS()
+