# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
-from image_creator.util import FatalError
+from image_creator.util import FatalError, check_guestfs_version
from image_creator.gpt import GPTPartitionTable
from image_creator.os_type import os_cls
# file descriptors. This can cause problems especially if the parent
# process has opened pipes. Since the recovery process is an optional
# feature of libguestfs, it's better to disable it.
- self.g.set_recovery_proc(0)
- version = self.g.version()
- if version['major'] > 1 or \
- (version['major'] == 1 and (version['minor'] >= 18 or
- (version['minor'] == 17 and
- version['release'] >= 14))):
- self.g.set_recovery_proc(1)
+ if check_guestfs_version(self.g, 1, 17, 14) >= 0:
self.out.output("Enabling recovery proc")
+ self.g.set_recovery_proc(1)
+ else:
+ self.g.set_recovery_proc(0)
#self.g.set_trace(1)
#self.g.set_verbose(1)
return checksum
+ def check_guestfs_version(ghandler, major, minor, release):
+ """Checks if the version of the used libguestfs is smaller, equal or
+ greater than the one specified by the major, minor and release triplet
+
+ Returns:
+ < 0 if the installed version is smaller than the specified one
+ = 0 if they are equal
+ > 0 if the installed one is greater than the specified one
+ """
+
+ ver = ghandler.version()
+
+ for (a, b) in (ver['major'], major), (ver['minor'], minor), \
+ (ver['release'], release):
+ if a != b:
+ return a - b
+
+ return 0
+
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :