~ubuntu-branches/ubuntu/raring/virtinst/raring-proposed

« back to all changes in this revision

Viewing changes to virtinst/CapabilitiesParser.py

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Léonard
  • Date: 2010-03-25 18:13:28 UTC
  • mfrom: (1.2.7 upstream)
  • mto: (1.6.1 sid)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20100325181328-ah0izdq4cdza60xd
Tags: 0.500.3-1
* [6e8ccf1] Imported Upstream version 0.500.3
* [140e8ed] Drop patches.
* [801ac3f] Switch to new source format 3.0 (quilt).

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
    def parseXML(self, node):
53
53
        d = self.features
54
 
        for n in node.xpathEval("*"):
55
 
            feature = n.name
 
54
 
 
55
        feature_list = []
 
56
        if node.name == "features":
 
57
            node_list = node.xpathEval("*")
 
58
            for n in node_list:
 
59
                feature_list.append(n.name)
 
60
        else:
 
61
            # New style features
 
62
            node_list = node.xpathEval("feature/@name")
 
63
            for n in node_list:
 
64
                feature_list.append(n.content)
 
65
 
 
66
        for feature in feature_list:
56
67
            if not d.has_key(feature):
57
68
                d[feature] = 0
58
69
 
72
83
        toggle = xpathString(n, "@toggle")
73
84
 
74
85
        if default is not None:
 
86
            # Format for guest features
75
87
            if default == "on":
76
88
                d[feature] = FEATURE_ON
77
89
            elif default == "off":
81
93
            if toggle == "yes":
82
94
                d[feature] |= d[feature] ^ (FEATURE_ON|FEATURE_OFF)
83
95
        else:
 
96
            # Format for old HOST features, on OLD old guest features
 
97
            # back compat is just <$featurename>, like <svm/>
84
98
            if feature == "nonpae":
85
99
                d["pae"] |= FEATURE_OFF
86
100
            else:
87
101
                d[feature] |= FEATURE_ON
88
102
 
 
103
class CPU(object):
 
104
    def __init__(self, node=None):
 
105
        # e.g. "i686" or "x86_64"
 
106
        self.arch = None
 
107
        self.model = None
 
108
        self.sockets = 1
 
109
        self.cores = 1
 
110
        self.threads = 1
 
111
        self.features = CapabilityFeatures()
 
112
 
 
113
        if not node is None:
 
114
            self.parseXML(node)
 
115
 
 
116
    def parseXML(self, node):
 
117
        newstyle_features = False
 
118
 
 
119
        child = node.children
 
120
        while child:
 
121
            # Do a first pass to try and detect new style features
 
122
            if child.name == "feature":
 
123
                newstyle_features = True
 
124
                break
 
125
            child = child.next
 
126
 
 
127
        if newstyle_features:
 
128
            self.features = CapabilityFeatures(node)
 
129
 
 
130
        child = node.children
 
131
        while child:
 
132
            if child.name == "arch":
 
133
                self.arch = child.content
 
134
            elif child.name == "model":
 
135
                self.model = child.content
 
136
            elif child.name == "topology":
 
137
                self.sockets = xpathString(child, "@sockets") or 1
 
138
                self.cores = xpathString(child, "@cores") or 1
 
139
                self.threads = xpathString(child, "@threads") or 1
 
140
 
 
141
            elif child.name == "features" and not newstyle_features:
 
142
                self.features = CapabilityFeatures(child)
 
143
 
 
144
            child = child.next
 
145
 
89
146
class Host(object):
90
147
    def __init__(self, node = None):
91
 
        # e.g. "i686" or "x86_64"
92
 
        self.arch = None
93
 
 
94
 
        self.features = CapabilityFeatures()
 
148
        self.cpu = CPU()
95
149
        self.topology = None
96
150
        self.secmodel = None
97
151
 
98
152
        if not node is None:
99
153
            self.parseXML(node)
100
154
 
 
155
    # Back compat for CPU class
 
156
    def get_arch(self):
 
157
        return self.cpu.arch
 
158
    def set_arch(self, val):
 
159
        self.cpu.arch = val
 
160
    arch = property(get_arch, set_arch)
 
161
 
 
162
    def get_features(self):
 
163
        return self.cpu.features
 
164
    def set_features(self, val):
 
165
        self.cpu.features = val
 
166
    features = property(get_features, set_features)
 
167
 
101
168
    def parseXML(self, node):
102
169
        child = node.children
103
170
        while child:
107
174
            if child.name == "secmodel":
108
175
                self.secmodel = SecurityModel(child)
109
176
 
110
 
            if child.name != "cpu":
111
 
                child = child.next
112
 
                continue
113
 
 
114
 
            n = child.children
115
 
            while n:
116
 
                if n.name == "arch":
117
 
                    self.arch = n.content
118
 
                elif n.name == "features":
119
 
                    self.features = CapabilityFeatures(n)
120
 
                n = n.next
 
177
            if child.name == "cpu":
 
178
                self.cpu = CPU(child)
121
179
 
122
180
            child = child.next
123
181
 
283
341
 
284
342
        self._fixBrokenEmulator()
285
343
 
 
344
    def _is_xen(self):
 
345
        for g in self.guests:
 
346
            if g.os_type != "xen":
 
347
                continue
 
348
 
 
349
            for d in g.domains:
 
350
                if d.hypervisor_type == "xen":
 
351
                    return True
 
352
 
 
353
        return False
 
354
 
 
355
    def no_install_options(self):
 
356
        """
 
357
        Return True if there are no install options available
 
358
        """
 
359
        for g in self.guests:
 
360
            if len(g.domains) > 0:
 
361
                return False
 
362
 
 
363
        return True
 
364
 
 
365
    def hw_virt_supported(self):
 
366
        """
 
367
        Return True if the machine supports hardware virtualization.
 
368
 
 
369
        For some cases (like qemu caps pre libvirt 0.7.4) this info isn't
 
370
        sufficiently provided, so we will return True in cases that we
 
371
        aren't sure.
 
372
        """
 
373
        # Obvious case of feature being specified
 
374
        if (self.host.features["vmx"] == FEATURE_ON or
 
375
            self.host.features["svm"] == FEATURE_ON):
 
376
            return True
 
377
 
 
378
        # If there is other features, but no virt bit, then HW virt
 
379
        # isn't supported
 
380
        if len(self.host.features.names()):
 
381
            return False
 
382
 
 
383
        # Xen caps have always shown this info, so if we didn't find any
 
384
        # features, the host really doesn't have the necc support
 
385
        if self._is_xen():
 
386
            return False
 
387
 
 
388
        # Otherwise, we can't be sure, because there was a period for along
 
389
        # time that qemu caps gave no indication one way or the other.
 
390
        return True
 
391
 
 
392
    def is_kvm_available(self):
 
393
        """
 
394
        Return True if kvm guests can be installed
 
395
        """
 
396
        for g in self.guests:
 
397
            if g.os_type != "hvm":
 
398
                continue
 
399
 
 
400
            for d in g.domains:
 
401
                if d.hypervisor_type == "kvm":
 
402
                    return True
 
403
 
 
404
        return False
 
405
 
 
406
    def is_xenner_available(self):
 
407
        """
 
408
        Return True if xenner install option is available
 
409
        """
 
410
        for g in self.guests:
 
411
            if g.os_type != "xen":
 
412
                continue
 
413
 
 
414
            for d in g.domains:
 
415
                if d.hypervisor_type == "kvm":
 
416
                    return True
 
417
 
 
418
        return False
 
419
 
 
420
    def is_bios_virt_disabled(self):
 
421
        """
 
422
        Try to determine if fullvirt may be disabled in the bios.
 
423
 
 
424
        Check is basically:
 
425
        - We support HW virt
 
426
        - We appear to be xen
 
427
        - There are no HVM install options
 
428
 
 
429
        We don't do this check for KVM, since no KVM options may mean
 
430
        KVM isn't installed or the module isn't loaded (and loading the
 
431
        module will give an appropriate error
 
432
        """
 
433
        if not self.hw_virt_supported():
 
434
            return False
 
435
 
 
436
        if not self._is_xen():
 
437
            return False
 
438
 
 
439
        for g in self.guests:
 
440
            if g.os_type == "hvm":
 
441
                return False
 
442
 
 
443
        return True
 
444
 
286
445
    def guestForOSType(self, type = None, arch = None):
287
446
        if self.host is None:
288
447
            return None