[virt-tools-list] [PATCH v3 1/2] virtinst: read CPU model from domain capabilities
Cole Robinson
crobinso at redhat.com
Tue Apr 3 15:09:14 UTC 2018
On 03/28/2018 03:45 PM, Charles Arnold wrote:
> 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")
> +
> +
CPU doesn't need to follow the HasValues weirdness which is there to
facilitate the '<enum> lists of <values>' pattern used multiple times in
domainCapabilities.
I amended your patch to rework this a bit and add test coverage, and pushed
Thanks,
Cole
> 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")
>
More information about the virt-tools-list
mailing list