Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 73733a9

Browse files
committed
CapabilitiesParser: Break out CPU into its own class
1 parent 7d53350 commit 73733a9

3 files changed

Lines changed: 64 additions & 27 deletions

File tree

tests/capabilities-xml/libvirt-0.7.6-qemu-caps.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<cpu>
55
<arch>x86_64</arch>
66
<model>core2duo</model>
7-
<topology sockets='1' cores='2' threads='1'/>
7+
<topology sockets='7' cores='5' threads='3'/>
88
<feature name='lahf_lm'/>
99
<feature name='xtpr'/>
1010
<feature name='cx16'/>

tests/capabilities.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ def testCapsCPUFeaturesNewSyntax(self):
157157
for f in feature_dict.keys():
158158
self.assertEquals(caps.host.features[f], feature_dict[f])
159159

160+
self.assertEquals(caps.host.cpu.model, "core2duo")
161+
self.assertEquals(caps.host.cpu.threads, "3")
162+
self.assertEquals(caps.host.cpu.cores, "5")
163+
self.assertEquals(caps.host.cpu.sockets, "7")
164+
160165
def testCapsUtilFuncs(self):
161166
new_caps = self._buildCaps("libvirt-0.7.6-qemu-caps.xml")
162167
new_caps_no_kvm = self._buildCaps(

virtinst/CapabilitiesParser.py

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,50 +100,82 @@ def _extractFeature(self, feature, d, n):
100100
else:
101101
d[feature] |= FEATURE_ON
102102

103-
class Host(object):
104-
def __init__(self, node = None):
103+
class CPU(object):
104+
def __init__(self, node=None):
105105
# e.g. "i686" or "x86_64"
106106
self.arch = None
107-
107+
self.model = None
108+
self.sockets = 1
109+
self.cores = 1
110+
self.threads = 1
108111
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+
146+
class Host(object):
147+
def __init__(self, node = None):
148+
self.cpu = CPU()
109149
self.topology = None
110150
self.secmodel = None
111151

112152
if not node is None:
113153
self.parseXML(node)
114154

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+
115168
def parseXML(self, node):
116169
child = node.children
117-
newstyle_features = False
118170
while child:
119171
if child.name == "topology":
120172
self.topology = Topology(child)
121173

122174
if child.name == "secmodel":
123175
self.secmodel = SecurityModel(child)
124176

125-
if child.name != "cpu":
126-
child = child.next
127-
continue
128-
129-
# Do a first pass to try and detect new style features
130-
n = child.children
131-
while n:
132-
if n.name == "feature":
133-
newstyle_features = True
134-
break
135-
n = n.next
136-
137-
if newstyle_features:
138-
self.features = CapabilityFeatures(child)
139-
140-
n = child.children
141-
while n:
142-
if n.name == "arch":
143-
self.arch = n.content
144-
elif n.name == "features" and not newstyle_features:
145-
self.features = CapabilityFeatures(n)
146-
n = n.next
177+
if child.name == "cpu":
178+
self.cpu = CPU(child)
147179

148180
child = child.next
149181

0 commit comments

Comments
 (0)