Subject: virtinst: read CPU model from domain capabilities From: Charles Arnold carnold@suse.com Wed Mar 28 13:45:29 2018 -0600 Date: Tue Apr 3 10:57:15 2018 -0400: Git: d15b78ab0d7b9e73261a19fafc841a4ee206d413 Add functionality to acquire the CPU model from the libvirt domain capabilities. This is used to compare with the host CPU model. (crobinso: add test coverage, rework domcaps layout a bit) Index: virt-manager-1.5.0/tests/capabilities-xml/kvm-x86_64-domcaps.xml =================================================================== --- virt-manager-1.5.0.orig/tests/capabilities-xml/kvm-x86_64-domcaps.xml +++ virt-manager-1.5.0/tests/capabilities-xml/kvm-x86_64-domcaps.xml @@ -18,6 +18,68 @@ + + + + Broadwell + Intel + + + + + + + + + + + + + + qemu64 + qemu32 + phenom + pentium3 + pentium2 + pentium + n270 + kvm64 + kvm32 + coreduo + core2duo + athlon + Westmere + Westmere-IBRS + Skylake-Server + Skylake-Server-IBRS + Skylake-Client + Skylake-Client-IBRS + SandyBridge + SandyBridge-IBRS + Penryn + Opteron_G5 + Opteron_G4 + Opteron_G3 + Opteron_G2 + Opteron_G1 + Nehalem + Nehalem-IBRS + IvyBridge + IvyBridge-IBRS + Haswell + Haswell-noTSX + Haswell-noTSX-IBRS + Haswell-IBRS + EPYC + EPYC-IBPB + Conroe + Broadwell + Broadwell-noTSX + Broadwell-noTSX-IBRS + Broadwell-IBRS + 486 + + @@ -32,8 +94,25 @@ scsi virtio usb + sata + + + sdl + vnc + spice + + + subsystem @@ -50,11 +129,10 @@ scsi - - default - kvm - vfio - + + + + Index: virt-manager-1.5.0/tests/capabilities.py =================================================================== --- virt-manager-1.5.0.orig/tests/capabilities.py +++ virt-manager-1.5.0/tests/capabilities.py @@ -131,6 +131,16 @@ class TestCapabilities(unittest.TestCase self.assertEqual(caps.os.loader.get_enum("type").get_values(), ["rom", "pflash"]) + def testDomainCapabilitiesx86(self): + xml = open("tests/capabilities-xml/kvm-x86_64-domcaps.xml").read() + caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml) + + custom_mode = caps.cpu.get_mode("custom") + self.assertTrue(bool(custom_mode)) + cpu_model = custom_mode.get_model("Opteron_G4") + self.assertTrue(bool(cpu_model)) + self.assertTrue(cpu_model.usable) + if __name__ == "__main__": unittest.main() Index: virt-manager-1.5.0/virtinst/domcapabilities.py =================================================================== --- virt-manager-1.5.0.orig/virtinst/domcapabilities.py +++ virt-manager-1.5.0/virtinst/domcapabilities.py @@ -76,6 +76,33 @@ class _Features(_CapsBlock): gic = XMLChildProperty(_make_capsblock("gic"), is_single=True) + +class _CPUModel(XMLBuilder): + _XML_ROOT_NAME = "model" + model = XMLProperty(".") + usable = XMLProperty("./@usable", is_yesno=True) + + +class _CPUMode(XMLBuilder): + _XML_ROOT_NAME = "mode" + name = XMLProperty("./@name") + models = XMLChildProperty(_CPUModel) + + def get_model(self, name): + for model in self.models: + if model.model == name: + return model + +class _CPU(XMLBuilder): + _XML_ROOT_NAME = "cpu" + modes = XMLChildProperty(_CPUMode) + + def get_mode(self, name): + for mode in self.modes: + if mode.name == name: + return mode + + class DomainCapabilities(XMLBuilder): @staticmethod def build_from_params(conn, emulator, arch, machine, hvtype): @@ -163,6 +190,7 @@ class DomainCapabilities(XMLBuilder): _XML_ROOT_NAME = "domainCapabilities" os = XMLChildProperty(_OS, is_single=True) + cpu = XMLChildProperty(_CPU, is_single=True) devices = XMLChildProperty(_Devices, is_single=True) arch = XMLProperty("./arch")