Revision 5756c277 image_creator/image.py

b/image_creator/image.py
33 33
# interpreted as representing official policies, either expressed
34 34
# or implied, of GRNET S.A.
35 35

  
36
from image_creator.util import FatalError, check_guestfs_version
36
from image_creator.util import FatalError
37 37
from image_creator.gpt import GPTPartitionTable
38 38
from image_creator.os_type import os_cls
39 39

  
......
61 61

  
62 62
        self.g = guestfs.GuestFS()
63 63
        self.guestfs_enabled = False
64
        self.guestfs_version = self.g.version()
65

  
66
    def check_guestfs_version(self, major, minor, release):
67
        """Checks if the version of the used libguestfs is smaller, equal or
68
        greater than the one specified by the major, minor and release triplet
69

  
70
        Returns:
71
            < 0 if the installed version is smaller than the specified one
72
            = 0 if they are equal
73
            > 0 if the installed one is greater than the specified one
74
        """
75

  
76
        for (a, b) in (self.guestfs_version['major'], major), \
77
                (self.guestfs_version['minor'], minor), \
78
                (self.guestfs_version['release'], release):
79
            if a != b:
80
                return a - b
81

  
82
        return 0
64 83

  
65 84
    def enable(self):
66 85
        """Enable a newly created Image instance"""
......
96 115
        # Before version 1.18.4 the behaviour of kill_subprocess was different
97 116
        # and you need to reset the guestfs handler to relaunch a previously
98 117
        # shut down qemu backend
99
        if check_guestfs_version(self.g, 1, 18, 4) < 0:
118
        if self.check_guestfs_version(1, 18, 4) < 0:
100 119
            self.g = guestfs.GuestFS()
101 120

  
102 121
        self.g.add_drive_opts(self.device, readonly=0, format="raw")
......
106 125
        # file descriptors. This can cause problems especially if the parent
107 126
        # process has opened pipes. Since the recovery process is an optional
108 127
        # feature of libguestfs, it's better to disable it.
109
        if check_guestfs_version(self.g, 1, 17, 14) >= 0:
128
        if self.check_guestfs_version(1, 17, 14) >= 0:
110 129
            self.out.output("Enabling recovery proc")
111 130
            self.g.set_recovery_proc(1)
112 131
        else:
......
126 145
        # self.progressbar.success('done')
127 146
        # self.progressbar = None
128 147

  
129
        if check_guestfs_version(self.g, 1, 18, 4) < 0:
148
        if self.check_guestfs_version(1, 18, 4) < 0:
130 149
            self.g.inspect_os()  # some calls need this
131 150

  
132 151
        self.out.success('done')
......
142 161
        self.g.sync()
143 162
        # guestfs_shutdown which is the prefered way to shutdown the backend
144 163
        # process was introduced in version 1.19.16
145
        if check_guestfs_version(self.g, 1, 19, 16) >= 0:
164
        if self.check_guestfs_version(1, 19, 16) >= 0:
146 165
            self.g.shutdown()
147 166
        else:
148 167
            self.g.kill_subprocess()

Also available in: Unified diff