'Check the host is compatible with the requested CPU
:param guest_cpu: nova.objects.VirtCPUModel or None
:param host_cpu_str: JSON from _get_cpu_info() method
If the \'guest_cpu\' parameter is not None, this will be
validated for migration compatibility with the host.
Otherwise the \'host_cpu_str\' JSON string will be used for
validation.
:returns:
None. if given cpu info is not compatible to this server,
raise exception.'

def _compare_cpu(self, guest_cpu, host_cpu_str, instance):

    if (CONF.libvirt.virt_type not in ['kvm']):
        return
    if (guest_cpu is None):
        info = jsonutils.loads(host_cpu_str)
        LOG.info('Instance    launched    has    CPU    info:    %s', host_cpu_str)
        cpu = vconfig.LibvirtConfigCPU()
        cpu.arch = info['arch']
        cpu.model = info['model']
        cpu.vendor = info['vendor']
        cpu.sockets = info['topology']['sockets']
        cpu.cores = info['topology']['cores']
        cpu.threads = info['topology']['threads']
        for f in info['features']:
            cpu.add_feature(vconfig.LibvirtConfigCPUFeature(f))
    else:
        cpu = self._vcpu_model_to_cpu_config(guest_cpu)
    u = 'http://libvirt.org/html/libvirt-libvirt-host.html#virCPUCompareResult'
    m = _("CPU    doesn't    have    compatibility.\n\n%(ret)s\n\nRefer    to    %(u)s")
    try:
        cpu_xml = cpu.to_xml()
        LOG.debug('cpu    compare    xml:    %s', cpu_xml, instance=instance)
        ret = self._host.compare_cpu(cpu_xml)
    except libvirt.libvirtError as e:
        error_code = e.get_error_code()
        if (error_code == libvirt.VIR_ERR_NO_SUPPORT):
            LOG.debug('URI    %(uri)s    does    not    support    cpu    comparison.    It    will    be    proceeded    though.    Error:    %(error)s', {'uri': self._uri(), 'error': e})
            return
        else:
            LOG.error(m, {'ret': e, 'u': u})
            raise exception.MigrationPreCheckError(reason=(m % {'ret': e, 'u': u}))
    if (ret <= 0):
        LOG.error(m, {'ret': ret, 'u': u})
        raise exception.InvalidCPUInfo(reason=(m % {'ret': ret, 'u': u}))
