[libvirt-users] Proper XML for compareCPU method
Jiri Denemark
jdenemar at redhat.com
Wed Aug 10 07:57:44 UTC 2016
On Sun, Aug 07, 2016 at 14:43:27 -0500, David Ashley wrote:
> All -
>
> What is the proper XML to supply to the Python Connections compareCPU
> method?
The same XML which can be used in domain XML to describe guest CPU
configuration, i.e., http://libvirt.org/formatdomain.html#elementsCPU
> I have looked at the cpu_map.xml file and I believe I have the
cpu_map.xml is an internal data file and its structure is completely
irrelevant.
> proper XML configured but the method always throws an exception with a
> missing CPU architecture error. Here is the code.
>
> from __future__ import print_function
> import sys
> import libvirt
>
> conn = libvirt.open('qemu:///system')
> if conn == None:
> print('Failed to open connection to qemu:///system', file=sys.stderr)
> exit(1)
>
> retc = conn.compareCPU('<cpu><arch name="x86"><model
> name="kvm64"/></arch></cpu>')
<cpu mode='custom' match='exact'>
<model fallback='forbid'>kvm64</model>
</cpu>
> if retc == -1:
> print("CPUs are not the same.")
> else:
> print("CPUs are the same.")
This won't work either. The documentation of this APIs clearly says the
function returns one of VIR_CPU_COMPARE_* values, where -1 is used for
errors and the result of the comparison (if there was no error) is
either 0, 1, or 2. So even if the result is != -1, the CPUs may still be
incompatible. In other words the return values are
-1 error
0 incompatible CPUs
1 identical CPUs
2 host CPU is better than the CPU described by XML
However, if you want to treat incompatible CPUs as a failure, you can
use VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE flag and than your check
for retc == -1 will work.
Jirka
More information about the libvirt-users
mailing list