# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
-from image_creator.util import FatalError, check_guestfs_version
+from image_creator.util import FatalError
from image_creator.gpt import GPTPartitionTable
from image_creator.os_type import os_cls
self.g = guestfs.GuestFS()
self.guestfs_enabled = False
+ self.guestfs_version = self.g.version()
+
+ def check_guestfs_version(self, 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
+ """
+
+ for (a, b) in (self.guestfs_version['major'], major), \
+ (self.guestfs_version['minor'], minor), \
+ (self.guestfs_version['release'], release):
+ if a != b:
+ return a - b
+
+ return 0
def enable(self):
"""Enable a newly created Image instance"""
# 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:
+ if self.check_guestfs_version(1, 18, 4) < 0:
self.g = guestfs.GuestFS()
self.g.add_drive_opts(self.device, readonly=0, format="raw")
# 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.
- if check_guestfs_version(self.g, 1, 17, 14) >= 0:
+ if self.check_guestfs_version(1, 17, 14) >= 0:
self.out.output("Enabling recovery proc")
self.g.set_recovery_proc(1)
else:
# self.progressbar.success('done')
# self.progressbar = None
- if check_guestfs_version(self.g, 1, 18, 4) < 0:
+ if self.check_guestfs_version(1, 18, 4) < 0:
self.g.inspect_os() # some calls need this
self.out.success('done')
self.g.sync()
# guestfs_shutdown which is the prefered way to shutdown the backend
# process was introduced in version 1.19.16
- if check_guestfs_version(self.g, 1, 19, 16) >= 0:
+ if self.check_guestfs_version(1, 19, 16) >= 0:
self.g.shutdown()
else:
self.g.kill_subprocess()
Windows OSs."""
from image_creator.os_type import OSBase, sysprep, add_sysprep_param
-from image_creator.util import FatalError, check_guestfs_version, \
- get_kvm_binary
+from image_creator.util import FatalError, get_kvm_binary
from image_creator.winexe import WinEXE, WinexeTimeout
import hivex
def __init__(self, image, **kargs):
super(Windows, self).__init__(image, **kargs)
- # This commit was added in libguestfs 1.17.18 and is critical because
- # Microsoft Sysprep removes this key:
+ # The commit with the following message was added in
+ # libguestfs 1.17.18:
#
# When a Windows guest doesn't have a HKLM\SYSTEM\MountedDevices node,
# inspection fails. However inspection should not completely fail just
# because we cannot get the drive letter mapping from a guest.
- if check_guestfs_version(self.image.g, 1, 17, 18) < 0:
+ #
+ # Since Microsoft Sysprep removes the aforementioned key, image
+ # creation for windows can only be supported if the installed guestfs
+ # version is 1.17.18 or higher
+ if self.image.check_guestfs_version(1, 17, 18) < 0:
raise FatalError(
- 'For windows support libguestfs 1.17.18 or above is needed')
+ 'For windows support libguestfs 1.17.18 or above is required')
device = self.image.g.part_to_dev(self.root)
return stat.f_bavail * stat.f_frsize
-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
-
-
class MD5:
"""Represents MD5 computations"""
def __init__(self, output):