[virt-tools-list] [PATCH v3 1/2] virtinst: read CPU model from domain capabilities

Charles Arnold carnold at suse.com
Wed Mar 28 19:45:29 UTC 2018


Add functionality to acquire the CPU model from the
libvirt domain capabilities. This is used to compare
with the host CPU model.

---
 virtinst/domcapabilities.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/virtinst/domcapabilities.py b/virtinst/domcapabilities.py
index f98c807..9b02c94 100644
--- a/virtinst/domcapabilities.py
+++ b/virtinst/domcapabilities.py
@@ -29,9 +29,27 @@ class _Enum(_HasValues):
     name = XMLProperty("./@name")
 
 
+class _Model(XMLBuilder):
+    XML_NAME = "model"
+    model = XMLProperty(".")
+
+
+class _HasModels(XMLBuilder):
+    models = XMLChildProperty(_Model)
+
+    def get_models(self):
+        return [m.model for m in self.models]
+
+
+class _CPUMode(_HasModels):
+    XML_NAME = "mode"
+    name = XMLProperty("./@name")
+
+
 class _CapsBlock(_HasValues):
     supported = XMLProperty("./@supported", is_yesno=True)
     enums = XMLChildProperty(_Enum)
+    modes = XMLChildProperty(_CPUMode)
 
     def enum_names(self):
         return [e.name for e in self.enums]
@@ -40,6 +58,12 @@ class _CapsBlock(_HasValues):
         d = dict((e.name, e) for e in self.enums)
         return d[name]
 
+    def mode_names(self):
+        return [m.name for m in self.modes]
+
+    def get_mode(self, name):
+        d = dict((m.name, m) for m in self.modes)
+        return d[name]
 
 def _make_capsblock(xml_root_name):
     class TmpClass(_CapsBlock):
@@ -53,6 +77,11 @@ class _OS(_CapsBlock):
     loader = XMLChildProperty(_make_capsblock("loader"), is_single=True)
 
 
+class _CPU(_CapsBlock):
+    XML_NAME = "cpu"
+    mode = XMLChildProperty(_make_capsblock("mode"), is_single=True)
+
+
 class _Devices(_CapsBlock):
     XML_NAME = "devices"
     hostdev = XMLChildProperty(_make_capsblock("hostdev"), is_single=True)
@@ -151,6 +180,7 @@ class DomainCapabilities(XMLBuilder):
 
     XML_NAME = "domainCapabilities"
     os = XMLChildProperty(_OS, is_single=True)
+    cpu = XMLChildProperty(_CPU, is_single=True)
     devices = XMLChildProperty(_Devices, is_single=True)
 
     arch = XMLProperty("./arch")
-- 
1.8.5.6




More information about the virt-tools-list mailing list